diff --git a/SabreTools.Helper/Tools/DatTools.cs b/SabreTools.Helper/Tools/DatTools.cs index 2ca2198a..b97dc3f2 100644 --- a/SabreTools.Helper/Tools/DatTools.cs +++ b/SabreTools.Helper/Tools/DatTools.cs @@ -1867,198 +1867,6 @@ namespace SabreTools.Helper return datHeaders; } - /// - /// Filter an input DAT file - /// - /// User specified inputs contained in a DatData 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 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 - /// Logging object for console and file output - /// Returns filtered DatData object - public static Dat Filter(Dat datdata, 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, Logger logger) - { - // Now loop through and create a new Rom dictionary using filtered values - Dictionary> dict = new Dictionary>(); - List keys = datdata.Files.Keys.ToList(); - foreach (string key in keys) - { - List roms = datdata.Files[key]; - for (int i = 0; i < roms.Count; i++) - { - Rom rom = roms[i]; - - // Filter on nodump status - if (nodump == true && !rom.Nodump) - { - continue; - } - if (nodump == false && rom.Nodump) - { - continue; - } - - // Filter on game name - if (gamename != "") - { - if (gamename.StartsWith("*") && gamename.EndsWith("*") && !rom.Machine.Name.ToLowerInvariant().Contains(gamename.ToLowerInvariant().Replace("*", ""))) - { - continue; - } - else if (gamename.StartsWith("*") && !rom.Machine.Name.EndsWith(gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - else if (gamename.EndsWith("*") && !rom.Machine.Name.StartsWith(gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - } - - // Filter on rom name - if (romname != "") - { - if (romname.StartsWith("*") && romname.EndsWith("*") && !rom.Name.ToLowerInvariant().Contains(romname.ToLowerInvariant().Replace("*", ""))) - { - continue; - } - else if (romname.StartsWith("*") && !rom.Name.EndsWith(romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - else if (romname.EndsWith("*") && !rom.Name.StartsWith(romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - } - - // Filter on rom type - if (romtype != "" && rom.Type.ToString().ToLowerInvariant() != romtype.ToLowerInvariant()) - { - continue; - } - - // Filter on rom size - if (seq != -1 && rom.HashData.Size != seq) - { - continue; - } - else - { - if (sgt != -1 && rom.HashData.Size < sgt) - { - continue; - } - if (slt != -1 && rom.HashData.Size > slt) - { - continue; - } - } - - // Filter on crc - if (crc != "") - { - if (crc.StartsWith("*") && crc.EndsWith("*") && !rom.HashData.CRC.ToLowerInvariant().Contains(crc.ToLowerInvariant().Replace("*", ""))) - { - continue; - } - else if (crc.StartsWith("*") && !rom.HashData.CRC.EndsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - else if (crc.EndsWith("*") && !rom.HashData.CRC.StartsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - } - - // Filter on md5 - if (md5 != "") - { - if (md5.StartsWith("*") && md5.EndsWith("*") && !rom.HashData.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", ""))) - { - continue; - } - else if (md5.StartsWith("*") && !rom.HashData.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - else if (md5.EndsWith("*") && !rom.HashData.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - } - - // Filter on sha1 - if (sha1 != "") - { - if (sha1.StartsWith("*") && sha1.EndsWith("*") && !rom.HashData.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", ""))) - { - continue; - } - else if (sha1.StartsWith("*") && !rom.HashData.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - else if (sha1.EndsWith("*") && !rom.HashData.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - } - - // If we are in single game mode, rename all games - if (single) - { - rom.Machine.Name = "!"; - } - - // If we are in NTFS trim mode, trim the game name - if (trim) - { - // Windows max name length is 260 - int usableLength = 260 - rom.Machine.Name.Length - root.Length; - if (rom.Name.Length > usableLength) - { - string ext = Path.GetExtension(rom.Name); - rom.Name = rom.Name.Substring(0, usableLength - ext.Length); - rom.Name += ext; - } - } - - // If it made it this far, add the rom to the output dictionary - if (dict.ContainsKey(key)) - { - dict[key].Add(rom); - } - else - { - List temp = new List(); - temp.Add(rom); - dict.Add(key, temp); - } - } - - // Now clean up by removing the old list - datdata.Files[key] = null; - } - - // Resassign the new dictionary to the DatData object - datdata.Files = dict; - - return datdata; - } - /// /// Determine if a rom should be included based on filters ///