Example #1
0
        private void PerformUpdate()
        {
#if DEBUG
            // Don't check for updates in debug
            return;
#endif

            // Check if settings allow updates
            if (!Settings.Stager.Current.AutoUpdate)
            {
                return;
            }

            // Check for updates
            bool updatesAvailable = CheckForUpdates();
            if (!updatesAvailable)
            {
                return;
            }

            // Prompt
            bool userAgreed = _windowService.ShowPromptWindowAsync(Localization.Current.Updater_UpdatePrompt).GetResult();
            if (!userAgreed)
            {
                return;
            }

            // Notify that the update started and show a dialog
            UpdateProcessStarted?.Invoke(this, EventArgs.Empty);
            _windowService.ShowUpdaterWindowAsync().Forget();

            // Abort all tasks
            _taskExecutionService.AbortAllTasks();

            // Get download URL
            string downloadURL = GetDownloadURL();
            if (downloadURL.IsBlank())
            {
                _windowService.ShowErrorWindowAsync(Localization.Current.Updater_UpdateDownloadFailed).GetResult();
                return;
            }

            // Download the file
            var downloadedFile = _webService.Download(downloadURL, FileSystem.CreateTempFile("ModboyUpdate.exe"));
            if (downloadedFile == null || !downloadedFile.Exists)
            {
                _windowService.ShowErrorWindowAsync(Localization.Current.Updater_UpdateDownloadFailed).GetResult();
                return;
            }

            // Launch the installer
            var process = Process.Start(downloadedFile.FullName, "/SP- /SILENT /SUPPRESSMSGBOXES /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS");
            if (process == null)
            {
                _windowService.ShowErrorWindowAsync(Localization.Current.Updater_UpdateInstallFailed).GetResult();
                return;
            }

            // Shutdown application
            Logger.Record("Update is being installed, shutting down");
            Application.Current.ShutdownSafe(ExitCode.UpdateInstallerExecuted);
        }
Example #2
0
        private bool ExecuteTask()
        {
            // Install
            if (Task.Type == TaskType.Install)
            {
                // Verify
                var integrity = ExecuteVerifyTask();

                // Prompt user
                if (integrity.IsEither(ModInstallationState.Installed, ModInstallationState.Corrupt) &&
                    !_windowService.ShowPromptWindowAsync(Localization.Current.Task_PromptReinstall).GetResult())
                {
                    return(false);
                }

                // Clean install
                bool installSuccess = false;
                if (integrity == ModInstallationState.NotInstalled)
                {
                    // Just install
                    installSuccess = ExecuteInstallTask();
                }
                // Dirty install
                else
                {
                    // Try to uninstall previous version
                    bool uninstallSuccess = ExecuteUninstallTask();
                    // If successful - install new version
                    if (uninstallSuccess)
                    {
                        installSuccess = ExecuteInstallTask();
                    }
                }

                // If failed to install - uninstall
                if (!installSuccess)
                {
                    ExecuteUninstallTask();
                }

                return(installSuccess);
            }

            // Uninstall
            if (Task.Type == TaskType.Uninstall)
            {
                // Check if installed
                if (!_persistenceService.IsInstalled(Task.ModID))
                {
                    return(true);
                }

                // Prompt user
                if (!_windowService.ShowPromptWindowAsync(Localization.Current.Task_PromptUninstall).GetResult())
                {
                    return(false);
                }

                // Execute uninstall
                return(ExecuteUninstallTask());
            }

            // Verify
            if (Task.Type == TaskType.Verify)
            {
                // Verify
                var integrity = ExecuteVerifyTask();

                // If not installed - remove trails
                if (integrity == ModInstallationState.NotInstalled)
                {
                    ExecuteUninstallTask();
                }

                return(ExecuteVerifyTask() == ModInstallationState.Installed);
            }

            // Unknown
            return(false);
        }
 private bool ExecutePrompt(string message)
 {
     return(_windowService.ShowPromptWindowAsync(message).GetResult());
 }