コード例 #1
0
        private void RunCheck()
        {
            if (updateStatePresent == null)
            {
                updateStatePresent = new BackgroundWorker
                {
                    WorkerSupportsCancellation = true
                };
                updateStatePresent.DoWork             += updateStatePresent_DoWork;
                updateStatePresent.RunWorkerCompleted += updateStatePresent_RunWorkerCompleted;
            }
            if (Instance.updateStatePresent.IsBusy)
            {
                return;
            }
            Busy = true;

            updateStatePresent.RunWorkerAsync();

            this.InvokeMethod(() =>
            {
                linkNow.Visible = linkIgnore.Visible = linkNext.Visible = false;
                lbCurrent.Text  = @"当前版本 " + Application.ProductVersion;
                lbMsg.Text      = @"正在检查更新版本...";
            });

            update = OnlineUpdate.Check();

            Settings.Update.LastUpdate = DateTime.Now;

            Busy = false;
            updateStatePresent.CancelAsync();

            this.InvokeMethod(() =>
            {
                if (update == null)
                {
                    lbMsg.Text = @"没有更新版本";
                    DelayHide();
                    return;
                }

                if (!update.Status)
                {
                    lbMsg.Text = @"检查更新失败";
                    DelayHide();
                    return;
                }

                if (update.Version == Settings.Update.IgnoreVersion)
                {
                    if (AutoClose)
                    {
                        DelayHide();
                        return;
                    }

                    lbMsg.Text = string.Format(@"有新版本 {0} (已忽略)", update.Version);
                }
                else
                {
                    lbMsg.Text = @"有新版本 " + update.Version;
                }

                lbUpdateDate.Text = update.Date.ToString("yyyy年MM月dd日");

                lbLog.Text = update.Message;

                Top    = Screen.PrimaryScreen.WorkingArea.Height - 240;
                Height = 240;
                pnDetail.Show();

                linkNow.Visible = linkIgnore.Visible = linkNext.Visible = true;

                if (!AutoClose)
                {
                    return;
                }

                SlideIn();
            });
        }
コード例 #2
0
        private void RunCheck()
        {
            if (updateStatePresent == null)
            {
                updateStatePresent = new BackgroundWorker
                {
                    WorkerSupportsCancellation = true
                };
                updateStatePresent.DoWork             += updateStatePresent_DoWork;
                updateStatePresent.RunWorkerCompleted += updateStatePresent_RunWorkerCompleted;
            }
            if (updateStatePresent.IsBusy)
            {
                return;
            }
            Busy = true;

            updateStatePresent.RunWorkerAsync();

            this.InvokeMethod(() =>
            {
                linkNow.Visible = linkIgnore.Visible = linkNext.Visible = false;
                lbCurrent.Text  = $"{resources.GetString("currentVersion")} " + Application.ProductVersion;
                lbMsg.Text      = resources.GetString("checking");
            });

            update = OnlineUpdate.Check();

            Settings.Update.LastUpdate = DateTime.Now;

            Busy = false;
            updateStatePresent.CancelAsync();

            this.InvokeMethod(() =>
            {
                // 没有更新
                if (update == null)
                {
                    lbMsg.Text = resources.GetString("noupdate");
                    DelayHide();
                    return;
                }

                // 检查更新失败
                if (!update.Status)
                {
                    lbMsg.Text = resources.GetString("checkFailed");
                    DelayHide();
                    return;
                }

                // 检查到更新,但是已经被忽略
                if (update.Version == Settings.Update.IgnoreVersion)
                {
                    lbMsg.Text = string.Format(resources.GetString("newVersionIgnored"), update.Version);
                    DelayHide();
                    return;
                }

                // 检查到可用的更新
                lbMsg.Text = $"{resources.GetString("newVersion")} " + update.Version;


                lbUpdateDate.Text = update.Date.ToLongDateString();

                lbLog.Text = update.Message;

                Top    = Screen.PrimaryScreen.WorkingArea.Height - 240;
                Height = 240;
                pnDetail.Show();

                linkNow.Visible = linkIgnore.Visible = linkNext.Visible = true;

                // 当不是来自于自动更新时,窗口已经处于可见状态
                if (!FromAutoUpdate)
                {
                    return;
                }

                // 只有来自于自动更新时,窗口才是在检查到更新到才显示
                this.SlideIn(() =>
                {
                    this.InvokeMethod(() =>
                    {
                        Left = Util.GetScreenSize().Width - Width;
                        btnExit.Show();
                    });
                    DelayHide(15000);
                });
            });
        }