public static void ProcessQuasarModTypes(ObservableCollection <InternalModType> V1InternalModTypes) { ObservableCollection <QuasarModType> QuasarModTypes = new ObservableCollection <QuasarModType>(); foreach (InternalModType imt in V1InternalModTypes) { QuasarModType qmt = new QuasarModType() { ID = imt.ID, Name = imt.Name, GameElementFamilyID = imt.Association, GroupName = imt.TypeGroup, IgnoreGameElementFamily = imt.IgnoreableGameDataAssociation, NoGameElement = imt.NoGameData, IsExternal = imt.OutsideFolder, ExternalFolderPath = imt.OutsideFolderPath, SlotCount = imt.Slots, QuasarModTypeFileDefinitions = new ObservableCollection <QuasarModTypeFileDefinition>() }; foreach (InternalModTypeFile bf in imt.Files) { QuasarModTypeFileDefinition fileDefinition = new QuasarModTypeFileDefinition() { ID = bf.ID, SearchPath = bf.SourcePath, SearchFileName = bf.SourceFile, QuasarModTypeBuilderDefinitions = new ObservableCollection <QuasarModTypeBuilderDefinition>() }; foreach (BuilderFile f in bf.Files) { fileDefinition.QuasarModTypeBuilderDefinitions.Add(new QuasarModTypeBuilderDefinition() { ModLoaderID = f.BuilderID, OutputFileName = f.File, OutputPath = f.Path }); } qmt.QuasarModTypeFileDefinitions.Add(fileDefinition); } QuasarModTypes.Add(qmt); } JSonHelper.SaveQuasarModTypes(QuasarModTypes); }
/// <summary> /// Outputs a list of Mod Files that can be built /// </summary> /// <param name="qmt"></param> /// <param name="Family"></param> /// <param name="ci"></param> /// <param name="Slot"></param> /// <param name="ModLoader"></param> /// <param name="li"></param> /// <param name="game"></param> /// <returns></returns> public static ObservableCollection <ModFile> GetModFiles(QuasarModType qmt, GameElementFamily Family, ContentItem ci, int Slot, int ModLoader, LibraryItem li, Game game) { string DefaultDir = Properties.Settings.Default.DefaultDir; ObservableCollection <ModFile> PreparedModFiles = new ObservableCollection <ModFile>(); foreach (ScanFile sf in ci.ScanFiles) { QuasarModTypeFileDefinition FileDefinition = qmt.QuasarModTypeFileDefinitions.Single(def => def.ID == sf.QuasarModTypeFileDefinitionID); GameElement ge = Family.GameElements.Single(e => e.ID == sf.GameElementID); string ModFolder = Properties.Settings.Default.DefaultDir + @"\Library\Mods\" + li.Guid + @"\"; ModFile mf = new ModFile() { SourceFilePath = ModFolder + sf.SourcePath, DestinationFilePath = ProcessOutput(ModFolder + sf.SourcePath, FileDefinition, ge, Slot, ModLoader, li, ModFolder), LibraryItemGuid = ci.LibraryItemGuid }; PreparedModFiles.Add(mf); } return(PreparedModFiles); }
/// <summary> /// Processes a Mod File's output path for building /// </summary> /// <param name="SourcePath"></param> /// <param name="FileDefinition"></param> /// <param name="GameElement"></param> /// <param name="Slot"></param> /// <param name="ModLoader"></param> /// <param name="li"></param> /// <param name="ModFolder"></param> /// <returns></returns> public static string ProcessOutput(string SourcePath, QuasarModTypeFileDefinition FileDefinition, GameElement GameElement, int Slot, int ModLoader, LibraryItem li, string ModFolder) { //Setup QuasarModTypeBuilderDefinition Definition = FileDefinition.QuasarModTypeBuilderDefinitions.Single(d => d.ModLoaderID == ModLoader); Regex FileRegex = new Regex(PrepareRegex(FileDefinition.SearchFileName)); Regex FolderRegex = new Regex(PrepareRegex(FileDefinition.SearchPath)); //Getting File Match values Match fileMatch = FileRegex.Match(ModFolder + SourcePath.Replace('\\', '/')); Group FilePartGroup = fileMatch.Groups["Part"]; Group FileFolderGroup = fileMatch.Groups["Folder"]; Group FileAnyFileGroup = fileMatch.Groups["AnyFile"]; Match folderMatch = FolderRegex.Match(ModFolder + SourcePath.Replace('\\', '/')); Group FolderPartGroup = folderMatch.Groups["Part"]; Group FolderFolderGroup = folderMatch.Groups["Folder"]; //Constructing output string OutputFile = Definition.OutputFileName; string OutputPath = Definition.OutputPath; Regex ModNameReplacinator = new Regex("{ModName}"); Regex ModNameSlotReplacinator = new Regex("{ModNameSlot}"); Regex illegalInFileName = new Regex(@"[\\/:*?""<>|.]"); Regex FolderReplacinator = new Regex("{Folder}"); Regex PartReplacinator = new Regex("{Part}"); Regex GameDataReplacinator = new Regex("{GameData}"); Regex SlotReplacinatorSingle = new Regex("{S0}"); Regex SlotReplacinatorDouble = new Regex("{S00}"); Regex SlotReplacinatorTriple = new Regex("{S000}"); Regex AnyReplacinator = new Regex("{AnyFile}"); //Processing File Output if (FilePartGroup.Captures.Count > 0) { CaptureCollection cc = FilePartGroup.Captures; foreach (Capture c in cc) { OutputFile = PartReplacinator.Replace(OutputFile, c.Value, 1); } } if (FileFolderGroup.Captures.Count > 0) { CaptureCollection cc = FileFolderGroup.Captures; foreach (Capture c in cc) { OutputFile = FolderReplacinator.Replace(OutputFile, c.Value, 1); } } if (GameElement.GameFolderName.Contains(';')) { string ProperGameFolder = ""; //Match Data Processing if (fileMatch.Success) { Group GameData = fileMatch.Groups["GameData"]; if (GameData.Value != "") { ProperGameFolder = GameData.Value; } OutputFile = GameDataReplacinator.Replace(OutputFile, ProperGameFolder, 1); } } else { OutputFile = GameDataReplacinator.Replace(OutputFile, GameElement.GameFolderName, 1); } OutputFile = SlotReplacinatorSingle.Replace(OutputFile, Slot.ToString("0"), 1); OutputFile = SlotReplacinatorDouble.Replace(OutputFile, Slot.ToString("00"), 1); OutputFile = SlotReplacinatorTriple.Replace(OutputFile, Slot.ToString("000"), 1); if (FileAnyFileGroup.Captures.Count > 0) { OutputFile = AnyReplacinator.Replace(OutputFile, FileAnyFileGroup.Value, 1); } //Processing Folder Output if (FolderPartGroup.Captures.Count > 0) { CaptureCollection cc = FolderPartGroup.Captures; foreach (Capture c in cc) { OutputPath = PartReplacinator.Replace(OutputPath, c.Value, 1); } } if (FolderFolderGroup.Captures.Count > 0) { CaptureCollection cc = FolderFolderGroup.Captures; foreach (Capture c in cc) { OutputPath = FolderReplacinator.Replace(OutputPath, c.Value, 1); } } if (GameElement.GameFolderName.Contains(';')) { string ProperGameFolder = ""; //Match Data Processing if (folderMatch.Success) { Group GameData = folderMatch.Groups["GameData"]; if (GameData.Value != "") { ProperGameFolder = GameData.Value; } OutputPath = GameDataReplacinator.Replace(OutputPath, ProperGameFolder, 1); } } else { OutputPath = GameDataReplacinator.Replace(OutputPath, GameElement.GameFolderName, 1); } OutputPath = SlotReplacinatorSingle.Replace(OutputPath, Slot.ToString("0"), 1); OutputPath = SlotReplacinatorDouble.Replace(OutputPath, Slot.ToString("00"), 1); OutputPath = SlotReplacinatorTriple.Replace(OutputPath, Slot.ToString("000"), 1); OutputPath = ModNameReplacinator.Replace(OutputPath, illegalInFileName.Replace(li.Name, "")); OutputPath = ModNameSlotReplacinator.Replace(OutputPath, String.Format("{0} Slot {1}", illegalInFileName.Replace(li.Name, ""), (Slot + 1).ToString())); OutputPath = OutputPath.Replace("{DLC}", GameElement.isDLC == true ? "_patch" : ""); return(OutputPath + "/" + OutputFile); }
/// <summary> /// Matches all scan files to a game entry /// </summary> /// <param name="FilesToMatch"></param> /// <param name="FileDefinition"></param> /// <param name="qmt"></param> /// <param name="game"></param> /// <param name="ModFolder"></param> /// <returns></returns> public static ObservableCollection <ScanFile> MatchFiles(ObservableCollection <ScanFile> FilesToMatch, QuasarModTypeFileDefinition FileDefinition, QuasarModType qmt, Game game, string ModFolder) { Regex FileRegex = new Regex(PrepareRegex(FileDefinition.SearchFileName)); Regex FolderRegex = new Regex(PrepareRegex(FileDefinition.SearchPath)); foreach (ScanFile FileToMatch in FilesToMatch) { Match fileMatch = FileRegex.Match(FileToMatch.SourcePath.Replace('\\', '/')); Match folderMatch = FolderRegex.Match(FileToMatch.SourcePath.Replace('\\', '/')); if (folderMatch.Success || fileMatch.Success) { //Match Data string FolderSlot = ""; string FileSlot = ""; GameElement RecognisedFolderGameData = null; GameElement RecognisedFileGameData = null; GameElementFamily Family = game.GameElementFamilies.Single(f => f.ID == qmt.GameElementFamilyID); //Match Data Processing if (folderMatch.Success) { Group GameData = folderMatch.Groups["GameData"]; string FolderGameData = GameData.Value; RecognisedFolderGameData = Family.GameElements.SingleOrDefault(ge => (ge.GameFolderName == FolderGameData.ToLower()) || (ge.GameFolderName.Contains(";") ? ge.GameFolderName.Split(';').Contains(FolderGameData.ToLower()) : false)); Group Slot = folderMatch.Groups["Slot"]; FolderSlot = Slot.Value; } if (fileMatch.Success) { Group GameData = fileMatch.Groups["GameData"]; string FileGameData = GameData.Value; RecognisedFileGameData = Family.GameElements.SingleOrDefault(ge => (ge.GameFolderName == FileGameData.ToLower()) || (ge.GameFolderName.Contains(";") ? ge.GameFolderName.Split(';').Contains(FileGameData.ToLower()) : false)); Group Slot = fileMatch.Groups["Slot"]; FileSlot = Slot.Value; } //Match Validation if ((RecognisedFileGameData != null || RecognisedFolderGameData != null) && (FileDefinition.SearchPath == "" || folderMatch.Success) && fileMatch.Success) { FileToMatch.QuasarModTypeID = qmt.ID; FileToMatch.QuasarModTypeFileDefinitionID = FileDefinition.ID; FileToMatch.GameElementID = RecognisedFolderGameData != null ? RecognisedFolderGameData.ID : RecognisedFileGameData.ID; FileToMatch.Slot = FolderSlot != "" ? FolderSlot : FileSlot != "" ? FileSlot : "00"; //Processing paths FileToMatch.SourcePath = FileToMatch.SourcePath.Replace('/', '\\').Replace(ModFolder, ""); if (folderMatch.Value == "") { FileToMatch.OriginPath = FileToMatch.SourcePath; } else { FileToMatch.OriginPath = FileToMatch.SourcePath.Replace("\\" + folderMatch.Value.Replace('/', '\\'), ""); } FileToMatch.OriginPath = FileToMatch.OriginPath.Replace(fileMatch.Value, "|"); FileToMatch.OriginPath = FileToMatch.OriginPath.Split('|')[0]; FileToMatch.Scanned = true; } } } return(FilesToMatch); }