Beispiel #1
0
        private void InputStartApp(LocalRunInfo localRunInfo)
        {
            FrmInput frm = new FrmInput("输入启动程序:", localRunInfo.AppRunCmd);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                localRunInfo.AppRunCmd = frm.Value;
                UpdateHelper.RunMainApp(localRunInfo);
            }
            else
            {
                Exit(localRunInfo);
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        private void InputUpdateUrl(LocalRunInfo localRunInfo)
        {
            FrmInput frm = new FrmInput("输入更新地址:", localRunInfo.UpdateUrl);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                localRunInfo.UpdateUrl = frm.Value;
                UpdateHelper.SaveLocalRunInfo(localRunInfo);

                UpdateHelper.Update("正常启动");
            }
            else
            {
                Exit(localRunInfo);
            }
        }
Beispiel #4
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, "由更新程序启动");
             }
         }
     }));
 }
Beispiel #5
0
        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);
                }
            }
        }
Beispiel #6
0
        /// <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;
            }
        }
Beispiel #7
0
        private void OnUpdateComplete(
            LocalRunInfo localRunInfo,
            IEnumerable <UpdateRunFile> fileDiff,
            List <string> failedUpdateFiles,
            List <string> failedDeleteFiles,
            bool initStart, bool runBat, string msg)
        {
            this.Invoke((Action)(() =>
            {
                _frmProgress.Hide();
                Show();

                OnUpdateStatus("正在保存配置信息...");
                UpdateHelper.SaveLocalRunInfo(localRunInfo);

                if (runBat)
                {
                    OnUpdateStatus("正在做初始化工作...");
                    UpdateHelper.RunBat();
                }

                if (!initStart && fileDiff.Count() > 0)
                { // 由于首次运行的时候更新的文件较多,不写更新日志
                    OnUpdateStatus("正在写更新日志...");
                    LogHelper.WriteUpdateLog(localRunInfo.Ver, fileDiff, failedUpdateFiles, failedDeleteFiles);
                }

                OnUpdateStatus("正在启动主程序...");
                if (string.IsNullOrEmpty(localRunInfo.AppRunCmd))
                {
                    InputStartApp(localRunInfo);
                }
                else
                {
                    UpdateHelper.RunMainApp(localRunInfo, msg);
                }
            }));
        }
Beispiel #8
0
 /// <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("手动更新");
         }
     }));
 }