diff --git a/SabreTools.Helper/Data/Build.cs b/SabreTools.Helper/Data/Build.cs index 3c51085d..96b7dc09 100644 --- a/SabreTools.Helper/Data/Build.cs +++ b/SabreTools.Helper/Data/Build.cs @@ -398,6 +398,10 @@ namespace SabreTools.Helper.Data helptext.Add(""); helptext.Add("Filter parameters for size can use postfixes for inputs:"); helptext.Add(" e.g. 8kb => 8000 or 8kib => 8192"); + + helptext.Add(""); + helptext.Add("Most of the filter parameters allow for multiple inputs:"); + helptext.Add(" e.g. --game-name=foo --game-name=bar"); break; default: diff --git a/SabreTools.Helper/Dats/Filter.cs b/SabreTools.Helper/Dats/Filter.cs index 59bd4e6a..b42ae557 100644 --- a/SabreTools.Helper/Dats/Filter.cs +++ b/SabreTools.Helper/Dats/Filter.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using SabreTools.Helper.Data; @@ -8,25 +9,25 @@ namespace SabreTools.Helper.Dats { #region Private instance variables - private string _gameName; - private string _notGameName; - private string _romName; - private string _notRomName; - private string _romType; - private string _notRomType; + private List _gameNames; + private List _notGameNames; + private List _romNames; + private List _notRomNames; + private List _romTypes; + private List _notRomTypes; private long _sizeGreaterThanOrEqual; private long _sizeLessThanOrEqual; private long _sizeEqualTo; - private string _crc; - private string _notCrc; - private string _md5; - private string _notMd5; - private string _sha1; - private string _notSha1; - private ItemStatus _itemStatus; - private ItemStatus _itemNotStatus; - private MachineType _machineType; - private MachineType _machineNotType; + private List _crcs; + private List _notCrcs; + private List _md5s; + private List _notMd5s; + private List _sha1s; + private List _notSha1s; + private ItemStatus _itemStatuses; + private ItemStatus _itemNotStatuses; + private MachineType _machineTypes; + private MachineType _machineNotTypes; private bool? _runnable; #endregion @@ -36,76 +37,76 @@ namespace SabreTools.Helper.Dats /// public Filter() { - _gameName = null; - _notGameName = null; - _romName = null; - _notRomName = null; - _romType = null; - _notRomType = null; + _gameNames = null; + _notGameNames = null; + _romNames = null; + _notRomNames = null; + _romTypes = null; + _notRomTypes = null; _sizeGreaterThanOrEqual = -1; _sizeLessThanOrEqual = -1; _sizeEqualTo = -1; - _crc = null; - _notCrc = null; - _md5 = null; - _notMd5 = null; - _sha1 = null; - _notSha1 = null; - _itemStatus = ItemStatus.NULL; - _itemNotStatus = ItemStatus.NULL; - _machineType = MachineType.NULL; - _machineNotType = MachineType.NULL; + _crcs = null; + _notCrcs = null; + _md5s = null; + _notMd5s = null; + _sha1s = null; + _notSha1s = null; + _itemStatuses = ItemStatus.NULL; + _itemNotStatuses = ItemStatus.NULL; + _machineTypes = MachineType.NULL; + _machineNotTypes = MachineType.NULL; _runnable = 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 + /// Names of the games to match (can use asterisk-partials) + /// Names of the roms to match (can use asterisk-partials) + /// Types of the roms 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 - /// Select games with the given type - /// 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 - /// 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 without the given status - /// Select games without the given type + /// CRCs of the roms to match (can use asterisk-partials) + /// MD5s of the roms to match (can use asterisk-partials) + /// SHA-1s of the roms to match (can use asterisk-partials) + /// Select roms with the given status + /// Select games with the given type + /// Names of the games to match (can use asterisk-partials) + /// Names of the roms to match (can use asterisk-partials) + /// Type of the roms to match + /// CRCs of the roms to match (can use asterisk-partials) + /// MD5s of the roms to match (can use asterisk-partials) + /// SHA-1s of the roms to match (can use asterisk-partials) + /// Select roms without the given status + /// Select games without the given type /// Select games that have a value for runnable - public Filter(string gamename, string romname, string romtype, long sgt, - long slt, long seq, string crc, string md5, string sha1, ItemStatus itemStatus, - MachineType machineType, string notgamename, string notromname, string notromtype, - string notcrc, string notmd5, string notsha1, ItemStatus itemNotStatus, - MachineType machineNotType, bool? runnable) + public Filter(List gamenames, List romnames, List romtypes, long sgt, + long slt, long seq, List crcs, List md5s, List sha1s, ItemStatus itemStatuses, + MachineType machineTypes, List notgamenames, List notromnames, List notromtypes, + List notcrcs, List notmd5s, List notsha1s, ItemStatus itemNotStatuses, + MachineType machineNotTypes, bool? runnable) { - _gameName = gamename; - _notGameName = notgamename; - _romName = romname; - _notRomName = notromname; - _romType = romtype; - _notRomType = notromtype; + _gameNames = gamenames; + _notGameNames = notgamenames; + _romNames = romnames; + _notRomNames = notromnames; + _romTypes = romtypes; + _notRomTypes = notromtypes; _sizeGreaterThanOrEqual = sgt; _sizeLessThanOrEqual = slt; _sizeEqualTo = seq; - _crc = crc; - _notCrc = notcrc; - _md5 = md5; - _notMd5 = notmd5; - _sha1 = sha1; - _notSha1 = notsha1; - _itemStatus = itemStatus; - _itemNotStatus = itemNotStatus; - _machineType = machineType; - _machineNotType = machineNotType; + _crcs = crcs; + _notCrcs = notcrcs; + _md5s = md5s; + _notMd5s = notmd5s; + _sha1s = sha1s; + _notSha1s = notsha1s; + _itemStatuses = itemStatuses; + _itemNotStatuses = itemNotStatuses; + _machineTypes = machineTypes; + _machineNotTypes = machineNotTypes; _runnable = runnable; } @@ -118,11 +119,11 @@ namespace SabreTools.Helper.Dats public bool ItemPasses(DatItem item, Logger logger) { // Filter on machine type - if (_machineType != MachineType.NULL && (item.Machine.MachineType & _machineType) == 0) + if (_machineTypes != MachineType.NULL && (item.Machine.MachineType & _machineTypes) == 0) { return false; } - if (_machineNotType != MachineType.NULL && (item.Machine.MachineType & _machineNotType) != 0) + if (_machineNotTypes != MachineType.NULL && (item.Machine.MachineType & _machineNotTypes) != 0) { return false; } @@ -139,11 +140,11 @@ namespace SabreTools.Helper.Dats Rom rom = (Rom)item; // Filter on status - if (_itemStatus != ItemStatus.NULL && (rom.ItemStatus & _itemStatus) == 0) + if (_itemStatuses != ItemStatus.NULL && (rom.ItemStatus & _itemStatuses) == 0) { return false; } - if (_itemNotStatus != ItemStatus.NULL && (rom.ItemStatus & _itemNotStatus) != 0) + if (_itemNotStatuses != ItemStatus.NULL && (rom.ItemStatus & _itemNotStatuses) != 0) { return false; } @@ -166,194 +167,263 @@ namespace SabreTools.Helper.Dats } // Filter on CRC - if (!String.IsNullOrEmpty(_crc)) + if (_crcs.Count > 0) { - if (_crc.StartsWith("*") && _crc.EndsWith("*")) + bool found = true; + foreach (string crc in _crcs) { - if (!rom.CRC.ToLowerInvariant().Contains(_crc.ToLowerInvariant().Replace("*", ""))) + if (!String.IsNullOrEmpty(crc)) { - return false; + if (crc.StartsWith("*") && crc.EndsWith("*")) + { + if (!rom.CRC.ToLowerInvariant().Contains(crc.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (crc.StartsWith("*")) + { + if (!rom.CRC.EndsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (crc.EndsWith("*")) + { + if (!rom.CRC.StartsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (!String.Equals(rom.CRC, crc, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } } } - else if (_crc.StartsWith("*")) + + // If the CRC didn't match, return false + if (!found) { - 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; - } + return false; } } - if (!String.IsNullOrEmpty(_notCrc)) + if (_notCrcs.Count > 0) { - if (_notCrc.StartsWith("*") && _notCrc.EndsWith("*")) + bool found = true; + foreach (string crc in _notCrcs) { - if (rom.CRC.ToLowerInvariant().Contains(_notCrc.ToLowerInvariant().Replace("*", ""))) + if (crc.StartsWith("*") && crc.EndsWith("*")) { - return false; + if (rom.CRC.ToLowerInvariant().Contains(crc.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (crc.StartsWith("*")) + { + if (rom.CRC.EndsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (crc.EndsWith("*")) + { + if (rom.CRC.StartsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (String.Equals(rom.CRC, crc, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } } } - else if (_notCrc.StartsWith("*")) + + // If the CRC matched, return false + if (!found) { - if (rom.CRC.EndsWith(_notCrc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (_notCrc.EndsWith("*")) - { - if (rom.CRC.StartsWith(_notCrc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (String.Equals(rom.CRC, _notCrc, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } + return false; } } // Filter on MD5 - if (!String.IsNullOrEmpty(_md5)) + if (_md5s.Count > 0) { - if (_md5.StartsWith("*") && _md5.EndsWith("*")) + bool found = true; + foreach (string md5 in _md5s) { - if (!rom.MD5.ToLowerInvariant().Contains(_md5.ToLowerInvariant().Replace("*", ""))) + if (!String.IsNullOrEmpty(md5)) { - return false; + if (md5.StartsWith("*") && md5.EndsWith("*")) + { + if (!rom.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (md5.StartsWith("*")) + { + if (!rom.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (md5.EndsWith("*")) + { + if (!rom.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (!String.Equals(rom.MD5, md5, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } } } - else if (_md5.StartsWith("*")) + + // If the MD5 didn't match, return false + if (!found) { - 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; - } + return false; } } - if (!String.IsNullOrEmpty(_notMd5)) + if (_notMd5s.Count > 0) { - if (_notMd5.StartsWith("*") && _notMd5.EndsWith("*")) + bool found = true; + foreach (string md5 in _notMd5s) { - if (rom.MD5.ToLowerInvariant().Contains(_notMd5.ToLowerInvariant().Replace("*", ""))) + if (md5.StartsWith("*") && md5.EndsWith("*")) { - return false; + if (rom.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (md5.StartsWith("*")) + { + if (rom.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (md5.EndsWith("*")) + { + if (rom.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (String.Equals(rom.MD5, md5, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } } } - else if (_notMd5.StartsWith("*")) + + // If the MD5 matched, return false + if (!found) { - if (rom.MD5.EndsWith(_notMd5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (_notMd5.EndsWith("*")) - { - if (rom.MD5.StartsWith(_notMd5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (String.Equals(rom.MD5, _notMd5, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } + return false; } } // Filter on SHA1 - if (!String.IsNullOrEmpty(_sha1)) + if (_sha1s.Count > 0) { - if (_sha1.StartsWith("*") && _sha1.EndsWith("*")) + bool found = true; + foreach (string sha1 in _sha1s) { - if (!rom.SHA1.ToLowerInvariant().Contains(_sha1.ToLowerInvariant().Replace("*", ""))) + if (!String.IsNullOrEmpty(sha1)) { - return false; + if (sha1.StartsWith("*") && sha1.EndsWith("*")) + { + if (!rom.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (sha1.StartsWith("*")) + { + if (!rom.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (sha1.EndsWith("*")) + { + if (!rom.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (!String.Equals(rom.SHA1, sha1, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } } } - else if (_sha1.StartsWith("*")) + + // If the SHA1 didn't match, return false + if (!found) { - 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; - } + return false; } } - if (!String.IsNullOrEmpty(_notSha1)) + if (_notSha1s.Count > 0) { - if (_notSha1.StartsWith("*") && _notSha1.EndsWith("*")) + bool found = true; + foreach (string sha1 in _notSha1s) { - if (rom.SHA1.ToLowerInvariant().Contains(_notSha1.ToLowerInvariant().Replace("*", ""))) + if (sha1.StartsWith("*") && sha1.EndsWith("*")) { - return false; + if (rom.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (sha1.StartsWith("*")) + { + if (rom.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (sha1.EndsWith("*")) + { + if (rom.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (String.Equals(rom.SHA1, sha1, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } } } - else if (_notSha1.StartsWith("*")) + + // If the SHA1 matched, return false + if (!found) { - if (rom.SHA1.EndsWith(_notSha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (_notSha1.EndsWith("*")) - { - if (rom.SHA1.StartsWith(_notSha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (String.Equals(rom.SHA1, _notSha1, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } + return false; } } } @@ -362,284 +432,396 @@ namespace SabreTools.Helper.Dats Disk rom = (Disk)item; // Filter on status - if (_itemStatus != ItemStatus.NULL && (rom.ItemStatus & _itemStatus) == 0) + if (_itemStatuses != ItemStatus.NULL && (rom.ItemStatus & _itemStatuses) == 0) { return false; } - if (_itemNotStatus != ItemStatus.NULL && (rom.ItemStatus & _itemNotStatus) != 0) + if (_itemNotStatuses != ItemStatus.NULL && (rom.ItemStatus & _itemNotStatuses) != 0) { return false; } // Filter on MD5 - if (!String.IsNullOrEmpty(_md5)) + if (_md5s.Count > 0) { - if (_md5.StartsWith("*") && _md5.EndsWith("*")) + bool found = true; + foreach (string md5 in _md5s) { - if (!rom.MD5.ToLowerInvariant().Contains(_md5.ToLowerInvariant().Replace("*", ""))) + if (!String.IsNullOrEmpty(md5)) { - return false; + if (md5.StartsWith("*") && md5.EndsWith("*")) + { + if (!rom.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (md5.StartsWith("*")) + { + if (!rom.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (md5.EndsWith("*")) + { + if (!rom.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (!String.Equals(rom.MD5, md5, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } } } - else if (_md5.StartsWith("*")) + + // If the MD5 didn't match, return false + if (!found) { - 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; - } + return false; } } - if (!String.IsNullOrEmpty(_notMd5)) + if (_notMd5s.Count > 0) { - if (_notMd5.StartsWith("*") && _notMd5.EndsWith("*")) + bool found = true; + foreach (string md5 in _notMd5s) { - if (rom.MD5.ToLowerInvariant().Contains(_notMd5.ToLowerInvariant().Replace("*", ""))) + if (md5.StartsWith("*") && md5.EndsWith("*")) { - return false; + if (rom.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (md5.StartsWith("*")) + { + if (rom.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (md5.EndsWith("*")) + { + if (rom.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (String.Equals(rom.MD5, md5, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } } } - else if (_notMd5.StartsWith("*")) + + // If the MD5 matched, return false + if (!found) { - if (rom.MD5.EndsWith(_notMd5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (_notMd5.EndsWith("*")) - { - if (rom.MD5.StartsWith(_notMd5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (String.Equals(rom.MD5, _notMd5, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } + return false; } } // Filter on SHA1 - if (!String.IsNullOrEmpty(_sha1)) + if (_sha1s.Count > 0) { - if (_sha1.StartsWith("*") && _sha1.EndsWith("*")) + bool found = true; + foreach (string sha1 in _sha1s) { - if (!rom.SHA1.ToLowerInvariant().Contains(_sha1.ToLowerInvariant().Replace("*", ""))) + if (!String.IsNullOrEmpty(sha1)) { - return false; + if (sha1.StartsWith("*") && sha1.EndsWith("*")) + { + if (!rom.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (sha1.StartsWith("*")) + { + if (!rom.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (sha1.EndsWith("*")) + { + if (!rom.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (!String.Equals(rom.SHA1, sha1, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } } } - else if (_sha1.StartsWith("*")) + + // If the SHA1 didn't match, return false + if (!found) { - 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; - } + return false; } } - if (!String.IsNullOrEmpty(_notSha1)) + if (_notSha1s.Count > 0) { - if (_notSha1.StartsWith("*") && _notSha1.EndsWith("*")) + bool found = true; + foreach (string sha1 in _notSha1s) { - if (rom.SHA1.ToLowerInvariant().Contains(_notSha1.ToLowerInvariant().Replace("*", ""))) + if (sha1.StartsWith("*") && sha1.EndsWith("*")) { - return false; + if (rom.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (sha1.StartsWith("*")) + { + if (rom.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (sha1.EndsWith("*")) + { + if (rom.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (String.Equals(rom.SHA1, sha1, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } } } - else if (_notSha1.StartsWith("*")) + + // If the SHA1 matched, return false + if (!found) { - if (rom.SHA1.EndsWith(_notSha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (_notSha1.EndsWith("*")) - { - if (rom.SHA1.StartsWith(_notSha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (String.Equals(rom.SHA1, _notSha1, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } + return false; } } } // Filter on game name - if (!String.IsNullOrEmpty(_gameName)) + if (_gameNames.Count > 0) { - if (_gameName.StartsWith("*") && _gameName.EndsWith("*")) + bool found = true; + foreach (string name in _gameNames) { - if (!item.Machine.Name.ToLowerInvariant().Contains(_gameName.ToLowerInvariant().Replace("*", ""))) + if (name.StartsWith("*") && name.EndsWith("*")) { - return false; + if (!item.Machine.Name.ToLowerInvariant().Contains(name.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (name.StartsWith("*")) + { + if (!item.Machine.Name.EndsWith(name.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (name.EndsWith("*")) + { + if (!item.Machine.Name.StartsWith(name.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (!String.Equals(item.Machine.Name, name, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } } } - else if (_gameName.StartsWith("*")) + + // If the game name was not matched, return false + if (!found) { - 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; - } + return false; } } - if (!String.IsNullOrEmpty(_notGameName)) + if (_notGameNames.Count > 0) { - if (_notGameName.StartsWith("*") && _notGameName.EndsWith("*")) + bool found = true; + foreach (string name in _notGameNames) { - if (item.Machine.Name.ToLowerInvariant().Contains(_notGameName.ToLowerInvariant().Replace("*", ""))) + if (name.StartsWith("*") && name.EndsWith("*")) { - return false; + if (item.Machine.Name.ToLowerInvariant().Contains(name.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (name.StartsWith("*")) + { + if (item.Machine.Name.EndsWith(name.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (name.EndsWith("*")) + { + if (item.Machine.Name.StartsWith(name.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (String.Equals(item.Machine.Name, name, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } } } - else if (_notGameName.StartsWith("*")) + + // If the game name was matched, return false + if (!found) { - if (item.Machine.Name.EndsWith(_notGameName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (_notGameName.EndsWith("*")) - { - if (item.Machine.Name.StartsWith(_notGameName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (String.Equals(item.Machine.Name, _notGameName, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } + return false; } } // Filter on rom name - if (!String.IsNullOrEmpty(_romName)) + if (_romNames.Count > 0) { - if (_romName.StartsWith("*") && _romName.EndsWith("*")) + bool found = true; + foreach (string name in _romNames) { - if (!item.Name.ToLowerInvariant().Contains(_romName.ToLowerInvariant().Replace("*", ""))) + if (name.StartsWith("*") && name.EndsWith("*")) { - return false; + if (!item.Name.ToLowerInvariant().Contains(name.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (name.StartsWith("*")) + { + if (!item.Name.EndsWith(name.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (name.EndsWith("*")) + { + if (!item.Name.StartsWith(name.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (!String.Equals(item.Name, name, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } } } - else if (_romName.StartsWith("*")) + + // If the rom name was not matched, return false + if (!found) { - 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; - } + return false; } } - if (!String.IsNullOrEmpty(_notRomName)) + if (_notRomNames.Count > 0) { - if (_notRomName.StartsWith("*") && _notRomName.EndsWith("*")) + bool found = true; + foreach (string name in _notRomNames) { - if (item.Name.ToLowerInvariant().Contains(_notRomName.ToLowerInvariant().Replace("*", ""))) + if (name.StartsWith("*") && name.EndsWith("*")) { - return false; + if (item.Name.ToLowerInvariant().Contains(name.ToLowerInvariant().Replace("*", ""))) + { + found = false; + } + } + else if (name.StartsWith("*")) + { + if (item.Name.EndsWith(name.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else if (name.EndsWith("*")) + { + if (item.Name.StartsWith(name.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + else + { + if (String.Equals(item.Name, name, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } } } - else if (_notRomName.StartsWith("*")) + + // If the rom name was matched, return false + if (!found) { - if (item.Name.EndsWith(_notRomName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else if (_notRomName.EndsWith("*")) - { - if (item.Name.StartsWith(_notRomName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - } - else - { - if (String.Equals(item.Name, _notRomName, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } + return false; } } // Filter on rom type - if (String.IsNullOrEmpty(_romType) && String.IsNullOrEmpty(_notRomType) && item.Type != ItemType.Rom && item.Type != ItemType.Disk) + if (_romTypes.Count == 0 && _notRomTypes.Count == 0 && item.Type != ItemType.Rom && item.Type != ItemType.Disk) { return false; } - if (!String.IsNullOrEmpty(_romType) && !String.Equals(item.Type.ToString(), _romType, StringComparison.InvariantCultureIgnoreCase)) + if (_romTypes.Count > 0) { - return false; + bool found = true; + foreach (string type in _romTypes) + { + if (!String.Equals(item.Type.ToString(), type, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + + // If the rom type was not found, return false + if (!found) + { + return false; + } } - if (!String.IsNullOrEmpty(_notRomType) && String.Equals(item.Type.ToString(), _notRomType, StringComparison.InvariantCultureIgnoreCase)) + if (_notRomTypes.Count > 0) { - return false; + bool found = true; + foreach (string type in _notRomTypes) + { + if (String.Equals(item.Type.ToString(), type, StringComparison.InvariantCultureIgnoreCase)) + { + found = false; + } + } + + // If the rom type was found, return false + if (!found) + { + return false; + } } return true; diff --git a/SabreTools.Helper/README.1ST b/SabreTools.Helper/README.1ST index 80c22592..294f2759 100644 --- a/SabreTools.Helper/README.1ST +++ b/SabreTools.Helper/README.1ST @@ -823,12 +823,15 @@ Options: 00* means starts with '00' *00* means contains '00' 00 means exactly equals '00' + Multiples of each of the above inputs are allowed. -rt=, --rom-type= Filter by rom type - This allows users to only include roms or disks to their liking + This allows users to only include roms or disks to their liking. Multiples of this + input are allowed. -nrt=, --not-type= Exclude by rom type - This allows users to only exclude roms or disks to their liking + This allows users to only exclude roms or disks to their liking. Multiples of this + input are allowed. -sgt=, --greater= Filter by size >= -slt=, --less= Filter by size <= diff --git a/SabreTools/Partials/SabreTools_Inits.cs b/SabreTools/Partials/SabreTools_Inits.cs index 6bed2a9f..e71bcd0e 100644 --- a/SabreTools/Partials/SabreTools_Inits.cs +++ b/SabreTools/Partials/SabreTools_Inits.cs @@ -427,23 +427,23 @@ namespace SabreTools /// 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] /// /* Filtering info */ - /// 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 + /// Names of the games to match (can use asterisk-partials) + /// Names of the roms to match (can use asterisk-partials) + /// Types of the roms 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) + /// CRCs of the roms to match (can use asterisk-partials) + /// MD5s of the roms to match (can use asterisk-partials) + /// SHA-1s of the roms to match (can use asterisk-partials) /// Select roms with the given item statuses /// Select games with the given types - /// 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 - /// 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) + /// 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 + /// CRCs of the roms to match (can use asterisk-partials) + /// MD5s of the roms to match (can use asterisk-partials) + /// SHA-1s of the roms to match (can use asterisk-partials) /// Select roms without the given item statuses /// Select games without the given types /// Select games with the given runability @@ -500,23 +500,23 @@ namespace SabreTools bool bare, /* Filtering info */ - string gamename, - string romname, - string romtype, + List gamenames, + List romnames, + List romtypes, long sgt, long slt, long seq, - string crc, - string md5, - string sha1, + List crcs, + List md5s, + List sha1s, List statuses, List gametypes, - string notgamename, - string notromname, - string notromtype, - string notcrc, - string notmd5, - string notsha1, + List notgamenames, + List notromnames, + List notromtypes, + List notcrcs, + List notmd5s, + List notsha1s, List notstatuses, List notgametypes, bool? runnable, @@ -767,8 +767,8 @@ namespace SabreTools }; // Create the Filter object to be used - Filter filter = new Filter(gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, machineType, - notgamename, notromname, notromtype, notcrc, notmd5, notsha1, itemNotStatus, machineNotType, runnable); + Filter filter = new Filter(gamenames, romnames, romtypes, sgt, slt, seq, crcs, md5s, sha1s, itemStatus, machineType, + notgamenames, notromnames, notromtypes, notcrcs, notmd5s, notsha1s, itemNotStatus, machineNotType, runnable); userInputDat.DetermineUpdateType(inputs, outDir, merge, diffMode, inplace, skip, bare, clean, softlist, filter, splitType, trim, single, root, maxDegreeOfParallelism, _logger); diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index 589f507e..d2b5f4d6 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -118,7 +118,6 @@ namespace SabreTools author = null, category = null, comment = null, - crc = "", date = null, description = null, email = null, @@ -128,48 +127,37 @@ namespace SabreTools forcemerge = "", forcend = "", forcepack = "", - gamename = "", header = null, homepage = null, - md5 = "", name = null, - notcrc = null, - notgamename = null, - notmd5 = null, - notromname = null, - notromtype = null, - notsha1 = null, outDir = "", postfix = "", prefix = "", repext = "", - romname = "", - romtype = "", root = "", rootdir = null, - sha1 = "", tempDir = "", url = null, version = null; - //List crc = new List(); + List crc = new List(); List datfiles = new List(); // SimpleSort //List exta = new List(); //List extb = new List(); - //List gamename = new List(); + List gamename = new List(); List gametype = new List(); List inputs = new List(); - //List md5 = new List(); - //List notcrc = new List(); - //List notgamename = new List(); + List md5 = new List(); + List notcrc = new List(); + List notgamename = new List(); List notgametype = new List(); - //List notmd5 = new List(); - //List notromname = new List(); - //List notromtype = new List(); - //List notsha1 = new List(); + List notmd5 = new List(); + List notromname = new List(); + List notromtype = new List(); + List notsha1 = new List(); List notstatus = new List(); - //List romname = new List(); - //List romtype = new List(); - //List sha1 = new List(); + List romname = new List(); + List romtype = new List(); + List sha1 = new List(); List status = new List(); // Determine which switches are enabled (with values if necessary) @@ -529,7 +517,7 @@ namespace SabreTools break; case "-crc": case "--crc": - crc = args[++i]; + crc.Add(args[++i]); break; case "-da": case "--date": @@ -580,7 +568,7 @@ namespace SabreTools break; case "-gn": case "--game-name": - gamename = args[++i]; + gamename.Add(args[++i]); break; case "-gt": case "--game-type": @@ -607,7 +595,7 @@ namespace SabreTools break; case "-md5": case "--md5": - md5 = args[++i]; + md5.Add(args[++i]); break; case "-mt": case "--mt": @@ -619,11 +607,11 @@ namespace SabreTools break; case "-ncrc": case "--not-crc": - notcrc = args[++i]; + notcrc.Add(args[++i]); break; case "-ngn": case "--not-game": - notgamename = args[++i]; + notgamename.Add(args[++i]); break; case "-ngt": case "--not-gtype": @@ -635,19 +623,19 @@ namespace SabreTools break; case "-nmd5": case "--not-md5": - notmd5 = args[++i]; + notmd5.Add(args[++i]); break; case "-nrn": case "--not-rom": - notromname = args[++i]; + notromname.Add(args[++i]); break; case "-nrt": case "--not-type": - notromtype = args[++i]; + notromtype.Add(args[++i]); break; case "-nsha1": case "--not-sha1": - notsha1 = args[++i]; + notsha1.Add(args[++i]); break; case "-out": case "--out": @@ -678,7 +666,7 @@ namespace SabreTools break; case "-rn": case "--rom-name": - romname = args[++i]; + romname.Add(args[++i]); break; case "-root": case "--root": @@ -686,7 +674,7 @@ namespace SabreTools break; case "-rt": case "--rom-type": - romtype = args[++i]; + romtype.Add(args[++i]); break; case "-seq": case "--equal": @@ -698,7 +686,7 @@ namespace SabreTools break; case "-sha1": case "--sha1": - sha1 = args[++i]; + sha1.Add(args[++i]); break; case "-slt": case "--less": @@ -763,7 +751,7 @@ namespace SabreTools break; case "-crc": case "--crc": - crc = split[1]; + crc.Add(split[1]); break; case "-da": case "--date": @@ -813,7 +801,7 @@ namespace SabreTools break; case "-gn": case "--game-name": - gamename = split[1]; + gamename.Add(split[1]); break; case "-gt": case "--game-type": @@ -840,7 +828,7 @@ namespace SabreTools break; case "-md5": case "--md5": - md5 = split[1]; + md5.Add(split[1]); break; case "-mt": case "--mt": @@ -852,11 +840,11 @@ namespace SabreTools break; case "-ncrc": case "--not-crc": - notcrc = split[1]; + notcrc.Add(split[1]); break; case "-ngn": case "--not-game": - notgamename = split[1]; + notgamename.Add(split[1]); break; case "-ngt": case "--not-gtype": @@ -868,19 +856,19 @@ namespace SabreTools break; case "-nmd5": case "--not-md5": - notmd5 = split[1]; + notmd5.Add(split[1]); break; case "-nrn": case "--not-rom": - notromname = split[1]; + notromname.Add(split[1]); break; case "-nrt": case "--not-type": - notromtype = split[1]; + notromtype.Add(split[1]); break; case "-nsha1": case "--not-sha1": - notsha1 = split[1]; + notsha1.Add(split[1]); break; case "-out": case "--out": @@ -915,11 +903,11 @@ namespace SabreTools break; case "-rn": case "--rom-name": - romname = split[1]; + romname.Add(split[1]); break; case "-rt": case "--rom-type": - romtype = split[1]; + romtype.Add(split[1]); break; case "-seq": case "--equal": @@ -931,7 +919,7 @@ namespace SabreTools break; case "-sha1": case "--sha1": - sha1 = split[1]; + sha1.Add(split[1]); break; case "-slt": case "--less":