mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
FilterRunner update to better support machine types
This commit is contained in:
@@ -20,24 +20,23 @@ namespace SabreTools.Core.Filter
|
||||
/// </summary>
|
||||
private readonly string[] _datItemTypeNames = TypeHelper.GetDatItemTypeNames();
|
||||
|
||||
/// <summary>
|
||||
/// Set of machine type keys that are logically grouped
|
||||
/// </summary>
|
||||
/// TODO: REMOVE THIS WHEN A PROPER IMPLEMENTATION IS FOUND
|
||||
private readonly string[] _machineTypeKeys =
|
||||
[
|
||||
$"{MetadataFile.MachineKey}.{Machine.IsBiosKey}",
|
||||
$"{MetadataFile.MachineKey}.{Machine.IsDeviceKey}",
|
||||
$"{MetadataFile.MachineKey}.{Machine.IsMechanicalKey}",
|
||||
];
|
||||
|
||||
public FilterRunner(FilterObject[] filters)
|
||||
{
|
||||
foreach (var filter in filters)
|
||||
{
|
||||
// Ensure the key exists
|
||||
// Get the key as a string
|
||||
string key = filter.Key.ToString();
|
||||
if (!Filters.ContainsKey(filter.Key.ToString()))
|
||||
|
||||
// Special case for machine types
|
||||
if (filter.Key.ItemName == MetadataFile.MachineKey && filter.Key.FieldName == Machine.IsBiosKey)
|
||||
key = $"{MetadataFile.MachineKey}.COMBINEDTYPE";
|
||||
else if (filter.Key.ItemName == MetadataFile.MachineKey && filter.Key.FieldName == Machine.IsDeviceKey)
|
||||
key = $"{MetadataFile.MachineKey}.COMBINEDTYPE";
|
||||
else if (filter.Key.ItemName == MetadataFile.MachineKey && filter.Key.FieldName == Machine.IsMechanicalKey)
|
||||
key = $"{MetadataFile.MachineKey}.COMBINEDTYPE";
|
||||
|
||||
// Ensure the key exists
|
||||
if (!Filters.ContainsKey(key))
|
||||
Filters[key] = new FilterGroup(GroupType.OR);
|
||||
|
||||
// Add the filter to the set
|
||||
@@ -53,9 +52,19 @@ namespace SabreTools.Core.Filter
|
||||
{
|
||||
var filter = new FilterObject(filterString);
|
||||
|
||||
// Ensure the key exists
|
||||
// Get the key as a string
|
||||
string key = filter.Key.ToString();
|
||||
if (!Filters.ContainsKey(filter.Key.ToString()))
|
||||
|
||||
// Special case for machine types
|
||||
if (filter.Key.ItemName == MetadataFile.MachineKey && filter.Key.FieldName == Machine.IsBiosKey)
|
||||
key = $"{MetadataFile.MachineKey}.COMBINEDTYPE";
|
||||
else if (filter.Key.ItemName == MetadataFile.MachineKey && filter.Key.FieldName == Machine.IsDeviceKey)
|
||||
key = $"{MetadataFile.MachineKey}.COMBINEDTYPE";
|
||||
else if (filter.Key.ItemName == MetadataFile.MachineKey && filter.Key.FieldName == Machine.IsMechanicalKey)
|
||||
key = $"{MetadataFile.MachineKey}.COMBINEDTYPE";
|
||||
|
||||
// Ensure the key exists
|
||||
if (!Filters.ContainsKey(key))
|
||||
Filters[key] = new FilterGroup(GroupType.OR);
|
||||
|
||||
// Add the filter to the set
|
||||
@@ -82,38 +91,6 @@ namespace SabreTools.Core.Filter
|
||||
if (itemName == null)
|
||||
return false;
|
||||
|
||||
// TODO: REMOVE THIS ENTIRE BLOCK WHEN A PROPER IMPLEMENTATION IS FOUND
|
||||
// Handle special keys that work in tandem
|
||||
if (itemName == MetadataFile.MachineKey)
|
||||
{
|
||||
// Check that one of the special keys exists
|
||||
bool containsKey = false;
|
||||
foreach (string key in _machineTypeKeys)
|
||||
{
|
||||
if (Filters.ContainsKey(key))
|
||||
containsKey = true;
|
||||
}
|
||||
|
||||
// If at least one exists
|
||||
if (containsKey)
|
||||
{
|
||||
bool matchAny = false;
|
||||
foreach (string filterKey in _machineTypeKeys)
|
||||
{
|
||||
// Skip missing keys
|
||||
if (!Filters.ContainsKey(filterKey))
|
||||
continue;
|
||||
|
||||
// Check for a match like normal
|
||||
matchAny |= Filters[filterKey].Matches(dictionaryBase);
|
||||
}
|
||||
|
||||
// If we don't get a match, it's a failure
|
||||
if (!matchAny)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Loop through and run each filter in order
|
||||
foreach (var filterKey in Filters.Keys)
|
||||
{
|
||||
@@ -123,10 +100,6 @@ namespace SabreTools.Core.Filter
|
||||
else if (!filterKey.StartsWith("item.") && !filterKey.StartsWith(itemName))
|
||||
continue;
|
||||
|
||||
// TODO: REMOVE THIS ENTIRE BLOCK WHEN A PROPER IMPLEMENTATION IS FOUND
|
||||
if (Array.Exists(_machineTypeKeys, key => key == filterKey))
|
||||
continue;
|
||||
|
||||
// If we don't get a match, it's a failure
|
||||
bool matchOne = Filters[filterKey].Matches(dictionaryBase);
|
||||
if (!matchOne)
|
||||
|
||||
Reference in New Issue
Block a user