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-18 22:59:51 +08:00
|
|
|
|
using System.Windows;
|
2024-03-07 21:04:59 +08:00
|
|
|
|
using Zerolauncher.Defender;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Zerolauncher.Manager
|
|
|
|
|
|
{
|
2024-03-09 18:29:16 +08:00
|
|
|
|
|
2024-03-07 21:04:59 +08:00
|
|
|
|
class UpDateManager
|
|
|
|
|
|
{
|
2024-03-18 22:59:51 +08:00
|
|
|
|
public static bool state = false;
|
2024-03-11 10:57:12 +08:00
|
|
|
|
static bool isCheeking = false;
|
2024-03-18 22:59:51 +08:00
|
|
|
|
static SingleGame? updateProcess;
|
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-18 22:59:51 +08:00
|
|
|
|
state = !(needEngine && needMian);
|
2024-03-09 18:29:16 +08:00
|
|
|
|
isCheeking = false;
|
2024-03-07 21:04:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-18 22:59:51 +08:00
|
|
|
|
public static void DoUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CacheSha.errorCode != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (CacheSha.errorCode)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
MessageBox.Show("检查更新出错。\n 请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
MessageBox.Show("软件已停止服务或服务错误。\n 请联系管理员", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
MessageBox.Show("检查更新出错。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
MessageBoxResult result = MessageBox.Show($"大厅组件需要更新\n是否更新?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
|
|
|
|
|
|
if (result == MessageBoxResult.OK)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
updateProcess = new SingleGame(null, StaticHandleA.UpdateMode);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception _ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("执行自动更新失败!,\n请手动访问链接重新下载大厅文件或联系管理员。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void DoUpdate1()
|
2024-03-07 21:04:59 +08:00
|
|
|
|
{
|
2024-03-19 12:09:31 +08:00
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
updateProcess.Send($"{StaticHandleS.ShowWindow} 自助更新");
|
|
|
|
|
|
await Task.Delay(1000);
|
|
|
|
|
|
updateProcess.Send($"{StaticHandleS.UpdateInfo} {UpDateData.tis}");
|
|
|
|
|
|
updateProcess.Send($"{StaticHandleS.UseBrowser} {UpDateData.lanzou + UpDateData.auto_packet_url}");
|
|
|
|
|
|
});
|
2024-03-18 22:59:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void OnDownLoadDone(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
updateProcess.Send(StaticHandleS.CloseGame);
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-03-19 12:09:31 +08:00
|
|
|
|
if (Directory.Exists("./cache/")) Directory.Delete("./cache/", true);
|
2024-03-18 22:59:51 +08:00
|
|
|
|
ZipFile.ExtractToDirectory(path, "./cache/");
|
|
|
|
|
|
File.Delete(path);
|
|
|
|
|
|
}catch(Exception e)
|
|
|
|
|
|
{
|
2024-03-19 12:09:31 +08:00
|
|
|
|
MessageBox.Show($"尝试更新文件时发生错误\n{e.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
2024-03-18 22:59:51 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
App.needUpdate = true;
|
2024-03-19 12:09:31 +08:00
|
|
|
|
Application.Current.Dispatcher.Invoke(() => Application.Current.Shutdown());
|
2024-03-07 21:04:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|