diff --git a/AboutDialog/About1.xaml b/AboutDialog/About1.xaml index 32095f4..3b53f1b 100644 --- a/AboutDialog/About1.xaml +++ b/AboutDialog/About1.xaml @@ -4,13 +4,38 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" - Title="About" Height="384" Width="700"> + AllowsTransparency="True" WindowStyle="None" Background="Transparent" + Title="About" Height="384" Width="700" MouseLeftButtonDown="Window_MouseLeftButtonDown"> - - - - + + + + + + + + diff --git a/AboutDialog/About1.xaml.cs b/AboutDialog/About1.xaml.cs index c959bd0..579fb34 100644 --- a/AboutDialog/About1.xaml.cs +++ b/AboutDialog/About1.xaml.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.Windows; using System.Windows.Documents; +using System.Windows.Input; namespace Zerolauncher.AboutDialog { @@ -14,6 +15,12 @@ namespace Zerolauncher.AboutDialog InitializeComponent(); } + private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + // 实现窗口的拖动 + DragMove(); + } + private void Hyperlink_Click(object sender, RoutedEventArgs e) { Process.Start(new ProcessStartInfo("http://github.com/1415ddfer/ZeroHelper") { UseShellExecute = true }); @@ -24,5 +31,10 @@ namespace Zerolauncher.AboutDialog MessageBox.Show("已拷贝到粘贴板", "提示"); Clipboard.SetDataObject("ddfgame@foxmail.com", true); } + + private void Button_Click(object sender, RoutedEventArgs e) + { + Close(); + } } } diff --git a/App.xaml.cs b/App.xaml.cs index 3326dfd..88b9a68 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,4 +1,6 @@ -using System.Windows; +using System.Diagnostics; +using System.IO; +using System.Windows; using Zerolauncher.Manager; namespace Zerolauncher @@ -8,16 +10,44 @@ namespace Zerolauncher /// public partial class App : Application { + public static bool needUpdate = false; + + static bool TryDeleteDirectory(string path, bool recursive) + { + try + { + Directory.Delete(path, recursive); + return true; + } + catch (IOException) + { + return false; + } + } + protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); + if (e.Args.Length == 1) + { + switch (e.Args[0]) + { + case "updateDone": + { + for (int i = 0; i < 3 && !TryDeleteDirectory(@"./cache", true); i++) + Thread.Sleep(3000); + } + break; + } + } + Task.Run(async () => { await CloundMananger.TakeQMessage(); UpDateManager.DoCheckUpdate(); - if (DownloadTask.state) + if (UpDateManager.state) { - + UpDateManager.DoUpdate(); } }); DataStream.Load(); @@ -28,6 +58,7 @@ namespace Zerolauncher { base.OnExit(e); WebApiManager.StopListener(); + if (needUpdate) Process.Start("./cache/upacket.bin"); } } diff --git a/MainWindow.xaml b/MainWindow.xaml index ebe2f11..dcb43a1 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -30,7 +30,6 @@ - diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 906b13f..ea470c8 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -122,27 +122,6 @@ namespace Zerolauncher EditTeamDialog.CreateDailog(AccountManager.teamName); } - private void Button_Click(object sender, RoutedEventArgs e) - { - // 创建新的按钮 - Button newButton = new Button(); - newButton.Content = "新按钮"; - - // 将新按钮添加到布局中 - // 假设你的布局是一个名为"myLayout"的StackPanel - mLayout.Children.Add(newButton); - } - - private void Button_Click_1(object sender, RoutedEventArgs e) - { - LoginManager.LoginTest(); - } - - private void Button_Click_2(object sender, RoutedEventArgs e) - { - LoginManager.GameTest(); - } - private void Button_Click_3(object sender, RoutedEventArgs e) { Close(); @@ -153,5 +132,6 @@ namespace Zerolauncher var ab = new About1(); ab.ShowDialog(); } + } } \ No newline at end of file diff --git a/Manager/CloundMananger.cs b/Manager/CloundMananger.cs index 0e0318a..45ac67d 100644 --- a/Manager/CloundMananger.cs +++ b/Manager/CloundMananger.cs @@ -2,6 +2,7 @@ using System.Net; using Zerolauncher.Defender; using Zerolauncher.util; +using System.Diagnostics; namespace Zerolauncher.Manager { @@ -10,7 +11,7 @@ namespace Zerolauncher.Manager public const string QMessageMain = "https://sharechain.qq.com/"; public const string MasterMessage = "54aeb77c47b967d22c2c1396d00d91f0"; public const string SummerMessage = "037846c482eddc948612b0d0f8ed98d5"; - public const string LoveMessage = ""; + public const string LoveMessage = "539e3389078daa765ac0abdcc97eebce"; } class UpDateData @@ -19,8 +20,9 @@ namespace Zerolauncher.Manager public static bool state = false; public static string version = ""; public static string tis = ""; - public static string mini_packet_url = ""; - public static string full_packet_url = ""; + public static string auto_packet_url = ""; + public static string user_packet_url = ""; + public const string lanzou = "https://www.lanzoub.com/"; } class CloundMananger @@ -35,7 +37,7 @@ namespace Zerolauncher.Manager try { client.Timeout = TimeSpan.FromMinutes(3); - response = await client.GetAsync($"{StaticUrl.QMessageMain}{StaticUrl.MasterMessage}"); + response = await client.GetAsync($"{StaticUrl.QMessageMain}{StaticUrl.LoveMessage}"); } catch (Exception _ex) { @@ -54,12 +56,15 @@ namespace Zerolauncher.Manager { message = message.Split("
")[1].Split("")[0].Replace("
", "").Replace("\n", "").Replace("\t", "").Replace("\r", "").Replace("'", ""); var arr = message.Split("
"); - if (arr.Length >= 7 && FormatSha(arr[6], false) && FormatSha(arr[5], true)) + Trace.WriteLine("bababababa" + arr.Length.ToString()); + Trace.WriteLine(message); + if (arr.Length == 7 && FormatSha(arr[6], false) && FormatSha(arr[5], true)) { + Trace.WriteLine("bababababa" + arr.Length.ToString()); UpDateData.version = arr[1]; UpDateData.tis = arr[2]; - UpDateData.mini_packet_url = arr[3]; - UpDateData.full_packet_url = arr[4]; + UpDateData.auto_packet_url = arr[3]; + UpDateData.user_packet_url = arr[4]; UpDateData.state = true; return true; } @@ -68,12 +73,12 @@ namespace Zerolauncher.Manager static bool FormatSha(string sha0, bool e) { - if (sha0.Length < 90) return false; + //if (sha0.Length < 80) return false; int count; var sha = SpaceEncoder.Decode(sha0, out count); if (sha == null || sha.Length < 64) { - //Console.WriteLine($"faile: {count}"); + Trace.WriteLine($"faile: {count}"); return false; } if (e) CacheSha.PutE(sha); diff --git a/Manager/DataStream.cs b/Manager/DataStream.cs index 7b76871..cb10cda 100644 --- a/Manager/DataStream.cs +++ b/Manager/DataStream.cs @@ -20,7 +20,7 @@ namespace Zerolauncher.Manager else { dataStream = JsonConvert.DeserializeObject( - "{\"teamIndex\":0,\"Groups\":[{\"Name\":\"队伍1\", \"Accounts\": [{\"providerId\":0,\"userName\":\"test\",\"userPWD\":\"test\",\"nickName\":\"测试账号\",\"serverId\":\"1\"}]}], \"engine_cache_ver\": 0}"); + "{\"teamIndex\":0,\"Groups\":[{\"Name\":\"队伍1\", \"Accounts\": [{\"providerId\":0,\"userName\":\"test\",\"userPWD\":\"test\",\"nickName\":\"测试账号\",\"serverId\":\"1\"}]}], \"ecs\": \"\"}"); } } @@ -28,7 +28,7 @@ namespace Zerolauncher.Manager public static void write() { string? data = JsonConvert.SerializeObject(dataStream); - Trace.WriteLine(data); + //Trace.WriteLine(data); if (data == null) return; File.WriteAllBytes(path, CompressBytes(Encoding.UTF8.GetBytes(data))); } @@ -85,6 +85,6 @@ namespace Zerolauncher.Manager { public int teamIndex; public List Groups; - public int engine_cache_ver; + public string ecs; } } \ No newline at end of file diff --git a/Manager/EngineManager.cs b/Manager/EngineManager.cs index b021cb2..6846213 100644 --- a/Manager/EngineManager.cs +++ b/Manager/EngineManager.cs @@ -1,4 +1,6 @@ using System.Diagnostics; +using System.IO; +using System.Security.Cryptography; using System.Windows; using Zerolauncher.Defender; @@ -20,7 +22,7 @@ namespace Zerolauncher.Manager showDialog = false; if (UpDateData.is_check == false) { - MessageBox.Show("正在更新数据,请等待1-3秒。\n 请检查网络", "错误", MessageBoxButton.OKCancel, MessageBoxImage.Warning); + MessageBox.Show("正在更新游戏数据,请等待1-3秒。\n 请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Warning); return true; } if (UpDateData.state) @@ -34,13 +36,13 @@ namespace Zerolauncher.Manager switch (CacheSha.errorCode) { case 1: - MessageBox.Show("发生网络错误==EMS。\n 请检查网络", "错误", MessageBoxButton.OKCancel, MessageBoxImage.Error); + MessageBox.Show("发生网络错误==EMS。\n 请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Error); break; case 2: - MessageBox.Show("发生游戏服务错误==EMS。\n 请联系管理员", "错误", MessageBoxButton.OKCancel, MessageBoxImage.Error); + MessageBox.Show("发生游戏服务错误==EMS。\n 请联系管理员", "错误", MessageBoxButton.OK, MessageBoxImage.Error); break; default: - MessageBox.Show("发生未知错误==EMS。\n 请联系管理员", "错误", MessageBoxButton.OKCancel, MessageBoxImage.Error); + MessageBox.Show("发生未知错误==EMS。\n 请联系管理员", "错误", MessageBoxButton.OK, MessageBoxImage.Error); break; } return true; @@ -50,7 +52,7 @@ namespace Zerolauncher.Manager mGame[key] = new SingleGame(account); }catch (Exception _ex) { - MessageBox.Show("发生错误!\n如重复发生此错误,\n请重新下载大厅文件或联系管理员。", "错误", MessageBoxButton.OKCancel, MessageBoxImage.Error); + UpDateManager.DoUpdate(); } return true; } @@ -121,11 +123,8 @@ namespace Zerolauncher.Manager class SingleGame { Process process; - string? restartUrl; - public int mHandle; - public Account? account; string gameMode; @@ -136,21 +135,12 @@ namespace Zerolauncher.Manager gameMode = mod; mHandle = 0; process = EngineShell.CheckEngineSafe(gameMode); - if (gameMode != StaticHandleA.UpdateMode) - { - process.OutputDataReceived += Handle; - process.Exited += Process_Exited; - } - process.Start(); - if (gameMode != StaticHandleA.UpdateMode) - { - process.BeginOutputReadLine(); // 开始异步读取 - if (gameMode == StaticHandleA.Version) - { - process.WaitForExit(); - } - } + process.OutputDataReceived += Handle; + process.Exited += Process_Exited; + process.Start(); + + process.BeginOutputReadLine(); // 开始异步读取 } private void CreateProcess() @@ -180,10 +170,15 @@ namespace Zerolauncher.Manager private void Handle(object sender, DataReceivedEventArgs e) { - var lines = e.Data == null? [""] : e.Data.Split(" "); + var lines = e.Data == null? [""] : e.Data.Split(" ", 2); // 切成两半 switch (lines[0]) { case StaticHandleC.StartDone: + if (gameMode == StaticHandleA.UpdateMode) + { + UpDateManager.DoUpdate1(); + return; + } if(restartUrl == null) { Send($"{StaticHandleS.ShowWindow} {ServicesStaticInfo.ServicesName[account.providerId]}-{account.nickName}"); @@ -210,6 +205,9 @@ namespace Zerolauncher.Manager case StaticHandleC.Version: mHandle = int.Parse(lines[1]); break; + case StaticHandleC.DownloadDone: + UpDateManager.OnDownLoadDone(lines[1]); + break; } } @@ -231,35 +229,57 @@ namespace Zerolauncher.Manager class EngineShell { + static bool needShowTis = true; static bool is_check = false; const string engine_file = @"ZeroEngine.exe"; public static Process CheckEngineSafe(string mod) { bool is_first_luancher = EngineManager.CheckEmpy(); - //if (!is_check && is_first_luancher) - //{ - // string? now_bit; - // using (SHA256 sha256 = SHA256.Create()) - // { - // using (FileStream fileStream = File.OpenRead(engine_file)) - // { - // byte[] hashBytes = sha256.ComputeHash(fileStream); - // now_bit = BitConverter.ToString(hashBytes).Replace("-", string.Empty); - // } - // } - // if (EngineCacheSha.Get() != now_bit) - // { - // throw new FileReadException("无法读取文件内容"); - // } - // is_check = true; - //} + if (mod == StaticHandleA.UpdateMode) + { + if (DataStream.dataStream.ecs != "") + { + string? now_bit; + using (SHA256 sha256 = SHA256.Create()) + { + using (FileStream fileStream = File.OpenRead(engine_file)) + { + byte[] hashBytes = sha256.ComputeHash(fileStream); + now_bit = BitConverter.ToString(hashBytes).Replace("-", string.Empty); + } + } + if (DataStream.dataStream.ecs != now_bit) + { + Trace.WriteLine("lalalala", DataStream.dataStream.ecs); + throw new FileReadException("error esu1!"); + } + } + } + else if (!is_check && is_first_luancher) + { + string? now_bit; + using (SHA256 sha256 = SHA256.Create()) + { + using (FileStream fileStream = File.OpenRead(engine_file)) + { + byte[] hashBytes = sha256.ComputeHash(fileStream); + now_bit = BitConverter.ToString(hashBytes).Replace("-", string.Empty); + } + } + if (CacheSha.GetE() != now_bit) + { + throw new FileReadException("error esu0!"); + } + if (DataStream.dataStream.ecs != now_bit) { DataStream.dataStream.ecs = now_bit; DataStream.write(); } + is_check = true; + } var process = new Process { StartInfo = new ProcessStartInfo { FileName = engine_file, - Arguments = $"{mod} {is_first_luancher}", + Arguments = $"{StaticHandleA.GameMode} {needShowTis}", UseShellExecute = false, CreateNoWindow = true, RedirectStandardInput = true, @@ -267,6 +287,7 @@ namespace Zerolauncher.Manager }, EnableRaisingEvents = true }; + if (needShowTis) needShowTis = false; return process; } } diff --git a/Manager/UpDateManager.cs b/Manager/UpDateManager.cs index 437accb..449d3c0 100644 --- a/Manager/UpDateManager.cs +++ b/Manager/UpDateManager.cs @@ -2,21 +2,17 @@ using System.IO; using System.IO.Compression; using System.Security.Cryptography; +using System.Windows; 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"; + public static bool state = false; static bool isCheeking = false; + static SingleGame? updateProcess; public static void DoCheckUpdate(bool checkMain=true, bool needEngine = false) { @@ -50,17 +46,64 @@ namespace Zerolauncher.Manager } 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; + state = !(needEngine && needMian); isCheeking = false; } - public static void OnDownLoadDone() + public static void DoUpdate() { - ZipFile.ExtractToDirectory(cache_file, "."); - Process.Start("./upacket.bin"); + 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() + { + updateProcess.Send($"{StaticHandleS.ShowWindow} 自助更新"); + updateProcess.Send($"{StaticHandleS.UseBrowser} {UpDateData.lanzou + UpDateData.auto_packet_url}"); + updateProcess.Send($"{StaticHandleS.UpdateInfo} {UpDateData.tis}"); + } + + public static void OnDownLoadDone(string path) + { + updateProcess.Send(StaticHandleS.CloseGame); + try + { + ZipFile.ExtractToDirectory(path, "./cache/"); + File.Delete(path); + }catch(Exception e) + { + MessageBox.Show($"尝试更新文件时发生错误\n{e.Message}", "错误", MessageBoxButton.OKCancel, MessageBoxImage.Error); + return; + } + App.needUpdate = true; + MainWindow.Instance.Close(); } } diff --git a/StaticHandleProtol.cs b/StaticHandleProtol.cs index 16df3a0..f7eeb36 100644 --- a/StaticHandleProtol.cs +++ b/StaticHandleProtol.cs @@ -9,6 +9,7 @@ public const string UseBrowser = "e0"; public const string GameSa = "f0"; public const string CloseGame = "g0"; + public const string UpdateInfo = "h0"; } class StaticHandleC @@ -18,12 +19,13 @@ public const string StartGame = "0c"; public const string GameDone = "0d"; public const string Version = "0e"; + public const string DownloadDone = "0f"; } class StaticHandleA { public const string GameMode = "0a"; public const string UpdateMode = "0b"; - public const string Version = "0c"; + public const string VersionMode = "0c"; } } diff --git a/Zerolauncher.csproj b/Zerolauncher.csproj index b6a26b6..b03a03e 100644 --- a/Zerolauncher.csproj +++ b/Zerolauncher.csproj @@ -27,6 +27,7 @@ + @@ -49,9 +50,16 @@ + + + + PreserveNewest + + + diff --git a/controls/MemberControl.xaml.cs b/controls/MemberControl.xaml.cs index 641eb80..026aaf0 100644 --- a/controls/MemberControl.xaml.cs +++ b/controls/MemberControl.xaml.cs @@ -97,13 +97,16 @@ namespace Zerolauncher.controls changeTeamItem.Items.Add(menuItem); } }; - return contextMenu; } private void delItem_Click(object sender, RoutedEventArgs e) { - AccountManager.DeleteAccount(memberId); + MessageBoxResult result = MessageBox.Show($"即将删除账号{text.Content}", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel); + if (result == MessageBoxResult.OK) + { + AccountManager.DeleteAccount(memberId); + } } private void editItem_Click(object sender, RoutedEventArgs e) diff --git a/dialog/EditTeamControl.xaml b/dialog/EditTeamControl.xaml index bbbcd4a..198bf2c 100644 --- a/dialog/EditTeamControl.xaml +++ b/dialog/EditTeamControl.xaml @@ -5,17 +5,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="169" d:DesignWidth="290"> - - - - - - - - - - - + + @@ -45,5 +36,5 @@ - + diff --git a/res/about1.png b/res/about1.png index e4b0f8a..336f6e7 100644 Binary files a/res/about1.png and b/res/about1.png differ diff --git a/res/about2.png b/res/about2.png new file mode 100644 index 0000000..e4b0f8a Binary files /dev/null and b/res/about2.png differ diff --git a/res/close.png b/res/close.png new file mode 100644 index 0000000..f8ed70d Binary files /dev/null and b/res/close.png differ