Exemplo n.º 1
0
        private async Task CheckUpdate()
        {
            bool hasUpdate = false;

            try
            {
                string updateUrl = GlobalData.Instance.AggregatedConfig.GetInterfaceItem().ServerUpdatePath;
                Log.Logger.Debug($"CheckUpdate => {updateUrl}");

                using (var updateMgr = new UpdateManager(updateUrl))
                {
                    var updateInfo = await updateMgr.CheckForUpdate();

                    if (updateInfo != null && updateInfo.ReleasesToApply?.Any() == true)
                    {
                        // 包含更新
                        hasUpdate = true;
                    }
                }

                if (hasUpdate)
                {
                    string updateMsg = "检测到有新版本,是否升级?";

                    UpdateConfirmView updateConfirmView = new UpdateConfirmView(updateMsg);
                    bool?update = updateConfirmView.ShowDialog();

                    if (update.HasValue && update.Value)
                    {
                        Log.Logger.Debug("【agree to update】");

                        UpdatingView updatingView = new UpdatingView();
                        updatingView.ShowDialog();
                    }
                    else
                    {
                        Log.Logger.Debug("【refuse to update】");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Error($"CheckUpdate => {ex}");
            }
        }
Exemplo n.º 2
0
        private void CheckUpdateBackground()
        {
            VersionInfo versionInfo = UpdateManager.GetVersionInfoFromServer();

            if (versionInfo != null)
            {
                try
                {
                    string[] versions = versionInfo.VersionNumber.Split(new[] { '.' },
                                                                        StringSplitOptions.RemoveEmptyEntries);

                    int major = int.Parse(versions[0]);
                    int minor = int.Parse(versions[1]);
                    int build = int.Parse(versions[2]);

                    string localVersion =
                        $"{GlobalData.Instance.Version.Major}.{GlobalData.Instance.Version.Minor}.{GlobalData.Instance.Version.Build}";
                    string serverVersion = $"{major}.{minor}.{build}";

                    Log.Logger.Debug(
                        $"【check update】:local version={localVersion}, server version={serverVersion}");

                    bool hasNewerVersion = false;
                    if (major > GlobalData.Instance.Version.Major)
                    {
                        hasNewerVersion = true;
                    }
                    else if (major == GlobalData.Instance.Version.Major)
                    {
                        if (minor > GlobalData.Instance.Version.Minor)
                        {
                            hasNewerVersion = true;
                        }
                        else if (minor == GlobalData.Instance.Version.Minor)
                        {
                            if (build > GlobalData.Instance.Version.Build)
                            {
                                hasNewerVersion = true;
                            }
                        }
                    }

                    if (hasNewerVersion)
                    {
                        string updateMsg =
                            $"当前版本为{localVersion},检测到有新版本{serverVersion},是否升级?";


                        UpdateConfirmView updateConfirmView = new UpdateConfirmView(updateMsg);
                        bool?update = updateConfirmView.ShowDialog();

                        if (update.HasValue && update.Value)
                        {
                            Log.Logger.Debug($"【agree to update】");

                            Task.Run(() => { UpdateManager.UpdateApp(); });

                            GlobalData.Instance.UpdatingDialog =
                                new SscDialogWithoutButton("请勿关闭程序,正在升级中......\r\n升级完成后会自动启动新版本。");
                            GlobalData.Instance.UpdatingDialog.ShowDialog();
                        }
                        else
                        {
                            Log.Logger.Debug($"【refuse to update】");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Logger.Error($"【version comparison exception】:{ex}");
                }
            }
            else
            {
                Log.Logger.Error("【get version info from server error】:returned version info is null");
            }
        }