diff --git a/SabreTools.Library/DatItems/BiosSet.cs b/SabreTools.Library/DatItems/BiosSet.cs
index 5ae42f79..7f598d22 100644
--- a/SabreTools.Library/DatItems/BiosSet.cs
+++ b/SabreTools.Library/DatItems/BiosSet.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using SabreTools.Library.Filtering;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
@@ -135,6 +136,32 @@ namespace SabreTools.Library.DatItems
#endregion
+ #region Filtering
+
+ ///
+ /// Check to see if a DatItem passes the filter
+ ///
+ /// Filter to check against
+ /// True if the item passed the filter, false otherwise
+ public override bool PassesFilter(Filter filter)
+ {
+ // Check common fields first
+ if (!base.PassesFilter(filter))
+ return false;
+
+ // Filter on description
+ if (filter.Description.MatchesNeutral(null, Description) == false)
+ return false;
+
+ // Filter on default
+ if (filter.Default.MatchesNeutral(null, Default) == false)
+ return false;
+
+ return true;
+ }
+
+ #endregion
+
#region Sorting and Merging
///
diff --git a/SabreTools.Library/DatItems/DatItem.cs b/SabreTools.Library/DatItems/DatItem.cs
index 063be6bf..75baa743 100644
--- a/SabreTools.Library/DatItems/DatItem.cs
+++ b/SabreTools.Library/DatItems/DatItem.cs
@@ -7,6 +7,7 @@ using System.Net;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.FileTypes;
+using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using NaturalSort;
using Newtonsoft.Json;
@@ -887,6 +888,201 @@ namespace SabreTools.Library.DatItems
#endregion
+ #region Filtering
+
+ ///
+ /// Check to see if a DatItem passes the filter
+ ///
+ /// Filter to check against
+ /// True if the item passed the filter, false otherwise
+ public virtual bool PassesFilter(Filter filter)
+ {
+ #region Machine Filters
+
+ // Filter on machine name
+ bool? machineNameFound = filter.MachineName.MatchesPositiveSet(MachineName);
+ if (filter.IncludeOfInGame)
+ {
+ machineNameFound |= (filter.MachineName.MatchesPositiveSet(CloneOf) == true);
+ machineNameFound |= (filter.MachineName.MatchesPositiveSet(RomOf) == true);
+ }
+ if (machineNameFound == false)
+ return false;
+
+ machineNameFound = filter.MachineName.MatchesNegativeSet(MachineName);
+ if (filter.IncludeOfInGame)
+ {
+ machineNameFound |= (filter.MachineName.MatchesNegativeSet(CloneOf) == true);
+ machineNameFound |= (filter.MachineName.MatchesNegativeSet(RomOf) == true);
+ }
+ if (machineNameFound == false)
+ return false;
+
+ // Filter on comment
+ if (filter.Comment.MatchesPositiveSet(Comment) == false)
+ return false;
+ if (filter.Comment.MatchesNegativeSet(Comment) == true)
+ return false;
+
+ // Filter on machine description
+ if (filter.MachineDescription.MatchesPositiveSet(MachineDescription) == false)
+ return false;
+ if (filter.MachineDescription.MatchesNegativeSet(MachineDescription) == true)
+ return false;
+
+ // Filter on year
+ if (filter.Year.MatchesPositiveSet(Year) == false)
+ return false;
+ if (filter.Year.MatchesNegativeSet(Year) == true)
+ return false;
+
+ // Filter on manufacturer
+ if (filter.Manufacturer.MatchesPositiveSet(Manufacturer) == false)
+ return false;
+ if (filter.Manufacturer.MatchesNegativeSet(Manufacturer) == true)
+ return false;
+
+ // Filter on publisher
+ if (filter.Publisher.MatchesPositiveSet(Publisher) == false)
+ return false;
+ if (filter.Publisher.MatchesNegativeSet(Publisher) == true)
+ return false;
+
+ // Filter on category
+ if (filter.Category.MatchesPositiveSet(Category) == false)
+ return false;
+ if (filter.Category.MatchesNegativeSet(Category) == true)
+ return false;
+
+ // Filter on romof
+ if (filter.RomOf.MatchesPositiveSet(RomOf) == false)
+ return false;
+ if (filter.RomOf.MatchesNegativeSet(RomOf) == true)
+ return false;
+
+ // Filter on cloneof
+ if (filter.CloneOf.MatchesPositiveSet(CloneOf) == false)
+ return false;
+ if (filter.CloneOf.MatchesNegativeSet(CloneOf) == true)
+ return false;
+
+ // Filter on sampleof
+ if (filter.SampleOf.MatchesPositiveSet(SampleOf) == false)
+ return false;
+ if (filter.SampleOf.MatchesNegativeSet(SampleOf) == true)
+ return false;
+
+ // Filter on supported
+ if (filter.Supported.MatchesNeutral(null, Supported) == false)
+ return false;
+
+ // Filter on source file
+ if (filter.SourceFile.MatchesPositiveSet(SourceFile) == false)
+ return false;
+ if (filter.SourceFile.MatchesNegativeSet(SourceFile) == true)
+ return false;
+
+ // Filter on runnable
+ if (filter.Runnable.MatchesNeutral(null, Runnable) == false)
+ return false;
+
+ // Filter on board
+ if (filter.Board.MatchesPositiveSet(Board) == false)
+ return false;
+ if (filter.Board.MatchesNegativeSet(Board) == true)
+ return false;
+
+ // Filter on rebuildto
+ if (filter.RebuildTo.MatchesPositiveSet(RebuildTo) == false)
+ return false;
+ if (filter.RebuildTo.MatchesNegativeSet(RebuildTo) == true)
+ return false;
+
+ // Filter on devices
+ if (Devices != null && Devices.Any())
+ {
+ bool anyPositiveDevice = false;
+ bool anyNegativeDevice = false;
+ foreach (string device in Devices)
+ {
+ anyPositiveDevice |= filter.Devices.MatchesPositiveSet(device) != false;
+ anyNegativeDevice |= filter.Devices.MatchesNegativeSet(device) == false;
+ }
+
+ if (!anyPositiveDevice || anyNegativeDevice)
+ return false;
+ }
+
+ // Filter on slot options
+ if (SlotOptions != null && SlotOptions.Any())
+ {
+ bool anyPositiveSlotOption = false;
+ bool anyNegativeSlotOption = false;
+ foreach (string slotOption in SlotOptions)
+ {
+ anyPositiveSlotOption |= filter.SlotOptions.MatchesPositiveSet(slotOption) != false;
+ anyNegativeSlotOption |= filter.SlotOptions.MatchesNegativeSet(slotOption) == false;
+ }
+
+ if (!anyPositiveSlotOption || anyNegativeSlotOption)
+ return false;
+ }
+
+ // Filter on machine type
+ if (filter.MachineTypes.MatchesPositive(MachineType.NULL, MachineType) == false)
+ return false;
+ if (filter.MachineTypes.MatchesNegative(MachineType.NULL, MachineType) == true)
+ return false;
+
+ #endregion
+
+ #region DatItem Filters
+
+ // Filter on item type
+ if (filter.ItemTypes.MatchesPositiveSet(ItemType.ToString()) == false)
+ return false;
+ if (filter.ItemTypes.MatchesNegativeSet(ItemType.ToString()) == true)
+ return false;
+
+ // Filter on item name
+ if (filter.ItemName.MatchesPositiveSet(Name) == false)
+ return false;
+ if (filter.ItemName.MatchesNegativeSet(Name) == true)
+ return false;
+
+ // Filter on part name
+ if (filter.PartName.MatchesPositiveSet(PartName) == false)
+ return false;
+ if (filter.PartName.MatchesNegativeSet(PartName) == true)
+ return false;
+
+ // Filter on part interface
+ if (filter.PartInterface.MatchesPositiveSet(PartInterface) == false)
+ return false;
+ if (filter.PartInterface.MatchesNegativeSet(PartInterface) == true)
+ return false;
+
+ // Filter on area name
+ if (filter.AreaName.MatchesPositiveSet(AreaName) == false)
+ return false;
+ if (filter.AreaName.MatchesNegativeSet(AreaName) == true)
+ return false;
+
+ // Filter on area size
+ if (filter.AreaSize.MatchesNeutral(null, AreaSize) == false)
+ return false;
+ else if (filter.AreaSize.MatchesPositive(null, AreaSize) == false)
+ return false;
+ else if (filter.AreaSize.MatchesNegative(null, AreaSize) == false)
+ return false;
+
+ #endregion
+
+ return true;
+ }
+
+ #endregion
+
#region Sorting and Merging
///
diff --git a/SabreTools.Library/DatItems/Disk.cs b/SabreTools.Library/DatItems/Disk.cs
index 4e69a03f..7efca8e2 100644
--- a/SabreTools.Library/DatItems/Disk.cs
+++ b/SabreTools.Library/DatItems/Disk.cs
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using SabreTools.Library.DatFiles;
using SabreTools.Library.FileTypes;
+using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
@@ -481,6 +482,94 @@ namespace SabreTools.Library.DatItems
#endregion
+ #region Filtering
+
+ ///
+ /// Check to see if a DatItem passes the filter
+ ///
+ /// Filter to check against
+ /// True if the item passed the filter, false otherwise
+ public override bool PassesFilter(Filter filter)
+ {
+ // Check common fields first
+ if (!base.PassesFilter(filter))
+ return false;
+
+ // Filter on MD5
+ if (filter.MD5.MatchesPositiveSet(MD5) == false)
+ return false;
+ if (filter.MD5.MatchesNegativeSet(MD5) == true)
+ return false;
+
+#if NET_FRAMEWORK
+ // Filter on RIPEMD160
+ if (filter.RIPEMD160.MatchesPositiveSet(RIPEMD160) == false)
+ return false;
+ if (filter.RIPEMD160.MatchesNegativeSet(RIPEMD160) == true)
+ return false;
+#endif
+
+ // Filter on SHA-1
+ if (filter.SHA1.MatchesPositiveSet(SHA1) == false)
+ return false;
+ if (filter.SHA1.MatchesNegativeSet(SHA1) == true)
+ return false;
+
+ // Filter on SHA-256
+ if (filter.SHA256.MatchesPositiveSet(SHA256) == false)
+ return false;
+ if (filter.SHA256.MatchesNegativeSet(SHA256) == true)
+ return false;
+
+ // Filter on SHA-384
+ if (filter.SHA384.MatchesPositiveSet(SHA384) == false)
+ return false;
+ if (filter.SHA384.MatchesNegativeSet(SHA384) == true)
+ return false;
+
+ // Filter on SHA-512
+ if (filter.SHA512.MatchesPositiveSet(SHA512) == false)
+ return false;
+ if (filter.SHA512.MatchesNegativeSet(SHA512) == true)
+ return false;
+
+ // Filter on merge tag
+ if (filter.MergeTag.MatchesPositiveSet(MergeTag) == false)
+ return false;
+ if (filter.MergeTag.MatchesNegativeSet(MergeTag) == true)
+ return false;
+
+ // Filter on region
+ if (filter.Region.MatchesPositiveSet(Region) == false)
+ return false;
+ if (filter.Region.MatchesNegativeSet(Region) == true)
+ return false;
+
+ // Filter on index
+ if (filter.Index.MatchesPositiveSet(Index) == false)
+ return false;
+ if (filter.Index.MatchesNegativeSet(Index) == true)
+ return false;
+
+ // Filter on writable
+ if (filter.Writable.MatchesNeutral(null, Writable) == false)
+ return false;
+
+ // Filter on status
+ if (filter.Status.MatchesPositive(ItemStatus.NULL, ItemStatus) == false)
+ return false;
+ if (filter.Status.MatchesNegative(ItemStatus.NULL, ItemStatus) == true)
+ return false;
+
+ // Filter on optional
+ if (filter.Optional.MatchesNeutral(null, Optional) == false)
+ return false;
+
+ return true;
+ }
+
+ #endregion
+
#region Sorting and Merging
///
diff --git a/SabreTools.Library/DatItems/Release.cs b/SabreTools.Library/DatItems/Release.cs
index be31e8a5..8e210ba9 100644
--- a/SabreTools.Library/DatItems/Release.cs
+++ b/SabreTools.Library/DatItems/Release.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using SabreTools.Library.Filtering;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
@@ -163,6 +164,46 @@ namespace SabreTools.Library.DatItems
#endregion
+ #region Filtering
+
+ ///
+ /// Check to see if a DatItem passes the filter
+ ///
+ /// Filter to check against
+ /// True if the item passed the filter, false otherwise
+ public override bool PassesFilter(Filter filter)
+ {
+ // Check common fields first
+ if (!base.PassesFilter(filter))
+ return false;
+
+ // Filter on region
+ if (filter.Region.MatchesPositiveSet(Region) == false)
+ return false;
+ if (filter.Region.MatchesNegativeSet(Region) == true)
+ return false;
+
+ // Filter on language
+ if (filter.Language.MatchesPositiveSet(Language) == false)
+ return false;
+ if (filter.Language.MatchesNegativeSet(Language) == true)
+ return false;
+
+ // Filter on date
+ if (filter.Date.MatchesPositiveSet(Date) == false)
+ return false;
+ if (filter.Date.MatchesNegativeSet(Date) == true)
+ return false;
+
+ // Filter on default
+ if (filter.Default.MatchesNeutral(null, Default) == false)
+ return false;
+
+ return true;
+ }
+
+ #endregion
+
#region Sorting and Merging
///
diff --git a/SabreTools.Library/DatItems/Rom.cs b/SabreTools.Library/DatItems/Rom.cs
index 709cbe81..7c4a9037 100644
--- a/SabreTools.Library/DatItems/Rom.cs
+++ b/SabreTools.Library/DatItems/Rom.cs
@@ -2,6 +2,7 @@
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.FileTypes;
+using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
@@ -506,6 +507,120 @@ namespace SabreTools.Library.DatItems
#endregion
+ #region Filtering
+
+ ///
+ /// Check to see if a DatItem passes the filter
+ ///
+ /// Filter to check against
+ /// True if the item passed the filter, false otherwise
+ public override bool PassesFilter(Filter filter)
+ {
+ // Check common fields first
+ if (!base.PassesFilter(filter))
+ return false;
+
+ // Filter on bios
+ if (filter.Bios.MatchesPositiveSet(Bios) == false)
+ return false;
+ if (filter.Bios.MatchesNegativeSet(Bios) == true)
+ return false;
+
+ // Filter on rom size
+ if (filter.Size.MatchesNeutral(-1, Size) == false)
+ return false;
+ else if (filter.Size.MatchesPositive(-1, Size) == false)
+ return false;
+ else if (filter.Size.MatchesNegative(-1, Size) == false)
+ return false;
+
+ // Filter on CRC
+ if (filter.CRC.MatchesPositiveSet(CRC) == false)
+ return false;
+ if (filter.CRC.MatchesNegativeSet(CRC) == true)
+ return false;
+
+ // Filter on MD5
+ if (filter.MD5.MatchesPositiveSet(MD5) == false)
+ return false;
+ if (filter.MD5.MatchesNegativeSet(MD5) == true)
+ return false;
+
+#if NET_FRAMEWORK
+ // Filter on RIPEMD160
+ if (filter.RIPEMD160.MatchesPositiveSet(RIPEMD160) == false)
+ return false;
+ if (filter.RIPEMD160.MatchesNegativeSet(RIPEMD160) == true)
+ return false;
+#endif
+
+ // Filter on SHA-1
+ if (filter.SHA1.MatchesPositiveSet(SHA1) == false)
+ return false;
+ if (filter.SHA1.MatchesNegativeSet(SHA1) == true)
+ return false;
+
+ // Filter on SHA-256
+ if (filter.SHA256.MatchesPositiveSet(SHA256) == false)
+ return false;
+ if (filter.SHA256.MatchesNegativeSet(SHA256) == true)
+ return false;
+
+ // Filter on SHA-384
+ if (filter.SHA384.MatchesPositiveSet(SHA384) == false)
+ return false;
+ if (filter.SHA384.MatchesNegativeSet(SHA384) == true)
+ return false;
+
+ // Filter on SHA-512
+ if (filter.SHA512.MatchesPositiveSet(SHA512) == false)
+ return false;
+ if (filter.SHA512.MatchesNegativeSet(SHA512) == true)
+ return false;
+
+ // Filter on merge tag
+ if (filter.MergeTag.MatchesPositiveSet(MergeTag) == false)
+ return false;
+ if (filter.MergeTag.MatchesNegativeSet(MergeTag) == true)
+ return false;
+
+ // Filter on region
+ if (filter.Region.MatchesPositiveSet(Region) == false)
+ return false;
+ if (filter.Region.MatchesNegativeSet(Region) == true)
+ return false;
+
+ // Filter on offset
+ if (filter.Offset.MatchesPositiveSet(Offset) == false)
+ return false;
+ if (filter.Offset.MatchesNegativeSet(Offset) == true)
+ return false;
+
+ // Filter on date
+ if (filter.Date.MatchesPositiveSet(Date) == false)
+ return false;
+ if (filter.Date.MatchesNegativeSet(Date) == true)
+ return false;
+
+ // Filter on status
+ if (filter.Status.MatchesPositive(ItemStatus.NULL, ItemStatus) == false)
+ return false;
+ if (filter.Status.MatchesNegative(ItemStatus.NULL, ItemStatus) == true)
+ return false;
+
+ // Filter on optional
+ if (filter.Optional.MatchesNeutral(null, Optional) == false)
+ return false;
+
+ // Filter on inverted
+ if (filter.Inverted.MatchesNeutral(null, Inverted) == false)
+ return false;
+
+ return true;
+ }
+
+ #endregion
+
#region Sorting and Merging
///
diff --git a/SabreTools.Library/Filtering/Filter.cs b/SabreTools.Library/Filtering/Filter.cs
index e84b30e8..9da95b56 100644
--- a/SabreTools.Library/Filtering/Filter.cs
+++ b/SabreTools.Library/Filtering/Filter.cs
@@ -19,101 +19,101 @@ namespace SabreTools.Library.Filtering
/// TODO: Can clever use of Filtering allow for easier external splitting methods?
public class Filter
{
- #region Private instance variables
+ #region Pubically facing variables
#region Machine Filters
///
/// Include or exclude machine names
///
- private FilterItem MachineName = new FilterItem();
+ public FilterItem MachineName { get; private set; } = new FilterItem();
///
/// Include or exclude machine comments
///
- private FilterItem Comment = new FilterItem();
+ public FilterItem Comment { get; private set; } = new FilterItem();
///
/// Include or exclude machine descriptions
///
- private FilterItem MachineDescription = new FilterItem();
+ public FilterItem MachineDescription { get; private set; } = new FilterItem();
///
/// Include or exclude machine years
///
- private FilterItem Year = new FilterItem();
+ public FilterItem Year { get; private set; } = new FilterItem();
///
/// Include or exclude machine manufacturers
///
- private FilterItem Manufacturer = new FilterItem();
+ public FilterItem Manufacturer { get; private set; } = new FilterItem();
///
/// Include or exclude machine publishers
///
- private FilterItem Publisher = new FilterItem();
+ public FilterItem Publisher { get; private set; } = new FilterItem();
///
/// Include or exclude machine categories
///
- private FilterItem Category = new FilterItem();
+ public FilterItem Category { get; private set; } = new FilterItem();
///
/// Include or exclude machine romof
///
- private FilterItem RomOf = new FilterItem();
+ public FilterItem RomOf { get; private set; } = new FilterItem();
///
/// Include or exclude machine cloneof
///
- private FilterItem CloneOf = new FilterItem();
+ public FilterItem CloneOf { get; private set; } = new FilterItem();
///
/// Include or exclude machine sampleof
///
- private FilterItem SampleOf = new FilterItem();
+ public FilterItem SampleOf { get; private set; } = new FilterItem();
///
/// Include or exclude items with the "Supported" tag
///
- private FilterItem Supported = new FilterItem() { Neutral = null };
+ public FilterItem Supported { get; private set; } = new FilterItem() { Neutral = null };
///
/// Include or exclude machine source file
///
- private FilterItem SourceFile = new FilterItem();
+ public FilterItem SourceFile { get; private set; } = new FilterItem();
///
/// Include or exclude items with the "Runnable" tag
///
- private FilterItem Runnable = new FilterItem() { Neutral = null };
+ public FilterItem Runnable { get; private set; } = new FilterItem() { Neutral = null };
///
/// Include or exclude machine board
///
- private FilterItem Board = new FilterItem();
+ public FilterItem Board { get; private set; } = new FilterItem();
///
/// Include or exclude machine rebuildto
///
- private FilterItem RebuildTo = new FilterItem();
+ public FilterItem RebuildTo { get; private set; } = new FilterItem();
///
/// Include or exclude machine devices
///
- private FilterItem Devices = new FilterItem();
+ public FilterItem Devices { get; private set; } = new FilterItem();
///
/// Include or exclude machine slotoptions
///
- private FilterItem SlotOptions = new FilterItem();
+ public FilterItem SlotOptions { get; private set; } = new FilterItem();
// TODO: Machine.Infos - List>
///
/// Include or exclude machine types
///
- private FilterItem MachineTypes = new FilterItem() { Positive = MachineType.NULL, Negative = MachineType.NULL };
+ public FilterItem MachineTypes { get; private set; } = new FilterItem() { Positive = MachineType.NULL, Negative = MachineType.NULL };
#endregion
@@ -122,150 +122,146 @@ namespace SabreTools.Library.Filtering
///
/// Include or exclude item types
///
- private FilterItem ItemTypes = new FilterItem();
+ public FilterItem ItemTypes { get; private set; } = new FilterItem();
///
/// Include or exclude item names
///
- private FilterItem ItemName = new FilterItem();
+ public FilterItem ItemName { get; private set; } = new FilterItem();
// TODO: DatItem.Features - List>
///
/// Include or exclude part names
///
- private FilterItem PartName = new FilterItem();
+ public FilterItem PartName { get; private set; } = new FilterItem();
///
/// Include or exclude part interfaces
///
- private FilterItem PartInterface = new FilterItem();
+ public FilterItem PartInterface { get; private set; } = new FilterItem();
///
/// Include or exclude area names
///
- private FilterItem AreaName = new FilterItem();
+ public FilterItem AreaName { get; private set; } = new FilterItem();
///
/// Include or exclude area sizes
///
/// Positive means "Greater than or equal", Negative means "Less than or equal", Neutral means "Equal"
- private FilterItem AreaSize = new FilterItem() { Positive = null, Negative = null, Neutral = null };
+ public FilterItem AreaSize { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null };
///
/// Include or exclude items with the "Default" tag
///
- private FilterItem Default = new FilterItem() { Neutral = null };
+ public FilterItem Default { get; private set; } = new FilterItem() { Neutral = null };
///
/// Include or exclude descriptions
///
- private FilterItem Description = new FilterItem();
+ public FilterItem Description { get; private set; } = new FilterItem();
///
/// Include or exclude item sizes
///
/// Positive means "Greater than or equal", Negative means "Less than or equal", Neutral means "Equal"
- private FilterItem Size = new FilterItem() { Positive = -1, Negative = -1, Neutral = -1 };
+ public FilterItem Size { get; private set; } = new FilterItem() { Positive = -1, Negative = -1, Neutral = -1 };
///
/// Include or exclude CRC32 hashes
///
- private FilterItem CRC = new FilterItem();
+ public FilterItem CRC { get; private set; } = new FilterItem();
///
/// Include or exclude MD5 hashes
///
- private FilterItem MD5 = new FilterItem();
+ public FilterItem MD5 { get; private set; } = new FilterItem();
#if NET_FRAMEWORK
///
/// Include or exclude RIPEMD160 hashes
///
- private FilterItem RIPEMD160 = new FilterItem();
+ public FilterItem RIPEMD160 { get; private set; } = new FilterItem();
#endif
///
/// Include or exclude SHA-1 hashes
///
- private FilterItem SHA1 = new FilterItem();
+ public FilterItem SHA1 { get; private set; } = new FilterItem();
///
/// Include or exclude SHA-256 hashes
///
- private FilterItem SHA256 = new FilterItem();
+ public FilterItem SHA256 { get; private set; } = new FilterItem();
///
/// Include or exclude SHA-384 hashes
///
- private FilterItem SHA384 = new FilterItem();
+ public FilterItem SHA384 { get; private set; } = new FilterItem();
///
/// Include or exclude SHA-512 hashes
///
- private FilterItem SHA512 = new FilterItem();
+ public FilterItem SHA512 { get; private set; } = new FilterItem();
///
/// Include or exclude merge tags
///
- private FilterItem MergeTag = new FilterItem();
+ public FilterItem MergeTag { get; private set; } = new FilterItem();
///
/// Include or exclude regions
///
- private FilterItem Region = new FilterItem();
+ public FilterItem Region { get; private set; } = new FilterItem();
///
/// Include or exclude indexes
///
- private FilterItem Index = new FilterItem();
+ public FilterItem Index { get; private set; } = new FilterItem();
///
/// Include or exclude items with the "Writable" tag
///
- private FilterItem Writable = new FilterItem() { Neutral = null };
+ public FilterItem Writable { get; private set; } = new FilterItem() { Neutral = null };
///
/// Include or exclude items with the "Writable" tag
///
- private FilterItem Optional = new FilterItem() { Neutral = null };
+ public FilterItem Optional { get; private set; } = new FilterItem() { Neutral = null };
///
/// Include or exclude item statuses
///
- private FilterItem Status = new FilterItem() { Positive = ItemStatus.NULL, Negative = ItemStatus.NULL };
+ public FilterItem Status { get; private set; } = new FilterItem() { Positive = ItemStatus.NULL, Negative = ItemStatus.NULL };
///
/// Include or exclude languages
///
- private FilterItem Language = new FilterItem();
+ public FilterItem Language { get; private set; } = new FilterItem();
///
/// Include or exclude dates
///
- private FilterItem Date = new FilterItem();
+ public FilterItem Date { get; private set; } = new FilterItem();
///
/// Include or exclude bioses
///
- private FilterItem Bios = new FilterItem();
+ public FilterItem Bios { get; private set; } = new FilterItem();
///
/// Include or exclude offsets
///
- private FilterItem Offset = new FilterItem();
+ public FilterItem Offset { get; private set; } = new FilterItem();
///
/// Include or exclude offsets
///
- private FilterItem Inverted = new FilterItem();
+ public FilterItem Inverted { get; private set; } = new FilterItem();
#endregion
- #endregion // Private instance variables
-
- #region Pubically facing variables
-
#region Manipulation Flags
///
@@ -806,20 +802,21 @@ namespace SabreTools.Library.Filtering
/// DatFile to filter
/// True if DatFile tags override splitting, false otherwise
/// True if the DatFile was filtered, false on error
+ /// TODO: Should this be inverted to be in DatFile?
public bool FilterDatFile(DatFile datFile, bool useTags)
{
try
{
// Process description to machine name
- if (this.DescriptionAsName)
+ if (DescriptionAsName)
MachineDescriptionToName(datFile);
// If we are using tags from the DAT, set the proper input for split type unless overridden
- if (useTags && this.InternalSplit == SplitType.None)
- this.InternalSplit = datFile.Header.ForceMerging.AsSplitType();
+ if (useTags && InternalSplit == SplitType.None)
+ InternalSplit = datFile.Header.ForceMerging.AsSplitType();
// Run internal splitting
- ProcessSplitType(datFile, this.InternalSplit);
+ ProcessSplitType(datFile, InternalSplit);
// Loop over every key in the dictionary
List keys = datFile.Items.Keys.ToList();
@@ -830,11 +827,15 @@ namespace SabreTools.Library.Filtering
List newitems = new List();
foreach (DatItem item in items)
{
+ // If we have a null item, we can't pass it
+ if (item == null)
+ continue;
+
// If the rom passes the filter, include it
- if (ItemPasses(item))
+ if (item.PassesFilter(this))
{
// If we're stripping unicode characters, do so from all relevant things
- if (this.RemoveUnicode)
+ if (RemoveUnicode)
{
item.Name = Sanitizer.RemoveUnicodeCharacters(item.Name);
item.MachineName = Sanitizer.RemoveUnicodeCharacters(item.MachineName);
@@ -842,21 +843,21 @@ namespace SabreTools.Library.Filtering
}
// If we're in cleaning mode, do so from all relevant things
- if (this.Clean)
+ if (Clean)
{
item.MachineName = Sanitizer.CleanGameName(item.MachineName);
item.MachineDescription = Sanitizer.CleanGameName(item.MachineDescription);
}
// If we are in single game mode, rename all games
- if (this.Single)
+ if (Single)
item.MachineName = "!";
// If we are in NTFS trim mode, trim the game name
- if (this.Trim)
+ if (Trim)
{
// Windows max name length is 260
- int usableLength = 260 - item.MachineName.Length - this.Root.Length;
+ int usableLength = 260 - item.MachineName.Length - Root.Length;
if (item.Name.Length > usableLength)
{
string ext = Path.GetExtension(item.Name);
@@ -919,437 +920,6 @@ namespace SabreTools.Library.Filtering
return true;
}
- ///
- /// Check to see if a DatItem passes the filter
- ///
- /// DatItem to check
- /// True if the file passed the filter, false otherwise
- public bool ItemPasses(DatItem item)
- {
- // If the item is null, we automatically fail it
- if (item == null)
- return false;
-
- #region Machine Filters
-
- // Filter on machine name
- bool? machineNameFound = this.MachineName.MatchesPositiveSet(item.MachineName);
- if (this.IncludeOfInGame)
- {
- machineNameFound |= (this.MachineName.MatchesPositiveSet(item.CloneOf) == true);
- machineNameFound |= (this.MachineName.MatchesPositiveSet(item.RomOf) == true);
- }
- if (machineNameFound == false)
- return false;
-
- machineNameFound = this.MachineName.MatchesNegativeSet(item.MachineName);
- if (this.IncludeOfInGame)
- {
- machineNameFound |= (this.MachineName.MatchesNegativeSet(item.CloneOf) == true);
- machineNameFound |= (this.MachineName.MatchesNegativeSet(item.RomOf) == true);
- }
- if (machineNameFound == false)
- return false;
-
- // Filter on comment
- if (this.Comment.MatchesPositiveSet(item.Comment) == false)
- return false;
- if (this.Comment.MatchesNegativeSet(item.Comment) == true)
- return false;
-
- // Filter on machine description
- if (this.MachineDescription.MatchesPositiveSet(item.MachineDescription) == false)
- return false;
- if (this.MachineDescription.MatchesNegativeSet(item.MachineDescription) == true)
- return false;
-
- // Filter on year
- if (this.Year.MatchesPositiveSet(item.Year) == false)
- return false;
- if (this.Year.MatchesNegativeSet(item.Year) == true)
- return false;
-
- // Filter on manufacturer
- if (this.Manufacturer.MatchesPositiveSet(item.Manufacturer) == false)
- return false;
- if (this.Manufacturer.MatchesNegativeSet(item.Manufacturer) == true)
- return false;
-
- // Filter on publisher
- if (this.Publisher.MatchesPositiveSet(item.Publisher) == false)
- return false;
- if (this.Publisher.MatchesNegativeSet(item.Publisher) == true)
- return false;
-
- // Filter on category
- if (this.Category.MatchesPositiveSet(item.Category) == false)
- return false;
- if (this.Category.MatchesNegativeSet(item.Category) == true)
- return false;
-
- // Filter on romof
- if (this.RomOf.MatchesPositiveSet(item.RomOf) == false)
- return false;
- if (this.RomOf.MatchesNegativeSet(item.RomOf) == true)
- return false;
-
- // Filter on cloneof
- if (this.CloneOf.MatchesPositiveSet(item.CloneOf) == false)
- return false;
- if (this.CloneOf.MatchesNegativeSet(item.CloneOf) == true)
- return false;
-
- // Filter on sampleof
- if (this.SampleOf.MatchesPositiveSet(item.SampleOf) == false)
- return false;
- if (this.SampleOf.MatchesNegativeSet(item.SampleOf) == true)
- return false;
-
- // Filter on supported
- if (this.Supported.MatchesNeutral(null, item.Supported) == false)
- return false;
-
- // Filter on source file
- if (this.SourceFile.MatchesPositiveSet(item.SourceFile) == false)
- return false;
- if (this.SourceFile.MatchesNegativeSet(item.SourceFile) == true)
- return false;
-
- // Filter on runnable
- if (this.Runnable.MatchesNeutral(null, item.Runnable) == false)
- return false;
-
- // Filter on board
- if (this.Board.MatchesPositiveSet(item.Board) == false)
- return false;
- if (this.Board.MatchesNegativeSet(item.Board) == true)
- return false;
-
- // Filter on rebuildto
- if (this.RebuildTo.MatchesPositiveSet(item.RebuildTo) == false)
- return false;
- if (this.RebuildTo.MatchesNegativeSet(item.RebuildTo) == true)
- return false;
-
- // Filter on devices
- if (item.Devices != null && item.Devices.Any())
- {
- bool anyPositiveDevice = false;
- bool anyNegativeDevice = false;
- foreach (string device in item.Devices)
- {
- anyPositiveDevice |= this.Devices.MatchesPositiveSet(device) != false;
- anyNegativeDevice |= this.Devices.MatchesNegativeSet(device) == false;
- }
-
- if (!anyPositiveDevice || anyNegativeDevice)
- return false;
- }
-
- // Filter on slot options
- if (item.SlotOptions != null && item.SlotOptions.Any())
- {
- bool anyPositiveSlotOption = false;
- bool anyNegativeSlotOption = false;
- foreach (string slotOption in item.SlotOptions)
- {
- anyPositiveSlotOption |= this.SlotOptions.MatchesPositiveSet(slotOption) != false;
- anyNegativeSlotOption |= this.SlotOptions.MatchesNegativeSet(slotOption) == false;
- }
-
- if (!anyPositiveSlotOption || anyNegativeSlotOption)
- return false;
- }
-
- // Filter on machine type
- if (this.MachineTypes.MatchesPositive(MachineType.NULL, item.MachineType) == false)
- return false;
- if (this.MachineTypes.MatchesNegative(MachineType.NULL, item.MachineType) == true)
- return false;
-
- #endregion
-
- #region DatItem Filters
-
- // Filter on item type
- // TODO: Remove default filtering at some point
- 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()) == false)
- return false;
- if (this.ItemTypes.MatchesNegativeSet(item.ItemType.ToString()) == true)
- return false;
-
- // Filter on item name
- if (this.ItemName.MatchesPositiveSet(item.Name) == false)
- return false;
- if (this.ItemName.MatchesNegativeSet(item.Name) == true)
- return false;
-
- // Filter on part name
- if (this.PartName.MatchesPositiveSet(item.PartName) == false)
- return false;
- if (this.PartName.MatchesNegativeSet(item.PartName) == true)
- return false;
-
- // Filter on part interface
- if (this.PartInterface.MatchesPositiveSet(item.PartInterface) == false)
- return false;
- if (this.PartInterface.MatchesNegativeSet(item.PartInterface) == true)
- return false;
-
- // Filter on area name
- if (this.AreaName.MatchesPositiveSet(item.AreaName) == false)
- return false;
- if (this.AreaName.MatchesNegativeSet(item.AreaName) == true)
- return false;
-
- // Filter on area size
- if (this.AreaSize.MatchesNeutral(null, item.AreaSize) == false)
- return false;
- else if (this.AreaSize.MatchesPositive(null, item.AreaSize) == false)
- return false;
- else if (this.AreaSize.MatchesNegative(null, item.AreaSize) == false)
- return false;
-
- // Take care of item-specific differences
- switch (item.ItemType)
- {
- case ItemType.Archive:
- // Archive has no special fields
- break;
-
- case ItemType.BiosSet:
- BiosSet biosSet = (BiosSet)item;
-
- // Filter on description
- if (this.Description.MatchesNeutral(null, biosSet.Description) == false)
- return false;
-
- // Filter on default
- if (this.Default.MatchesNeutral(null, biosSet.Default) == false)
- return false;
-
- break;
-
- case ItemType.Blank:
- // Blank has no special fields
- break;
-
- case ItemType.Disk:
- Disk disk = (Disk)item;
-
- // Filter on MD5
- if (this.MD5.MatchesPositiveSet(disk.MD5) == false)
- return false;
- if (this.MD5.MatchesNegativeSet(disk.MD5) == true)
- return false;
-
-#if NET_FRAMEWORK
- // Filter on RIPEMD160
- if (this.RIPEMD160.MatchesPositiveSet(disk.RIPEMD160) == false)
- return false;
- if (this.RIPEMD160.MatchesNegativeSet(disk.RIPEMD160) == true)
- return false;
-#endif
-
- // Filter on SHA-1
- if (this.SHA1.MatchesPositiveSet(disk.SHA1) == false)
- return false;
- if (this.SHA1.MatchesNegativeSet(disk.SHA1) == true)
- return false;
-
- // Filter on SHA-256
- if (this.SHA256.MatchesPositiveSet(disk.SHA256) == false)
- return false;
- if (this.SHA256.MatchesNegativeSet(disk.SHA256) == true)
- return false;
-
- // Filter on SHA-384
- if (this.SHA384.MatchesPositiveSet(disk.SHA384) == false)
- return false;
- if (this.SHA384.MatchesNegativeSet(disk.SHA384) == true)
- return false;
-
- // Filter on SHA-512
- if (this.SHA512.MatchesPositiveSet(disk.SHA512) == false)
- return false;
- if (this.SHA512.MatchesNegativeSet(disk.SHA512) == true)
- return false;
-
- // Filter on merge tag
- if (this.MergeTag.MatchesPositiveSet(disk.MergeTag) == false)
- return false;
- if (this.MergeTag.MatchesNegativeSet(disk.MergeTag) == true)
- return false;
-
- // Filter on region
- if (this.Region.MatchesPositiveSet(disk.Region) == false)
- return false;
- if (this.Region.MatchesNegativeSet(disk.Region) == true)
- return false;
-
- // Filter on index
- if (this.Index.MatchesPositiveSet(disk.Index) == false)
- return false;
- if (this.Index.MatchesNegativeSet(disk.Index) == true)
- return false;
-
- // Filter on writable
- if (this.Writable.MatchesNeutral(null, disk.Writable) == false)
- return false;
-
- // Filter on status
- if (this.Status.MatchesPositive(ItemStatus.NULL, disk.ItemStatus) == false)
- return false;
- if (this.Status.MatchesNegative(ItemStatus.NULL, disk.ItemStatus) == true)
- return false;
-
- // Filter on optional
- if (this.Optional.MatchesNeutral(null, disk.Optional) == false)
- return false;
-
- break;
-
- case ItemType.Release:
- Release release = (Release)item;
-
- // Filter on region
- if (this.Region.MatchesPositiveSet(release.Region) == false)
- return false;
- if (this.Region.MatchesNegativeSet(release.Region) == true)
- return false;
-
- // Filter on language
- if (this.Language.MatchesPositiveSet(release.Language) == false)
- return false;
- if (this.Language.MatchesNegativeSet(release.Language) == true)
- return false;
-
- // Filter on date
- if (this.Date.MatchesPositiveSet(release.Date) == false)
- return false;
- if (this.Date.MatchesNegativeSet(release.Date) == true)
- return false;
-
- // Filter on default
- if (this.Default.MatchesNeutral(null, release.Default) == false)
- return false;
-
- break;
-
- case ItemType.Rom:
- Rom rom = (Rom)item;
-
- // Filter on bios
- if (this.Bios.MatchesPositiveSet(rom.Bios) == false)
- return false;
- if (this.Bios.MatchesNegativeSet(rom.Bios) == true)
- return false;
-
- // Filter on rom size
- if (this.Size.MatchesNeutral(-1, rom.Size) == false)
- return false;
- else if (this.Size.MatchesPositive(-1, rom.Size) == false)
- return false;
- else if (this.Size.MatchesNegative(-1, rom.Size) == false)
- return false;
-
- // Filter on CRC
- if (this.CRC.MatchesPositiveSet(rom.CRC) == false)
- return false;
- if (this.CRC.MatchesNegativeSet(rom.CRC) == true)
- return false;
-
- // Filter on MD5
- if (this.MD5.MatchesPositiveSet(rom.MD5) == false)
- return false;
- if (this.MD5.MatchesNegativeSet(rom.MD5) == true)
- return false;
-
-#if NET_FRAMEWORK
- // Filter on RIPEMD160
- if (this.RIPEMD160.MatchesPositiveSet(rom.RIPEMD160) == false)
- return false;
- if (this.RIPEMD160.MatchesNegativeSet(rom.RIPEMD160) == true)
- return false;
-#endif
-
- // Filter on SHA-1
- if (this.SHA1.MatchesPositiveSet(rom.SHA1) == false)
- return false;
- if (this.SHA1.MatchesNegativeSet(rom.SHA1) == true)
- return false;
-
- // Filter on SHA-256
- if (this.SHA256.MatchesPositiveSet(rom.SHA256) == false)
- return false;
- if (this.SHA256.MatchesNegativeSet(rom.SHA256) == true)
- return false;
-
- // Filter on SHA-384
- if (this.SHA384.MatchesPositiveSet(rom.SHA384) == false)
- return false;
- if (this.SHA384.MatchesNegativeSet(rom.SHA384) == true)
- return false;
-
- // Filter on SHA-512
- if (this.SHA512.MatchesPositiveSet(rom.SHA512) == false)
- return false;
- if (this.SHA512.MatchesNegativeSet(rom.SHA512) == true)
- return false;
-
- // Filter on merge tag
- if (this.MergeTag.MatchesPositiveSet(rom.MergeTag) == false)
- return false;
- if (this.MergeTag.MatchesNegativeSet(rom.MergeTag) == true)
- return false;
-
- // Filter on region
- if (this.Region.MatchesPositiveSet(rom.Region) == false)
- return false;
- if (this.Region.MatchesNegativeSet(rom.Region) == true)
- return false;
-
- // Filter on offset
- if (this.Offset.MatchesPositiveSet(rom.Offset) == false)
- return false;
- if (this.Offset.MatchesNegativeSet(rom.Offset) == true)
- return false;
-
- // Filter on date
- if (this.Date.MatchesPositiveSet(rom.Date) == false)
- return false;
- if (this.Date.MatchesNegativeSet(rom.Date) == true)
- return false;
-
- // Filter on status
- if (this.Status.MatchesPositive(ItemStatus.NULL, rom.ItemStatus) == false)
- return false;
- if (this.Status.MatchesNegative(ItemStatus.NULL, rom.ItemStatus) == true)
- return false;
-
- // Filter on optional
- if (this.Optional.MatchesNeutral(null, rom.Optional) == false)
- return false;
-
- // Filter on inverted
- if (this.Inverted.MatchesNeutral(null, rom.Inverted) == false)
- return false;
-
- break;
-
- case ItemType.Sample:
- // Sample has no special fields
- break;
- }
-
- #endregion
-
- return true;
- }
-
#endregion
#region Internal Splitting/Merging