ZeroLauncher/Manager/UpDateManager.cs

68 lines
2.2 KiB
C#
Raw Normal View History

2024-03-09 18:29:16 +08:00
using System.Diagnostics;
using System.IO;
2024-03-11 10:57:12 +08:00
using System.IO.Compression;
2024-03-09 18:29:16 +08:00
using System.Security.Cryptography;
2024-03-07 21:04:59 +08:00
using Zerolauncher.Defender;
namespace Zerolauncher.Manager
{
2024-03-09 18:29:16 +08:00
class DownloadTask
{
public static bool state = false;
public static string url = "";
}
2024-03-07 21:04:59 +08:00
class UpDateManager
{
2024-03-11 10:57:12 +08:00
const string cache_file = "cache.zip";
static bool isCheeking = false;
2024-03-07 21:04:59 +08:00
2024-03-09 18:29:16 +08:00
public static void DoCheckUpdate(bool checkMain=true, bool needEngine = false)
2024-03-07 21:04:59 +08:00
{
2024-03-09 18:29:16 +08:00
if (isCheeking) return;
isCheeking=true;
bool needMian= false;
if(checkMain)
2024-03-07 21:04:59 +08:00
{
2024-03-09 18:29:16 +08:00
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;
2024-03-07 21:04:59 +08:00
}
2024-03-09 18:29:16 +08:00
if(!needEngine)
2024-03-07 21:04:59 +08:00
{
2024-03-09 18:29:16 +08:00
string? now_bit;
using (SHA256 sha256 = SHA256.Create())
2024-03-07 21:04:59 +08:00
{
2024-03-09 18:29:16 +08:00
using (FileStream fileStream = File.OpenRead(@"ZeroEngine.exe"))
{
byte[] hashBytes = sha256.ComputeHash(fileStream);
now_bit = BitConverter.ToString(hashBytes).Replace("-", string.Empty);
}
2024-03-07 21:04:59 +08:00
}
2024-03-09 18:29:16 +08:00
needEngine = now_bit == CacheSha.GetE() && now_bit != null;
2024-03-07 21:04:59 +08:00
}
2024-03-09 18:29:16 +08:00
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;
2024-03-07 21:04:59 +08:00
}
2024-03-11 10:57:12 +08:00
public static void OnDownLoadDone()
2024-03-07 21:04:59 +08:00
{
2024-03-11 10:57:12 +08:00
ZipFile.ExtractToDirectory(cache_file, ".");
Process.Start("./upacket.bin");
2024-03-07 21:04:59 +08:00
}
}
}