private async void btnInstall_Click(object sender, EventArgs e) { if (cbVersions.SelectedItem is UpdateInfo selectedUpdateInfo) { using var progressDlg = new ProgressForm(); try { Enabled = false; Cursor.Current = Cursors.WaitCursor; progressDlg.Text = string.Format(Resources.Localization_InstallVersion_Title, selectedUpdateInfo.GetVersion()); var downloadDialogAdapter = new DownloadProgressDialogAdapter(progressDlg); progressDlg.Show(this); var filePath = await _currentRepository.DownloadAsync(selectedUpdateInfo, null, progressDlg.CancelToken, downloadDialogAdapter); var installDialogAdapter = new InstallProgressDialogAdapter(progressDlg); var result = _currentRepository.Installer.Install(filePath, _currentGame.RootFolder.FullName); switch (result) { case InstallStatus.Success: _gameSettings.Load(); progressDlg.CurrentTaskProgress = 1.0f; Program.RepositoryManager.SetInstalledRepository(_currentGame.Mode, _currentRepository); break; case InstallStatus.PackageError: MessageBox.Show(Resources.Localization_Package_ErrorText, Resources.Localization_Package_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); break; case InstallStatus.VerifyError: MessageBox.Show(Resources.Localization_Verify_ErrorText, Resources.Localization_Verify_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); break; case InstallStatus.FileError: MessageBox.Show(Resources.Localization_File_ErrorText, Resources.Localization_File_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); break; case InstallStatus.UnknownError: default: MessageBox.Show(Resources.Localization_Install_ErrorText, Resources.Localization_Install_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } catch { if (!progressDlg.IsCanceledByUser) { MessageBox.Show(Resources.Localization_Download_ErrorText, Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { Cursor.Current = Cursors.Default; Enabled = true; progressDlg.Hide(); UpdateControls(); } } }
private async void btnAppUpdate_Click(object sender, EventArgs e) { if (AppUpdate.Updater.GetScheduledUpdateInfo() != null) { if (AppUpdate.InstallScheduledUpdate()) { Close(); } UpdateAppInstallButton(); return; } using var progressDlg = new ProgressForm(); try { Enabled = false; Cursor.Current = Cursors.WaitCursor; progressDlg.BindAdapter(new CheckForUpdateDialogAdapter()); progressDlg.Show(this); var availableUpdate = await AppUpdate.Updater.CheckForUpdateVersionAsync(progressDlg.CancelToken); progressDlg.CurrentTaskProgress = 1.0f; if (availableUpdate == null) { progressDlg.Hide(); MessageBox.Show(this, Resources.Application_NoUpdatesFound_Text, Resources.Application_CheckForUpdate_Title, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var dialogResult = MessageBox.Show(this, string.Format(Resources.Application_UpdateAvailableDownloadAsk_Text, availableUpdate.GetVersion()), Resources.Application_CheckForUpdate_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { var downloadDialogAdapter = new DownloadProgressDialogAdapter(null); progressDlg.BindAdapter(downloadDialogAdapter); var filePath = await AppUpdate.Updater.DownloadVersionAsync(availableUpdate, progressDlg.CancelToken, downloadDialogAdapter); AppUpdate.Updater.ScheduleInstallUpdate(availableUpdate, filePath); } } catch (Exception exception) { if (!progressDlg.IsCanceledByUser) { progressDlg.Hide(); if (exception is HttpRequestException) { MessageBox.Show(this, Resources.Localization_Download_ErrorText + '\n' + exception.Message, Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(this, Resources.Localization_Download_ErrorText, Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } finally { Cursor.Current = Cursors.Default; Enabled = true; progressDlg.Hide(); UpdateAppInstallButton(); } }