mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make filters more sensible, reduce allocated items
This change ended up being three-fold: 1. Remove the entirely unused header field filters 2. Move filter running to their appropriate filter classes 3. Separate out DatItem filters into more managable private methods
This commit is contained in:
@@ -187,7 +187,7 @@ namespace SabreTools.DatTools
|
||||
public static bool ApplyFilters(DatFile datFile, Cleaner cleaner, bool perMachine = false, bool throwOnError = false)
|
||||
{
|
||||
// If we have a null cleaner or filters, return false
|
||||
if (cleaner == null || cleaner.DatHeaderFilter == null || cleaner.MachineFilter == null || cleaner.DatItemFilter == null)
|
||||
if (cleaner == null || cleaner.MachineFilter == null || cleaner.DatItemFilter == null)
|
||||
return false;
|
||||
|
||||
// If we're filtering per machine, bucket by machine first
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,55 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
using SabreTools.Logging;
|
||||
|
||||
namespace SabreTools.Filtering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the filtering operations that need to be performed on a DatHeader
|
||||
/// </summary>
|
||||
public class DatHeaderFilter : Filter
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public DatHeaderFilter()
|
||||
{
|
||||
logger = new Logger(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Filter Population
|
||||
|
||||
/// <summary>
|
||||
/// Set multiple filters from key
|
||||
/// </summary>
|
||||
/// <param name="key">Key for the filter to be set</param>
|
||||
/// <param name="values">List of values for the filter</param>
|
||||
/// <param name="negate">True if negative filter, false otherwise</param>
|
||||
public void SetFilter(DatHeaderField key, List<string> values, bool negate)
|
||||
{
|
||||
foreach (string value in values)
|
||||
{
|
||||
SetFilter(key, value, negate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a single filter from key
|
||||
/// </summary>
|
||||
/// <param name="key">Key for the filter to be set</param>
|
||||
/// <param name="value">Value of the filter</param>
|
||||
/// <param name="negate">True if negative filter, false otherwise</param>
|
||||
public void SetFilter(DatHeaderField key, string value, bool negate)
|
||||
{
|
||||
// TODO: Add DatHeader filters
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -302,7 +302,7 @@ namespace SabreTools.Filtering
|
||||
/// <param name="filterItem">Filter item to check</param>
|
||||
/// <param name="value">Value to check</param>
|
||||
/// <returns>True if the value passes, false otherwise</returns>
|
||||
public static bool PassBoolFilter(FilterItem<bool?> filterItem, bool? value)
|
||||
protected static bool PassBoolFilter(FilterItem<bool?> filterItem, bool? value)
|
||||
{
|
||||
if (filterItem.MatchesNeutral(null, value) == false)
|
||||
return false;
|
||||
@@ -316,7 +316,7 @@ namespace SabreTools.Filtering
|
||||
/// <param name="filterItem">Filter item to check</param>
|
||||
/// <param name="value">Value to check</param>
|
||||
/// <returns>True if the value passes, false otherwise</returns>
|
||||
public static bool PassDoubleFilter(FilterItem<double?> filterItem, double? value)
|
||||
protected static bool PassDoubleFilter(FilterItem<double?> filterItem, double? value)
|
||||
{
|
||||
if (filterItem.MatchesNeutral(null, value) == false)
|
||||
return false;
|
||||
@@ -334,7 +334,7 @@ namespace SabreTools.Filtering
|
||||
/// <param name="filterItem">Filter item to check</param>
|
||||
/// <param name="value">Value to check</param>
|
||||
/// <returns>True if the value passes, false otherwise</returns>
|
||||
public static bool PassLongFilter(FilterItem<long?> filterItem, long? value)
|
||||
protected static bool PassLongFilter(FilterItem<long?> filterItem, long? value)
|
||||
{
|
||||
if (filterItem.MatchesNeutral(null, value) == false)
|
||||
return false;
|
||||
@@ -352,7 +352,7 @@ namespace SabreTools.Filtering
|
||||
/// <param name="filterItem">Filter item to check</param>
|
||||
/// <param name="value">Value to check</param>
|
||||
/// <returns>True if the value passes, false otherwise</returns>
|
||||
public static bool PassStringFilter(FilterItem<string> filterItem, string value)
|
||||
protected static bool PassStringFilter(FilterItem<string> filterItem, string value)
|
||||
{
|
||||
if (filterItem.MatchesPositiveSet(value) == false)
|
||||
return false;
|
||||
|
||||
@@ -322,5 +322,206 @@ namespace SabreTools.Filtering
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Filter Running
|
||||
|
||||
/// <summary>
|
||||
/// Check to see if a Machine passes the filters
|
||||
/// </summary>
|
||||
/// <param name="machine">Machine to check</param>
|
||||
/// <returns>True if the machine passed the filter, false otherwise</returns>
|
||||
public bool PassesFilters(Machine machine)
|
||||
{
|
||||
if (machine == null)
|
||||
return false;
|
||||
|
||||
#region Common
|
||||
|
||||
// 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_Comment
|
||||
if (!PassStringFilter(Comment, machine.Comment))
|
||||
return false;
|
||||
|
||||
// Machine_Description
|
||||
if (!PassStringFilter(Description, machine.Description))
|
||||
return false;
|
||||
|
||||
// Machine_Year
|
||||
if (!PassStringFilter(Year, machine.Year))
|
||||
return false;
|
||||
|
||||
// Machine_Manufacturer
|
||||
if (!PassStringFilter(Manufacturer, machine.Manufacturer))
|
||||
return false;
|
||||
|
||||
// Machine_Publisher
|
||||
if (!PassStringFilter(Publisher, machine.Publisher))
|
||||
return false;
|
||||
|
||||
// Machine_Category
|
||||
if (!PassStringFilter(Category, machine.Category))
|
||||
return false;
|
||||
|
||||
// Machine_RomOf
|
||||
if (!PassStringFilter(RomOf, machine.RomOf))
|
||||
return false;
|
||||
|
||||
// Machine_CloneOf
|
||||
if (!PassStringFilter(CloneOf, machine.CloneOf))
|
||||
return false;
|
||||
|
||||
// Machine_SampleOf
|
||||
if (!PassStringFilter(SampleOf, machine.SampleOf))
|
||||
return false;
|
||||
|
||||
// Machine_Type
|
||||
if (Type.MatchesPositive(0x0, machine.MachineType) == false)
|
||||
return false;
|
||||
if (Type.MatchesNegative(0x0, machine.MachineType) == true)
|
||||
return false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region AttractMode
|
||||
|
||||
// Machine_Players
|
||||
if (!PassStringFilter(Players, machine.Players))
|
||||
return false;
|
||||
|
||||
// Machine_Rotation
|
||||
if (!PassStringFilter(Rotation, machine.Rotation))
|
||||
return false;
|
||||
|
||||
// Machine_Control
|
||||
if (!PassStringFilter(Control, machine.Control))
|
||||
return false;
|
||||
|
||||
// Machine_Status
|
||||
if (!PassStringFilter(Status, machine.Status))
|
||||
return false;
|
||||
|
||||
// Machine_DisplayCount
|
||||
if (!PassStringFilter(DisplayCount, machine.DisplayCount))
|
||||
return false;
|
||||
|
||||
// Machine_DisplayType
|
||||
if (!PassStringFilter(DisplayType, machine.DisplayType))
|
||||
return false;
|
||||
|
||||
// Machine_Buttons
|
||||
if (!PassStringFilter(Buttons, machine.Buttons))
|
||||
return false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ListXML
|
||||
|
||||
// Machine_History
|
||||
if (!PassStringFilter(History, machine.History))
|
||||
return false;
|
||||
|
||||
// Machine_SourceFile
|
||||
if (!PassStringFilter(SourceFile, machine.SourceFile))
|
||||
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;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Logiqx
|
||||
|
||||
// Machine_Board
|
||||
if (!PassStringFilter(Board, machine.Board))
|
||||
return false;
|
||||
|
||||
// Machine_RebuildTo
|
||||
if (!PassStringFilter(RebuildTo, machine.RebuildTo))
|
||||
return false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Logiqx EmuArc
|
||||
|
||||
// Machine_TitleID
|
||||
if (!PassStringFilter(TitleID, machine.TitleID))
|
||||
return false;
|
||||
|
||||
// Machine_Developer
|
||||
if (!PassStringFilter(Developer, machine.Developer))
|
||||
return false;
|
||||
|
||||
// Machine_Genre
|
||||
if (!PassStringFilter(Genre, machine.Genre))
|
||||
return false;
|
||||
|
||||
// Machine_Subgenre
|
||||
if (!PassStringFilter(Subgenre, machine.Subgenre))
|
||||
return false;
|
||||
|
||||
// Machine_Ratings
|
||||
if (!PassStringFilter(Ratings, machine.Ratings))
|
||||
return false;
|
||||
|
||||
// Machine_Score
|
||||
if (!PassStringFilter(Score, machine.Score))
|
||||
return false;
|
||||
|
||||
// Machine_Enabled
|
||||
if (!PassStringFilter(Enabled, machine.Enabled))
|
||||
return false;
|
||||
|
||||
// Machine_CRC
|
||||
if (!PassBoolFilter(CRC, machine.Crc))
|
||||
return false;
|
||||
|
||||
// Machine_RelatedTo
|
||||
if (!PassStringFilter(RelatedTo, machine.RelatedTo))
|
||||
return false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region OpenMSX
|
||||
|
||||
// Machine_GenMSXID
|
||||
if (!PassStringFilter(GenMSXID, machine.GenMSXID))
|
||||
return false;
|
||||
|
||||
// Machine_System
|
||||
if (!PassStringFilter(System, machine.System))
|
||||
return false;
|
||||
|
||||
// Machine_Country
|
||||
if (!PassStringFilter(Country, machine.Country))
|
||||
return false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region SoftwareList
|
||||
|
||||
// Machine_Supported
|
||||
if (Supported.MatchesPositive(Core.Supported.NULL, machine.Supported) == false)
|
||||
return false;
|
||||
if (Supported.MatchesNegative(Core.Supported.NULL, machine.Supported) == true)
|
||||
return false;
|
||||
|
||||
#endregion // SoftwareList
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2025,7 +2025,6 @@ Some special strings that can be used:
|
||||
{
|
||||
Cleaner cleaner = new Cleaner()
|
||||
{
|
||||
DatHeaderFilter = new DatHeaderFilter(),
|
||||
DatItemFilter = new DatItemFilter(),
|
||||
MachineFilter = new MachineFilter(),
|
||||
|
||||
|
||||
@@ -208,13 +208,11 @@ Reset the internal state: reset();";
|
||||
// Create cleaner to run filters from
|
||||
Cleaner cleaner = new Cleaner
|
||||
{
|
||||
DatHeaderFilter = new DatHeaderFilter(),
|
||||
MachineFilter = new MachineFilter(),
|
||||
DatItemFilter = new DatItemFilter(),
|
||||
};
|
||||
|
||||
// Set the possible filters
|
||||
cleaner.DatHeaderFilter.SetFilter(filterDatHeaderField, filterValue, filterRemove.Value);
|
||||
cleaner.MachineFilter.SetFilter(filterMachineField, filterValue, filterRemove.Value);
|
||||
cleaner.DatItemFilter.SetFilter(filterDatItemField, filterValue, filterRemove.Value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user