using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Security.Cryptography; using Zerolauncher.Defender; namespace Zerolauncher.Manager { class DownloadTask { public static bool state = false; public static string url = ""; } class UpDateManager { const string cache_file = "cache.zip"; static bool isCheeking = false; public static void DoCheckUpdate(bool checkMain=true, bool needEngine = false) { if (isCheeking) return; isCheeking=true; bool needMian= false; if(checkMain) { string filePath = Process.GetCurrentProcess().MainModule.FileName; string? now_bit; using (SHA256 sha256 = SHA256.Create()) { using (FileStream fileStream = File.OpenRead(filePath)) { byte[] hashBytes = sha256.ComputeHash(fileStream); now_bit = BitConverter.ToString(hashBytes).Replace("-", string.Empty); } } needMian = now_bit == CacheSha.GetM() && now_bit != null; } if(!needEngine) { string? now_bit; using (SHA256 sha256 = SHA256.Create()) { using (FileStream fileStream = File.OpenRead(@"ZeroEngine.exe")) { byte[] hashBytes = sha256.ComputeHash(fileStream); now_bit = BitConverter.ToString(hashBytes).Replace("-", string.Empty); } } needEngine = now_bit == CacheSha.GetE() && now_bit != null; } if(needEngine && needMian) { isCheeking = false; return; } DownloadTask.state = true; if(needEngine == needMian) DownloadTask.url = UpDateData.full_packet_url; else DownloadTask.url = UpDateData.mini_packet_url; isCheeking = false; } public static void OnDownLoadDone() { ZipFile.ExtractToDirectory(cache_file, "."); Process.Start("./upacket.bin"); } } }