Example #1
0
        private void DoGracefulExit()
        {
            _mutex.ReleaseMutex();
            _mutex.Close();
            this.Hide();
            ov?.Close();
            br.SaveConfig();
            SystemTrayIcon.Visible = false;

            SupportStatic.ExitAll();

            Environment.Exit(0);
        }
Example #2
0
        public static void UpdateLogic(bool hideNoUpdateMessage = true, bool includeOptional = true)
        {
            var         up         = new UpdateProcedure();
            var         needUpdate = false;
            VersionInfo info       = null;
            int         ret;

            try
            {
                ret = up.Step1(out needUpdate, out info);
            }
            catch (HttpRequestException e)
            {
                ret = 02_0000 + (int)e.Data["StatusCode"];
            }

            if (CheckVendor.NotValidResponseCode(ret))
            {
                MessageBox.Show($"客户端检查更新失败:{MessageVendor.FormatError(ret)}", "Milvaneth 客户端更新");
                return;
            }

            if (!needUpdate)
            {
                if (!hideNoUpdateMessage)
                {
                    MessageBox.Show($"已经是最新版本", "Milvaneth 客户端更新");
                }

                return;
            }

            if (!info.ForceUpdate)
            {
                if (!includeOptional)
                {
                    return;
                }

                var result =
                    MessageBox.Show(
                        $"有可用新版本 {info.EligibleMilvanethVersion} (D-{info.EligibleDataVersion} / G-{info.EligibleGameVersion})\n" +
                        $"版本说明:{info.DisplayMessage}\n" + "是否现在更新?", "Milvaneth 客户端更新", MessageBoxButton.YesNo);

                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }
            else
            {
                Task.Run(() => MessageBox.Show(
                             $"有可用新版本 {info.EligibleMilvanethVersion} (D-{info.EligibleDataVersion} / G-{info.EligibleGameVersion})\n" +
                             $"版本说明:{info.DisplayMessage}\n" + "本版本为必要更新,将自动下载并安装更新\n请不要关闭或退出程序,程序将在更新完成后自动重启", "Milvaneth 客户端更新", MessageBoxButton.OK));
            }

            VersionDownload download = null;

            try
            {
                ret = up.Step2(out download);
            }
            catch (HttpRequestException e)
            {
                ret = 02_0000 + (int)e.Data["StatusCode"];
            }

            if (CheckVendor.NotValidResponseCode(ret))
            {
                MessageBox.Show($"客户端下载更新失败:{MessageVendor.FormatError(ret)}", "Milvaneth 客户端更新");
                return;
            }

            var patches = UpdateVendor.DownloadPatches(download, null);

            UpdateVendor.WaitAllFinish(patches);

            if (!info.ForceUpdate)
            {
                MessageBox.Show($"更新即将开始,请不要关闭或退出程序\n程序将在更新完成后自动重启", "Milvaneth 客户端更新");
            }

            SupportStatic.ExitAll();
            UpdateVendor.InvokeUpdateAndExitProgram(download, true);
        }