diff --git a/SabreTools.Helper/Dats/DatFile.cs b/SabreTools.Helper/Dats/DatFile.cs index 4de5b21a..cb904767 100644 --- a/SabreTools.Helper/Dats/DatFile.cs +++ b/SabreTools.Helper/Dats/DatFile.cs @@ -781,7 +781,7 @@ namespace SabreTools.Helper.Dats #region Converting and Updating /// - /// Convert, update, and filter a DAT file or set of files using a base + /// Determine if input files should be merged, diffed, or processed invidually /// /// Names of the input files and/or folders /// Optional param for output directory @@ -807,7 +807,7 @@ namespace SabreTools.Helper.Dats /// String representing root directory to compare against for length calculation /// Integer representing the maximum amount of parallelization to be used /// Logging object for console and file output - public void Update(List inputFileNames, string outDir, bool merge, DiffMode diff, bool inplace, bool skip, + public void DetermineUpdateType(List inputFileNames, string outDir, bool merge, DiffMode diff, bool inplace, bool skip, bool bare, bool clean, bool softlist, string gamename, string romname, string romtype, long sgt, long slt, long seq, string crc, string md5, string sha1, ItemStatus itemStatus, bool trim, bool single, string root, int maxDegreeOfParallelism, Logger logger) { @@ -884,58 +884,8 @@ namespace SabreTools.Helper.Dats // Otherwise, loop through all of the inputs individually else { - Parallel.ForEach(inputFileNames, - new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, - inputFileName => - { - // Clean the input string - if (inputFileName != "") - { - inputFileName = Path.GetFullPath(inputFileName); - } - - if (File.Exists(inputFileName)) - { - DatFile innerDatdata = (DatFile)CloneHeader(); - logger.User("Processing \"" + Path.GetFileName(inputFileName) + "\""); - innerDatdata.Parse(inputFileName, 0, 0, gamename, romname, - romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, - root, logger, true, clean, softlist, - keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0)); - - // If we have roms, output them - if (innerDatdata.Files.Count != 0) - { - innerDatdata.WriteToFile((outDir == "" ? Path.GetDirectoryName(inputFileName) : outDir), logger, overwrite: (outDir != "")); - } - } - else if (Directory.Exists(inputFileName)) - { - inputFileName = Path.GetFullPath(inputFileName) + Path.DirectorySeparatorChar; - - Parallel.ForEach(Directory.EnumerateFiles(inputFileName, "*", SearchOption.AllDirectories), - new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, - file => - { - logger.User("Processing \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\""); - DatFile innerDatdata = (DatFile)Clone(); - innerDatdata.Files = null; - innerDatdata.Parse(file, 0, 0, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, - trim, single, root, logger, true, clean, softlist, - keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0)); - - // If we have roms, output them - if (innerDatdata.Files != null && innerDatdata.Files.Count != 0) - { - innerDatdata.WriteToFile((outDir == "" ? Path.GetDirectoryName(file) : outDir + Path.GetDirectoryName(file).Remove(0, inputFileName.Length - 1)), logger, overwrite: (outDir != "")); - } - }); - } - else - { - logger.Error("I'm sorry but " + inputFileName + " doesn't exist!"); - } - }); + Update(inputFileNames, outDir, clean, softlist, gamename, romname, romtype, sgt, slt, seq, + crc, md5, sha1, itemStatus, trim, single, root, maxDegreeOfParallelism, logger); } return; } @@ -1332,6 +1282,91 @@ namespace SabreTools.Helper.Dats } } + /// + /// Convert, update, and filter a DAT file or set of files using a base + /// + /// Names of the input files and/or folders + /// Optional param for output directory + /// True if input files should be merged into a single file, false otherwise + /// Non-zero flag for diffing mode, zero otherwise + /// True if the cascade-diffed files should overwrite their inputs, false otherwise + /// True if the first cascaded diff file should be skipped on output, false otherwise + /// True if the date should not be appended to the default name, false otherwise [OBSOLETE] + /// True to clean the game names to WoD standard, false otherwise (default) + /// True to allow SL DATs to have game names used instead of descriptions, false otherwise (default) + /// Name of the game to match (can use asterisk-partials) + /// Name of the rom to match (can use asterisk-partials) + /// Type of the rom to match + /// Find roms greater than or equal to this size + /// Find roms less than or equal to this size + /// Find roms equal to this size + /// CRC of the rom to match (can use asterisk-partials) + /// MD5 of the rom to match (can use asterisk-partials) + /// SHA-1 of the rom to match (can use asterisk-partials) + /// Select roms with the given status + /// True if we are supposed to trim names to NTFS length, false otherwise + /// True if all games should be replaced by '!', false otherwise + /// String representing root directory to compare against for length calculation + /// Integer representing the maximum amount of parallelization to be used + /// Logging object for console and file output + public void Update(List inputFileNames, string outDir, bool clean, bool softlist, string gamename, string romname, + string romtype, long sgt, long slt, long seq, string crc, string md5, string sha1, ItemStatus itemStatus, bool trim, + bool single, string root, int maxDegreeOfParallelism, Logger logger) + { + Parallel.ForEach(inputFileNames, + new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, + inputFileName => + { + // Clean the input string + if (inputFileName != "") + { + inputFileName = Path.GetFullPath(inputFileName); + } + + if (File.Exists(inputFileName)) + { + DatFile innerDatdata = (DatFile)CloneHeader(); + logger.User("Processing \"" + Path.GetFileName(inputFileName) + "\""); + innerDatdata.Parse(inputFileName, 0, 0, gamename, romname, + romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, + root, logger, true, clean, softlist, + keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0)); + + // If we have roms, output them + if (innerDatdata.Files.Count != 0) + { + innerDatdata.WriteToFile((outDir == "" ? Path.GetDirectoryName(inputFileName) : outDir), logger, overwrite: (outDir != "")); + } + } + else if (Directory.Exists(inputFileName)) + { + inputFileName = Path.GetFullPath(inputFileName) + Path.DirectorySeparatorChar; + + Parallel.ForEach(Directory.EnumerateFiles(inputFileName, "*", SearchOption.AllDirectories), + new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, + file => + { + logger.User("Processing \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\""); + DatFile innerDatdata = (DatFile)Clone(); + innerDatdata.Files = null; + innerDatdata.Parse(file, 0, 0, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, + trim, single, root, logger, true, clean, softlist, + keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0)); + + // If we have roms, output them + if (innerDatdata.Files != null && innerDatdata.Files.Count != 0) + { + innerDatdata.WriteToFile((outDir == "" ? Path.GetDirectoryName(file) : outDir + Path.GetDirectoryName(file).Remove(0, inputFileName.Length - 1)), logger, overwrite: (outDir != "")); + } + }); + } + else + { + logger.Error("I'm sorry but " + inputFileName + " doesn't exist!"); + } + }); + } + #endregion #region Parsing diff --git a/SabreTools/Partials/SabreTools_Inits.cs b/SabreTools/Partials/SabreTools_Inits.cs index e9a73623..25e876b3 100644 --- a/SabreTools/Partials/SabreTools_Inits.cs +++ b/SabreTools/Partials/SabreTools_Inits.cs @@ -640,7 +640,7 @@ namespace SabreTools Romba = romba, }; - userInputDat.Update(inputs, outDir, merge, diffMode, inplace, skip, bare, clean, softlist, + userInputDat.DetermineUpdateType(inputs, outDir, merge, diffMode, inplace, skip, bare, clean, softlist, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, maxDegreeOfParallelism, _logger); }