/// <summary> /// Extracts and loads an archived modpack into the model /// </summary> /// <param name="modpackPath"></param> public static void LoadModpack(string modpackPath) { var modpackExtractionPath = string.Empty; var modpackHeader = new Header(); var modpackMods = new List <Mod>(); // Extract the modpack archive out to a temp folder using (var extractionHandler = new ArchiveExtractor(modpackPath)) { extractionHandler.ExtractModpack(); } modpackExtractionPath = AutomatonInstance.ModpackExtractionLocation; // Load the modpack header var modpackHeaderPath = Path.Combine(modpackExtractionPath, $"modpack.json"); if (!File.Exists(modpackHeaderPath)) { GenericErrorHandler.Throw(GenericErrorType.ModpackStructure, "Valid modpack.json was not found.", new StackTrace()); return; } // Load modpack header into Instance modpackHeader = Json.TryDeserializeJson <Header>(File.ReadAllText(modpackHeaderPath), out string parseError); // The json string was not parsed correctly, throw error if (parseError != string.Empty) { GenericErrorHandler.Throw(GenericErrorType.JSONParse, parseError, new StackTrace()); return; } // Set global instances, these will update viewmodels automatically via the message service Instance.AutomatonInstance.ModpackHeader = modpackHeader; Instance.AutomatonInstance.ModpackMods = LoadModInstallParameters(modpackHeader, modpackExtractionPath); ModpackLoadedEvent(); }
public static void InstallModpack(IProgress <InstallModpackProgress> progress) { var progressObject = new InstallModpackProgress(); // If Mod Organizer is set to be used, locate it and install if (AutomatonInstance.ModpackHeader.InstallModOrganizer) { } var mods = AutomatonInstance.ModpackMods; var extractionDirectory = AutomatonInstance.ModpackExtractionLocation; foreach (var mod in mods) { progressObject.UpdateString = $"{mod.ModName} | ({mods.IndexOf(mod) + 1}, {mods.Count})"; progress.Report(progressObject); // Extract the archive into the extract folder var archivePath = mod.FilePath; var archiveExtractor = new ArchiveExtractor(archivePath); var modExtractionPath = Path.Combine(extractionDirectory, mod.ModName); string modInstallPath = Path.Combine(AutomatonInstance.InstallLocation, mod.ModName); // Extract the archive into the target path var extractionResponse = archiveExtractor.ExtractArchive(modExtractionPath); // Something broke during the extraction process, pass message back to user and attempt to solve if (!extractionResponse) { } // Catch non-existent install parameters. In this instance, move all files / directories. if (!mod.InstallationParameters.ContainsAny()) { if (Directory.Exists(modInstallPath)) { Directory.Delete(modInstallPath, true); } Directory.Move(modExtractionPath, modInstallPath); continue; } foreach (var installParameter in mod.InstallationParameters) { var sourcePath = Path.Combine(modExtractionPath, installParameter.SourceLocation.StandardizePathSeparators()); var targetPath = Path.Combine(AutomatonInstance.InstallLocation, installParameter.TargetLocation.StandardizePathSeparators()); // Copy/move operation if the source is a directory if (Directory.Exists(sourcePath)) { CopyDirectory(sourcePath, targetPath); } // Copy/move directory if the source is a file if (File.Exists(sourcePath)) { File.Copy(sourcePath, targetPath); } } // Delete the extracted files archiveExtractor.Dispose(); } }