Exemplo n.º 1
0
        private void updateInteractionManager_UpdateAccepted(object sender, UpdateInfo update)
        {
            this.InvokeAsyncSafe(() => {
                FormManager.CloseAllDialogs();

                if (!string.IsNullOrEmpty(Config.DismissedUpdate))
                {
                    Config.DismissedUpdate = null;
                    Config.Save();
                }

                void OnFinished()
                {
                    UpdateDownloadStatus status = update.DownloadStatus;

                    if (status == UpdateDownloadStatus.Done)
                    {
                        UpdateInstaller = new UpdateInstaller(update.InstallerPath);
                        ForceClose();
                    }
                    else if (status != UpdateDownloadStatus.Canceled && FormMessage.Error("Update Has Failed", "Could not automatically download the update: " + (update.DownloadError?.Message ?? "unknown error") + "\n\nWould you like to open the website and try downloading the update manually?", FormMessage.Yes, FormMessage.No))
                    {
                        App.SystemHandler.OpenBrowser(Program.Website);
                        ForceClose();
                    }
                    else
                    {
                        Show();
                    }
                }

                if (update.DownloadStatus.IsFinished(true))
                {
                    OnFinished();
                }
                else
                {
                    FormUpdateDownload downloadForm = new FormUpdateDownload(update);

                    downloadForm.VisibleChanged += (sender2, args2) => {
                        downloadForm.MoveToCenter(this);
                        Hide();
                    };

                    downloadForm.FormClosed += (sender2, args2) => {
                        if (downloadForm.DialogResult != DialogResult.OK)
                        {
                            update.CancelDownload();
                        }

                        downloadForm.Dispose();
                        OnFinished();
                    };

                    downloadForm.Show();
                }
            });
        }