diff --git a/SabreTools.Helper/Dats/Filter.cs b/SabreTools.Helper/Dats/Filter.cs index 46c78d0e..1cf5ca7b 100644 --- a/SabreTools.Helper/Dats/Filter.cs +++ b/SabreTools.Helper/Dats/Filter.cs @@ -9,106 +9,199 @@ namespace SabreTools.Helper.Dats { #region Private instance variables + #region Positive + private List _gameNames; - private List _notGameNames; private List _romNames; - private List _notRomNames; private List _romTypes; + private List _crcs; + private List _md5s; + private List _sha1s; + private ItemStatus _itemStatuses; + private MachineType _machineTypes; + + #endregion + + #region Negative + + private List _notGameNames; + private List _notRomNames; private List _notRomTypes; + private List _notCrcs; + private List _notMd5s; + private List _notSha1s; + private ItemStatus _itemNotStatuses; + private MachineType _machineNotTypes; + + #endregion + + #region Neutral + private long _sizeGreaterThanOrEqual; private long _sizeLessThanOrEqual; private long _sizeEqualTo; - 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 + #endregion // Private instance variables + + #region Pubically facing variables + + #region Positive + + public List GameNames + { + get { return _gameNames; } + set { _gameNames = value; } + } + public List RomNames + { + get { return _romNames; } + set { _romNames = value; } + } + public List RomTypes + { + get { return _romTypes; } + set { _romTypes = value; } + } + public List CRCs + { + get { return _crcs; } + set { _crcs = value; } + } + public List MD5s + { + get { return _md5s; } + set { _md5s = value; } + } + public List SHA1s + { + get { return _sha1s; } + set { _sha1s = value; } + } + public ItemStatus ItemStatuses + { + get { return _itemStatuses; } + set { _itemStatuses = value; } + } + public MachineType MachineTypes + { + get { return _machineTypes; } + set { _machineTypes = value; } + } + + #endregion + + #region Negative + + public List NotGameNames + { + get { return _notGameNames; } + set { _notGameNames = value; } + } + public List NotRomNames + { + get { return _notRomNames; } + set { _notRomNames = value; } + } + public List NotRomTypes + { + get { return _notRomTypes; } + set { _notRomTypes = value; } + } + public List NotCRCs + { + get { return _notCrcs; } + set { _notCrcs = value; } + } + public List NotMD5s + { + get { return _notMd5s; } + set { _notMd5s = value; } + } + public List NotSHA1s + { + get { return _notSha1s; } + set { _notSha1s = value; } + } + public ItemStatus NotItemStatuses + { + get { return _itemNotStatuses; } + set { _itemNotStatuses = value; } + } + public MachineType NotMachineTypes + { + get { return _machineNotTypes; } + set { _machineNotTypes = value; } + } + + #endregion + + #region Neutral + + public long SizeGreaterThanOrEqual + { + get { return _sizeGreaterThanOrEqual; } + set { _sizeGreaterThanOrEqual = value; } + } + public long SizeLessThanOrEqual + { + get { return _sizeLessThanOrEqual; } + set { _sizeLessThanOrEqual = value; } + } + public long SizeEqualTo + { + get { return _sizeEqualTo; } + set { _sizeEqualTo = value; } + } + public bool? Runnable + { + get { return _runnable; } + set { _runnable = value; } + } + + #endregion + + #endregion // Pubically facing variables + + #region Constructors + /// /// Create an empty Filter object /// public Filter() { + // Positive _gameNames = new List(); - _notGameNames = new List(); _romNames = new List(); - _notRomNames = new List(); _romTypes = new List(); + _crcs = new List(); + _md5s = new List(); + _sha1s = new List(); + _itemStatuses = ItemStatus.NULL; + _machineTypes = MachineType.NULL; + + // Negative + _notGameNames = new List(); + _notRomNames = new List(); _notRomTypes = new List(); + _notCrcs = new List(); + _notMd5s = new List(); + _notSha1s = new List(); + _itemNotStatuses = ItemStatus.NULL; + _machineNotTypes = MachineType.NULL; + + // Neutral _sizeGreaterThanOrEqual = -1; _sizeLessThanOrEqual = -1; _sizeEqualTo = -1; - _crcs = new List(); - _notCrcs = new List(); - _md5s = new List(); - _notMd5s = new List(); - _sha1s = new List(); - _notSha1s = new List(); - _itemStatuses = ItemStatus.NULL; - _itemNotStatuses = ItemStatus.NULL; - _machineTypes = MachineType.NULL; - _machineNotTypes = MachineType.NULL; _runnable = null; } - /// - /// Create a populated Filter object - /// - /// 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 - /// 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(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) - { - _gameNames = gamenames; - _notGameNames = notgamenames; - _romNames = romnames; - _notRomNames = notromnames; - _romTypes = romtypes; - _notRomTypes = notromtypes; - _sizeGreaterThanOrEqual = sgt; - _sizeLessThanOrEqual = slt; - _sizeEqualTo = seq; - _crcs = crcs; - _notCrcs = notcrcs; - _md5s = md5s; - _notMd5s = notmd5s; - _sha1s = sha1s; - _notSha1s = notsha1s; - _itemStatuses = itemStatuses; - _itemNotStatuses = itemNotStatuses; - _machineTypes = machineTypes; - _machineNotTypes = machineNotTypes; - _runnable = runnable; - } + #endregion + + #region Instance methods /// /// Check to see if a DatItem passes the filter @@ -838,5 +931,78 @@ namespace SabreTools.Helper.Dats return true; } + + #endregion + + #region Static methods + + /// + /// Get the machine type from a string + /// + /// Machine type as a string + /// Logger object for file and console output + /// A machine type based on the input + public static MachineType GetMachneTypeFromString(string gametype, Logger logger) + { + MachineType machineType = MachineType.NULL; + switch (gametype.ToLowerInvariant()) + { + case "none": + machineType |= MachineType.None; + break; + case "bios": + machineType |= MachineType.Bios; + break; + case "dev": + case "device": + machineType |= MachineType.Device; + break; + case "mech": + case "mechanical": + machineType |= MachineType.Mechanical; + break; + default: + logger.Warning(gametype + " is not a valid type"); + break; + } + + return machineType; + } + + /// + /// Get the item status from a string + /// + /// Item status as a string + /// Logger object for file and console output + /// An item status based on the input + public static ItemStatus GetStatusFromString(string status, Logger logger) + { + ItemStatus itemStatus = ItemStatus.NULL; + switch (status.ToLowerInvariant()) + { + case "none": + itemStatus |= ItemStatus.None; + break; + case "good": + itemStatus |= ItemStatus.Good; + break; + case "baddump": + itemStatus |= ItemStatus.BadDump; + break; + case "nodump": + itemStatus |= ItemStatus.Nodump; + break; + case "verified": + itemStatus |= ItemStatus.Verified; + break; + default: + logger.Warning(status + " is not a valid status"); + break; + } + + return itemStatus; + } + + #endregion } } diff --git a/SabreTools/Partials/SabreTools.Inits.cs b/SabreTools/Partials/SabreTools.Inits.cs index 2e980d39..5b4efb75 100644 --- a/SabreTools/Partials/SabreTools.Inits.cs +++ b/SabreTools/Partials/SabreTools.Inits.cs @@ -460,26 +460,7 @@ 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 */ - /// 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 - /// 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 - /// 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 + /// Pre-populated filter object for DAT filtering /// /* Trimming info */ /// Type of the split that should be performed (split, merged, fully merged) /// True if we are supposed to trim names to NTFS length, false otherwise @@ -533,26 +514,7 @@ namespace SabreTools bool bare, /* Filtering info */ - List gamenames, - List romnames, - List romtypes, - long sgt, - long slt, - long seq, - List crcs, - List md5s, - List sha1s, - List statuses, - List gametypes, - List notgamenames, - List notromnames, - List notromtypes, - List notcrcs, - List notmd5s, - List notsha1s, - List notstatuses, - List notgametypes, - bool? runnable, + Filter filter, /* Trimming info */ SplitType splitType, @@ -565,7 +527,7 @@ namespace SabreTools bool clean, bool softlist, bool dedup, - + /* Multithreading info */ int maxDegreeOfParallelism) { @@ -633,112 +595,6 @@ namespace SabreTools } } - // Set the status flag for filtering - ItemStatus itemStatus = ItemStatus.NULL; - foreach (string status in statuses) - { - switch (status.ToLowerInvariant()) - { - case "none": - itemStatus |= ItemStatus.None; - break; - case "good": - itemStatus |= ItemStatus.Good; - break; - case "baddump": - itemStatus |= ItemStatus.BadDump; - break; - case "nodump": - itemStatus |= ItemStatus.Nodump; - break; - case "verified": - itemStatus |= ItemStatus.Verified; - break; - default: - _logger.Warning(status + " is not a valid status"); - break; - } - } - - // Set the not status flag for filtering - ItemStatus itemNotStatus = ItemStatus.NULL; - foreach (string status in notstatuses) - { - switch (status.ToLowerInvariant()) - { - case "none": - itemNotStatus |= ItemStatus.None; - break; - case "good": - itemNotStatus |= ItemStatus.Good; - break; - case "baddump": - itemNotStatus |= ItemStatus.BadDump; - break; - case "nodump": - itemNotStatus |= ItemStatus.Nodump; - break; - case "verified": - itemNotStatus |= ItemStatus.Verified; - break; - default: - _logger.Warning(status + " is not a valid status"); - break; - } - } - - // Set the machine type flag for filtering - MachineType machineType = MachineType.NULL; - foreach (string gametype in gametypes) - { - switch (gametype.ToLowerInvariant()) - { - case "none": - machineType |= MachineType.None; - break; - case "bios": - machineType |= MachineType.Bios; - break; - case "dev": - case "device": - machineType |= MachineType.Device; - break; - case "mech": - case "mechanical": - machineType |= MachineType.Mechanical; - break; - default: - _logger.Warning(gametype + " is not a valid type"); - break; - } - } - - // Set the not machine type flag for filtering - MachineType machineNotType = MachineType.NULL; - foreach (string gametype in notgametypes) - { - switch (gametype.ToLowerInvariant()) - { - case "none": - machineNotType = MachineType.None; - break; - case "bios": - machineNotType = MachineType.Bios; - break; - case "dev": - case "device": - machineNotType = MachineType.Device; - break; - case "mech": - case "mechanical": - machineNotType = MachineType.Mechanical; - break; - default: - _logger.Warning(gametype + " is not a valid type"); - break; - } - } - // Normalize the extensions addext = (addext == "" || addext.StartsWith(".") ? addext : "." + addext); repext = (repext == "" || repext.StartsWith(".") ? repext : "." + repext); @@ -807,11 +663,7 @@ namespace SabreTools GameName = datprefix, Romba = romba, }; - - // Create the Filter object to be used - 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 eb3a4a5f..c1a2e253 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -4,6 +4,7 @@ using System.Linq; using SabreTools.Helper; using SabreTools.Helper.Data; +using SabreTools.Helper.Dats; using SabreTools.Helper.Help; #if MONO @@ -118,7 +119,6 @@ namespace SabreTools skip = false, updateDat = false, usegame = true; - bool? runnable = null; DatFormat datFormat = 0x0; DiffMode diffMode = 0x0; OutputFormat outputFormat = OutputFormat.Folder; @@ -131,9 +131,6 @@ namespace SabreTools rar = 2, sevenzip = 1, zip = 1; - long sgt = -1, - slt = -1, - seq = -1; string addext = "", author = null, category = null, @@ -157,26 +154,11 @@ namespace SabreTools tempDir = "", url = null, version = null; - List crc = new List(); + Filter filter = new Filter(); List datfiles = new List(); List exta = new List(); List extb = 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 notgametype = 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 status = new List(); // Get the first argument as a feature flag string feature = args[0]; @@ -406,7 +388,7 @@ namespace SabreTools break; case "-nrun": case "--not-run": - runnable = false; + filter.Runnable = false; break; case "-ns": case "--noSHA1": @@ -498,7 +480,7 @@ namespace SabreTools break; case "-run": case "--runnable": - runnable = true; + filter.Runnable = true; break; case "-s": case "--short": @@ -591,7 +573,7 @@ namespace SabreTools break; case "-crc": case "--crc": - crc.Add(args[++i]); + filter.CRCs.Add(args[++i]); break; case "-da": case "--date": @@ -642,11 +624,11 @@ namespace SabreTools break; case "-gn": case "--game-name": - gamename.Add(args[++i]); + filter.GameNames.Add(args[++i]); break; case "-gt": case "--game-type": - gametype.Add(args[++i]); + filter.MachineTypes |= Filter.GetMachneTypeFromString(args[++i], _logger); break; case "-gz": case "--gz": @@ -665,11 +647,11 @@ namespace SabreTools break; case "-is": case "--status": - status.Add(args[++i]); + filter.ItemStatuses |= Filter.GetStatusFromString(args[++i], _logger); break; case "-md5": case "--md5": - md5.Add(args[++i]); + filter.MD5s.Add(args[++i]); break; case "-mt": case "--mt": @@ -681,35 +663,35 @@ namespace SabreTools break; case "-ncrc": case "--not-crc": - notcrc.Add(args[++i]); + filter.NotCRCs.Add(args[++i]); break; case "-ngn": case "--not-game": - notgamename.Add(args[++i]); + filter.NotGameNames.Add(args[++i]); break; case "-ngt": case "--not-gtype": - notgametype.Add(args[++i]); + filter.NotMachineTypes |= Filter.GetMachneTypeFromString(args[++i], _logger); break; case "-nis": case "--not-status": - notstatus.Add(args[++i]); + filter.NotItemStatuses |= Filter.GetStatusFromString(args[++i], _logger); break; case "-nmd5": case "--not-md5": - notmd5.Add(args[++i]); + filter.NotMD5s.Add(args[++i]); break; case "-nrn": case "--not-rom": - notromname.Add(args[++i]); + filter.NotRomNames.Add(args[++i]); break; case "-nrt": case "--not-type": - notromtype.Add(args[++i]); + filter.NotRomTypes.Add(args[++i]); break; case "-nsha1": case "--not-sha1": - notsha1.Add(args[++i]); + filter.NotSHA1s.Add(args[++i]); break; case "-out": case "--out": @@ -740,7 +722,7 @@ namespace SabreTools break; case "-rn": case "--rom-name": - romname.Add(args[++i]); + filter.RomNames.Add(args[++i]); break; case "-root": case "--root": @@ -748,23 +730,23 @@ namespace SabreTools break; case "-rt": case "--rom-type": - romtype.Add(args[++i]); + filter.RomTypes.Add(args[++i]); break; case "-seq": case "--equal": - seq = GetSizeFromString(args[++i]); + filter.SizeEqualTo = GetSizeFromString(args[++i]); break; case "-sgt": case "--greater": - sgt = GetSizeFromString(args[++i]); + filter.SizeGreaterThanOrEqual = GetSizeFromString(args[++i]); break; case "-sha1": case "--sha1": - sha1.Add(args[++i]); + filter.SHA1s.Add(args[++i]); break; case "-slt": case "--less": - slt = GetSizeFromString(args[++i]); + filter.SizeLessThanOrEqual = GetSizeFromString(args[++i]); break; case "-t": case "--temp": @@ -825,7 +807,7 @@ namespace SabreTools break; case "-crc": case "--crc": - crc.Add(split[1]); + filter.CRCs.Add(split[1]); break; case "-da": case "--date": @@ -875,11 +857,11 @@ namespace SabreTools break; case "-gn": case "--game-name": - gamename.Add(split[1]); + filter.GameNames.Add(split[1]); break; case "-gt": case "--game-type": - gametype.Add(split[1]); + filter.MachineTypes |= Filter.GetMachneTypeFromString(split[1], _logger); break; case "-gz": case "--gz": @@ -898,11 +880,11 @@ namespace SabreTools break; case "-is": case "--status": - status.Add(split[1]); + filter.ItemStatuses |= Filter.GetStatusFromString(split[1], _logger); break; case "-md5": case "--md5": - md5.Add(split[1]); + filter.MD5s.Add(split[1]); break; case "-mt": case "--mt": @@ -914,35 +896,35 @@ namespace SabreTools break; case "-ncrc": case "--not-crc": - notcrc.Add(split[1]); + filter.NotCRCs.Add(split[i]); break; case "-ngn": case "--not-game": - notgamename.Add(split[1]); + filter.NotGameNames.Add(split[1]); break; case "-ngt": case "--not-gtype": - notgametype.Add(split[1]); + filter.NotMachineTypes |= Filter.GetMachneTypeFromString(split[1], _logger); break; case "-nis": case "--not-status": - notstatus.Add(split[1]); + filter.NotItemStatuses |= Filter.GetStatusFromString(split[1], _logger); break; case "-nmd5": case "--not-md5": - notmd5.Add(split[1]); + filter.NotMD5s.Add(split[1]); break; case "-nrn": case "--not-rom": - notromname.Add(split[1]); + filter.NotRomNames.Add(split[1]); break; case "-nrt": case "--not-type": - notromtype.Add(split[1]); + filter.NotRomTypes.Add(split[1]); break; case "-nsha1": case "--not-sha1": - notsha1.Add(split[1]); + filter.NotSHA1s.Add(split[1]); break; case "-out": case "--out": @@ -977,27 +959,27 @@ namespace SabreTools break; case "-rn": case "--rom-name": - romname.Add(split[1]); + filter.RomNames.Add(split[1]); break; case "-rt": case "--rom-type": - romtype.Add(split[1]); + filter.RomTypes.Add(split[1]); break; case "-seq": case "--equal": - seq = GetSizeFromString(split[1]); + filter.SizeEqualTo = GetSizeFromString(split[1]); break; case "-sgt": case "--greater": - sgt = GetSizeFromString(split[1]); + filter.SizeGreaterThanOrEqual = GetSizeFromString(split[1]); break; case "-sha1": case "--sha1": - sha1.Add(split[1]); + filter.SHA1s.Add(split[1]); break; case "-slt": case "--less": - slt = GetSizeFromString(split[1]); + filter.SizeLessThanOrEqual = GetSizeFromString(split[1]); break; case "-t": case "--temp": @@ -1168,9 +1150,7 @@ namespace SabreTools InitUpdate(inputs, filename, name, description, rootdir, category, version, date, author, email, homepage, url, comment, header, superdat, forcemerge, forcend, forcepack, excludeOf, datFormat, usegame, prefix, postfix, quotes, repext, addext, remext, datPrefix, romba, merge, diffMode, inplace, skip, removeDateFromAutomaticName, - gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, status, gametype, - notgamename, notromname, notromtype, notcrc, notmd5, notsha1, notstatus, notgametype, runnable, - splitType, trim, single, root, outDir, cleanGameNames, softlist, dedup, maxParallelism); + filter, splitType, trim, single, root, outDir, cleanGameNames, softlist, dedup, maxParallelism); } // If we're using the verifier