mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Items are responsible for their own filters
This commit is contained in:
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Check to see if a DatItem passes the filter
|
||||
/// </summary>
|
||||
/// <param name="filter">Filter to check against</param>
|
||||
/// <returns>True if the item passed the filter, false otherwise</returns>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Check to see if a DatItem passes the filter
|
||||
/// </summary>
|
||||
/// <param name="filter">Filter to check against</param>
|
||||
/// <returns>True if the item passed the filter, false otherwise</returns>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Check to see if a DatItem passes the filter
|
||||
/// </summary>
|
||||
/// <param name="filter">Filter to check against</param>
|
||||
/// <returns>True if the item passed the filter, false otherwise</returns>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Check to see if a DatItem passes the filter
|
||||
/// </summary>
|
||||
/// <param name="filter">Filter to check against</param>
|
||||
/// <returns>True if the item passed the filter, false otherwise</returns>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Check to see if a DatItem passes the filter
|
||||
/// </summary>
|
||||
/// <param name="filter">Filter to check against</param>
|
||||
/// <returns>True if the item passed the filter, false otherwise</returns>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user