Ejemplo n.º 1
0
        private async void btnAppUpdate_Click(object sender, EventArgs e)
        {
            if (Program.Updater.GetScheduledUpdateInfo() != null)
            {
                if (Program.InstallScheduledUpdate())
                {
                    Close();
                }
                UpdateInstallButton();
                return;
            }
            using var progressDlg = new ProgressForm();
            try
            {
                Enabled          = false;
                Cursor.Current   = Cursors.WaitCursor;
                progressDlg.Text = Resources.Localization_ApplicationUpdate_Title;
                var checkForUpdateDialogAdapter = new CheckForUpdateDialogAdapter(progressDlg);
                progressDlg.Show(this);
                var availableUpdate = await Program.Updater.CheckForUpdateVersionAsync(progressDlg.CancelToken);

                progressDlg.CurrentTaskProgress = 1.0f;
                if (availableUpdate == null)
                {
                    progressDlg.Hide();
                    MessageBox.Show(this, Resources.Localization_NoUpdatesFound_Text, Resources.Localization_CheckForUpdate_Title,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                var dialogResult = MessageBox.Show(string.Format(Resources.Localization_UpdateAvailableDownloadAsk_Text, availableUpdate.GetVersion()),
                                                   Resources.Localization_CheckForUpdate_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    var downloadDialogAdapter = new DownloadProgressDialogAdapter(progressDlg);
                    var filePath = await Program.Updater.DownloadVersionAsync(availableUpdate, progressDlg.CancelToken, downloadDialogAdapter);

                    Program.Updater.ScheduleInstallUpdate(availableUpdate, filePath);
                }
            }
            catch
            {
                if (!progressDlg.IsCanceledByUser)
                {
                    progressDlg.Hide();
                    MessageBox.Show(this, Resources.Localization_Download_ErrorText,
                                    Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                Enabled        = true;
                progressDlg.Hide();
                UpdateInstallButton();
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> InstallVersionAsync(Control window, UpdateInfo selectedUpdateInfo)
        {
            if (!CurrentGame.IsAvailable())
            {
                _logger.Error($"Install localization mode path unavailable: {CurrentGame.RootFolderPath}");
                MessageBox.Show(window, Resources.Localization_File_ErrorText,
                                Resources.Localization_File_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (!Program.Settings.AcceptInstallWarning)
            {
                var dialogResult = MessageBox.Show(window, Resources.Localization_InstallWarning_Text,
                                                   Resources.Localization_InstallWarning_Title, MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (dialogResult != DialogResult.Yes)
                {
                    return(false);
                }
                Program.Settings.AcceptInstallWarning = true;
                Program.SaveAppSettings();
            }
            _logger.Info($"Install localization: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
            bool          status          = false;
            DirectoryInfo?downloadDirInfo = null;

            using var progressDlg = new ProgressForm();
            try
            {
                window.Enabled = false;
                Cursor.Current = Cursors.WaitCursor;
                var downloadDialogAdapter = new DownloadProgressDialogAdapter(selectedUpdateInfo.GetVersion());
                progressDlg.BindAdapter(downloadDialogAdapter);
                progressDlg.Show(window);
                downloadDirInfo = Directory.CreateDirectory(Path.Combine(CurrentGame.RootFolderPath, "download_" + Path.GetRandomFileName()));
                var packageIndex   = new LocalizationPackageIndex(CurrentGame.RootFolderPath);
                var downloadResult = await CurrentRepository.DownloadAsync(selectedUpdateInfo, downloadDirInfo.FullName, packageIndex,
                                                                           progressDlg.CancelToken, downloadDialogAdapter);

                progressDlg.BindAdapter(new InstallProgressDialogAdapter());
                using var gameMutex = new GameMutex();
                if (!GameMutexController.AcquireWithRetryDialog(progressDlg, gameMutex))
                {
                    _logger.Info($"Install localization aborted by user because game running");
                    return(false);
                }
                var installStatus = downloadResult switch
                {
                    FullDownoadResult fullResult => CurrentRepository.Installer.Install(fullResult.ArchiveFilePath, CurrentGame.RootFolderPath),
                    IncrementalDownloadResult incrementalResult => CurrentRepository.Installer.Install(incrementalResult.DownloadPath, CurrentGame.RootFolderPath, incrementalResult.DiffList),
                    _ => throw new InvalidOperationException("Download result is empty")
                };
                switch (installStatus)
                {
                case InstallStatus.Success:
                    if (selectedUpdateInfo is GitHubUpdateInfo githubUpateInfo)
                    {
                        CurrentRepository.Installer.WriteTimestamp(githubUpateInfo.Released, CurrentGame.RootFolderPath);
                    }
                    GameSettings.Load();
                    gameMutex.Release();
                    progressDlg.CurrentTaskProgress = 1.0f;
                    RepositoryManager.SetInstalledRepository(CurrentRepository, selectedUpdateInfo.GetVersion());
                    status = true;
                    break;

                case InstallStatus.PackageError:
                    gameMutex.Release();
                    _logger.Error($"Failed install localization due to package error: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_Package_ErrorText,
                                    Resources.Localization_Package_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                case InstallStatus.VerifyError:
                    gameMutex.Release();
                    _logger.Error($"Failed install localization due to core verify error: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_Verify_ErrorText,
                                    Resources.Localization_Verify_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                case InstallStatus.FileError:
                    gameMutex.Release();
                    _logger.Error($"Failed install localization due to file error: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_File_ErrorText,
                                    Resources.Localization_File_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                default:
                    gameMutex.Release();
                    _logger.Error($"Failed install localization: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_Install_ErrorText,
                                    Resources.Localization_Install_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
            catch (Exception e)
            {
                if (!progressDlg.IsCanceledByUser)
                {
                    _logger.Error(e, $"Error during install localization: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    if (e is HttpRequestException)
                    {
                        MessageBox.Show(window, Resources.Localization_Download_ErrorText + '\n' + e.Message,
                                        Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(window, Resources.Localization_Download_ErrorText,
                                        Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                window.Enabled = true;
                progressDlg.Hide();
                if (downloadDirInfo != null && selectedUpdateInfo is GitHubUpdateInfo)
                {
                    if (downloadDirInfo.Exists && !FileUtils.DeleteDirectoryNoThrow(downloadDirInfo, true))
                    {
                        _logger.Warn($"Failed remove download directory: {downloadDirInfo.FullName}");
                    }
                }
            }
            return(status);
        }
        public async Task <bool> InstallVersionAsync(Control window, UpdateInfo selectedUpdateInfo)
        {
            if (!CurrentGame.IsAvailable())
            {
                _logger.Error($"Install localization mode path unavailable: {CurrentGame.RootFolderPath}");
                MessageBox.Show(window, Resources.Localization_File_ErrorText,
                                Resources.Localization_File_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (!Program.Settings.AcceptInstallWarning)
            {
                var dialogResult = MessageBox.Show(window, Resources.Localization_InstallWarning_Text,
                                                   Resources.Localization_InstallWarning_Title, MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (dialogResult != DialogResult.Yes)
                {
                    return(false);
                }
                Program.Settings.AcceptInstallWarning = true;
                Program.SaveAppSettings();
            }
            _logger.Info($"Install localization: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
            bool status = false;

            using var progressDlg = new ProgressForm();
            try
            {
                window.Enabled = false;
                Cursor.Current = Cursors.WaitCursor;
                var downloadDialogAdapter = new DownloadProgressDialogAdapter(selectedUpdateInfo.GetVersion());
                progressDlg.BindAdapter(downloadDialogAdapter);
                progressDlg.Show(window);
                var filePath = await CurrentRepository.DownloadAsync(selectedUpdateInfo, Path.GetTempPath(),
                                                                     progressDlg.CancelToken, downloadDialogAdapter);

                progressDlg.BindAdapter(new InstallProgressDialogAdapter());
                var result = CurrentRepository.Installer.Install(filePath, CurrentGame.RootFolderPath);
                switch (result)
                {
                case InstallStatus.Success:
                    GameSettings.Load();
                    progressDlg.CurrentTaskProgress = 1.0f;
                    RepositoryManager.SetInstalledRepository(CurrentRepository, selectedUpdateInfo.GetVersion());
                    status = true;
                    break;

                case InstallStatus.PackageError:
                    _logger.Error($"Failed install localization due to package error: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_Package_ErrorText,
                                    Resources.Localization_Package_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                case InstallStatus.VerifyError:
                    _logger.Error($"Failed install localization due to core verify error: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_Verify_ErrorText,
                                    Resources.Localization_Verify_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                case InstallStatus.FileError:
                    _logger.Error($"Failed install localization due to file error: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_File_ErrorText,
                                    Resources.Localization_File_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                default:
                    _logger.Error($"Failed install localization: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_Install_ErrorText,
                                    Resources.Localization_Install_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
            catch (Exception e)
            {
                if (!progressDlg.IsCanceledByUser)
                {
                    _logger.Error(e, $"Error during install localization: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    if (e is HttpRequestException)
                    {
                        MessageBox.Show(window, Resources.Localization_Download_ErrorText + '\n' + e.Message,
                                        Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(window, Resources.Localization_Download_ErrorText,
                                        Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                window.Enabled = true;
                progressDlg.Hide();
            }
            return(status);
        }
Ejemplo n.º 4
0
        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();
                }
            }
        }