下载更新异常捕捉

This commit is contained in:
ChsBuffer
2020-08-12 22:05:53 +08:00
parent 41c9269c9a
commit 1f520b2f8f
2 changed files with 26 additions and 21 deletions

View File

@@ -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");
}
}
}
}

View File

@@ -47,6 +47,7 @@
"Check for updates": "检查更新",
"Download and install now?": "立即下载并安装?",
"Start downloading new version": "开始下载新版本",
"Download update failed": "下载更新错误",
"Create Process Mode": "创建进程模式",
"Edit Process Mode": "修改进程模式",