[C#/COMMON/ADVANCED INSTALLER] updates.txt 파일 정보 구하기
■ updates.txt 파일 정보를 구하는 방법을 보여준다. ▶ Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace TestProject { /// <summary> /// 프로그램 /// </summary> class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region SHA256 해시 문자열 구하기 - GetSHA256HashString(filePath) /// <summary> /// SHA256 해시 문자열 구하기 /// </summary> /// <param name="filePath">파일 경로</param> /// <returns>SHA256 해시 문자열</returns> private static string GetSHA256HashString(string filePath) { SHA256 sha256 = new SHA256Managed(); StringBuilder stringBuilder = new StringBuilder(); using(FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { byte[] hashByteArray = sha256.ComputeHash(fileStream); foreach(byte hashByte in hashByteArray) { stringBuilder.Append(hashByte.ToString("X2")); } } return stringBuilder.ToString(); } #endregion #region MD5 해시 문자열 구하기 - GetMD5HashString(filePath) /// <summary> /// MD5 해시 문자열 구하기 /// </summary> /// <param name="filePath">파일 경로</param> /// <returns>MD5 해시 문자열</returns> private static string GetMD5HashString(string filePath) { MD5 md5 = MD5.Create(); StringBuilder stringBuilder = new StringBuilder(); using(FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { byte[] hashByteArray = md5.ComputeHash(fileStream); foreach(byte hashByte in hashByteArray) { stringBuilder.Append(hashByte.ToString("x2")); } } return stringBuilder.ToString(); } #endregion #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> private static void Main() { string filePath = "d:\\TestProject.exe"; string deploymentVersion = "V1.0.0"; string name = "TestProject"; string programName = "TestProject.exe"; string productVersion = "1.0.0.0"; string serverIPAddress = "127.0.0.1"; int serverPort = 8000; string url = $"http://{serverIPAddress}:{serverPort}/download/{deploymentVersion}/{programName}"; long size = new FileInfo(filePath).Length; string sha256 = GetSHA256HashString(filePath); string md5 = GetMD5HashString(filePath); string serverFileName = programName; string registryKey = @"HKUD\Software\DSCore\TestProject\Version"; string version = productVersion; string description = deploymentVersion; string meta = $@"[{deploymentVersion}] Name = {name} ProductVersion = {productVersion} URL = {url} Size = {size} SHA256 = {sha256} MD5 = {md5} ServerFileName = {serverFileName} RegistryKey = {registryKey} Version = {version} Description = {description}"; Console.WriteLine(meta); } #endregion } } |
TestProject.zip