From 24d0038e2866291e5bca8e522c6f1e30f89dfa91 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 8 Feb 2019 15:05:15 -0800 Subject: [PATCH] [Filter] Fix filtering after last cleanup --- SabreTools.Library/DatFiles/Filter.cs | 90 +++++++++++------------ SabreTools.Library/DatFiles/FilterItem.cs | 44 +++++------ 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/SabreTools.Library/DatFiles/Filter.cs b/SabreTools.Library/DatFiles/Filter.cs index 41239603..65d40ca8 100644 --- a/SabreTools.Library/DatFiles/Filter.cs +++ b/SabreTools.Library/DatFiles/Filter.cs @@ -184,13 +184,13 @@ namespace SabreTools.Library.DatFiles return false; // Filter on machine type - if (!this.MachineTypes.MatchesPositive(MachineType.NULL, item.MachineType)) + if (this.MachineTypes.MatchesPositive(MachineType.NULL, item.MachineType) == false) return false; - if (this.MachineTypes.MatchesNegative(MachineType.NULL, item.MachineType)) + if (this.MachineTypes.MatchesNegative(MachineType.NULL, item.MachineType) == true) return false; // Filter on machine runability - if (!this.Runnable.MatchesNeutral(null, item.Runnable)) + if (this.Runnable.MatchesNeutral(null, item.Runnable) == false) return false; // Take care of Rom and Disk specific differences @@ -199,53 +199,53 @@ namespace SabreTools.Library.DatFiles Rom rom = (Rom)item; // Filter on status - if (!this.ItemStatuses.MatchesPositive(ItemStatus.NULL, rom.ItemStatus)) + if (this.ItemStatuses.MatchesPositive(ItemStatus.NULL, rom.ItemStatus) == false) return false; - if (this.ItemStatuses.MatchesNegative(ItemStatus.NULL, rom.ItemStatus)) + if (this.ItemStatuses.MatchesNegative(ItemStatus.NULL, rom.ItemStatus) == true) return false; // Filter on rom size - if (!this.Size.MatchesNeutral(-1, rom.Size)) + if (this.Size.MatchesNeutral(-1, rom.Size) == false) return false; - else if (!this.Size.MatchesPositive(-1, rom.Size)) + else if (this.Size.MatchesPositive(-1, rom.Size) == false) return false; - else if (!this.Size.MatchesNegative(-1, rom.Size)) + else if (this.Size.MatchesNegative(-1, rom.Size) == false) return false; // Filter on CRC - if (!this.CRC.MatchesPositiveSet(rom.CRC)) + if (this.CRC.MatchesPositiveSet(rom.CRC) == false) return false; - if (this.CRC.MatchesNegativeSet(rom.CRC)) + if (this.CRC.MatchesNegativeSet(rom.CRC) == true) return false; // Filter on MD5 - if (!this.MD5.MatchesPositiveSet(rom.MD5)) + if (this.MD5.MatchesPositiveSet(rom.MD5) == false) return false; - if (this.MD5.MatchesNegativeSet(rom.MD5)) + if (this.MD5.MatchesNegativeSet(rom.MD5) == true) return false; // Filter on SHA-1 - if (!this.SHA1.MatchesPositiveSet(rom.SHA1)) + if (this.SHA1.MatchesPositiveSet(rom.SHA1) == false) return false; - if (this.SHA1.MatchesNegativeSet(rom.SHA1)) + if (this.SHA1.MatchesNegativeSet(rom.SHA1) == true) return false; // Filter on SHA-256 - if (!this.SHA256.MatchesPositiveSet(rom.SHA256)) + if (this.SHA256.MatchesPositiveSet(rom.SHA256) == false) return false; - if (this.SHA256.MatchesNegativeSet(rom.SHA256)) + if (this.SHA256.MatchesNegativeSet(rom.SHA256) == true) return false; // Filter on SHA-384 - if (!this.SHA384.MatchesPositiveSet(rom.SHA384)) + if (this.SHA384.MatchesPositiveSet(rom.SHA384) == false) return false; - if (this.SHA384.MatchesNegativeSet(rom.SHA384)) + if (this.SHA384.MatchesNegativeSet(rom.SHA384) == true) return false; // Filter on SHA-512 - if (!this.SHA512.MatchesPositiveSet(rom.SHA512)) + if (this.SHA512.MatchesPositiveSet(rom.SHA512) == false) return false; - if (this.SHA512.MatchesNegativeSet(rom.SHA512)) + if (this.SHA512.MatchesNegativeSet(rom.SHA512) == true) return false; } else if (item.ItemType == ItemType.Disk) @@ -253,80 +253,80 @@ namespace SabreTools.Library.DatFiles Disk rom = (Disk)item; // Filter on status - if (!this.ItemStatuses.MatchesPositive(ItemStatus.NULL, rom.ItemStatus)) + if (this.ItemStatuses.MatchesPositive(ItemStatus.NULL, rom.ItemStatus) == false) return false; - if (this.ItemStatuses.MatchesNegative(ItemStatus.NULL, rom.ItemStatus)) + if (this.ItemStatuses.MatchesNegative(ItemStatus.NULL, rom.ItemStatus) == true) return false; // Filter on MD5 - if (!this.MD5.MatchesPositiveSet(rom.MD5)) + if (this.MD5.MatchesPositiveSet(rom.MD5) == false) return false; - if (this.MD5.MatchesNegativeSet(rom.MD5)) + if (this.MD5.MatchesNegativeSet(rom.MD5) == true) return false; // Filter on SHA-1 - if (!this.SHA1.MatchesPositiveSet(rom.SHA1)) + if (this.SHA1.MatchesPositiveSet(rom.SHA1) == false) return false; - if (this.SHA1.MatchesNegativeSet(rom.SHA1)) + if (this.SHA1.MatchesNegativeSet(rom.SHA1) == true) return false; // Filter on SHA-256 - if (!this.SHA256.MatchesPositiveSet(rom.SHA256)) + if (this.SHA256.MatchesPositiveSet(rom.SHA256) == false) return false; - if (this.SHA256.MatchesNegativeSet(rom.SHA256)) + if (this.SHA256.MatchesNegativeSet(rom.SHA256) == true) return false; // Filter on SHA-384 - if (!this.SHA384.MatchesPositiveSet(rom.SHA384)) + if (this.SHA384.MatchesPositiveSet(rom.SHA384) == false) return false; - if (this.SHA384.MatchesNegativeSet(rom.SHA384)) + if (this.SHA384.MatchesNegativeSet(rom.SHA384) == true) return false; // Filter on SHA-512 - if (!this.SHA512.MatchesPositiveSet(rom.SHA512)) + if (this.SHA512.MatchesPositiveSet(rom.SHA512) == false) return false; - if (this.SHA512.MatchesNegativeSet(rom.SHA512)) + if (this.SHA512.MatchesNegativeSet(rom.SHA512) == true) return false; } // Filter on machine name - bool machineNameFound = this.MachineName.MatchesPositiveSet(item.MachineName); + bool? machineNameFound = this.MachineName.MatchesPositiveSet(item.MachineName); if (this.IncludeOfInGame.Neutral) { - machineNameFound |= this.MachineName.MatchesPositiveSet(item.CloneOf); - machineNameFound |= this.MachineName.MatchesPositiveSet(item.RomOf); + machineNameFound |= (this.MachineName.MatchesPositiveSet(item.CloneOf) == true); + machineNameFound |= (this.MachineName.MatchesPositiveSet(item.RomOf) == true); } - if (!machineNameFound) + if (machineNameFound == false) return false; machineNameFound = this.MachineName.MatchesNegativeSet(item.MachineName); if (this.IncludeOfInGame.Neutral) { - machineNameFound |= this.MachineName.MatchesNegativeSet(item.CloneOf); - machineNameFound |= this.MachineName.MatchesNegativeSet(item.RomOf); + machineNameFound |= (this.MachineName.MatchesNegativeSet(item.CloneOf) == true); + machineNameFound |= (this.MachineName.MatchesNegativeSet(item.RomOf) == true); } - if (machineNameFound) + if (machineNameFound == false) return false; // Filter on machine description - if (!this.MachineDescription.MatchesPositiveSet(item.MachineDescription)) + if (this.MachineDescription.MatchesPositiveSet(item.MachineDescription) == false) return false; - if (this.MachineDescription.MatchesNegativeSet(item.MachineDescription)) + if (this.MachineDescription.MatchesNegativeSet(item.MachineDescription) == true) return false; // Filter on item name - if (!this.ItemName.MatchesPositiveSet(item.Name)) + if (this.ItemName.MatchesPositiveSet(item.Name) == false) return false; - if (this.ItemName.MatchesNegativeSet(item.Name)) + if (this.ItemName.MatchesNegativeSet(item.Name) == true) return false; // Filter on item type if (this.ItemTypes.PositiveSet.Count == 0 && this.ItemTypes.NegativeSet.Count == 0 && item.ItemType != ItemType.Rom && item.ItemType != ItemType.Disk && item.ItemType != ItemType.Blank) return false; - if (!this.ItemTypes.MatchesPositiveSet(item.ItemType.ToString())) + if (this.ItemTypes.MatchesPositiveSet(item.ItemType.ToString()) == false) return false; - if (this.ItemTypes.MatchesNegativeSet(item.ItemType.ToString())) + if (this.ItemTypes.MatchesNegativeSet(item.ItemType.ToString()) == true) return false; return true; diff --git a/SabreTools.Library/DatFiles/FilterItem.cs b/SabreTools.Library/DatFiles/FilterItem.cs index 1139ad5f..90f7f4cf 100644 --- a/SabreTools.Library/DatFiles/FilterItem.cs +++ b/SabreTools.Library/DatFiles/FilterItem.cs @@ -45,8 +45,8 @@ namespace SabreTools.Library.DatFiles /// /// Default value to check filter value /// Value to check - /// True if the value was found in the positive filter, false otherwise - public bool MatchesPositive(T def, T value) + /// True if the value was found in the positive filter, null on default value, false otherwise + public bool? MatchesPositive(T def, T value) { return Matches(this.Positive, def, value); } @@ -56,8 +56,8 @@ namespace SabreTools.Library.DatFiles /// /// Default value to check filter value /// Value to check - /// True if the value was found in the negative filter, false otherwise - public bool MatchesNegative(T def, T value) + /// True if the value was found in the negative filter, null on default value, false otherwise + public bool? MatchesNegative(T def, T value) { return Matches(this.Negative, def, value); } @@ -67,8 +67,8 @@ namespace SabreTools.Library.DatFiles /// /// Default value to check filter value /// Value to check - /// True if the value was found in the neutral filter, false otherwise - public bool MatchesNeutral(T def, T value) + /// True if the value was found in the neutral filter, null on default value, false otherwise + public bool? MatchesNeutral(T def, T value) { return Matches(this.Neutral, def, value); } @@ -77,8 +77,8 @@ namespace SabreTools.Library.DatFiles /// Check if the given value matches any of the positive filters /// /// Value to check - /// True if the value was found in a positive filter, false otherwise - public bool MatchesPositiveSet(T value) + /// True if the value was found in a positive filter, null on an empty set, false otherwise + public bool? MatchesPositiveSet(T value) { return MatchesSet(this.PositiveSet, value); } @@ -87,8 +87,8 @@ namespace SabreTools.Library.DatFiles /// Check if the given value matches any of the negative filters /// /// Value to check - /// True if the value was found in a negative filter, false otherwise - public bool MatchesNegativeSet(T value) + /// True if the value was found in a negative filter, null on an empty set, false otherwise + public bool? MatchesNegativeSet(T value) { return MatchesSet(this.NegativeSet, value); } @@ -97,8 +97,8 @@ namespace SabreTools.Library.DatFiles /// Check if the given value matches any of the neutral filters /// /// Value to check - /// True if the value was found in a neutral filter, false otherwise - public bool MatchesNeutralSet(T value) + /// True if the value was found in a neutral filter, null on an empty set, false otherwise + public bool? MatchesNeutralSet(T value) { return MatchesSet(this.NeutralSet, value); } @@ -109,12 +109,12 @@ namespace SabreTools.Library.DatFiles /// Value to check against /// Default value to check filter value /// Value to check - /// True if the value was found in the supplied filter, false otherwise - private bool Matches(T single, T def, T value) + /// True if the value was found in the supplied filter, null on default value, false otherwise + private bool? Matches(T single, T def, T value) { // If the filter is default, we ignore if (single.Equals(def)) - return true; + return null; // If we have a flag if (typeof(T).IsEnum && (single as Enum).HasFlag(value as Enum)) @@ -128,14 +128,14 @@ namespace SabreTools.Library.DatFiles /// /// Set to check against /// Value to check - /// True if the value was found in the supplied filter, false otherwise - private bool MatchesSet(List set, T value) + /// True if the value was found in the supplied filter, null on an empty set, false otherwise + private bool? MatchesSet(List set, T value) { - if (set.Count > 0) - { - if (this.FindValueInList(set, value)) - return true; - } + if (set.Count == 0) + return null; + + if (this.FindValueInList(set, value)) + return true; return false; }