/// <summary> /// Parse the buffer file, enqueue all tasks it has and delete it /// </summary> private void ParseBufferFile() { // If the file doesn't exist - return if (!File.Exists(FileSystem.TaskBufferFilePath)) { return; } // Silence the watcher temporarily _watcher.EnableRaisingEvents = false; // Get the data var bufferLines = File.ReadAllLines(FileSystem.TaskBufferFilePath); // Enqueue everything foreach (string bufferLine in bufferLines.Distinct()) { var parts = bufferLine.SplitTrim(Constants.UniformSeparator); var taskType = parts[0]; var subType = parts[1]; var subId = parts[2]; var fileId = parts[3]; SubmissionType parsedSubType; try { parsedSubType = subType.ParseEnum <SubmissionType>(); } catch (ArgumentException ex) { // Resume the watcher _watcher.EnableRaisingEvents = true; _windowService.ShowErrorWindowAsync(Localization.Current.Task_UnknownInstallationProcess).GetResult(); return; } _taskExecutionService.EnqueueTask( new Task( taskType.ParseEnum <TaskType>(), parsedSubType, subId, fileId ) ); } // Clear file File.WriteAllText(FileSystem.TaskBufferFilePath, string.Empty); // Resume the watcher _watcher.EnableRaisingEvents = true; }
/// <summary> /// Checks whether the user is authorized and if not - prompts them to log in /// </summary> public void PerformAuthCheck() { // HACK: this is kind of a pattern-reversal if (Settings.Stager.Current.IsAuthorized) { _taskExecutionService.IsEnabled = true; } else { _taskExecutionService.IsEnabled = false; _windowService.ShowErrorWindowAsync(Localization.Current.Auth_NotLoggedIn).GetResult(); } }
private bool ExecuteInstallTask() { UpdateStatus(TaskExecutionStatus.Install); // Get mod info UpdateStatus(TaskExecutionStatus.InstallGetModInfo); var modInfo = _apiService.GetModInfo(Task.ModID); if (modInfo == null) { return(false); } // Reset everything _fileChanges.Clear(); // Download archive UpdateStatus(TaskExecutionStatus.InstallDownload); var downloadedFile = _webService.Download(modInfo.DownloadURL, FileSystem.CreateTempFile($"Mod_{modInfo.ModID}")); if (downloadedFile == null) { return(false); } if (IsAbortPending) { TaskAborted?.Invoke(this, new TaskEventArgs(Task)); return(false); } // Unpack archive UpdateStatus(TaskExecutionStatus.InstallUnpack); string unpackedDir = FileSystem.CreateTempDirectory($"Mod_{modInfo.ModID}"); _aliasService.Set(new InternalAlias(InternalAliasKeyword.ArchiveExtractedDirectory, unpackedDir)); _archivingService.ExtractFiles(downloadedFile.FullName, unpackedDir); if (!Directory.Exists(unpackedDir)) { return(false); } if (IsAbortPending) { TaskAborted?.Invoke(this, new TaskEventArgs(Task)); return(false); } // Get commands UpdateStatus(TaskExecutionStatus.InstallExecute); var commands = _apiService.GetInstallationCommands(modInfo.ModID); string commandContextID = modInfo.ModID; // can be improved later // Execute commands foreach (var command in commands) { if (IsAbortPending) { TaskAborted?.Invoke(this, new TaskEventArgs(Task)); return(false); } bool success = _commandExecutionService.ExecuteCommand(command, commandContextID); if (!success) { #if !DEBUG _windowService.ShowErrorWindowAsync(Localization.Current.Task_CommandExecutionFailed).GetResult(); return(false); #endif } UpdateStatus(Progress + 100.0 / commands.Count); } // Clear local aliases _aliasService.Clear(commandContextID); // Store results UpdateStatus(TaskExecutionStatus.InstallStoreResults); _persistenceService.RecordInstall(commandContextID, _fileChanges.ToArray()); #if !DEBUG // Submit results UpdateStatus(TaskExecutionStatus.InstallSubmitResults); _apiService.ReportSuccessfulExecution(Task.ModID, TaskType.Install); #endif return(true); }
private bool ExecuteInstallTask() { UpdateStatus(TaskExecutionStatus.Install); // Get mod info UpdateStatus(TaskExecutionStatus.InstallGetModInfo); var modInfo = _apiService.GetModInfo(Task.Identifier); if (modInfo == null) { return(false); } // Reset everything _fileChanges.Clear(); // Retrieve file info var fileInfo = _apiService.GetFileInfo(modInfo.FileId); // Download archive UpdateStatus(TaskExecutionStatus.InstallDownload); var downloadedFileContainer = _webService.Download(fileInfo.DownloadUrl, FileSystem.CreateTempFile($"Mod_{modInfo.FileId}")); if (downloadedFileContainer == null) { _windowService.ShowErrorWindowAsync(Localization.Current.Task_Install_Download_Failed).GetResult(); return(false); } var contentType = downloadedFileContainer.ResponseHeaders[HttpResponseHeader.ContentType]; var downloadedFile = downloadedFileContainer.FileInfo; if (IsAbortPending) { TaskAborted?.Invoke(this, new TaskEventArgs(Task)); return(false); } // Unpack archive UpdateStatus(TaskExecutionStatus.InstallUnpack); string unpackedDir = FileSystem.CreateTempDirectory($"Mod_{modInfo.FileId}"); _aliasService.Set(new InternalAlias(InternalAliasKeyword.ArchiveExtractedDirectory, unpackedDir)); var extractSuccess = _archivingService.ExtractFiles(downloadedFile.FullName, unpackedDir); if (!extractSuccess || !Directory.Exists(unpackedDir)) { // Note: RAR5 supported now, but might be useful for future formats //if ("application/x-rar-compressed".Equals(contentType)) //{ // _windowService.ShowErrorWindowAsync(Localization.Current.Task_Install_Unpack_Failed_RAR5).GetResult(); //} //else //{ _windowService.ShowErrorWindowAsync(Localization.Current.Task_Install_Unpack_Failed).GetResult(); //} return(false); } if (IsAbortPending) { TaskAborted?.Invoke(this, new TaskEventArgs(Task)); return(false); } // Get commands UpdateStatus(TaskExecutionStatus.InstallExecute); var commands = fileInfo.InstallationCommands; string commandContextID = modInfo.FileId; // can be improved later // If we aren't copying files, we probably don't have an installation scheme for this type of submission if (!commands.Any(c => CommandType.Copy.Equals(c.Type))) { _windowService.ShowErrorWindowAsync(Localization.Current.Task_UnknownInstallationProcess).GetResult(); return(false); } // Execute commands foreach (var command in commands) { if (IsAbortPending) { TaskAborted?.Invoke(this, new TaskEventArgs(Task)); return(false); } bool success = _commandExecutionService.ExecuteCommand(command, commandContextID); if (!success) { #if !DEBUG _windowService.ShowErrorWindowAsync(Localization.Current.Task_CommandExecutionFailed).GetResult(); return(false); #endif } UpdateStatus(Progress + 100.0 / commands.Count); } // Clear local aliases _aliasService.Clear(commandContextID); // Store results UpdateStatus(TaskExecutionStatus.InstallStoreResults); _persistenceService.RecordInstall(modInfo.Identifier, _fileChanges.ToArray()); return(true); }
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); }