/// <summary> /// Deletes all files of the mod and removes it from the list. /// Saves the xml file afterwards. /// </summary> public static void DeleteMod(ManagedMods mods, int index, Action <Progress> ProgressChanged = null) { ModActions.DeleteFiles(mods[index]); mods.RemoveAt(index); mods.Save(); ProgressChanged?.Invoke(Progress.Done("Mod deleted.")); }
/// <summary> /// Creates a new mod from a folder. /// </summary> /// <param name="gamePath">Path to the game installation</param> /// <param name="folderPath">Path to folder</param> /// <returns></returns> private static ManagedMod FromFolder(string gamePath, string folderPath, Action <Progress> ProgressChanged = null) { // Get path information: folderPath = EnsureLongPathSupport(folderPath); string folderName = Path.GetFileName(folderPath); // Install mod: ManagedMod newMod = new ManagedMod(gamePath); newMod.Title = folderName; newMod.ArchiveName = folderName + ".ba2"; newMod.ManagedFolderName = folderName; if (!Utils.IsFileNameValid(newMod.ManagedFolderName) || Directory.Exists(newMod.ManagedFolderPath)) { newMod.ManagedFolderName = newMod.DefaultManagedFolderName; } // Copy folder: CopyDirectory(folderPath, newMod.ManagedFolderPath, ProgressChanged); ModActions.CleanUpFolder(newMod.ManagedFolderPath, ProgressChanged); ModActions.DetectOptimalModInstallationOptions(newMod); return(newMod); }
/// <summary> /// Freezes the mods. /// </summary> public static void Freeze(ManagedMods mods, IEnumerable <int> indices) { foreach (int index in indices) { ModActions.Freeze(mods[index]); } mods.Save(); }
/// <summary> /// Deletes multiple mods and removes them from the list. /// Saves the xml file afterwards. /// </summary> public static void DeleteMods(ManagedMods mods, List <int> indices, Action <Progress> ProgressChanged = null) { indices = indices.OrderByDescending(i => i).ToList(); int fi = 0; int count = indices.Count(); foreach (int index in indices) { ProgressChanged?.Invoke(Progress.Ongoing($"Deleting mod {++fi} of {count}.", (float)(fi - 1) / (float)count)); ModActions.DeleteMod(mods, index); } ProgressChanged?.Invoke(Progress.Done($"{count} mods deleted.")); }
/// <summary> /// Unfreezes the mods. /// </summary> public static void Unfreeze(ManagedMods mods, IEnumerable <int> indices, Action <Progress> ProgressChanged = null) { int count = indices.Count(); int n = 1; foreach (int index in indices) { ModActions.Unfreeze(mods[index]); ProgressChanged?.Invoke(Progress.Ongoing($"Unfreezing {n} of {count} mod(s)...", (float)n++ / (float)count)); } mods.Save(); ProgressChanged?.Invoke(Progress.Done($"{count} mod(s) thawed.")); }
/// <summary> /// Creates a new mod from any supported archive. (zip, tar, rar, 7z, ba2) /// BA2 files can be installed frozen if needed. /// </summary> /// <param name="gamePath">Path to the game installation</param> /// <param name="filePath">Path to archive</param> /// <param name="useSourceBA2Archive">When false, creates a new "frozen" mod.</param> /// <returns></returns> private static ManagedMod FromArchive(string gamePath, string filePath, bool useSourceBA2Archive = false, Action <Progress> ProgressChanged = null) { // Get path information: string longFilePath = EnsureLongPathSupport(filePath); string fileNameWOEx = Path.GetFileNameWithoutExtension(longFilePath); string fileExtension = Path.GetExtension(longFilePath); // Install mod: ManagedMod newMod = new ManagedMod(gamePath); newMod.Title = fileNameWOEx; newMod.ArchiveName = fileNameWOEx + ".ba2"; newMod.ManagedFolderName = fileNameWOEx; if (!Utils.IsFileNameValid(newMod.ManagedFolderName) || Directory.Exists(newMod.ManagedFolderPath)) { newMod.ManagedFolderName = newMod.DefaultManagedFolderName; } // Extract mod: ProgressChanged?.Invoke(Progress.Indetermined($"Extracting {Path.GetFileName(filePath)}")); ModInstallations.ExtractArchive(longFilePath, newMod.ManagedFolderPath); // Freeze mod conditionally: if (useSourceBA2Archive && fileExtension == ".ba2") { // Copy *.ba2 into FrozenData: FileInfo frozenPath = new FileInfo(newMod.FrozenArchivePath); ProgressChanged?.Invoke(Progress.Indetermined($"Copying {Path.GetFileName(filePath)} to {frozenPath.DirectoryName}")); Directory.CreateDirectory(frozenPath.DirectoryName); File.Copy(longFilePath, frozenPath.FullName, true); newMod.Frozen = true; newMod.Freeze = true; newMod.PreviousMethod = ManagedMod.DeploymentMethod.SeparateBA2; newMod.Method = ManagedMod.DeploymentMethod.SeparateBA2; } else { ModActions.CleanUpFolder(newMod.ManagedFolderPath, ProgressChanged); ModActions.DetectOptimalModInstallationOptions(newMod); } return(newMod); }
/// <summary> /// Extracts the archive and then copy and replaces from the temp folder into the managed mod folder. /// </summary> public static void AddArchive(ManagedMod mod, string filePath, Action <Progress> ProgressChanged = null) { string longFilePath = EnsureLongPathSupport(filePath); string tempFolderPath = Path.Combine(Path.GetTempPath(), $"tmp_{mod.guid}"); if (Directory.Exists(tempFolderPath)) { Directory.Delete(tempFolderPath, true); } Directory.CreateDirectory(tempFolderPath); ProgressChanged?.Invoke(Progress.Indetermined($"Extracting {Path.GetFileName(filePath)}")); ModInstallations.ExtractArchive(longFilePath, tempFolderPath); ModActions.CleanUpFolder(tempFolderPath, ProgressChanged); CopyDirectory(tempFolderPath, mod.ManagedFolderPath, ProgressChanged); Directory.Delete(tempFolderPath, true); ProgressChanged?.Invoke(Progress.Done("Archive added to mod.")); }
/// <summary> /// Used in the deployment chain to deploy a single mod with the SeparateBA2 method. /// Freezes a mod if necessary. /// </summary> private static void DeploySeparateArchive(ManagedMod mod, ResourceList resources) { LogFile.WriteLine($" Installing mod '{mod.Title}' as SeparateBA2"); // If mod is supposed to be deployed frozen... if (mod.Freeze) { // ... freeze if necessary ... if (!mod.Frozen) { //LogFile.WriteLine($" Freezing mod..."); ModActions.Freeze(mod); } LogFile.WriteLine($" Copying frozen archive..."); // ... and copy it to the Data folder. if (Configuration.bUseHardlinks) { Utils.CreateHardLink( mod.FrozenArchivePath, mod.ArchivePath, true); } else { File.Copy( mod.FrozenArchivePath, mod.ArchivePath, true); } } // If mod isn't supposed to be deployed frozen... else { // ... unfreeze mod if needed ... if (mod.Frozen) { LogFile.WriteLine($" Unfreezing mod..."); ModActions.Unfreeze(mod); } // Getting preset: Archive2.Preset preset = ModHelpers.GetArchive2Preset(mod); LogFile.WriteLine($" Creating new archive..."); LogFile.WriteLine($" Format: {preset.format}"); LogFile.WriteLine($" Compression: {preset.compression}"); // ... and create a new archive. Archive2.Create( mod.ArchivePath, mod.ManagedFolderPath, preset); } // Finally, update the disk state ... mod.CurrentArchiveName = mod.ArchiveName; mod.CurrentCompression = mod.Frozen ? mod.FrozenCompression : mod.Compression; mod.CurrentFormat = mod.Frozen ? mod.FrozenFormat : mod.Format; mod.Deployed = true; mod.PreviousMethod = ManagedMod.DeploymentMethod.SeparateBA2; // ... and add the archive to the resource list. resources.Add(mod.ArchiveName); LogFile.WriteLine($" Installed."); }
/// <summary> /// Freezes the mod. /// </summary> public static void Freeze(ManagedMods mods, int index) { ModActions.Freeze(mods[index]); mods.Save(); }
/// <summary> /// Unfreezes the mod. /// </summary> public static void Unfreeze(ManagedMods mods, int index, Action <Progress> ProgressChanged = null) { ModActions.Unfreeze(mods[index]); mods.Save(); ProgressChanged?.Invoke(Progress.Done("Mod thawed.")); }