private Dictionary <string, List <string> > getFileSupercedances() { Mod.MEGame game = target.Game; //make dictionary from basegame files var fileListMapping = new CaseInsensitiveDictionary <List <string> >(); var directories = MELoadedFiles.GetEnabledDLC(target).OrderBy(dir => MELoadedFiles.GetMountPriority(dir, target.Game)); foreach (string directory in directories) { var dlc = Path.GetFileName(directory); if (MEDirectories.OfficialDLC(target.Game).Contains(dlc)) { continue; //skip } foreach (string filePath in MELoadedFiles.GetCookedFiles(target.Game, directory, false)) { string fileName = Path.GetFileName(filePath); if (fileName != null && fileName.RepresentsPackageFilePath()) { if (fileListMapping.TryGetValue(fileName, out var supercedingList)) { supercedingList.Insert(0, dlc); } else { fileListMapping[fileName] = new List <string>(new[] { dlc }); } } } } return(fileListMapping); }
/// <summary> /// Gets a list of superceding package files from the DLC of the game. Only files in DLC mods are returned /// </summary> /// <param name="target">Target to get supercedances for</param> /// <returns>Dictionary mapping filename to list of DLCs that contain that file, in order of highest priority to lowest</returns> public static Dictionary <string, List <string> > GetFileSupercedances(GameTarget target, string[] additionalExtensionsToInclude = null) { //make dictionary from basegame files var fileListMapping = new CaseInsensitiveDictionary <List <string> >(); var directories = MELoadedFiles.GetEnabledDLCFolders(target.Game, target.TargetPath).OrderBy(dir => MELoadedFiles.GetMountPriority(dir, target.Game)).ToList(); foreach (string directory in directories) { var dlc = Path.GetFileName(directory); if (MEDirectories.OfficialDLC(target.Game).Contains(dlc)) { continue; //skip } foreach (string filePath in MELoadedFiles.GetCookedFiles(target.Game, directory, false, additionalExtensions: additionalExtensionsToInclude)) { string fileName = Path.GetFileName(filePath); if (fileName != null && fileName.RepresentsPackageFilePath() || (additionalExtensionsToInclude != null && additionalExtensionsToInclude.Contains(Path.GetExtension(fileName)))) { if (fileListMapping.TryGetValue(fileName, out var supercedingList)) { supercedingList.Insert(0, dlc); } else { fileListMapping[fileName] = new List <string>(new[] { dlc }); } } } } return(fileListMapping); }
public static AFCInventory GetInventory(string inputPath, MEGame game, Action <string> currentScanningFileCallback = null, Action <string> debugOut = null) { AFCInventory inventory = new AFCInventory(); inventory.LocalFolderAFCFiles.ReplaceAll(Directory.GetFiles(inputPath, "*.afc", SearchOption.AllDirectories)); debugOut?.Invoke($"Beginning AFC references scan. Input path: {inputPath}, game {game}"); inventory.BasegameAFCFiles.ReplaceAll(MELoadedFiles.GetCookedFiles(game, GameFilesystem.MEDirectories.GetBioGamePath(game), includeAFCs: true).Where(x => Path.GetExtension(x) == ".afc")); foreach (var oafc in inventory.BasegameAFCFiles) { debugOut?.Invoke($@" >> Found Basegame AFC {oafc}"); } inventory.OfficialDLCAFCFiles = MELoadedFiles.GetOfficialDLCFolders(game).SelectMany(x => Directory.GetFiles(x, "*.afc", SearchOption.AllDirectories)).ToList(); foreach (var oafc in inventory.OfficialDLCAFCFiles) { debugOut?.Invoke($@" >> Found AFC in DLC directory {oafc}"); } // ME3: Inspect SFARs for AFCs if (game == MEGame.ME3 && Directory.Exists(ME3Directory.DLCPath)) { debugOut?.Invoke($@"DLC directory: {ME3Directory.DLCPath}"); foreach (var officialDLC in ME3Directory.OfficialDLC) { var sfarPath = Path.Combine(ME3Directory.DLCPath, officialDLC, "CookedPCConsole", "Default.sfar"); if (File.Exists(sfarPath)) { currentScanningFileCallback?.Invoke(ME3Directory.OfficialDLCNames[officialDLC]); debugOut?.Invoke($@"{ME3Directory.OfficialDLCNames[officialDLC]} is installed ({officialDLC})"); DLCPackage dlc = new DLCPackage(sfarPath); inventory.SFARAFCsMap[officialDLC] = dlc.Files.Where(x => x.FileName.EndsWith(".afc")).Select(x => x.FileName).ToList(); foreach (var oafc in inventory.SFARAFCsMap[officialDLC]) { debugOut?.Invoke($@" >> Found SFAR AFC {oafc}"); } inventory.OfficialDLCAFCFiles.AddRange(inventory.SFARAFCsMap[officialDLC]); } } } return(inventory); }