private void WriteModWADFiles(ModFile mod) { Action <KeyValuePair <string, WADFile> > writeWadFileDelegate = new Action <KeyValuePair <string, WADFile> >(WriteWadFile); if (Config.Get <bool>("ParallelWadInstallation")) { ParallelOptions parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }; Parallel.ForEach(mod.GetWadFiles(this.Index), parallelOptions, (modWadFile) => { writeWadFileDelegate.Invoke(modWadFile); }); } else { foreach (KeyValuePair <string, WADFile> modWadFile in mod.GetWadFiles(this.Index)) { writeWadFileDelegate.Invoke(modWadFile); } } void WriteWadFile(KeyValuePair <string, WADFile> modWadFile) { string wadPath = this.Index.FindWADPath(modWadFile.Key); string overlayModWadPath = string.Format(@"{0}\{1}", OVERLAY_FOLDER, wadPath); string gameModWadPath = string.Format(@"{0}\{1}", this.LeagueFolder, wadPath); //Check if the WAD already exists, if it does, we need to merge the 2 WADs //if it doesnt, then we need to copy it from the game directory if (!File.Exists(overlayModWadPath)) { Directory.CreateDirectory(Path.GetDirectoryName(overlayModWadPath)); WADFile baseWad = new WADFile(gameModWadPath); bool returnedModdedWad = false; using (WADFile mergedWad = WadMerger.Merge(baseWad, modWadFile.Value, out returnedModdedWad)) { mergedWad.Write(overlayModWadPath); } if (returnedModdedWad) { baseWad.Dispose(); } else { modWadFile.Value.Dispose(); } } else { File.Move(overlayModWadPath, overlayModWadPath + ".temp"); using (WADFile mergedWad = WadMerger.Merge(new WADFile(overlayModWadPath + ".temp"), modWadFile.Value)) { mergedWad.Write(overlayModWadPath); } //Delete temp wad file File.Delete(overlayModWadPath + ".temp"); modWadFile.Value.Dispose(); } } }
public void UninstallMod(ModFile mod) { Log.Information("Uninstalling Mod: " + mod.GetID()); List <ulong> modFiles = new List <ulong>(this.Index.ModEntryMap[mod.GetID()]); Dictionary <string, WADFile> wadFiles = new Dictionary <string, WADFile>(); this.Index.StartEdit(); //In this loop we remove the installed WAD entries foreach (ulong modFile in modFiles) { List <string> modFileWadFiles = this.Index.Mod[modFile]; //Initialize WAD files for entry deletion foreach (string modFileWadFile in modFileWadFiles) { if (!wadFiles.ContainsKey(modFileWadFile)) { wadFiles.Add(modFileWadFile, new WADFile(string.Format(@"{0}\{1}", OVERLAY_FOLDER, modFileWadFile))); } WADFile wad = wadFiles[modFileWadFile]; wad.RemoveEntry(modFile); } this.Index.RemoveModFile(modFile, mod.GetID()); } //Now we need to either delete empty WAD files or fill the ones from which we removed the entries with original files //if the modified ones are the same as original then we need to delete those too foreach (KeyValuePair <string, WADFile> wadFile in wadFiles) { //If the WAD isn't being used by any other mod or is empty we can delete it if (!this.Index.WadModMap[wadFile.Key].Any(x => x != mod.GetID()) || wadFile.Value.Entries.Count == 0) { wadFile.Value.Dispose(); File.Delete(string.Format(@"{0}\{1}", OVERLAY_FOLDER, wadFile.Key)); } //If it's used by some other mods we need to merge it into the original WAD else { string gameWadPath = string.Format(@"{0}\{1}", this.LeagueFolder, wadFile.Key); string overlayWadPath = string.Format(@"{0}\{1}", OVERLAY_FOLDER, wadFile.Key); WADFile originalWad = new WADFile(gameWadPath); using (WADFile mergedWad = WadMerger.Merge(originalWad, wadFile.Value)) { mergedWad.Write(overlayWadPath + ".temp"); } wadFile.Value.Dispose(); File.Delete(overlayWadPath); File.Move(overlayWadPath + ".temp", overlayWadPath); } } this.Database.ChangeModState(mod.GetID(), false); this.Index.RemoveMod(mod.GetID()); this.Index.EndEdit(); }
public void UninstallMod(ModFile mod) { Log.Information("Uninstalling Mod: " + mod.GetID()); List <ulong> moddedEntries = new List <ulong>(); if (this.Index.ModEntryMap.TryGetValue(mod.GetID(), out List <ulong> _moddedEntries)) { moddedEntries = new List <ulong>(_moddedEntries); } Dictionary <string, WadBuilder> moddedWads = new Dictionary <string, WadBuilder>(); this.Index.StartEdit(); //In this loop we remove the installed WAD entries foreach (ulong moddedEntry in moddedEntries) { List <string> moddedEntryWadFiles = this.Index.Mod[moddedEntry]; //Initialize WAD files for entry deletion foreach (string moddedEntryWadFile in moddedEntryWadFiles) { if (!moddedWads.ContainsKey(moddedEntryWadFile)) { using Wad moddedWad = Wad.Mount(string.Format(@"{0}\{1}", OVERLAY_FOLDER, moddedEntryWadFile), false); moddedWads.Add(moddedEntryWadFile, new WadBuilder(moddedWad)); } moddedWads[moddedEntryWadFile].RemoveEntry(moddedEntry); } this.Index.RemoveModdedEntry(moddedEntry, mod.GetID()); } //Now we need to either delete empty WAD files or fill the ones from which we removed the entries with original files //if the modified ones are the same as original then we need to delete those too foreach (KeyValuePair <string, WadBuilder> moddedWad in moddedWads) { //If the WAD isn't being used by any other mod or is empty we can delete it if (this.Index.WadModMap[moddedWad.Key].All(x => x == mod.GetID()) || moddedWad.Value.Entries.Count == 0) { File.Delete(string.Format(@"{0}\{1}", OVERLAY_FOLDER, moddedWad.Key)); } //If it's used by some other mods we need to merge it into the original WAD else { string gameWadPath = string.Format(@"{0}\{1}", this.LeagueFolder, moddedWad.Key); string overlayWadPath = string.Format(@"{0}\{1}", OVERLAY_FOLDER, moddedWad.Key); using Wad originalWad = Wad.Mount(gameWadPath, false); WadBuilder mergedWad = WadMerger.Merge(new WadBuilder(originalWad), moddedWad.Value); mergedWad.Build(overlayWadPath + ".temp"); File.Delete(overlayWadPath); File.Move(overlayWadPath + ".temp", overlayWadPath); } } this.Database.ChangeModState(mod.GetID(), false); this.Index.RemoveMod(mod.GetID()); this.Index.EndEdit(); }