From 03c6fb641c87893f49859012d1824a4b844a0197 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 5 Mar 2024 22:51:19 -0500 Subject: [PATCH] Remove old Filter and variants --- SabreTools.Filtering/DatItemFilter.cs | 2042 ------------------ SabreTools.Filtering/Filter.cs | 455 ---- SabreTools.Filtering/MachineFilter.cs | 459 ---- SabreTools.Test/Filtering/FilteringTests.cs | 87 - SabreTools.Test/Filtering/PopulationTests.cs | 72 - SabreTools/Features/Batch.cs | 27 +- 6 files changed, 11 insertions(+), 3131 deletions(-) delete mode 100644 SabreTools.Filtering/DatItemFilter.cs delete mode 100644 SabreTools.Filtering/Filter.cs delete mode 100644 SabreTools.Filtering/MachineFilter.cs delete mode 100644 SabreTools.Test/Filtering/FilteringTests.cs diff --git a/SabreTools.Filtering/DatItemFilter.cs b/SabreTools.Filtering/DatItemFilter.cs deleted file mode 100644 index 70eee361..00000000 --- a/SabreTools.Filtering/DatItemFilter.cs +++ /dev/null @@ -1,2042 +0,0 @@ -using System.Collections.Generic; -using SabreTools.Core; -using SabreTools.Core.Tools; -using SabreTools.DatItems; -using SabreTools.DatItems.Formats; -using SabreTools.Logging; - -namespace SabreTools.Filtering -{ - /// - /// Represents the filtering operations that need to be performed on a set of items, usually a DAT - /// - public class DatItemFilter : Filter - { - #region Fields - - #region Filters - - public FilterItem AltName { get; private set; } = new FilterItem(); - public FilterItem AltTitle { get; private set; } = new FilterItem(); - public FilterItem Analog_Mask { get; private set; } = new FilterItem(); - public FilterItem ArchiveDotOrgFormat { get; private set; } = new FilterItem(); - public FilterItem ArchiveDotOrgSource { get; private set; } = new FilterItem(); - public FilterItem AreaEndianness { get; private set; } = new FilterItem() { Positive = Endianness.NULL, Negative = Endianness.NULL }; - public FilterItem AreaName { get; private set; } = new FilterItem(); - public FilterItem AreaSize { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem AreaWidth { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Bios { get; private set; } = new FilterItem(); - public FilterItem Boot { get; private set; } = new FilterItem(); - public FilterItem Categories { get; private set; } = new FilterItem(); - public FilterItem Channels { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem ChipType { get; private set; } = new FilterItem() { Positive = Core.ChipType.NULL, Negative = Core.ChipType.NULL }; - public FilterItem Clock { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Clone { get; private set; } = new FilterItem(); - public FilterItem CocktailStatus { get; private set; } = new FilterItem() { Positive = Core.SupportStatus.NULL, Negative = Core.SupportStatus.NULL }; - public FilterItem Coins { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Complete { get; private set; } = new FilterItem(); - public FilterItem Condition_Mask { get; private set; } = new FilterItem(); - public FilterItem Condition_Relation { get; private set; } = new FilterItem() { Positive = Core.Relation.NULL, Negative = Core.Relation.NULL }; - public FilterItem Condition_Tag { get; private set; } = new FilterItem(); - public FilterItem Condition_Value { get; private set; } = new FilterItem(); - public FilterItem Content { get; private set; } = new FilterItem(); - public FilterItem Control_Buttons { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Control_KeyDelta { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Control_Maximum { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Control_Minimum { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Control_Player { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Control_ReqButtons { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Control_Reverse { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Control_Sensitivity { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Control_Type { get; private set; } = new FilterItem() { Positive = ControlType.NULL, Negative = ControlType.NULL }; - public FilterItem Control_Ways { get; private set; } = new FilterItem(); - public FilterItem Control_Ways2 { get; private set; } = new FilterItem(); - public FilterItem Control_Ways3 { get; private set; } = new FilterItem(); - public FilterItem CRC { get; private set; } = new FilterItem(); - public FilterItem Date { get; private set; } = new FilterItem(); - public FilterItem Default { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Description { get; private set; } = new FilterItem(); - public FilterItem DeviceType { get; private set; } = new FilterItem() { Positive = Core.DeviceType.NULL, Negative = Core.DeviceType.NULL }; - public FilterItem DevStatus { get; private set; } = new FilterItem(); - public FilterItem DisplayType { get; private set; } = new FilterItem() { Positive = Core.DisplayType.NULL, Negative = Core.DisplayType.NULL }; - public FilterItem EmulationStatus { get; private set; } = new FilterItem() { Positive = Core.SupportStatus.NULL, Negative = Core.SupportStatus.NULL }; - public FilterItem Extension_Name { get; private set; } = new FilterItem(); - public FilterItem FeatureOverall { get; private set; } = new FilterItem() { Positive = Core.FeatureStatus.NULL, Negative = Core.FeatureStatus.NULL }; - public FilterItem FeatureStatus { get; private set; } = new FilterItem() { Positive = Core.FeatureStatus.NULL, Negative = Core.FeatureStatus.NULL }; - public FilterItem FeatureType { get; private set; } = new FilterItem() { Positive = Core.FeatureType.NULL, Negative = Core.FeatureType.NULL }; - public FilterItem Filter { get; private set; } = new FilterItem(); - public FilterItem FixedImage { get; private set; } = new FilterItem(); - public FilterItem FlipX { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem HBEnd { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem HBStart { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Height { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem HTotal { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Incomplete { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Index { get; private set; } = new FilterItem(); - public FilterItem Instance_BriefName { get; private set; } = new FilterItem(); - public FilterItem Instance_Name { get; private set; } = new FilterItem(); - public FilterItem Interface { get; private set; } = new FilterItem(); - public FilterItem Inverted { get; private set; } = new FilterItem(); - public FilterItem Language { get; private set; } = new FilterItem(); - public FilterItem Languages { get; private set; } = new FilterItem(); - public FilterItem LoadFlag { get; private set; } = new FilterItem() { Positive = Core.LoadFlag.NULL, Negative = Core.LoadFlag.NULL }; - public FilterItem Location_Inverted { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Location_Name { get; private set; } = new FilterItem(); - public FilterItem Location_Number { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Mandatory { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Mask { get; private set; } = new FilterItem(); - public FilterItem MD5 { get; private set; } = new FilterItem(); - public FilterItem Merge { get; private set; } = new FilterItem(); - public FilterItem MIA { get; private set; } = new FilterItem(); - public FilterItem Name { get; private set; } = new FilterItem(); - public FilterItem NoSoundHardware { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Number { get; private set; } = new FilterItem(); - public FilterItem Offset { get; private set; } = new FilterItem(); - public FilterItem OpenMSXSubType { get; private set; } = new FilterItem() { Positive = Core.OpenMSXSubType.NULL, Negative = Core.OpenMSXSubType.NULL }; - public FilterItem OpenMSXType { get; private set; } = new FilterItem(); - public FilterItem Optional { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Original { get; private set; } = new FilterItem(); - public FilterItem OriginalFilename { get; private set; } = new FilterItem(); - public FilterItem Part_Feature_Name { get; private set; } = new FilterItem(); - public FilterItem Part_Feature_Value { get; private set; } = new FilterItem(); - public FilterItem Part_Interface { get; private set; } = new FilterItem(); - public FilterItem Part_Name { get; private set; } = new FilterItem(); - public FilterItem PixClock { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Physical { get; private set; } = new FilterItem(); - public FilterItem Players { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Refresh { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Region { get; private set; } = new FilterItem(); - public FilterItem RegParent { get; private set; } = new FilterItem(); - public FilterItem Relation { get; private set; } = new FilterItem() { Positive = Core.Relation.NULL, Negative = Core.Relation.NULL }; - public FilterItem Remark { get; private set; } = new FilterItem(); - public FilterItem RequiresArtwork { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Rotate { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Rotation { get; private set; } = new FilterItem(); - public FilterItem SaveStateStatus { get; private set; } = new FilterItem() { Positive = Supported.NULL, Negative = Supported.NULL }; - public FilterItem Service { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Setting_Default { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Setting_Name { get; private set; } = new FilterItem(); - public FilterItem Setting_Value { get; private set; } = new FilterItem(); - public FilterItem SHA1 { get; private set; } = new FilterItem(); - public FilterItem SHA256 { get; private set; } = new FilterItem(); - public FilterItem SHA384 { get; private set; } = new FilterItem(); - public FilterItem SHA512 { get; private set; } = new FilterItem(); - public FilterItem Size { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem SlotOption_Default { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem SlotOption_DeviceName { get; private set; } = new FilterItem(); - public FilterItem SlotOption_Name { get; private set; } = new FilterItem(); - public FilterItem SoftwareListStatus { get; private set; } = new FilterItem() { Positive = Core.SoftwareListStatus.None, Negative = Core.SoftwareListStatus.None }; - public FilterItem SpamSum { get; private set; } = new FilterItem(); - public FilterItem Status { get; private set; } = new FilterItem() { Positive = ItemStatus.NULL, Negative = ItemStatus.NULL }; - public FilterItem Summation { get; private set; } = new FilterItem(); - public FilterItem SupportStatus { get; private set; } = new FilterItem() { Positive = Core.SupportStatus.NULL, Negative = Core.SupportStatus.NULL }; - public FilterItem Tag { get; private set; } = new FilterItem(); - public FilterItem Tilt { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Type { get; private set; } = new FilterItem(); - public FilterItem Unofficial { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Value { get; private set; } = new FilterItem(); - public FilterItem VBEnd { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem VBStart { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem VTotal { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Width { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; - public FilterItem Writable { get; private set; } = new FilterItem() { Neutral = null }; - - #endregion - - /// - /// Determines if any filters have been set - /// - public bool HasFilters { get; set; } = false; - - #endregion // Fields - - #region Constructors - - /// - /// Constructor - /// - public DatItemFilter() - { - logger = new Logger(this); - } - - #endregion - - #region Population - - /// - /// Set multiple filters from key - /// - /// Key for the filter to be set - /// List of values for the filter - /// True if negative filter, false otherwise - public void SetFilter(DatItemField key, List values, bool negate) - { - foreach (string value in values) - { - SetFilter(key, value, negate); - } - } - - /// - /// Set a single filter from key - /// - /// Key for the filter to be set - /// Value of the filter - /// True if negative filter, false otherwise - public void SetFilter(DatItemField key, string? value, bool negate) - { - switch (key) - { - case DatItemField.AltName: - SetStringFilter(AltName, value, negate); - break; - - case DatItemField.AltTitle: - SetStringFilter(AltTitle, value, negate); - break; - - case DatItemField.Analog_Mask: - SetStringFilter(Analog_Mask, value, negate); - break; - - case DatItemField.ArchiveDotOrgFormat: - SetStringFilter(ArchiveDotOrgFormat, value, negate); - break; - - case DatItemField.ArchiveDotOrgSource: - SetStringFilter(ArchiveDotOrgSource, value, negate); - break; - - case DatItemField.AreaEndianness: - if (negate) - AreaEndianness.Negative |= value.AsEnumValue(); - else - AreaEndianness.Positive |= value.AsEnumValue(); - break; - - case DatItemField.AreaName: - SetStringFilter(AreaName, value, negate); - break; - - case DatItemField.AreaSize: - SetLongFilter(AreaSize, value, negate); - break; - - case DatItemField.AreaWidth: - SetLongFilter(AreaWidth, value, negate); - break; - - case DatItemField.Bios: - SetStringFilter(Bios, value, negate); - break; - - case DatItemField.Boot: - SetStringFilter(Boot, value, negate); - break; - - case DatItemField.Categories: - SetStringFilter(Categories, value, negate); - break; - - case DatItemField.Channels: - SetLongFilter(Channels, value, negate); - break; - - case DatItemField.ChipType: - if (negate) - ChipType.Negative |= value.AsEnumValue(); - else - ChipType.Positive |= value.AsEnumValue(); - break; - - case DatItemField.Clock: - SetLongFilter(Clock, value, negate); - break; - - case DatItemField.Clone: - SetStringFilter(Clone, value, negate); - break; - - case DatItemField.CocktailStatus: - if (negate) - CocktailStatus.Negative |= value.AsEnumValue(); - else - CocktailStatus.Positive |= value.AsEnumValue(); - break; - - case DatItemField.Coins: - SetLongFilter(Coins, value, negate); - break; - - case DatItemField.Complete: - SetStringFilter(Complete, value, negate); - break; - - case DatItemField.Condition_Mask: - SetStringFilter(Condition_Mask, value, negate); - break; - - case DatItemField.Condition_Relation: - if (negate) - Condition_Relation.Negative |= value.AsEnumValue(); - else - Condition_Relation.Positive |= value.AsEnumValue(); - break; - - case DatItemField.Condition_Tag: - SetStringFilter(Condition_Tag, value, negate); - break; - - case DatItemField.Condition_Value: - SetStringFilter(Condition_Value, value, negate); - break; - - case DatItemField.Content: - SetStringFilter(Content, value, negate); - break; - - case DatItemField.Control_Buttons: - SetLongFilter(Control_Buttons, value, negate); - break; - - case DatItemField.Control_KeyDelta: - SetLongFilter(Control_KeyDelta, value, negate); - break; - - case DatItemField.Control_Player: - SetLongFilter(Control_Player, value, negate); - break; - - case DatItemField.Control_Maximum: - SetLongFilter(Control_Maximum, value, negate); - break; - - case DatItemField.Control_Minimum: - SetLongFilter(Control_Minimum, value, negate); - break; - - case DatItemField.Control_RequiredButtons: - SetLongFilter(Control_ReqButtons, value, negate); - break; - - case DatItemField.Control_Reverse: - SetBooleanFilter(Control_Reverse, value, negate); - break; - - case DatItemField.Control_Sensitivity: - SetLongFilter(Control_Sensitivity, value, negate); - break; - - case DatItemField.Control_Type: - - if (negate) - Control_Type.Negative |= value.AsEnumValue(); - else - Control_Type.Positive |= value.AsEnumValue(); - break; - - case DatItemField.Control_Ways: - SetStringFilter(Control_Ways, value, negate); - break; - - case DatItemField.Control_Ways2: - SetStringFilter(Control_Ways2, value, negate); - break; - - case DatItemField.Control_Ways3: - SetStringFilter(Control_Ways3, value, negate); - break; - - case DatItemField.CRC: - SetStringFilter(CRC, value, negate); - break; - - case DatItemField.Date: - SetStringFilter(Date, value, negate); - break; - - case DatItemField.Default: - SetBooleanFilter(Default, value, negate); - break; - - case DatItemField.Description: - SetStringFilter(Description, value, negate); - break; - - case DatItemField.DeviceType: - if (negate) - DeviceType.Negative |= value.AsEnumValue(); - else - DeviceType.Positive |= value.AsEnumValue(); - break; - - case DatItemField.DevStatus: - SetStringFilter(DevStatus, value, negate); - break; - - case DatItemField.DisplayType: - if (negate) - DisplayType.Negative |= value.AsEnumValue(); - else - DisplayType.Positive |= value.AsEnumValue(); - break; - - case DatItemField.EmulationStatus: - if (negate) - EmulationStatus.Negative |= value.AsEnumValue(); - else - EmulationStatus.Positive |= value.AsEnumValue(); - break; - - case DatItemField.Extension_Name: - SetStringFilter(Extension_Name, value, negate); - break; - - case DatItemField.FeatureOverall: - if (negate) - FeatureOverall.Negative |= value.AsEnumValue(); - else - FeatureOverall.Positive |= value.AsEnumValue(); - break; - - case DatItemField.FeatureStatus: - if (negate) - FeatureStatus.Negative |= value.AsEnumValue(); - else - FeatureStatus.Positive |= value.AsEnumValue(); - break; - - case DatItemField.FeatureType: - if (negate) - FeatureType.Negative |= value.AsEnumValue(); - else - FeatureType.Positive |= value.AsEnumValue(); - break; - - case DatItemField.Filter: - SetStringFilter(Filter, value, negate); - break; - - case DatItemField.FixedImage: - SetStringFilter(FixedImage, value, negate); - break; - - case DatItemField.FlipX: - SetBooleanFilter(FlipX, value, negate); - break; - - case DatItemField.HBEnd: - SetLongFilter(HBEnd, value, negate); - break; - - case DatItemField.HBStart: - SetLongFilter(HBStart, value, negate); - break; - - case DatItemField.Height: - SetLongFilter(Height, value, negate); - break; - - case DatItemField.HTotal: - SetLongFilter(HTotal, value, negate); - break; - - case DatItemField.Incomplete: - SetBooleanFilter(Incomplete, value, negate); - break; - - case DatItemField.Index: - SetStringFilter(Index, value, negate); - break; - - case DatItemField.Instance_BriefName: - SetStringFilter(Instance_BriefName, value, negate); - break; - - case DatItemField.Instance_Name: - SetStringFilter(Instance_Name, value, negate); - break; - - case DatItemField.Interface: - SetStringFilter(Interface, value, negate); - break; - - case DatItemField.Inverted: - SetBooleanFilter(Inverted, value, negate); - break; - - case DatItemField.Language: - SetStringFilter(Language, value, negate); - break; - - case DatItemField.Languages: - SetStringFilter(Languages, value, negate); - break; - - case DatItemField.LoadFlag: - if (negate) - LoadFlag.Negative |= value.AsEnumValue(); - else - LoadFlag.Positive |= value.AsEnumValue(); - break; - - case DatItemField.Location_Inverted: - SetBooleanFilter(Location_Inverted, value, negate); - break; - - case DatItemField.Location_Name: - SetStringFilter(Location_Name, value, negate); - break; - - case DatItemField.Location_Number: - SetLongFilter(Location_Number, value, negate); - break; - - case DatItemField.Mandatory: - SetLongFilter(Mandatory, value, negate); - break; - - case DatItemField.Mask: - SetStringFilter(Mask, value, negate); - break; - - case DatItemField.MD5: - SetStringFilter(MD5, value, negate); - break; - - case DatItemField.Merge: - SetStringFilter(Merge, value, negate); - break; - - case DatItemField.MIA: - SetBooleanFilter(MIA, value, negate); - break; - - case DatItemField.Name: - SetStringFilter(Name, value, negate); - break; - - case DatItemField.NoSoundHardware: - SetBooleanFilter(NoSoundHardware, value, negate); - break; - - case DatItemField.Number: - SetStringFilter(Number, value, negate); - break; - - case DatItemField.Offset: - SetStringFilter(Offset, value, negate); - break; - - case DatItemField.OpenMSXSubType: - if (negate) - OpenMSXSubType.Negative |= value.AsEnumValue(); - else - OpenMSXSubType.Positive |= value.AsEnumValue(); - break; - - case DatItemField.OpenMSXType: - SetStringFilter(OpenMSXType, value, negate); - break; - - case DatItemField.Optional: - SetBooleanFilter(Optional, value, negate); - break; - - case DatItemField.Original: - SetStringFilter(Original, value, negate); - break; - - case DatItemField.OriginalFilename: - SetStringFilter(OriginalFilename, value, negate); - break; - - case DatItemField.Part_Feature_Name: - SetStringFilter(Part_Feature_Name, value, negate); - break; - - case DatItemField.Part_Feature_Value: - SetStringFilter(Part_Feature_Value, value, negate); - break; - - case DatItemField.Part_Interface: - SetStringFilter(Part_Interface, value, negate); - break; - - case DatItemField.Part_Name: - SetStringFilter(Part_Name, value, negate); - break; - - case DatItemField.Physical: - SetStringFilter(Physical, value, negate); - break; - - case DatItemField.PixClock: - SetLongFilter(PixClock, value, negate); - break; - - case DatItemField.Players: - SetLongFilter(Players, value, negate); - break; - - case DatItemField.Refresh: - SetDoubleFilter(Refresh, value, negate); - break; - - case DatItemField.Region: - SetStringFilter(Region, value, negate); - break; - - case DatItemField.RegParent: - SetStringFilter(RegParent, value, negate); - break; - - case DatItemField.Relation: - if (negate) - Relation.Negative |= value.AsEnumValue(); - else - Relation.Positive |= value.AsEnumValue(); - break; - - case DatItemField.Remark: - SetStringFilter(Remark, value, negate); - break; - - case DatItemField.RequiresArtwork: - SetBooleanFilter(RequiresArtwork, value, negate); - break; - - case DatItemField.Rotate: - SetLongFilter(Rotate, value, negate); - break; - - case DatItemField.Rotation: - SetStringFilter(Rotation, value, negate); - break; - - case DatItemField.SaveStateStatus: - if (negate) - SaveStateStatus.Negative |= value.AsEnumValue(); - else - SaveStateStatus.Positive |= value.AsEnumValue(); - break; - - case DatItemField.Service: - SetBooleanFilter(Service, value, negate); - break; - - case DatItemField.Setting_Default: - SetBooleanFilter(Setting_Default, value, negate); - break; - - case DatItemField.Setting_Name: - SetStringFilter(Setting_Name, value, negate); - break; - - case DatItemField.Setting_Value: - SetStringFilter(Setting_Value, value, negate); - break; - - case DatItemField.SHA1: - SetStringFilter(SHA1, value, negate); - break; - - case DatItemField.SHA256: - SetStringFilter(SHA256, value, negate); - break; - - case DatItemField.SHA384: - SetStringFilter(SHA384, value, negate); - break; - - case DatItemField.SHA512: - SetStringFilter(SHA512, value, negate); - break; - - case DatItemField.Size: - SetLongFilter(Size, value, negate); - break; - - case DatItemField.SlotOption_Default: - SetBooleanFilter(SlotOption_Default, value, negate); - break; - - case DatItemField.SlotOption_DeviceName: - SetStringFilter(SlotOption_DeviceName, value, negate); - break; - - case DatItemField.SlotOption_Name: - SetStringFilter(SlotOption_Name, value, negate); - break; - - case DatItemField.SoftwareListStatus: - if (negate) - SoftwareListStatus.Negative |= value.AsEnumValue(); - else - SoftwareListStatus.Positive |= value.AsEnumValue(); - break; - - case DatItemField.SpamSum: - SetStringFilter(SpamSum, value, negate); - break; - - case DatItemField.Status: - if (negate) - Status.Negative |= value.AsEnumValue(); - else - Status.Positive |= value.AsEnumValue(); - break; - - case DatItemField.Summation: - SetStringFilter(Summation, value, negate); - break; - - case DatItemField.SupportStatus: - if (negate) - SupportStatus.Negative |= value.AsEnumValue(); - else - SupportStatus.Positive |= value.AsEnumValue(); - break; - - case DatItemField.Tag: - SetStringFilter(Tag, value, negate); - break; - - case DatItemField.Tilt: - SetBooleanFilter(Tilt, value, negate); - break; - - case DatItemField.Type: - if (value.AsEnumValue() == ItemType.NULL) - return; - - SetStringFilter(Type, value, negate); - break; - - case DatItemField.Unofficial: - SetBooleanFilter(Unofficial, value, negate); - break; - - case DatItemField.Value: - SetStringFilter(Value, value, negate); - break; - - case DatItemField.VBEnd: - SetLongFilter(VBEnd, value, negate); - break; - - case DatItemField.VBStart: - SetLongFilter(VBStart, value, negate); - break; - - case DatItemField.VTotal: - SetLongFilter(VTotal, value, negate); - break; - - case DatItemField.Width: - SetLongFilter(Width, value, negate); - break; - - case DatItemField.Writable: - SetBooleanFilter(Writable, value, negate); - break; - } - } - - #endregion - - #region Running - - /// - /// Check to see if a DatItem passes the filters - /// - /// DatItem to check - /// True if the item passed the filter, false otherwise - public bool PassesFilters(DatItem datItem) - { - if (datItem == null) - return false; - - #region Common - - // Filter on item type - if (!PassStringFilter(Type, datItem.ItemType.ToString())) - return false; - - // Name is common if the name is non-null - if (datItem.GetName() != null) - { - // Filter on item name - if (!PassStringFilter(Name, datItem.GetName())) - return false; - } - - #endregion - - #region Item-Specific - - return datItem switch - { - Adjuster adjuster => PassesFilters(adjuster), - Analog analog => PassesFilters(analog), - Archive archive => PassesFilters(archive), - BiosSet biosSet => PassesFilters(biosSet), - Chip chip => PassesFilters(chip), - Condition condition => PassesFilters(condition), - Configuration configuration => PassesFilters(configuration), - ConfLocation confLocation => PassesFilters(confLocation), - ConfSetting confSetting => PassesFilters(confSetting), - Control control => PassesFilters(control), - DataArea dataArea => PassesFilters(dataArea), - Device device => PassesFilters(device), - DipLocation dipLocation => PassesFilters(dipLocation), - DipSwitch dipSwitch => PassesFilters(dipSwitch), - DipValue dipValue => PassesFilters(dipValue), - Disk disk => PassesFilters(disk), - DiskArea diskArea => PassesFilters(diskArea), - Display display => PassesFilters(display), - Driver driver => PassesFilters(driver), - Extension extension => PassesFilters(extension), - Feature feature => PassesFilters(feature), - Info info => PassesFilters(info), - Input input => PassesFilters(input), - Instance instance => PassesFilters(instance), - Media media => PassesFilters(media), - Part part => PassesFilters(part), - PartFeature partFeature => PassesFilters(partFeature), - Port port => PassesFilters(port), - RamOption ramOption => PassesFilters(ramOption), - Release release => PassesFilters(release), - Rom rom => PassesFilters(rom), - SharedFeature sharedFeature => PassesFilters(sharedFeature), - Slot slot => PassesFilters(slot), - SlotOption slotOption => PassesFilters(slotOption), - SoftwareList softwareList => PassesFilters(softwareList), - Sound sound => PassesFilters(sound), - _ => false, - }; - - #endregion - } - - /// - /// Check to see if an Adjuster passes the filters - /// - /// Adjuster to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Adjuster adjuster) - { - // DatItem_Default - if (!PassBoolFilter(Default, adjuster.Default)) - return false; - - // Filter on individual conditions - if (adjuster.ConditionsSpecified) - { - foreach (Condition condition in adjuster.Conditions!) - { - if (!PassesFilters(condition, true)) - return false; - } - } - - return true; - } - - /// - /// Check to see if an Analog passes the filters - /// - /// Analog to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Analog analog) - { - // DatItem_Analog_Mask - if (!PassStringFilter(Analog_Mask, analog.Mask)) - return false; - - return true; - } - - /// - /// Check to see if an Archive passes the filters - /// - /// Archive to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Archive archive) - { - // DatItem_Categories - if (!PassStringFilter(Categories, archive.Categories)) - return false; - - // DatItem_Clone - if (!PassStringFilter(Clone, archive.CloneValue)) - return false; - - // DatItem_Complete - if (!PassStringFilter(Complete, archive.Complete)) - return false; - - // DatItem_DevStatus - if (!PassStringFilter(DevStatus, archive.DevStatus)) - return false; - - // DatItem_Languages - if (!PassStringFilter(Languages, archive.Languages)) - return false; - - // DatItem_Number - if (!PassStringFilter(Number, archive.Number)) - return false; - - // DatItem_Physical - if (!PassStringFilter(Physical, archive.Physical)) - return false; - - // DatItem_Region - if (!PassStringFilter(Region, archive.Region)) - return false; - - // DatItem_RegParent - if (!PassStringFilter(RegParent, archive.RegParent)) - return false; - - return true; - } - - /// - /// Check to see if a BiosSet passes the filters - /// - /// BiosSet to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(BiosSet biosSet) - { - // DatItem_Default - if (!PassBoolFilter(Default, biosSet.Default)) - return false; - - // DatItem_Description - if (!PassStringFilter(Description, biosSet.Description)) - return false; - - return true; - } - - /// - /// Check to see if a Chip passes the filters - /// - /// Chip to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Chip chip) - { - // DatItem_ChipType - if (ChipType.MatchesPositive(Core.ChipType.NULL, chip.ChipType) == false) - return false; - if (ChipType.MatchesNegative(Core.ChipType.NULL, chip.ChipType) == true) - return false; - - // DatItem_Clock - if (!PassLongFilter(Clock, chip.Clock)) - return false; - - // DatItem_Tag - if (!PassStringFilter(Tag, chip.Tag)) - return false; - - return true; - } - - /// - /// Check to see if a Condition passes the filters - /// - /// Condition to check - /// True if this is a subitem, false otherwise - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Condition condition, bool sub = false) - { - if (sub) - { - // DatItem_Condition_Mask - if (!PassStringFilter(Condition_Mask, condition.Mask)) - return false; - - // DatItem_Condition_Relation - if (Condition_Relation.MatchesPositive(Core.Relation.NULL, condition.Relation) == false) - return false; - if (Condition_Relation.MatchesNegative(Core.Relation.NULL, condition.Relation) == true) - return false; - - // DatItem_Condition_Tag - if (!PassStringFilter(Condition_Tag, condition.Tag)) - return false; - - // DatItem_Condition_Value - if (!PassStringFilter(Condition_Value, condition.Value)) - return false; - } - else - { - // DatItem_Mask - if (!PassStringFilter(Mask, condition.Mask)) - return false; - - // DatItem_Relation - if (Relation.MatchesPositive(Core.Relation.NULL, condition.Relation) == false) - return false; - if (Relation.MatchesNegative(Core.Relation.NULL, condition.Relation) == true) - return false; - - // DatItem_Tag - if (!PassStringFilter(Tag, condition.Tag)) - return false; - - // DatItem_Value - if (!PassStringFilter(Value, condition.Value)) - return false; - } - - return true; - } - - /// - /// Check to see if a Configuration passes the filters - /// - /// Configuration to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Configuration configuration) - { - // DatItem_Mask - if (!PassStringFilter(Mask, configuration.Mask)) - return false; - - // DatItem_Tag - if (!PassStringFilter(Tag, configuration.Tag)) - return false; - - // Filter on individual conditions - if (configuration.ConditionsSpecified) - { - foreach (Condition subCondition in configuration.Conditions!) - { - if (!PassesFilters(subCondition, true)) - return false; - } - } - - // Filter on individual locations - if (configuration.LocationsSpecified) - { - foreach (ConfLocation subLocation in configuration.Locations!) - { - if (!PassesFilters(subLocation)) - return false; - } - } - - // Filter on individual settings - if (configuration.SettingsSpecified) - { - foreach (ConfSetting subSetting in configuration.Settings!) - { - if (!PassesFilters(subSetting)) - return false; - } - } - - return true; - } - - /// - /// Check to see if a ConfLocation passes the filters - /// - /// ConfLocation to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(ConfLocation confLocation) - { - // DatItem_Location_Inverted - if (!PassBoolFilter(Location_Inverted, confLocation.Inverted)) - return false; - - // DatItem_Location_Name - if (!PassStringFilter(Location_Name, confLocation.Name)) - return false; - - // DatItem_Location_Number - if (!PassLongFilter(Location_Number, confLocation.Number)) - return false; - - return true; - } - - /// - /// Check to see if a ConfSetting passes the filters - /// - /// ConfSetting to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(ConfSetting confSetting) - { - // DatItem_Setting_Default - if (!PassBoolFilter(Setting_Default, confSetting.Default)) - return false; - - // DatItem_Setting_Name - if (!PassStringFilter(Setting_Name, confSetting.Name)) - return false; - - // DatItem_Setting_Value - if (!PassStringFilter(Setting_Value, confSetting.Value)) - return false; - - // Filter on individual conditions - if (confSetting.ConditionsSpecified) - { - foreach (Condition subCondition in confSetting.Conditions!) - { - if (!PassesFilters(subCondition, true)) - return false; - } - } - - return true; - } - - /// - /// Check to see if a Control passes the filters - /// - /// Control to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Control control) - { - // DatItem_Control_Buttons - if (!PassLongFilter(Control_Buttons, control.Buttons)) - return false; - - // DatItem_Control_KeyDelta - if (!PassLongFilter(Control_KeyDelta, control.KeyDelta)) - return false; - - // DatItem_Control_Maximum - if (!PassLongFilter(Control_Maximum, control.Maximum)) - return false; - - // DatItem_Control_Minimum - if (!PassLongFilter(Control_Minimum, control.Minimum)) - return false; - - // DatItem_Control_Player - if (!PassLongFilter(Control_Player, control.Player)) - return false; - - // DatItem_Control_ReqButtons - if (!PassLongFilter(Control_ReqButtons, control.RequiredButtons)) - return false; - - // DatItem_Control_Reverse - if (!PassBoolFilter(Control_Reverse, control.Reverse)) - return false; - - // DatItem_Control_Sensitivity - if (!PassLongFilter(Control_Sensitivity, control.Sensitivity)) - return false; - - // DatItem_Control_Type - if (Control_Type.MatchesPositive(ControlType.NULL, control.ControlType) == false) - return false; - if (Control_Type.MatchesNegative(ControlType.NULL, control.ControlType) == true) - return false; - - // DatItem_Control_Ways - if (!PassStringFilter(Control_Ways, control.Ways)) - return false; - - // DatItem_Control_Ways2 - if (!PassStringFilter(Control_Ways2, control.Ways2)) - return false; - - // DatItem_Control_Ways3 - if (!PassStringFilter(Control_Ways3, control.Ways3)) - return false; - - return true; - } - - /// - /// Check to see if a DataArea passes the filters - /// - /// DataArea to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(DataArea dataArea) - { - // DatItem_AreaEndianness - if (AreaEndianness.MatchesPositive(Endianness.NULL, dataArea.Endianness) == false) - return false; - if (AreaEndianness.MatchesNegative(Endianness.NULL, dataArea.Endianness) == true) - return false; - - // DatItem_AreaName - if (!PassStringFilter(AreaName, dataArea.Name)) - return false; - - // DatItem_AreaSize - if (!PassLongFilter(AreaSize, dataArea.Size)) - return false; - - // DatItem_AreaWidth - if (!PassLongFilter(AreaWidth, dataArea.Width)) - return false; - - return true; - } - - /// - /// Check to see if a Device passes the filters - /// - /// Device to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Device device) - { - // DatItem_DeviceType - if (DeviceType.MatchesPositive(Core.DeviceType.NULL, device.DeviceType) == false) - return false; - if (DeviceType.MatchesNegative(Core.DeviceType.NULL, device.DeviceType) == true) - return false; - - // DatItem_FixedImage - if (!PassStringFilter(FixedImage, device.FixedImage)) - return false; - - // DatItem_Interface - if (!PassStringFilter(Interface, device.Interface)) - return false; - - // DatItem_Mandatory - if (!PassLongFilter(Mandatory, device.Mandatory)) - return false; - - // DatItem_Tag - if (!PassStringFilter(Tag, device.Tag)) - return false; - - // Filter on individual extensions - if (device.ExtensionsSpecified) - { - foreach (Extension subExtension in device.Extensions!) - { - if (!PassesFilters(subExtension)) - return false; - } - } - - // Filter on individual instances - if (device.InstancesSpecified) - { - foreach (Instance subInstance in device.Instances!) - { - if (!PassesFilters(subInstance)) - return false; - } - } - - return true; - } - - /// - /// Check to see if a DipLocation passes the filters - /// - /// DipLocation to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(DipLocation dipLocation) - { - // DatItem_Location_Inverted - if (!PassBoolFilter(Location_Inverted, dipLocation.Inverted)) - return false; - - // DatItem_Location_Name - if (!PassStringFilter(Location_Name, dipLocation.Name)) - return false; - - // DatItem_Location_Number - if (!PassLongFilter(Location_Number, dipLocation.Number)) - return false; - - return true; - } - - /// - /// Check to see if a DipSwitch passes the filters - /// - /// DipSwitch to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(DipSwitch dipSwitch) - { - // DatItem_Mask - if (!PassStringFilter(Mask, dipSwitch.Mask)) - return false; - - // DatItem_Tag - if (!PassStringFilter(Tag, dipSwitch.Tag)) - return false; - - // Filter on individual conditions - if (dipSwitch.ConditionsSpecified) - { - foreach (Condition subCondition in dipSwitch.Conditions!) - { - if (!PassesFilters(subCondition, true)) - return false; - } - } - - // Filter on individual locations - if (dipSwitch.LocationsSpecified) - { - foreach (DipLocation subLocation in dipSwitch.Locations!) - { - if (!PassesFilters(subLocation)) - return false; - } - } - - // Filter on individual values - if (dipSwitch.ValuesSpecified) - { - foreach (DipValue subValue in dipSwitch.Values!) - { - if (!PassesFilters(subValue)) - return false; - } - } - - // Filter on Part - if (dipSwitch.PartSpecified) - { - if (!PassesFilters(dipSwitch.Part!)) - return false; - } - - return true; - } - - /// - /// Check to see if a DipValue passes the filters - /// - /// DipValue to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(DipValue dipValue) - { - // DatItem_Setting_Default - if (!PassBoolFilter(Setting_Default, dipValue.Default)) - return false; - - // DatItem_Setting_Name - if (!PassStringFilter(Setting_Name, dipValue.Name)) - return false; - - // DatItem_Setting_Value - if (!PassStringFilter(Setting_Value, dipValue.Value)) - return false; - - // Filter on individual conditions - if (dipValue.ConditionsSpecified) - { - foreach (Condition subCondition in dipValue.Conditions!) - { - if (!PassesFilters(subCondition, true)) - return false; - } - } - - return true; - } - - /// - /// Check to see if a Disk passes the filters - /// - /// Disk to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Disk disk) - { - // DatItem_Index - if (!PassStringFilter(Index, disk.Index)) - return false; - - // DatItem_MD5 - if (!PassStringFilter(MD5, disk.MD5)) - return false; - - // DatItem_Merge - if (!PassStringFilter(Merge, disk.MergeTag)) - return false; - - // DatItem_Optional - if (!PassBoolFilter(Optional, disk.Optional)) - return false; - - // DatItem_Region - if (!PassStringFilter(Region, disk.Region)) - return false; - - // DatItem_SHA1 - if (!PassStringFilter(SHA1, disk.SHA1)) - return false; - - // DatItem_Status - if (Status.MatchesPositive(ItemStatus.NULL, disk.ItemStatus) == false) - return false; - if (Status.MatchesNegative(ItemStatus.NULL, disk.ItemStatus) == true) - return false; - - // DatItem_Writable - if (!PassBoolFilter(Writable, disk.Writable)) - return false; - - // Filter on DiskArea - if (disk.DiskAreaSpecified) - { - if (!PassesFilters(disk.DiskArea!)) - return false; - } - - // Filter on Part - if (disk.PartSpecified) - { - if (!PassesFilters(disk.Part!)) - return false; - } - - return true; - } - - /// - /// Check to see if a DiskArea passes the filters - /// - /// DiskArea to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(DiskArea diskArea) - { - // DatItem_AreaName - if (!PassStringFilter(AreaName, diskArea.Name)) - return false; - - return true; - } - - /// - /// Check to see if a Display passes the filters - /// - /// Display to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Display display) - { - // DatItem_DisplayType - if (DisplayType.MatchesPositive(Core.DisplayType.NULL, display.DisplayType) == false) - return false; - if (DisplayType.MatchesNegative(Core.DisplayType.NULL, display.DisplayType) == true) - return false; - - // DatItem_FlipX - if (!PassBoolFilter(FlipX, display.FlipX)) - return false; - - // DatItem_HBEnd - if (!PassLongFilter(HBEnd, display.HBEnd)) - return false; - - // DatItem_HBStart - if (!PassLongFilter(HBStart, display.HBStart)) - return false; - - // DatItem_Height - if (!PassLongFilter(Height, display.Height)) - return false; - - // DatItem_HTotal - if (!PassLongFilter(HTotal, display.HTotal)) - return false; - - // DatItem_PixClock - if (!PassLongFilter(PixClock, display.PixClock)) - return false; - - // DatItem_Refresh - if (!PassDoubleFilter(Refresh, display.Refresh)) - return false; - - // DatItem_Rotate - if (!PassLongFilter(Rotate, display.Rotate)) - return false; - - // DatItem_Tag - if (!PassStringFilter(Tag, display.Tag)) - return false; - - // DatItem_VBEnd - if (!PassLongFilter(VBEnd, display.VBEnd)) - return false; - - // DatItem_VBStart - if (!PassLongFilter(VBStart, display.VBStart)) - return false; - - // DatItem_VTotal - if (!PassLongFilter(VTotal, display.VTotal)) - return false; - - // DatItem_Width - if (!PassLongFilter(Width, display.Width)) - return false; - - return true; - } - - /// - /// Check to see if a Driver passes the filters - /// - /// Driver to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Driver driver) - { - // DatItem_CocktailStatus - if (CocktailStatus.MatchesPositive(Core.SupportStatus.NULL, driver.Cocktail) == false) - return false; - if (CocktailStatus.MatchesNegative(Core.SupportStatus.NULL, driver.Cocktail) == true) - return false; - - // DatItem_EmulationStatus - if (EmulationStatus.MatchesPositive(Core.SupportStatus.NULL, driver.Emulation) == false) - return false; - if (EmulationStatus.MatchesNegative(Core.SupportStatus.NULL, driver.Emulation) == true) - return false; - - // DatItem_Incomplete - if (!PassBoolFilter(Incomplete, driver.Incomplete)) - return false; - - // DatItem_NoSoundHardware - if (!PassBoolFilter(NoSoundHardware, driver.NoSoundHardware)) - return false; - - // DatItem_RequiresArtwork - if (!PassBoolFilter(RequiresArtwork, driver.RequiresArtwork)) - return false; - - // DatItem_SaveStateStatus - if (SaveStateStatus.MatchesPositive(Supported.NULL, driver.SaveState) == false) - return false; - if (SaveStateStatus.MatchesNegative(Supported.NULL, driver.SaveState) == true) - return false; - - // DatItem_SupportStatus - if (SupportStatus.MatchesPositive(Core.SupportStatus.NULL, driver.Status) == false) - return false; - if (SupportStatus.MatchesNegative(Core.SupportStatus.NULL, driver.Status) == true) - return false; - - // DatItem_Unofficial - if (!PassBoolFilter(Unofficial, driver.Unofficial)) - return false; - - return true; - } - - /// - /// Check to see if a Extension passes the filters - /// - /// Extension to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Extension extension) - { - // DatItem_Extension_Name - if (!PassStringFilter(Extension_Name, extension.Name)) - return false; - - return true; - } - - /// - /// Check to see if a Feature passes the filters - /// - /// Feature to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Feature feature) - { - // DatItem_FeatureOverall - if (FeatureOverall.MatchesPositive(Core.FeatureStatus.NULL, feature.Overall) == false) - return false; - if (FeatureOverall.MatchesNegative(Core.FeatureStatus.NULL, feature.Overall) == true) - return false; - - // DatItem_FeatureStatus - if (FeatureStatus.MatchesPositive(Core.FeatureStatus.NULL, feature.Status) == false) - return false; - if (FeatureStatus.MatchesNegative(Core.FeatureStatus.NULL, feature.Status) == true) - return false; - - // DatItem_FeatureType - if (FeatureType.MatchesPositive(Core.FeatureType.NULL, feature.Type) == false) - return false; - if (FeatureType.MatchesNegative(Core.FeatureType.NULL, feature.Type) == true) - return false; - - return true; - } - - /// - /// Check to see if a Info passes the filters - /// - /// Info to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Info info) - { - // DatItem_Value - if (!PassStringFilter(Value, info.Value)) - return false; - - return true; - } - - /// - /// Check to see if a Input passes the filters - /// - /// Input to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Input input) - { - // DatItem_Coins - if (!PassLongFilter(Coins, input.Coins)) - return false; - - // DatItem_Players - if (!PassLongFilter(Players, input.Players)) - return false; - - // DatItem_Service - if (!PassBoolFilter(Service, input.Service)) - return false; - - // DatItem_Tilt - if (!PassBoolFilter(Tilt, input.Tilt)) - return false; - - // Filter on individual controls - if (input.ControlsSpecified) - { - foreach (Control subControl in input.Controls!) - { - if (!PassesFilters(subControl)) - return false; - } - } - - return true; - } - - /// - /// Check to see if a Instance passes the filters - /// - /// Instance to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Instance instance) - { - // DatItem_Instance_BriefName - if (!PassStringFilter(Instance_BriefName, instance.BriefName)) - return false; - - // DatItem_Instance_Name - if (!PassStringFilter(Instance_Name, instance.Name)) - return false; - - return true; - } - - /// - /// Check to see if a Media passes the filters - /// - /// Media to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Media media) - { - // DatItem_MD5 - if (!PassStringFilter(MD5, media.MD5)) - return false; - - // DatItem_SHA1 - if (!PassStringFilter(SHA1, media.SHA1)) - return false; - - // DatItem_SHA256 - if (!PassStringFilter(SHA256, media.SHA256)) - return false; - - // DatItem_SpamSum - if (!PassStringFilter(SpamSum, media.SpamSum)) - return false; - - return true; - } - - /// - /// Check to see if a Part passes the filters - /// - /// Part to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Part part) - { - // DatItem_Part_Interface - if (!PassStringFilter(Part_Interface, part.Interface)) - return false; - - // DatItem_Part_Name - if (!PassStringFilter(Part_Name, part.Name)) - return false; - - // Filter on features - if (part.FeaturesSpecified) - { - foreach (PartFeature subPartFeature in part.Features!) - { - if (!PassesFilters(subPartFeature)) - return false; - } - } - - return true; - } - - /// - /// Check to see if a PartFeature passes the filters - /// - /// PartFeature to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(PartFeature partFeature) - { - // DatItem_Part_Feature_Name - if (!PassStringFilter(Part_Feature_Name, partFeature.Name)) - return false; - - // DatItem_Part_Feature_Value - if (!PassStringFilter(Part_Feature_Value, partFeature.Value)) - return false; - - return true; - } - - /// - /// Check to see if a Port passes the filters - /// - /// Port to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Port port) - { - // DatItem_Tag - if (!PassStringFilter(Tag, port.Tag)) - return false; - - // Filter on individual analogs - if (port.AnalogsSpecified) - { - foreach (Analog subAnalog in port.Analogs!) - { - if (!PassesFilters(subAnalog)) - return false; - } - } - - return true; - } - - /// - /// Check to see if a RamOption passes the filters - /// - /// RamOption to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(RamOption ramOption) - { - // DatItem_Content - if (!PassStringFilter(Content, ramOption.Content)) - return false; - - // DatItem_Default - if (!PassBoolFilter(Default, ramOption.Default)) - return false; - - return true; - } - - /// - /// Check to see if a Release passes the filters - /// - /// Release to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Release release) - { - // DatItem_Date - if (!PassStringFilter(Date, release.Date)) - return false; - - // DatItem_Default - if (!PassBoolFilter(Default, release.Default)) - return false; - - // DatItem_Language - if (!PassStringFilter(Language, release.Language)) - return false; - - // DatItem_Region - if (!PassStringFilter(Region, release.Region)) - return false; - - return true; - } - - /// - /// Check to see if a Rom passes the filters - /// - /// Rom to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Rom rom) - { - // DatItem_AltName - if (!PassStringFilter(AltName, rom.AltName)) - return false; - - // DatItem_AltTitle - if (!PassStringFilter(AltTitle, rom.AltTitle)) - return false; - - // DatItem_ArchiveDotOrgFormat - if (!PassStringFilter(ArchiveDotOrgFormat, rom.ArchiveDotOrgFormat)) - return false; - - // DatItem_ArchiveDotOrgSource - if (!PassStringFilter(ArchiveDotOrgSource, rom.ArchiveDotOrgSource)) - return false; - - // DatItem_Bios - if (!PassStringFilter(Bios, rom.Bios)) - return false; - - // DatItem_Boot - if (!PassStringFilter(Boot, rom.Boot)) - return false; - - // DatItem_CRC - if (!PassStringFilter(CRC, rom.CRC)) - return false; - - // DatItem_Date - if (!PassStringFilter(Date, rom.Date)) - return false; - - // DatItem_Inverted - if (!PassBoolFilter(Inverted, rom.Inverted)) - return false; - - // DatItem_LoadFlag - if (LoadFlag.MatchesPositive(Core.LoadFlag.NULL, rom.LoadFlag) == false) - return false; - if (LoadFlag.MatchesNegative(Core.LoadFlag.NULL, rom.LoadFlag) == true) - return false; - - // DatItem_MD5 - if (!PassStringFilter(MD5, rom.MD5)) - return false; - - // DatItem_Merge - if (!PassStringFilter(Merge, rom.MergeTag)) - return false; - - // DatItem_MIA - if (!PassBoolFilter(MIA, rom.MIA)) - return false; - - // DatItem_Offset - if (!PassStringFilter(Offset, rom.Offset)) - return false; - - // DatItem_OpenMSXSubType - if (OpenMSXSubType.MatchesPositive(Core.OpenMSXSubType.NULL, rom.OpenMSXSubType) == false) - return false; - if (OpenMSXSubType.MatchesNegative(Core.OpenMSXSubType.NULL, rom.OpenMSXSubType) == true) - return false; - - // DatItem_OpenMSXType - if (!PassStringFilter(OpenMSXType, rom.OpenMSXType)) - return false; - - // DatItem_Optional - if (!PassBoolFilter(Optional, rom.Optional)) - return false; - - // DatItem_Original - if (!PassStringFilter(Original, rom.Original?.Content)) - return false; - - // DatItem_OriginalFilename - if (!PassStringFilter(OriginalFilename, rom.OriginalFilename)) - return false; - - // DatItem_Region - if (!PassStringFilter(Region, rom.Region)) - return false; - - // DatItem_Remark - if (!PassStringFilter(Remark, rom.Remark)) - return false; - - // DatItem_Rotation - if (!PassStringFilter(Rotation, rom.Rotation)) - return false; - - // DatItem_SHA1 - if (!PassStringFilter(SHA1, rom.SHA1)) - return false; - - // DatItem_SHA256 - if (!PassStringFilter(SHA256, rom.SHA256)) - return false; - - // DatItem_SHA384 - if (!PassStringFilter(SHA384, rom.SHA384)) - return false; - - // DatItem_SHA512 - if (!PassStringFilter(SHA512, rom.SHA512)) - return false; - - // DatItem_Size - if (!PassLongFilter(Size, rom.Size)) - return false; - - // DatItem_SpamSum - if (!PassStringFilter(SpamSum, rom.SpamSum)) - return false; - - // DatItem_Status - if (Status.MatchesPositive(ItemStatus.NULL, rom.ItemStatus) == false) - return false; - if (Status.MatchesNegative(ItemStatus.NULL, rom.ItemStatus) == true) - return false; - - // DatItem_Summation - if (!PassStringFilter(Summation, rom.Summation)) - return false; - - // DatItem_Value - if (!PassStringFilter(Value, rom.Value)) - return false; - - // Filter on DataArea - if (rom.DataAreaSpecified) - { - if (!PassesFilters(rom.DataArea!)) - return false; - } - - // Filter on Part - if (rom.PartSpecified) - { - if (!PassesFilters(rom.Part!)) - return false; - } - - return true; - } - - /// - /// Check to see if a SharedFeature passes the filters - /// - /// SharedFeature to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(SharedFeature sharedFeature) - { - // DatItem_Value - if (!PassStringFilter(Value, sharedFeature.Value)) - return false; - - return true; - } - - /// - /// Check to see if a Slot passes the filters - /// - /// Slot to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Slot slot) - { - // Filter on individual slot options - if (slot.SlotOptionsSpecified) - { - foreach (SlotOption subSlotOption in slot.SlotOptions!) - { - if (!PassesFilters(subSlotOption)) - return false; - } - } - - return true; - } - - /// - /// Check to see if a SlotOption passes the filters - /// - /// SlotOption to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(SlotOption slotOption) - { - // DatItem_SlotOption_Default - if (!PassBoolFilter(SlotOption_Default, slotOption.Default)) - return false; - - // DatItem_SlotOption_DeviceName - if (!PassStringFilter(SlotOption_DeviceName, slotOption.DeviceName)) - return false; - - // DatItem_SlotOption_Name - if (!PassStringFilter(SlotOption_Name, slotOption.Name)) - return false; - - return true; - } - - /// - /// Check to see if a SoftwareList passes the filters - /// - /// SoftwareList to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(SoftwareList softwareList) - { - // DatItem_Filter - if (!PassStringFilter(Filter, softwareList.Filter)) - return false; - - // DatItem_SoftwareListStatus - if (SoftwareListStatus.MatchesPositive(Core.SoftwareListStatus.None, softwareList.Status) == false) - return false; - if (SoftwareListStatus.MatchesNegative(Core.SoftwareListStatus.None, softwareList.Status) == true) - return false; - - // DatItem_Tag - if (!PassStringFilter(Tag, softwareList.Tag)) - return false; - - return true; - } - - /// - /// Check to see if a Sound passes the filters - /// - /// Sound to check - /// True if the item passed the filter, false otherwise - private bool PassesFilters(Sound sound) - { - // DatItem_Channels - if (!PassLongFilter(Channels, sound.Channels)) - return false; - - return true; - } - - #endregion - } -} diff --git a/SabreTools.Filtering/Filter.cs b/SabreTools.Filtering/Filter.cs deleted file mode 100644 index 434d1ab1..00000000 --- a/SabreTools.Filtering/Filter.cs +++ /dev/null @@ -1,455 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -using SabreTools.Core; -using SabreTools.Core.Tools; -using SabreTools.DatFiles; -using SabreTools.DatItems; -using SabreTools.Logging; - -namespace SabreTools.Filtering -{ - /// - /// Represents the filtering operations that need to be performed on a set of items, usually a DAT - /// - public class Filter - { - #region Fields - - /// - /// Filter for DatItem fields - /// - public DatItemFilter? DatItemFilter { get; set; } - - /// - /// Filter for Machine fields - /// - public MachineFilter? MachineFilter { get; set; } - - #endregion - - #region Logging - - /// - /// Logging object - /// - protected Logger logger; - - #endregion - - #region Constructors - - /// - /// Constructor - /// - public Filter() - { - logger = new Logger(this); - } - - #endregion - - #region Population - - /// - /// Populate the filters objects using a set of key:value filters - /// - /// List of key:value where ~key/!key is negated - public void PopulateFiltersFromList(List? filters) - { - // Instantiate the filters, if necessary - MachineFilter ??= new MachineFilter(); - DatItemFilter ??= new DatItemFilter(); - - // If the list is null or empty, just return - if (filters == null || filters.Count == 0) - return; - - InternalStopwatch watch = new("Populating filters from list"); - - foreach (string filterPair in filters) - { - (string? field, string? value, bool negate) = ProcessFilterPair(filterPair); - - // If we don't even have a possible filter pair - if (field == null && value == null) - continue; - - // Machine fields - MachineField machineField = field.AsMachineField(); - if (machineField != MachineField.NULL) - { - MachineFilter.SetFilter(machineField, value, negate); - MachineFilter.HasFilters = true; - continue; - } - - // DatItem fields - DatItemField datItemField = field.AsDatItemField(); - if (datItemField != DatItemField.NULL) - { - DatItemFilter.SetFilter(datItemField, value, negate); - DatItemFilter.HasFilters = true; - continue; - } - - // If we didn't match anything, log an error - logger.Warning($"The value {field} did not match any filterable field names. Please check the wiki for more details on supported field names."); - } - - watch.Stop(); - } - - /// - /// Split the parts of a filter statement - /// - /// key:value where ~key/!key is negated - protected (string? field, string? value, bool negate) ProcessFilterPair(string filter) - { - // If we don't even have a possible filter pair - if (!filter.Contains(':')) - { - logger.Warning($"'{filter}` is not a valid filter string. Valid filter strings are of the form 'key:value'. Please refer to README.1ST or the help feature for more details."); - return (null, null, false); - } - - string filterTrimmed = filter.Trim('"', ' ', '\t'); - bool negate = filterTrimmed.StartsWith("!") - || filterTrimmed.StartsWith("~") - || filterTrimmed.StartsWith("not-"); - filterTrimmed = filterTrimmed.TrimStart('!', '~'); - filterTrimmed = filterTrimmed.StartsWith("not-") ? filterTrimmed.Substring(4) : filterTrimmed; - - string filterFieldString = filterTrimmed.Split(':')[0].ToLowerInvariant().Trim('"', ' ', '\t'); - string filterValue = filterTrimmed.Substring(filterFieldString.Length + 1).Trim('"', ' ', '\t'); - - return (filterFieldString, filterValue, negate); - } - - /// - /// Set a bool? filter - /// - /// FilterItem to populate - /// String value to add - /// True to set negative filter, false otherwise - protected static void SetBooleanFilter(FilterItem filterItem, string? value, bool negate) - { - if (negate || (value?.Equals("false", StringComparison.OrdinalIgnoreCase) ?? false)) - filterItem.Neutral = false; - else - filterItem.Neutral = true; - } - - /// - /// Set a long? filter - /// - /// FilterItem to populate - /// String value to add - /// True to set negative filter, false otherwise - protected static void SetDoubleFilter(FilterItem filterItem, string? value, bool negate) - { - bool? operation = null; - if (value?.StartsWith(">") == true) - operation = true; - else if (value?.StartsWith("<") == true) - operation = false; - else if (value?.StartsWith("=") == true) - operation = null; - - string? valueString = value?.TrimStart('>', '<', '='); - if (!Double.TryParse(valueString, out double valueDouble)) - return; - - // Equal - if (operation == null && !negate) - { - filterItem.Neutral = valueDouble; - } - - // Not Equal - else if (operation == null && negate) - { - filterItem.Negative = valueDouble - 1; - filterItem.Positive = valueDouble + 1; - } - - // Greater Than or Equal - else if (operation == true && !negate) - { - filterItem.Positive = valueDouble; - } - - // Strictly Less Than - else if (operation == true && negate) - { - filterItem.Negative = valueDouble - 1; - } - - // Less Than or Equal - else if (operation == false && !negate) - { - filterItem.Negative = valueDouble; - } - - // Strictly Greater Than - else if (operation == false && negate) - { - filterItem.Positive = valueDouble + 1; - } - } - - /// - /// Set a long? filter - /// - /// FilterItem to populate - /// String value to add - /// True to set negative filter, false otherwise - protected static void SetLongFilter(FilterItem filterItem, string? value, bool negate) - { - bool? operation = null; - if (value?.StartsWith(">") == true) - operation = true; - else if (value?.StartsWith("<") == true) - operation = false; - else if (value?.StartsWith("=") == true) - operation = null; - - string? valueString = value?.TrimStart('>', '<', '='); - long? valueLong = NumberHelper.ConvertToInt64(valueString); - if (valueLong == null) - return; - - // Equal - if (operation == null && !negate) - { - filterItem.Neutral = valueLong; - } - - // Not Equal - else if (operation == null && negate) - { - filterItem.Negative = valueLong - 1; - filterItem.Positive = valueLong + 1; - } - - // Greater Than or Equal - else if (operation == true && !negate) - { - filterItem.Positive = valueLong; - } - - // Strictly Less Than - else if (operation == true && negate) - { - filterItem.Negative = valueLong - 1; - } - - // Less Than or Equal - else if (operation == false && !negate) - { - filterItem.Negative = valueLong; - } - - // Strictly Greater Than - else if (operation == false && negate) - { - filterItem.Positive = valueLong + 1; - } - } - - /// - /// Set a string filter - /// - /// FilterItem to populate - /// String value to add - /// True to set negative filter, false otherwise - protected static void SetStringFilter(FilterItem filterItem, string? value, bool negate) - { - if (negate) - filterItem.NegativeSet.Add(value); - else - filterItem.PositiveSet.Add(value); - } - - #endregion - - #region Running - - /// - /// Apply a set of Filters on the DatFile - /// - /// Current DatFile object to run operations on - /// True if entire machines are considered, false otherwise (default) - /// True if the error that is thrown should be thrown back to the caller, false otherwise - /// True if the DatFile was filtered, false on error - public bool ApplyFilters(DatFile datFile, bool perMachine = false, bool throwOnError = false) - { - // If we have null filters, return false - if (MachineFilter == null || DatItemFilter == null) - return false; - - // If no filters were set, return true - if (!MachineFilter.HasFilters && !DatItemFilter.HasFilters) - return true; - - InternalStopwatch watch = new("Applying filters to DAT"); - - // If we're filtering per machine, bucket by machine first - if (perMachine) - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None); - - try - { - // Loop over every key in the dictionary - List keys = [.. datFile.Items.Keys]; - foreach (string key in keys) - { - // For every item in the current key - bool machinePass = true; - var items = datFile.Items[key]; - if (items == null) - continue; - - foreach (DatItem item in items) - { - // If we have a null item, we can't pass it - if (item == null) - continue; - - // If the item is already filtered out, we skip - if (item.Remove) - continue; - - // If the rom doesn't pass the filter, mark for removal - if (!PassesAllFilters(item)) - { - item.Remove = true; - - // If we're in machine mode, set and break - if (perMachine) - { - machinePass = false; - break; - } - } - } - - // If we didn't pass and we're in machine mode, set all items as remove - if (perMachine && !machinePass) - { - foreach (DatItem item in items) - { - item.Remove = true; - } - } - - // Assign back for caution - datFile.Items[key] = items; - } - } - catch (Exception ex) when (!throwOnError) - { - logger.Error(ex); - return false; - } - finally - { - watch.Stop(); - } - - return true; - } - - /// - /// Check to see if a DatItem passes the filters - /// - /// DatItem to check - /// True if the item passed the filter, false otherwise - internal bool PassesAllFilters(DatItem datItem) - { - // Null item means it will never pass - if (datItem == null) - return false; - - // Filter on Machine fields - if (MachineFilter == null || (MachineFilter.HasFilters && !MachineFilter.PassesFilters(datItem.Machine))) - return false; - - // If we have no DatItemFilters set, just return true - if (DatItemFilter == null || !DatItemFilter.HasFilters) - return true; - - // Filter on DatItem fields - return DatItemFilter.PassesFilters(datItem); - } - - /// - /// Determines if a value passes a bool? filter - /// - /// Filter item to check - /// Value to check - /// True if the value passes, false otherwise - protected static bool PassBoolFilter(FilterItem filterItem, bool? value) - { - if (filterItem.MatchesNeutral(null, value) == false) - return false; - - return true; - } - - /// - /// Determines if a value passes a double? filter - /// - /// Filter item to check - /// Value to check - /// True if the value passes, false otherwise - protected static bool PassDoubleFilter(FilterItem filterItem, double? value) - { - if (filterItem.MatchesNeutral(null, value) == false) - return false; - else if (filterItem.MatchesPositive(null, value) == false) - return false; - else if (filterItem.MatchesNegative(null, value) == false) - return false; - - return true; - } - - /// - /// Determines if a value passes a long? filter - /// - /// Filter item to check - /// Value to check - /// True if the value passes, false otherwise - protected static bool PassLongFilter(FilterItem filterItem, long? value) - { - if (filterItem.MatchesNeutral(null, value) == false) - return false; - else if (filterItem.MatchesPositive(null, value) == false) - return false; - else if (filterItem.MatchesNegative(null, value) == false) - return false; - - return true; - } - - /// - /// Determines if a value passes a string filter - /// - /// Filter item to check - /// Value to check - /// True if the value passes, false otherwise - protected static bool PassStringFilter(FilterItem filterItem, string? value) - { - if (filterItem.MatchesPositiveSet(value) == false) - return false; - if (filterItem.MatchesNegativeSet(value) == true) - return false; - - return true; - } - - #endregion - } -} diff --git a/SabreTools.Filtering/MachineFilter.cs b/SabreTools.Filtering/MachineFilter.cs deleted file mode 100644 index be9a8a60..00000000 --- a/SabreTools.Filtering/MachineFilter.cs +++ /dev/null @@ -1,459 +0,0 @@ -using System.Collections.Generic; -using SabreTools.Core; -using SabreTools.Core.Tools; -using SabreTools.DatItems; -using SabreTools.Logging; - -namespace SabreTools.Filtering -{ - /// - /// Represents the filtering operations that need to be performed on a set of items, usually a DAT - /// - public class MachineFilter : Filter - { - #region Fields - - #region Filters - - public FilterItem Board { get; private set; } = new FilterItem(); - public FilterItem Buttons { get; private set; } = new FilterItem(); - public FilterItem Category { get; private set; } = new FilterItem(); - public FilterItem CloneOf { get; private set; } = new FilterItem(); - public FilterItem CloneOfID { get; private set; } = new FilterItem(); - public FilterItem Comment { get; private set; } = new FilterItem(); - public FilterItem Control { get; private set; } = new FilterItem(); - public FilterItem Country { get; private set; } = new FilterItem(); - public FilterItem CRC { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Description { get; private set; } = new FilterItem(); - public FilterItem Developer { get; private set; } = new FilterItem(); - public FilterItem DisplayCount { get; private set; } = new FilterItem(); - public FilterItem DisplayType { get; private set; } = new FilterItem(); - public FilterItem Enabled { get; private set; } = new FilterItem(); - public FilterItem GenMSXID { get; private set; } = new FilterItem(); - public FilterItem Genre { get; private set; } = new FilterItem(); - public FilterItem History { get; private set; } = new FilterItem(); - public FilterItem ID { get; private set; } = new FilterItem(); - public FilterItem Manufacturer { get; private set; } = new FilterItem(); - public FilterItem Name { get; private set; } = new FilterItem(); - public FilterItem Players { get; private set; } = new FilterItem(); - public FilterItem Publisher { get; private set; } = new FilterItem(); - public FilterItem Ratings { get; private set; } = new FilterItem(); - public FilterItem RebuildTo { get; private set; } = new FilterItem(); - public FilterItem RelatedTo { get; private set; } = new FilterItem(); - public FilterItem RomOf { get; private set; } = new FilterItem(); - public FilterItem Rotation { get; private set; } = new FilterItem(); - public FilterItem Runnable { get; private set; } = new FilterItem() { Positive = Core.Runnable.NULL, Negative = Core.Runnable.NULL }; - public FilterItem SampleOf { get; private set; } = new FilterItem(); - public FilterItem Score { get; private set; } = new FilterItem(); - public FilterItem SourceFile { get; private set; } = new FilterItem(); - public FilterItem Status { get; private set; } = new FilterItem(); - public FilterItem Subgenre { get; private set; } = new FilterItem(); - public FilterItem Supported { get; private set; } = new FilterItem() { Positive = Core.Supported.NULL, Negative = Core.Supported.NULL }; - public FilterItem System { get; private set; } = new FilterItem(); - public FilterItem TitleID { get; private set; } = new FilterItem(); - public FilterItem Type { get; private set; } = new FilterItem() { Positive = 0x0, Negative = 0x0 }; - public FilterItem Year { get; private set; } = new FilterItem(); - - #endregion // Machine Filters - - #region Additional Flags - - /// - /// Include romof and cloneof when filtering machine names - /// - public bool IncludeOfInGame { get; set; } - - /// - /// Determines if any filters have been set - /// - public bool HasFilters { get; set; } = false; - - #endregion - - #endregion // Fields - - #region Constructors - - /// - /// Constructor - /// - public MachineFilter() - { - logger = new Logger(this); - } - - #endregion - - #region Population - - /// - /// Set multiple filters from key - /// - /// Key for the filter to be set - /// List of values for the filter - /// True if negative filter, false otherwise - public void SetFilter(MachineField key, List values, bool negate) - { - foreach (string value in values) - { - SetFilter(key, value, negate); - } - } - - /// - /// Set a single filter from key - /// - /// Key for the filter to be set - /// Value of the filter - /// True if negative filter, false otherwise - public void SetFilter(MachineField key, string? value, bool negate) - { - switch (key) - { - case MachineField.Board: - SetStringFilter(Board, value, negate); - break; - - case MachineField.Buttons: - SetStringFilter(Buttons, value, negate); - break; - - case MachineField.Category: - SetStringFilter(Category, value, negate); - break; - - case MachineField.CloneOf: - SetStringFilter(CloneOf, value, negate); - break; - - case MachineField.CloneOfID: - SetStringFilter(CloneOfID, value, negate); - break; - - case MachineField.Comment: - SetStringFilter(Comment, value, negate); - break; - - case MachineField.Control: - SetStringFilter(Control, value, negate); - break; - - case MachineField.CRC: - SetBooleanFilter(CRC, value, negate); - break; - - case MachineField.Country: - SetStringFilter(Country, value, negate); - break; - - case MachineField.Description: - SetStringFilter(Description, value, negate); - break; - - case MachineField.Developer: - SetStringFilter(Developer, value, negate); - break; - - case MachineField.DisplayCount: - SetStringFilter(DisplayCount, value, negate); - break; - - case MachineField.DisplayType: - SetStringFilter(DisplayType, value, negate); - break; - - case MachineField.Enabled: - SetStringFilter(Enabled, value, negate); - break; - - case MachineField.GenMSXID: - SetStringFilter(GenMSXID, value, negate); - break; - - case MachineField.Genre: - SetStringFilter(Genre, value, negate); - break; - - case MachineField.History: - SetStringFilter(History, value, negate); - break; - - case MachineField.ID: - SetStringFilter(ID, value, negate); - break; - - case MachineField.Manufacturer: - SetStringFilter(Manufacturer, value, negate); - break; - - case MachineField.Name: - SetStringFilter(Name, value, negate); - break; - - case MachineField.Players: - SetStringFilter(Players, value, negate); - break; - - case MachineField.Publisher: - SetStringFilter(Publisher, value, negate); - break; - - case MachineField.Ratings: - SetStringFilter(Ratings, value, negate); - break; - - case MachineField.RebuildTo: - SetStringFilter(RebuildTo, value, negate); - break; - - case MachineField.RelatedTo: - SetStringFilter(RelatedTo, value, negate); - break; - - case MachineField.RomOf: - SetStringFilter(RomOf, value, negate); - break; - - case MachineField.Rotation: - SetStringFilter(Rotation, value, negate); - break; - - case MachineField.Runnable: - if (negate) - Runnable.Negative |= value.AsEnumValue(); - else - Runnable.Positive |= value.AsEnumValue(); - break; - - case MachineField.SampleOf: - SetStringFilter(SampleOf, value, negate); - break; - - case MachineField.Score: - SetStringFilter(Score, value, negate); - break; - - case MachineField.SourceFile: - SetStringFilter(SourceFile, value, negate); - break; - - case MachineField.Status: - SetStringFilter(Status, value, negate); - break; - - case MachineField.Subgenre: - SetStringFilter(Subgenre, value, negate); - break; - - case MachineField.Supported: - if (negate) - Supported.Negative |= value.AsEnumValue(); - else - Supported.Positive |= value.AsEnumValue(); - break; - - case MachineField.System: - SetStringFilter(System, value, negate); - break; - - case MachineField.TitleID: - SetStringFilter(TitleID, value, negate); - break; - - case MachineField.Type: - if (negate) - Type.Negative |= value.AsEnumValue(); - else - Type.Positive |= value.AsEnumValue(); - break; - - case MachineField.Year: - SetStringFilter(Year, value, negate); - break; - } - } - - #endregion - - #region Running - - /// - /// Check to see if a Machine passes the filters - /// - /// Machine to check - /// True if the machine passed the filter, false otherwise - public bool PassesFilters(Machine machine) - { - if (machine == null) - return false; - - // Machine_Board - if (!PassStringFilter(Board, machine.Board)) - return false; - - // Machine_Buttons - if (!PassStringFilter(Buttons, machine.Buttons)) - return false; - - // Machine_Category - if (!PassStringFilter(Category, machine.Category)) - return false; - - // Machine_CloneOf - if (!PassStringFilter(CloneOf, machine.CloneOf)) - return false; - - // Machine_CloneOfID - if (!PassStringFilter(CloneOfID, value: machine.NoIntroCloneOfId)) - return false; - - // Machine_Comment - if (!PassStringFilter(Comment, machine.Comment)) - return false; - - // Machine_Control - if (!PassStringFilter(Control, machine.Control)) - return false; - - // Machine_Country - if (!PassStringFilter(Country, machine.Country)) - return false; - - // Machine_CRC - if (!PassBoolFilter(CRC, machine.Crc)) - return false; - - // Machine_Description - if (!PassStringFilter(Description, machine.Description)) - return false; - - // Machine_Developer - if (!PassStringFilter(Developer, machine.Developer)) - return false; - - // Machine_DisplayCount - if (!PassStringFilter(DisplayCount, machine.DisplayCount)) - return false; - - // Machine_DisplayType - if (!PassStringFilter(DisplayType, machine.DisplayType)) - return false; - - // Machine_Enabled - if (!PassStringFilter(Enabled, machine.Enabled)) - return false; - - // Machine_GenMSXID - if (!PassStringFilter(GenMSXID, machine.GenMSXID)) - return false; - - // Machine_Genre - if (!PassStringFilter(Genre, machine.Genre)) - return false; - - // Machine_History - if (!PassStringFilter(History, machine.History)) - return false; - - // Machine_ID - if (!PassStringFilter(ID, machine.NoIntroId)) - return false; - - // Machine_Manufacturer - if (!PassStringFilter(Manufacturer, machine.Manufacturer)) - return false; - - // Machine_Name - bool passes = PassStringFilter(Name, machine.Name); - if (IncludeOfInGame) - { - passes |= PassStringFilter(Name, machine.CloneOf); - passes |= PassStringFilter(Name, machine.RomOf); - } - if (!passes) - return false; - - // Machine_Players - if (!PassStringFilter(Players, machine.Players)) - return false; - - // Machine_Publisher - if (!PassStringFilter(Publisher, machine.Publisher)) - return false; - - // Machine_Ratings - if (!PassStringFilter(Ratings, machine.Ratings)) - return false; - - // Machine_RebuildTo - if (!PassStringFilter(RebuildTo, machine.RebuildTo)) - return false; - - // Machine_RelatedTo - if (!PassStringFilter(RelatedTo, machine.RelatedTo)) - return false; - - // Machine_RomOf - if (!PassStringFilter(RomOf, machine.RomOf)) - return false; - - // Machine_Rotation - if (!PassStringFilter(Rotation, machine.Rotation)) - return false; - - // Machine_Runnable - if (Runnable.MatchesPositive(Core.Runnable.NULL, machine.Runnable) == false) - return false; - if (Runnable.MatchesNegative(Core.Runnable.NULL, machine.Runnable) == true) - return false; - - // Machine_SampleOf - if (!PassStringFilter(SampleOf, machine.SampleOf)) - return false; - - // Machine_Score - if (!PassStringFilter(Score, machine.Score)) - return false; - - // Machine_SourceFile - if (!PassStringFilter(SourceFile, machine.SourceFile)) - return false; - - // Machine_Status - if (!PassStringFilter(Status, machine.Status)) - return false; - - // Machine_Subgenre - if (!PassStringFilter(Subgenre, machine.Subgenre)) - return false; - - // Machine_Supported - if (Supported.MatchesPositive(Core.Supported.NULL, machine.Supported) == false) - return false; - if (Supported.MatchesNegative(Core.Supported.NULL, machine.Supported) == true) - return false; - - // Machine_System - if (!PassStringFilter(System, machine.System)) - return false; - - // Machine_TitleID - if (!PassStringFilter(TitleID, machine.TitleID)) - return false; - - // Machine_Type - if (Type.MatchesPositive(0x0, machine.MachineType) == false) - return false; - if (Type.MatchesNegative(0x0, machine.MachineType) == true) - return false; - - // Machine_Year - if (!PassStringFilter(Year, machine.Year)) - return false; - - return true; - } - - #endregion - } -} diff --git a/SabreTools.Test/Filtering/FilteringTests.cs b/SabreTools.Test/Filtering/FilteringTests.cs deleted file mode 100644 index 883d207c..00000000 --- a/SabreTools.Test/Filtering/FilteringTests.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System.Collections.Generic; - -using SabreTools.DatItems; -using SabreTools.DatItems.Formats; -using Xunit; - -namespace SabreTools.Test.Filtering -{ - public class FilteringTests - { - [Fact] - public void PassesFiltersDatItemFilterPass() - { - // Setup filter - var filter = new SabreTools.Filtering.Filter(); - filter.PopulateFiltersFromList(new List { "item.name:foo" }); - - // Setup DatItem - var datItem = CreateDatItem(); - - // Run filters - bool actual = filter.PassesAllFilters(datItem); - Assert.True(actual); - } - - [Fact] - public void PassesFiltersDatItemFilterFail() - { - // Setup filter - var filter = new SabreTools.Filtering.Filter(); - filter.PopulateFiltersFromList(new List { "item.name:bar" }); - - // Setup DatItem - var datItem = CreateDatItem(); - - // Run filters - bool actual = filter.PassesAllFilters(datItem); - Assert.False(actual); - } - - [Fact] - public void PassesFiltersMachineFilterPass() - { - // Setup filter - var filter = new SabreTools.Filtering.Filter(); - filter.PopulateFiltersFromList(new List { "machine.name:bar" }); - - // Setup DatItem - var datItem = CreateDatItem(); - - // Run filters - bool actual = filter.PassesAllFilters(datItem); - Assert.True(actual); - } - - [Fact] - public void PassesFiltersMachineFilterFail() - { - // Setup filter - var filter = new SabreTools.Filtering.Filter(); - filter.PopulateFiltersFromList(new List { "machine.name:foo" }); - - // Setup DatItem - var datItem = CreateDatItem(); - - // Run filters - bool actual = filter.PassesAllFilters(datItem); - Assert.False(actual); - } - - /// - /// Generate a consistent DatItem for testing - /// - private static DatItem CreateDatItem() - { - return new Rom - { - Name = "foo", - Machine = new Machine - { - Name = "bar", - Description = "bar", - } - }; - } - } -} \ No newline at end of file diff --git a/SabreTools.Test/Filtering/PopulationTests.cs b/SabreTools.Test/Filtering/PopulationTests.cs index 933db414..63710a65 100644 --- a/SabreTools.Test/Filtering/PopulationTests.cs +++ b/SabreTools.Test/Filtering/PopulationTests.cs @@ -94,77 +94,5 @@ namespace SabreTools.Test.Filtering Assert.Empty(remover.MachineFieldNames); Assert.Single(remover.ItemFieldNames); } - - [Fact] - public void PopulateFilterNullListTest() - { - // Setup the list - List? filters = null; - - // Setup the filter - var filter = new SabreTools.Filtering.Filter(); - filter.PopulateFiltersFromList(filters); - - // Check the filters - Assert.NotNull(filter.MachineFilter); - Assert.NotNull(filter.DatItemFilter); - } - - [Fact] - public void PopulateFilterEmptyListTest() - { - // Setup the list - List filters = []; - - // Setup the filter - var filter = new SabreTools.Filtering.Filter(); - filter.PopulateFiltersFromList(filters); - - // Check the filters - Assert.NotNull(filter.MachineFilter); - Assert.NotNull(filter.DatItemFilter); - } - - [Fact] - public void PopulateFilterMachineFieldTest() - { - // Setup the list - List filters = - [ - "machine.name:foo", - "!machine.name:bar", - ]; - - // Setup the filter - var filter = new SabreTools.Filtering.Filter(); - filter.PopulateFiltersFromList(filters); - - // Check the filters - Assert.NotNull(filter.MachineFilter); - Assert.NotNull(filter.DatItemFilter); - Assert.Contains("foo", filter.MachineFilter.Name.PositiveSet); - Assert.Contains("bar", filter.MachineFilter.Name.NegativeSet); - } - - [Fact] - public void PopulateFilterDatItemFieldTest() - { - // Setup the list - List filters = - [ - "item.name:foo", - "!item.name:bar" - ]; - - // Setup the filter - var filter = new SabreTools.Filtering.Filter(); - filter.PopulateFiltersFromList(filters); - - // Check the filters - Assert.NotNull(filter.MachineFilter); - Assert.NotNull(filter.DatItemFilter); - Assert.Contains("foo", filter.DatItemFilter.Name.PositiveSet); - Assert.Contains("bar", filter.DatItemFilter.Name.NegativeSet); - } } } \ No newline at end of file diff --git a/SabreTools/Features/Batch.cs b/SabreTools/Features/Batch.cs index 99b67edf..a87c0ff1 100644 --- a/SabreTools/Features/Batch.cs +++ b/SabreTools/Features/Batch.cs @@ -139,7 +139,7 @@ Reset the internal state: reset();"; private abstract class BatchCommand { public string Name { get; private set; } - public List Arguments { get; private set; } = new List(); + public List Arguments { get; private set; } = []; /// /// Default constructor for setting arguments @@ -153,7 +153,7 @@ Reset the internal state: reset();"; /// Create a command based on parsing a line /// /// Current line to parse into a command - public static BatchCommand Create(string line) + public static BatchCommand? Create(string line) { // Empty lines don't count if (string.IsNullOrEmpty(line)) @@ -207,7 +207,7 @@ Reset the internal state: reset();"; /// /// Validate that a set of arguments are sufficient for a given command /// - public abstract (bool, string) ValidateArguments(); + public abstract (bool, string?) ValidateArguments(); /// /// Process a batch file state with the current command @@ -370,7 +370,7 @@ Reset the internal state: reset();"; } /// - public override (bool, string) ValidateArguments() + public override (bool, string?) ValidateArguments() { if (Arguments.Count < 2 || Arguments.Count > 4) { @@ -415,29 +415,24 @@ Reset the internal state: reset();"; public override void Process(BatchState batchState) { // Read in the individual arguments - MachineField filterMachineField = Arguments[0].AsMachineField(); - DatItemField filterDatItemField = Arguments[0].AsDatItemField(); + string filterField = Arguments[0]; string filterValue = Arguments[1]; bool? filterRemove = false; if (Arguments.Count >= 3) filterRemove = Arguments[2].AsYesNo(); + // TODO: Add back this functionality bool? filterPerMachine = false; if (Arguments.Count >= 4) filterPerMachine = Arguments[3].AsYesNo(); - // Create filter to run filters from - Filtering.Filter filter = new() - { - MachineFilter = new MachineFilter { HasFilters = true }, - DatItemFilter = new DatItemFilter { HasFilters = true }, - }; + // Build the filter statement + string filterString = $"{filterField}{(filterRemove == true ? "!" : string.Empty)}:{filterValue}"; - // Set the possible filters - filter.MachineFilter.SetFilter(filterMachineField, filterValue, filterRemove.Value); - filter.DatItemFilter.SetFilter(filterDatItemField, filterValue, filterRemove.Value); + // Create filter to run filters from + var filter = new Filter.FilterRunner([filterString]); // Apply the filters blindly - filter.ApplyFilters(batchState.DatFile, filterPerMachine.Value); + batchState.DatFile.ExecuteFilters(filter); // Cleanup after the filter // TODO: We might not want to remove immediately