public static void Remove(ManagedMod mod, ResourceList resources, String GamePath) { if (mod.Deployed) { switch (mod.PreviousMethod) { case ManagedMod.DeploymentMethod.BundledBA2: LogFile.WriteLine($" Skipped (mod is bundled)"); break; case ManagedMod.DeploymentMethod.SeparateBA2: LogFile.WriteLine($" Deleting {mod.CurrentArchiveName}"); File.Delete(mod.CurrentArchivePath); resources.Remove(mod.CurrentArchiveName); break; case ManagedMod.DeploymentMethod.LooseFiles: LogFile.WriteLine($" Deleting loose files"); foreach (string relFilePath in mod.LooseFiles) { string installedFilePath = Path.GetFullPath(Path.Combine(GamePath, mod.CurrentRootFolder, relFilePath)); // .Replace("\\.\\", "\\") // Delete file, if existing: if (File.Exists(installedFilePath)) { File.Delete(installedFilePath); } // Rename backup, if there is one: if (File.Exists(installedFilePath + ".old")) { File.Move(installedFilePath + ".old", installedFilePath); } // Remove empty folders one by one, if existing: else { RemoveEmptyFolders(Path.GetDirectoryName(installedFilePath)); } } mod.LooseFiles.Clear(); break; } mod.Deployed = false; } }
/// <summary> /// Looks through the resource lists in the *.ini and imports *.ba2 archives. /// </summary> public static void ImportInstalledMods(ManagedMods mods, Action <Progress> ProgressChanged = null) { // TODO: ProgressChanged for ImportInstalledMods ProgressChanged?.Invoke(Progress.Indetermined("Importing already installed mods...")); // Get all archives: ResourceList IndexFileList = ResourceList.GetResourceIndexFileList(); ResourceList Archive2List = ResourceList.GetResourceArchive2List(); /* * Prepare list: */ // Add all archives: List <string> installedMods = new List <string>(); installedMods.AddRange(IndexFileList); installedMods.AddRange(Archive2List); installedMods.AddRange(mods.Resources); // Remove bundled archives: installedMods = installedMods.FindAll(e => !e.ToLower().Contains("bundled")); // Remove currently managed archives: foreach (ManagedMod mod in mods) { if (mod.PreviousMethod == ManagedMod.DeploymentMethod.SeparateBA2) { installedMods.Remove(mod.CurrentArchiveName); } } // Ignore any game files ("SeventySix - *.ba2"): foreach (string archiveName in IndexFileList) { if (archiveName.Trim().ToLower().StartsWith("seventysix")) { installedMods.Remove(archiveName); } } foreach (string archiveName in Archive2List) { if (archiveName.Trim().ToLower().StartsWith("seventysix")) { installedMods.Remove(archiveName); } } foreach (string archiveName in mods.Resources) { if (archiveName.Trim().ToLower().StartsWith("seventysix")) { installedMods.Remove(archiveName); } } /* * Import installed mods: */ foreach (string archiveName in installedMods) { string path = Path.Combine(mods.GamePath, "Data", archiveName); if (File.Exists(path) && !archiveName.Trim().ToLower().StartsWith("seventysix")) { // Import archive: ModInstallations.InstallArchive(mods, path, true); File.Delete(path); // Remove from lists: IndexFileList.Remove(archiveName); Archive2List.Remove(archiveName); } } // Save *.ini files: IndexFileList.CommitToINI(); Archive2List.CommitToINI(); //IniFiles.Instance.SaveAll(); mods.Save(); }