private async Task CheckUpdateAsync() { if (!SysInfo.IsNetworkConnected()) { MsgBoxHelper.ShowInfo("未偵測到網路連線,無法執行線上更新!"); return; } if (await DoUpdateAsync(false)) { string msg = "應用程式必須重新啟動才能完成更新程序,是否立即重新啟動?\r\n若您有資料尚未儲存,請選擇【否】。"; if (MsgBoxHelper.ShowYesNo(msg) == DialogResult.Yes) { Process.Start(Application.ExecutablePath); Application.Exit(); return; } } }
private async Task <bool> DoUpdateAsync(bool autoMode) { HttpUpdater updater = new HttpUpdater() { ClientPath = Application.StartupPath, ServerUri = AppGlobals.Config.AutoUpdateFilesUrl, ChangeLogFileName = "ChangeLog.txt" }; // debug using local update feed. //updater.ServerUri = "http://localhost/ebeupdate/"; try { await updater.GetUpdateListAsync(); } catch (Exception ex) { // 無法取得檔案更新清單(可能是網際網路無法連線) string msg = "無法取得檔案更新清單: " + ex.Message; if (autoMode) { StatusText = msg; } else { MsgBoxHelper.ShowError(msg); } return(false); } if (updater.HasUpdates()) { if (MsgBoxHelper.ShowYesNo("「易點雙視」有新版本,是否立即更新?") == DialogResult.Yes) { UpdateProgressForm updForm = new UpdateProgressForm(); updForm.Show(); try { updater.FileUpdating += updForm.updator_FileUpdating; updater.FileUpdated += updForm.updator_FileUpdated; updater.DownloadProgressChanged += updForm.updator_DownloadProgressChanged; if (await updater.UpdateAsync() > 0) { updForm.TopMost = false; var fvi = FileVersionInfo.GetVersionInfo(Application.ExecutablePath); MsgBoxHelper.ShowInfo("「易點雙視」更新完成!"); return(true); } } catch (Exception ex) { updForm.TopMost = false; MsgBoxHelper.ShowError("更新失敗!\r\n" + ex.Message); } finally { updForm.Close(); updForm.Dispose(); } } } else { if (!autoMode) { MsgBoxHelper.ShowInfo("您使用的已經是最新版,無須更新。"); } } return(false); }