private void UpdateApp(string msg) { var appRunning = UpdateHelper.IsAppRunning(_mainAppPath); if (appRunning) { UpdateHelper.KillRunningApps(_mainAppPath); StopUpdateDetect(); StopMainAppActiveDetect(); } ShowAsNormal(appRunning ? "准备更新,正在关闭程序..." : null); UpdateHelper.Update(msg, appRunning ? 5000 : 0); }
/// <summary> /// 所有主程序关闭事件 /// </summary> /// <param name="detector"></param> private void OnMainAppsClose(MainAppStateDetector detector, LocalRunInfo localRunInfo) { this.Invoke((Action)(() => { if (!this._config.KeepUpdaterRunning) { Exit(null); } else if (this._config.KeepAppRunning) { if (!UpdateHelper.IsAppRunning(_mainAppPath)) { UpdateHelper.RunMainApp(localRunInfo, "由更新程序启动"); } } })); }
public override void Do() { var active = UpdateHelper.IsAppRunning(mainAppPath); if (config.KeepUpdaterRunning) { ClientCommand cmd = Ping(active); if (cmd != null) { OnCommandRequest?.Invoke(cmd, localRunInfo); } } if (!active) { if (IsStarted) { OnMainAppsClose?.Invoke(this, localRunInfo); } } }
/// <summary> /// 运行服务端命令 /// </summary> /// <param name="cmd"></param> /// <param name="localRunInfo"></param> private void OnServerCommandRequest(ClientCommand cmd, LocalRunInfo localRunInfo) { switch (cmd.Type) { case ClientCommandType.Start: if (!UpdateHelper.IsAppRunning(_mainAppPath)) { UpdateHelper.RunMainApp(localRunInfo, "由服务端启动"); } break; case ClientCommandType.Stop: if (UpdateHelper.IsAppRunning(_mainAppPath)) { UpdateHelper.KillRunningApps(_mainAppPath); } break; default: break; } }
/// <summary> /// 更新请求事件 /// </summary> private void OnUpdateRequest() { this.Invoke((Action)(() => { if (UpdateHelper.IsAppRunning(_mainAppPath)) { if (MessageBox.Show("是否退出当前运行的所有程序?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { UpdateApp("手动更新"); } else { // 选择不退出主程序(放弃更新) IgnoreUpdate(); } } else { UpdateApp("手动更新"); } })); }