From 1f520b2f8f02ca665bc3e3faff2f821bdf148546 Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Wed, 12 Aug 2020 22:05:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=9B=B4=E6=96=B0=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=8D=95=E6=8D=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netch/Forms/MainForm.Misc.cs | 46 ++++++++++++++++++++---------------- Netch/Resources/zh-CN | 1 + 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Netch/Forms/MainForm.Misc.cs b/Netch/Forms/MainForm.Misc.cs index b00b0250..c7b7ab18 100644 --- a/Netch/Forms/MainForm.Misc.cs +++ b/Netch/Forms/MainForm.Misc.cs @@ -47,40 +47,44 @@ namespace Netch.Forms NotifyTip(i18N.Translate("Start downloading new version")); var fileName = $"Netch{_updater.LatestVersionNumber}.zip"; var fileFullPath = Path.Combine(Global.NetchDir, "data", fileName); - if (File.Exists(fileFullPath)) + var updateFileValid = false; + + try { - if (Utils.Utils.IsZipValid(fileFullPath)) + if (File.Exists(fileFullPath)) { - // if debugging process stopped, debugger will kill child processes!!!! - // 调试进程结束,调试器将会杀死子进程 - // uncomment if(!Debugger.isAttach) block in NetchUpdater Project's main() method and attach to NetchUpdater process to debug - // 在 NetchUpdater 项目的 main() 方法中取消注释 if(!Debugger.isAttach)块,并附加到 NetchUpdater 进程进行调试 - Process.Start(new ProcessStartInfo + if (!(updateFileValid = Utils.Utils.IsZipValid(fileFullPath))) { - FileName = Path.Combine(Global.NetchDir, "NetchUpdater.exe"), - Arguments = - $"{Global.Settings.UDPSocketPort} {fileFullPath} {Global.NetchDir}" - }); - return; + File.Delete(fileFullPath); + } } - File.Delete(fileFullPath); + if (!File.Exists(fileFullPath)) + await WebUtil.DownloadFileAsync(WebUtil.CreateRequest(_updater.LatestVersionDownloadUrl), fileFullPath); + if (updateFileValid || Utils.Utils.IsZipValid(fileFullPath)) + RunUpdater(); + else + throw new InvalidDataException($"{fileFullPath} invalid"); + } + catch (Exception exception) + { + NotifyTip($"{i18N.Translate("Download update failed")}\n{exception.Message}"); + Logging.Error($"下载更新失败 {exception}"); } - await WebUtil.DownloadFileAsync(WebUtil.CreateRequest(_updater.LatestVersionDownloadUrl), fileFullPath); - if (Utils.Utils.IsZipValid(fileFullPath)) + void RunUpdater() { + // if debugging process stopped, debugger will kill child processes!!!! + // 调试进程结束,调试器将会杀死子进程 + // uncomment if(!Debugger.isAttach) block in NetchUpdater Project's main() method and attach to NetchUpdater process to debug + // 在 NetchUpdater 项目的 main() 方法中取消注释 if(!Debugger.isAttach)块,并附加到 NetchUpdater 进程进行调试 Process.Start(new ProcessStartInfo { - FileName = "cmd", + FileName = Path.Combine(Global.NetchDir, "NetchUpdater.exe"), Arguments = - $"/c {Path.Combine(Global.NetchDir, "NetchUpdater.exe")} {Global.Settings.UDPSocketPort} {fileFullPath} {Global.NetchDir}" + $"{Global.Settings.UDPSocketPort} {fileFullPath} {Global.NetchDir}" }); } - else - { - NotifyTip("Download update failed"); - } } } } \ No newline at end of file diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index 2b874571..ef28bd5d 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -47,6 +47,7 @@ "Check for updates": "检查更新", "Download and install now?": "立即下载并安装?", "Start downloading new version": "开始下载新版本", + "Download update failed": "下载更新错误", "Create Process Mode": "创建进程模式", "Edit Process Mode": "修改进程模式",