diff --git a/SabreTools.Helper/Dats/DatFile.cs b/SabreTools.Helper/Dats/DatFile.cs index cb904767..72e4fae2 100644 --- a/SabreTools.Helper/Dats/DatFile.cs +++ b/SabreTools.Helper/Dats/DatFile.cs @@ -792,24 +792,14 @@ namespace SabreTools.Helper.Dats /// 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 + /// Filter object to be passed to the DatItem level /// 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 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) + bool bare, bool clean, bool softlist, Filter filter, bool trim, bool single, string root, int maxDegreeOfParallelism, Logger logger) { // If we're in merging or diffing mode, use the full list of inputs if (merge || diff != 0) @@ -862,8 +852,7 @@ namespace SabreTools.Helper.Dats // Create a dictionary of all ROMs from the input DATs List datHeaders = PopulateUserData(newInputFileNames, inplace, clean, softlist, - outDir, gamename, romname, romtype, sgt, slt, seq, - crc, md5, sha1, itemStatus, trim, single, root, maxDegreeOfParallelism, logger); + outDir, filter, trim, single, root, maxDegreeOfParallelism, logger); // Modify the Dictionary if necessary and output the results if (diff != 0 && diff < DiffMode.Cascade) @@ -884,8 +873,7 @@ namespace SabreTools.Helper.Dats // Otherwise, loop through all of the inputs individually else { - Update(inputFileNames, outDir, clean, softlist, gamename, romname, romtype, sgt, slt, seq, - crc, md5, sha1, itemStatus, trim, single, root, maxDegreeOfParallelism, logger); + Update(inputFileNames, outDir, clean, softlist, filter, trim, single, root, maxDegreeOfParallelism, logger); } return; } @@ -893,16 +881,7 @@ namespace SabreTools.Helper.Dats /// /// Populate the user DatData object from the input files /// - /// 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 + /// Filter object to be passed to the DatItem level /// 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 @@ -910,8 +889,7 @@ namespace SabreTools.Helper.Dats /// Logging object for console and file output /// List of DatData objects representing headers private List PopulateUserData(List inputs, bool inplace, bool clean, bool softlist, string outDir, - 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) + Filter filter, bool trim, bool single, string root, int maxDegreeOfParallelism, Logger logger) { DatFile[] datHeaders = new DatFile[inputs.Count]; DateTime start = DateTime.Now; @@ -931,8 +909,7 @@ namespace SabreTools.Helper.Dats MergeRoms = MergeRoms, }; - datHeaders[i].Parse(input.Split('¬')[0], i, 0, gamename, romname, romtype, sgt, slt, seq, - crc, md5, sha1, itemStatus, trim, single, root, logger, true, clean, softlist); + datHeaders[i].Parse(input.Split('¬')[0], i, 0, filter, trim, single, root, logger, true, clean, softlist); }); logger.User("Processing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); @@ -1294,24 +1271,14 @@ namespace SabreTools.Helper.Dats /// 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 + /// Filter object to be passed to the DatItem level /// 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) + public void Update(List inputFileNames, string outDir, bool clean, bool softlist, Filter filter, + bool trim, bool single, string root, int maxDegreeOfParallelism, Logger logger) { Parallel.ForEach(inputFileNames, new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, @@ -1327,8 +1294,7 @@ namespace SabreTools.Helper.Dats { 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, + innerDatdata.Parse(inputFileName, 0, 0, filter, trim, single, root, logger, true, clean, softlist, keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0)); @@ -1349,7 +1315,7 @@ namespace SabreTools.Helper.Dats 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, + innerDatdata.Parse(file, 0, 0, filter, trim, single, root, logger, true, clean, softlist, keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0)); @@ -1385,7 +1351,7 @@ namespace SabreTools.Helper.Dats /// True if original extension should be kept, false otherwise (default) public void Parse(string filename, int sysid, int srcid, Logger logger, bool keep = false, bool clean = false, bool softlist = false, bool keepext = false) { - Parse(filename, sysid, srcid, null, null, null, -1, -1, -1, null, null, null, ItemStatus.NULL, false, false, "", logger, keep, clean, softlist, keepext); + Parse(filename, sysid, srcid, new Filter(), false, false, "", logger, keep, clean, softlist, keepext); } /// @@ -1394,16 +1360,7 @@ namespace SabreTools.Helper.Dats /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT - /// 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 + /// Filter object for passing to the DatItem level /// 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 @@ -1419,16 +1376,7 @@ namespace SabreTools.Helper.Dats int srcid, // Rom filtering - string gamename, - string romname, - string romtype, - long sgt, - long slt, - long seq, - string crc, - string md5, - string sha1, - ItemStatus itemStatus, + Filter filter, // Rom renaming bool trim, @@ -1470,25 +1418,25 @@ namespace SabreTools.Helper.Dats { case DatFormat.ClrMamePro: case DatFormat.DOSCenter: - ParseCMP(filename, sysid, srcid, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, logger, keep, clean); + ParseCMP(filename, sysid, srcid, filter, trim, single, root, logger, keep, clean); break; case DatFormat.Logiqx: case DatFormat.OfflineList: case DatFormat.SabreDat: case DatFormat.SoftwareList: - ParseGenericXML(filename, sysid, srcid, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, logger, keep, clean, softlist); + ParseGenericXML(filename, sysid, srcid, filter, trim, single, root, logger, keep, clean, softlist); break; case DatFormat.RedumpMD5: - ParseRedumpMD5(filename, sysid, srcid, romname, md5, trim, single, root, logger, clean); + ParseRedumpMD5(filename, sysid, srcid, filter, trim, single, root, logger, clean); break; case DatFormat.RedumpSFV: - ParseRedumpSFV(filename, sysid, srcid, romname, crc, trim, single, root, logger, clean); + ParseRedumpSFV(filename, sysid, srcid, filter, trim, single, root, logger, clean); break; case DatFormat.RedumpSHA1: - ParseRedumpSHA1(filename, sysid, srcid, romname, sha1, trim, single, root, logger, clean); + ParseRedumpSHA1(filename, sysid, srcid, filter, trim, single, root, logger, clean); break; case DatFormat.RomCenter: - ParseRC(filename, sysid, srcid, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, logger, clean); + ParseRC(filename, sysid, srcid, filter, trim, single, root, logger, clean); break; default: return; @@ -1501,16 +1449,7 @@ namespace SabreTools.Helper.Dats /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT - /// 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 + /// Filter object for passing to the DatItem level /// 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 @@ -1524,16 +1463,7 @@ namespace SabreTools.Helper.Dats int srcid, // Rom filtering - string gamename, - string romname, - string romtype, - long sgt, - long slt, - long seq, - string crc, - string md5, - string sha1, - ItemStatus itemStatus, + Filter filter, // Rom renaming bool trim, @@ -2047,7 +1977,7 @@ namespace SabreTools.Helper.Dats // Now process and add the rom string key = ""; - ParseAddHelper(item, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key); + ParseAddHelper(item, filter, trim, single, root, clean, logger, out key); } // If the line is anything but a rom or disk and we're in a block else if (Regex.IsMatch(line, Constants.ItemPatternCMP) && block) @@ -2209,16 +2139,7 @@ namespace SabreTools.Helper.Dats /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT - /// 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 + /// Filter object for passing to the DatItem level /// 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 @@ -2233,16 +2154,7 @@ namespace SabreTools.Helper.Dats int srcid, // Rom filtering - string gamename, - string romname, - string romtype, - long sgt, - long slt, - long seq, - string crc, - string md5, - string sha1, - ItemStatus itemStatus, + Filter filter, // Rom renaming bool trim, @@ -2288,7 +2200,7 @@ namespace SabreTools.Helper.Dats Rom rom = new Rom("null", tempgame); // Now process and add the rom - ParseAddHelper(rom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key); + ParseAddHelper(rom, filter, trim, single, root, clean, logger, out key); } // Regardless, end the current folder @@ -2790,7 +2702,7 @@ namespace SabreTools.Helper.Dats }; // Now process and add the rom - ParseAddHelper(olrom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key); + ParseAddHelper(olrom, filter, trim, single, root, clean, logger, out key); break; // For Software List only @@ -2872,7 +2784,7 @@ namespace SabreTools.Helper.Dats }; // Now process and add the rom - ParseAddHelper(relrom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key); + ParseAddHelper(relrom, filter, trim, single, root, clean, logger, out key); subreader.Read(); break; @@ -2915,7 +2827,7 @@ namespace SabreTools.Helper.Dats }; // Now process and add the rom - ParseAddHelper(biosrom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key); + ParseAddHelper(biosrom, filter, trim, single, root, clean, logger, out key); subreader.Read(); break; @@ -2943,7 +2855,7 @@ namespace SabreTools.Helper.Dats }; // Now process and add the rom - ParseAddHelper(archiverom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key); + ParseAddHelper(archiverom, filter, trim, single, root, clean, logger, out key); subreader.Read(); break; @@ -2971,7 +2883,7 @@ namespace SabreTools.Helper.Dats }; // Now process and add the rom - ParseAddHelper(samplerom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key); + ParseAddHelper(samplerom, filter, trim, single, root, clean, logger, out key); subreader.Read(); break; @@ -3107,7 +3019,7 @@ namespace SabreTools.Helper.Dats } // Now process and add the rom - ParseAddHelper(inrom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key); + ParseAddHelper(inrom, filter, trim, single, root, clean, logger, out key); subreader.Read(); break; @@ -3279,7 +3191,7 @@ namespace SabreTools.Helper.Dats } // Now process and add the rom - ParseAddHelper(rom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key); + ParseAddHelper(rom, filter, trim, single, root, clean, logger, out key); xtr.Read(); break; @@ -3306,8 +3218,7 @@ namespace SabreTools.Helper.Dats /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT - /// Name of the rom to match (can use asterisk-partials) - /// MD5 of the rom to match (can use asterisk-partials) + /// Filter object for passing to the DatItem level /// 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 @@ -3320,8 +3231,7 @@ namespace SabreTools.Helper.Dats int srcid, // Rom filtering - string romname, - string md5, + Filter filter, // Rom renaming bool trim, @@ -3358,7 +3268,7 @@ namespace SabreTools.Helper.Dats // Now process and add the rom string key = ""; - ParseAddHelper(rom, null, romname, null, -1, -1, -1, null, md5, null, ItemStatus.NULL, trim, single, root, clean, logger, out key); + ParseAddHelper(rom, filter, trim, single, root, clean, logger, out key); } sr.Dispose(); @@ -3370,8 +3280,7 @@ namespace SabreTools.Helper.Dats /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT - /// Name of the rom to match (can use asterisk-partials) - /// CRC of the rom to match (can use asterisk-partials) + /// Filter object for passing to the DatItem level /// 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 @@ -3384,8 +3293,7 @@ namespace SabreTools.Helper.Dats int srcid, // Rom filtering - string romname, - string crc, + Filter filter, // Rom renaming bool trim, @@ -3422,7 +3330,7 @@ namespace SabreTools.Helper.Dats // Now process and add the rom string key = ""; - ParseAddHelper(rom, null, romname, null, -1, -1, -1, crc, null, null, ItemStatus.NULL, trim, single, root, clean, logger, out key); + ParseAddHelper(rom, filter, trim, single, root, clean, logger, out key); } sr.Dispose(); @@ -3434,8 +3342,7 @@ namespace SabreTools.Helper.Dats /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT - /// Name of the rom to match (can use asterisk-partials) - /// SHA-1 of the rom to match (can use asterisk-partials) + /// Filter object for passing to the DatItem level /// 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 @@ -3448,8 +3355,7 @@ namespace SabreTools.Helper.Dats int srcid, // Rom filtering - string romname, - string sha1, + Filter filter, // Rom renaming bool trim, @@ -3486,7 +3392,7 @@ namespace SabreTools.Helper.Dats // Now process and add the rom string key = ""; - ParseAddHelper(rom, null, romname, null, -1, -1, -1, null, null, sha1, ItemStatus.NULL, trim, single, root, clean, logger, out key); + ParseAddHelper(rom, filter, trim, single, root, clean, logger, out key); } sr.Dispose(); @@ -3498,16 +3404,7 @@ namespace SabreTools.Helper.Dats /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT - /// 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 + /// Filter object for passing to the DatItem level /// 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 @@ -3520,16 +3417,7 @@ namespace SabreTools.Helper.Dats int srcid, // Rom filtering - string gamename, - string romname, - string romtype, - long sgt, - long slt, - long seq, - string crc, - string md5, - string sha1, - ItemStatus itemStatus, + Filter filter, // Rom renaming bool trim, @@ -3680,7 +3568,7 @@ namespace SabreTools.Helper.Dats // Now process and add the rom string key = ""; - ParseAddHelper(rom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key); + ParseAddHelper(rom, filter, trim, single, root, clean, logger, out key); } } } @@ -3692,22 +3580,12 @@ namespace SabreTools.Helper.Dats /// Add a rom to the Dat after checking /// /// Item data to check against - /// 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 + /// Filter object for passing to the DatItem level /// 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 /// Logger object for console and/or file output - private void ParseAddHelper(DatItem item, 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, bool clean, Logger logger, out string key) + private void ParseAddHelper(DatItem item, Filter filter, bool trim, bool single, string root, bool clean, Logger logger, out string key) { key = ""; @@ -3782,7 +3660,7 @@ namespace SabreTools.Helper.Dats } // If the rom passes the filter, include it - if (item.Filter(gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, logger)) + if (filter.ItemPasses(item, logger)) { // If we are in single game mode, rename all games if (single) diff --git a/SabreTools.Helper/Dats/DatItem.cs b/SabreTools.Helper/Dats/DatItem.cs index ccce3ef6..6c32e63a 100644 --- a/SabreTools.Helper/Dats/DatItem.cs +++ b/SabreTools.Helper/Dats/DatItem.cs @@ -228,321 +228,6 @@ namespace SabreTools.Helper.Dats #region Sorting and Merging - /// - /// Determine if a rom should be included based on filters - /// - /// 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 - /// Logging object for console and file output - /// Returns true if it should be included, false otherwise - public bool Filter(string gamename, string romname, string romtype, long sgt, - long slt, long seq, string crc, string md5, string sha1, ItemStatus itemStatus, Logger logger) - { - // Take care of Rom and Disk specific differences - if (Type == ItemType.Rom) - { - Rom rom = (Rom)this; - - // Filter on status - if (itemStatus != ItemStatus.NULL) - { - if (itemStatus == ItemStatus.NotNodump && rom.ItemStatus == ItemStatus.Nodump) - { - return false; - } - else if (itemStatus != ItemStatus.NotNodump && rom.ItemStatus != itemStatus) - { - return false; - } - } - - // Filter on rom size - if (seq != -1 && rom.Size != seq) - { - return false; - } - else - { - if (sgt != -1 && rom.Size < sgt) - { - return false; - } - if (slt != -1 && rom.Size > slt) - { - return false; - } - } - - // Filter on crc - if (!String.IsNullOrEmpty(crc)) - { - if (crc.StartsWith("*") && crc.EndsWith("*")) - { - if (!rom.CRC.ToLowerInvariant().Contains(crc.ToLowerInvariant().Replace("*", ""))) - { - return false; - } - } - else if (crc.StartsWith("*")) - { - if (!rom.CRC.EndsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (crc.EndsWith("*")) - { - if (!rom.CRC.StartsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (!String.Equals(rom.CRC, crc, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - } - - // Filter on md5 - if (!String.IsNullOrEmpty(md5)) - { - if (md5.StartsWith("*") && md5.EndsWith("*")) - { - if (!rom.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", ""))) - { - return false; - } - } - else if (md5.StartsWith("*")) - { - if (!rom.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (md5.EndsWith("*")) - { - if (!rom.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (!String.Equals(rom.MD5, md5, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - } - - // Filter on sha1 - if (!String.IsNullOrEmpty(sha1)) - { - if (sha1.StartsWith("*") && sha1.EndsWith("*")) - { - if (!rom.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", ""))) - { - return false; - } - } - else if (sha1.StartsWith("*")) - { - if (!rom.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (sha1.EndsWith("*")) - { - if (!rom.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (!String.Equals(rom.SHA1, sha1, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - } - } - else if (Type == ItemType.Disk) - { - Disk rom = (Disk)this; - - // Filter on status - if (itemStatus != ItemStatus.NULL && rom.ItemStatus != itemStatus) - { - if (itemStatus == ItemStatus.NotNodump && rom.ItemStatus == ItemStatus.Nodump) - { - return false; - } - else if (itemStatus != ItemStatus.NotNodump && rom.ItemStatus != itemStatus) - { - return false; - } - } - - // Filter on md5 - if (!String.IsNullOrEmpty(md5)) - { - if (md5.StartsWith("*") && md5.EndsWith("*")) - { - if (!rom.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", ""))) - { - return false; - } - } - else if (md5.StartsWith("*")) - { - if (!rom.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (md5.EndsWith("*")) - { - if (!rom.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (!String.Equals(rom.MD5, md5, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - } - - // Filter on sha1 - if (!String.IsNullOrEmpty(sha1)) - { - if (sha1.StartsWith("*") && sha1.EndsWith("*")) - { - if (!rom.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", ""))) - { - return false; - } - } - else if (sha1.StartsWith("*")) - { - if (!rom.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (sha1.EndsWith("*")) - { - if (!rom.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (!String.Equals(rom.SHA1, sha1, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - } - } - - // Filter on game name - if (!String.IsNullOrEmpty(gamename)) - { - if (gamename.StartsWith("*") && gamename.EndsWith("*")) - { - if (!Machine.Name.ToLowerInvariant().Contains(gamename.ToLowerInvariant().Replace("*", ""))) - { - return false; - } - } - else if (gamename.StartsWith("*")) - { - if (!Machine.Name.EndsWith(gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (gamename.EndsWith("*")) - { - if (!Machine.Name.StartsWith(gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (!String.Equals(Machine.Name, gamename, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - } - - // Filter on rom name - if (!String.IsNullOrEmpty(romname)) - { - if (romname.StartsWith("*") && romname.EndsWith("*")) - { - if (!Name.ToLowerInvariant().Contains(romname.ToLowerInvariant().Replace("*", ""))) - { - return false; - } - } - else if (romname.StartsWith("*")) - { - if (!Name.EndsWith(romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (romname.EndsWith("*")) - { - if (!Name.StartsWith(romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (!String.Equals(Name, romname, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - } - - // Filter on rom type - if (String.IsNullOrEmpty(romtype) && Type != ItemType.Rom && Type != ItemType.Disk) - { - return false; - } - if (!String.IsNullOrEmpty(romtype) && !String.Equals(Type.ToString(), romtype, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - - return true; - } - /// /// Check if a DAT contains the given rom /// diff --git a/SabreTools.Helper/Dats/Filter.cs b/SabreTools.Helper/Dats/Filter.cs new file mode 100644 index 00000000..173e7246 --- /dev/null +++ b/SabreTools.Helper/Dats/Filter.cs @@ -0,0 +1,374 @@ +using System; + +using SabreTools.Helper.Data; + +namespace SabreTools.Helper.Dats +{ + public class Filter + { + #region Private instance variables + + private string _gameName; + private string _romName; + private string _romType; + private long _sizeGreaterThanOrEqual; + private long _sizeLessThanOrEqual; + private long _sizeEqualTo; + private string _crc; + private string _md5; + private string _sha1; + private ItemStatus _itemStatus; + + #endregion + + /// + /// Create an empty Filter object + /// + public Filter() + { + _gameName = null; + _romName = null; + _romType = null; + _sizeGreaterThanOrEqual = -1; + _sizeLessThanOrEqual = -1; + _sizeEqualTo = -1; + _crc = null; + _md5 = null; + _sha1 = null; + _itemStatus = ItemStatus.NULL; + } + + /// + /// Create a populated Filter object + /// + /// 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 + public Filter(string gamename, string romname, string romtype, long sgt, + long slt, long seq, string crc, string md5, string sha1, ItemStatus itemStatus) + { + _gameName = gamename; + _romName = romname; + _romType = romtype; + _sizeGreaterThanOrEqual = sgt; + _sizeLessThanOrEqual = slt; + _sizeEqualTo = seq; + _crc = crc; + _md5 = md5; + _sha1 = sha1; + _itemStatus = itemStatus; + } + + /// + /// Check to see if a DatItem passes the filter + /// + /// DatItem to check + /// Logger object for file and console output + /// True if the file passed the filter, false otherwise + public bool ItemPasses(DatItem item, Logger logger) + { + // Take care of Rom and Disk specific differences + if (item.Type == ItemType.Rom) + { + Rom rom = (Rom)item; + + // Filter on status + if (_itemStatus != ItemStatus.NULL) + { + if (_itemStatus == ItemStatus.NotNodump && rom.ItemStatus == ItemStatus.Nodump) + { + return false; + } + else if (_itemStatus != ItemStatus.NotNodump && rom.ItemStatus != _itemStatus) + { + return false; + } + } + + // Filter on rom size + if (_sizeEqualTo != -1 && rom.Size != _sizeEqualTo) + { + return false; + } + else + { + if (_sizeGreaterThanOrEqual != -1 && rom.Size < _sizeGreaterThanOrEqual) + { + return false; + } + if (_sizeLessThanOrEqual != -1 && rom.Size > _sizeLessThanOrEqual) + { + return false; + } + } + + // Filter on _crc + if (!String.IsNullOrEmpty(_crc)) + { + if (_crc.StartsWith("*") && _crc.EndsWith("*")) + { + if (!rom.CRC.ToLowerInvariant().Contains(_crc.ToLowerInvariant().Replace("*", ""))) + { + return false; + } + } + else if (_crc.StartsWith("*")) + { + if (!rom.CRC.EndsWith(_crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else if (_crc.EndsWith("*")) + { + if (!rom.CRC.StartsWith(_crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else + { + if (!String.Equals(rom.CRC, _crc, StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + } + + // Filter on _md5 + if (!String.IsNullOrEmpty(_md5)) + { + if (_md5.StartsWith("*") && _md5.EndsWith("*")) + { + if (!rom.MD5.ToLowerInvariant().Contains(_md5.ToLowerInvariant().Replace("*", ""))) + { + return false; + } + } + else if (_md5.StartsWith("*")) + { + if (!rom.MD5.EndsWith(_md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else if (_md5.EndsWith("*")) + { + if (!rom.MD5.StartsWith(_md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else + { + if (!String.Equals(rom.MD5, _md5, StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + } + + // Filter on _sha1 + if (!String.IsNullOrEmpty(_sha1)) + { + if (_sha1.StartsWith("*") && _sha1.EndsWith("*")) + { + if (!rom.SHA1.ToLowerInvariant().Contains(_sha1.ToLowerInvariant().Replace("*", ""))) + { + return false; + } + } + else if (_sha1.StartsWith("*")) + { + if (!rom.SHA1.EndsWith(_sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else if (_sha1.EndsWith("*")) + { + if (!rom.SHA1.StartsWith(_sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else + { + if (!String.Equals(rom.SHA1, _sha1, StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + } + } + else if (item.Type == ItemType.Disk) + { + Disk rom = (Disk)item; + + // Filter on status + if (_itemStatus != ItemStatus.NULL && rom.ItemStatus != _itemStatus) + { + if (_itemStatus == ItemStatus.NotNodump && rom.ItemStatus == ItemStatus.Nodump) + { + return false; + } + else if (_itemStatus != ItemStatus.NotNodump && rom.ItemStatus != _itemStatus) + { + return false; + } + } + + // Filter on _md5 + if (!String.IsNullOrEmpty(_md5)) + { + if (_md5.StartsWith("*") && _md5.EndsWith("*")) + { + if (!rom.MD5.ToLowerInvariant().Contains(_md5.ToLowerInvariant().Replace("*", ""))) + { + return false; + } + } + else if (_md5.StartsWith("*")) + { + if (!rom.MD5.EndsWith(_md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else if (_md5.EndsWith("*")) + { + if (!rom.MD5.StartsWith(_md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else + { + if (!String.Equals(rom.MD5, _md5, StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + } + + // Filter on _sha1 + if (!String.IsNullOrEmpty(_sha1)) + { + if (_sha1.StartsWith("*") && _sha1.EndsWith("*")) + { + if (!rom.SHA1.ToLowerInvariant().Contains(_sha1.ToLowerInvariant().Replace("*", ""))) + { + return false; + } + } + else if (_sha1.StartsWith("*")) + { + if (!rom.SHA1.EndsWith(_sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else if (_sha1.EndsWith("*")) + { + if (!rom.SHA1.StartsWith(_sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else + { + if (!String.Equals(rom.SHA1, _sha1, StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + } + } + + // Filter on game name + if (!String.IsNullOrEmpty(_gameName)) + { + if (_gameName.StartsWith("*") && _gameName.EndsWith("*")) + { + if (!item.Machine.Name.ToLowerInvariant().Contains(_gameName.ToLowerInvariant().Replace("*", ""))) + { + return false; + } + } + else if (_gameName.StartsWith("*")) + { + if (!item.Machine.Name.EndsWith(_gameName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else if (_gameName.EndsWith("*")) + { + if (!item.Machine.Name.StartsWith(_gameName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else + { + if (!String.Equals(item.Machine.Name, _gameName, StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + } + + // Filter on rom name + if (!String.IsNullOrEmpty(_romName)) + { + if (_romName.StartsWith("*") && _romName.EndsWith("*")) + { + if (!item.Name.ToLowerInvariant().Contains(_romName.ToLowerInvariant().Replace("*", ""))) + { + return false; + } + } + else if (_romName.StartsWith("*")) + { + if (!item.Name.EndsWith(_romName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else if (_romName.EndsWith("*")) + { + if (!item.Name.StartsWith(_romName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + else + { + if (!String.Equals(item.Name, _romName, StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + } + } + + // Filter on rom type + if (String.IsNullOrEmpty(_romType) && item.Type != ItemType.Rom && item.Type != ItemType.Disk) + { + return false; + } + if (!String.IsNullOrEmpty(_romType) && !String.Equals(item.Type.ToString(), _romType, StringComparison.InvariantCultureIgnoreCase)) + { + return false; + } + + return true; + } + } +} diff --git a/SabreTools.Helper/SabreTools.Helper.csproj b/SabreTools.Helper/SabreTools.Helper.csproj index 59ce4ab3..261a18a0 100644 --- a/SabreTools.Helper/SabreTools.Helper.csproj +++ b/SabreTools.Helper/SabreTools.Helper.csproj @@ -86,6 +86,7 @@ + diff --git a/SabreTools/Partials/SabreTools_Inits.cs b/SabreTools/Partials/SabreTools_Inits.cs index 25e876b3..cb34d93e 100644 --- a/SabreTools/Partials/SabreTools_Inits.cs +++ b/SabreTools/Partials/SabreTools_Inits.cs @@ -640,8 +640,11 @@ namespace SabreTools Romba = romba, }; + // Create the Filter object to be used + Filter filter = new Filter(gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus); + 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); + filter, trim, single, root, maxDegreeOfParallelism, _logger); } ///