diff --git a/SabreTools.Helper/Tools/DatTools.cs b/SabreTools.Helper/Tools/DatTools.cs index 483749ae..7bad83fe 100644 --- a/SabreTools.Helper/Tools/DatTools.cs +++ b/SabreTools.Helper/Tools/DatTools.cs @@ -2583,6 +2583,83 @@ namespace SabreTools.Helper return; } + /// + /// Populate the user DatData object from the input files + /// + /// Output user DatData object to output + /// 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 nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump) + /// 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 + /// List of DatData objects representing headers + private static List PopulateUserDataParallel(List inputs, bool inplace, bool clean, bool softlist, string outdir, + Dat inputDat, out Dat userData, string gamename, string romname, string romtype, long sgt, long slt, long seq, string crc, + string md5, string sha1, bool? nodump, bool trim, bool single, string root, int maxDegreeOfParallelism, Logger logger) + { + Dat[] datHeaders = new Dat[inputs.Count]; + DateTime start = DateTime.Now; + logger.User("Processing individual DATs"); + + userData = new Dat + { + OutputFormat = (inputDat.OutputFormat != OutputFormat.None ? inputDat.OutputFormat : OutputFormat.None), + Files = new Dictionary>(), + MergeRoms = inputDat.MergeRoms, + }; + + Parallel.For(0, inputs.Count, i => + { + string input = inputs[i]; + logger.User("Adding DAT: " + input.Split('¬')[0]); + datHeaders[i] = new Dat + { + OutputFormat = (inputDat.OutputFormat != OutputFormat.None ? inputDat.OutputFormat : OutputFormat.None), + Files = new Dictionary>(), + MergeRoms = inputDat.MergeRoms, + }; + + datHeaders[i] = Parse(input.Split('¬')[0], i, 0, datHeaders[i], gamename, romname, romtype, sgt, slt, seq, + crc, md5, sha1, nodump, trim, single, root, logger, true, clean, softlist); + }); + + logger.User("Populating internal DAT"); + for (int i = 0; i < inputs.Count; i++) + { + foreach (string key in datHeaders[i].Files.Keys) + { + if (userData.Files.ContainsKey(key)) + { + userData.Files[key].AddRange(datHeaders[i].Files[key]); + } + else + { + userData.Files.Add(key, datHeaders[i].Files[key]); + } + } + datHeaders[i].Files = null; + } + + // Set the output values + Dictionary> roms = userData.Files; + userData = (Dat)inputDat.CloneHeader(); + userData.Files = roms; + + logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); + + return datHeaders.ToList(); + } + #endregion #region DAT Writing