Beispiel #1
0
        /// <summary>
        /// 立即更新 被点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void linkNow_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            CancelHide();
            linkNow.Visible = linkIgnore.Visible = linkNext.Visible = false;
            lbMsg.Text      = string.Format(resources.GetString("downloading") + "({0})...", updateInfo.Version);

            lbPercentage.Text = "0K / 0K    0%";
            if (!lbPercentage.Visible)
            {
                lbPercentage.Show();
                lbProgress.Show();
            }
            Application.DoEvents();
            new Thread(() =>
            {
                OnlineUpdate.Update(updateInfo, result =>
                {
                    if (!result.Success)
                    {
                        this.InvokeMethod(() =>
                        {
                            lbMsg.Text = resources.GetString("downloadFailed");
                        });
                        return;
                    }

                    this.InvokeMethod(() =>
                    {
                        lbPercentage.Text = string.Format(@"{0}K / {1}K    {2}%",
                                                          Math.Ceiling(result.BytesReceived / 1024.0),
                                                          Math.Ceiling(result.TotalBytesToReceive / 1024.0),
                                                          result.Percentage);

                        lbProgress.Width = lbPercentage.Width * result.Percentage / 100;

                        if (result.TotalBytesToReceive != result.BytesReceived)
                        {
                            return;
                        }
                        lbMsg.Text = resources.GetString("downloadComplete");
                    });
                });
            })
            {
                IsBackground = true
            }.Start();
        }
Beispiel #2
0
        private void linkNow_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            CancelHide();
            linkNow.Visible = linkIgnore.Visible = linkNext.Visible = false;
            lbMsg.Text      = string.Format(@"正在下载更新包({0})...", update.Version);
            new Thread(() =>
            {
                OnlineUpdate.Update(update.Link, update.Version, result =>
                {
                    if (!result.Success)
                    {
                        this.InvokeMethod(() =>
                        {
                            lbMsg.Text = @"更新包下载失败";
                        });
                        return;
                    }

                    this.InvokeMethod(() =>
                    {
                        if (!lbPercentage.Visible)
                        {
                            lbPercentage.Show();
                            lbProgress.Show();
                        }
                        lbPercentage.Text = string.Format(@"{0}K / {1}K    {2}%",
                                                          Math.Ceiling(result.BytesReceived / 1024.0),
                                                          Math.Ceiling(result.TotalBytesToReceive / 1024.0),
                                                          result.Percentage);

                        lbProgress.Width = lbPercentage.Width * result.Percentage / 100;

                        if (result.TotalBytesToReceive == result.BytesReceived)
                        {
                            lbMsg.Text = @"更新包下载完成,即将更新...";
                        }
                    });

                    DelayHide();
                });
            })
            {
                IsBackground = true
            }.Start();
        }
Beispiel #3
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);
                });
            });
        }
Beispiel #4
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();
            });
        }