Ejemplo n.º 1
0
        /// <summary>
        ///     Look for updates while displaying a progress bar. At the end display a message box with the result.
        /// </summary>
        public static void LookForUpdates()
        {
            var result = UpdateSystem.UpdateStatus.CheckFailed;
            var error  = LoadingDialog.ShowDialog(null, Localisable.LoadingDialogTitleSearchingForUpdates,
                                                  x => { result = UpdateSystem.CheckForUpdates(); });

            if (error == null)
            {
                switch (result)
                {
                case UpdateSystem.UpdateStatus.CheckFailed:
                    MessageBoxes.UpdateFailed(UpdateSystem.LastError != null
                            ? UpdateSystem.LastError.Message
                            : "Unknown error");
                    break;

                case UpdateSystem.UpdateStatus.NewAvailable:
                    if (MessageBoxes.UpdateAskToDownload())
                    {
                        UpdateSystem.BeginUpdate();
                    }
                    break;

                case UpdateSystem.UpdateStatus.UpToDate:
                    MessageBoxes.UpdateUptodate();
                    break;
                }
            }
            else
            {
                MessageBoxes.UpdateFailed(error.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Automatically search for updates if auto update is enabled.
        ///     Doesn't block, use delegates to interface.
        /// </summary>
        /// <param name="canDisplayMessage">updateFoundCallback will be called after this returns true</param>
        /// <param name="updateFoundCallback">Launched only if a new update was found. It's launched from a background thread.</param>
        public static void AutoUpdate(Func <bool> canDisplayMessage, Action updateFoundCallback)
        {
            if (Settings.Default.MiscCheckForUpdates && WindowsTools.IsNetworkAvailable())
            {
                new Thread(() =>
                {
                    if (UpdateSystem.CheckForUpdates() != UpdateSystem.UpdateStatus.NewAvailable)
                    {
                        return;
                    }

                    while (!canDisplayMessage())
                    {
                        Thread.Sleep(100);
                    }

                    try
                    {
                        updateFoundCallback();
                    }
                    catch
                    {
                        // Ignore background error, not necessary
                    }
                })
                {
                    Name = "UpdateCheck_Thread", IsBackground = true
                }.Start();
            }
        }
Ejemplo n.º 3
0
        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show(UpdateSystem.CheckForUpdates().ToString());
            if (UpdateSystem.LastError != null)
            {
                MessageBox.Show(UpdateSystem.LastError.Message);
            }

            if (UpdateSystem.LatestReply != null)
            {
                MessageBox.Show(UpdateSystem.LatestReply.FullReply.ToString());
                labelVersion.Text = UpdateSystem.LatestReply.GetUpdateVersion().ToString();
            }
        }