From d0f0fd6f7c25f53913558cccf4538bd62ff856c0 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 14 May 2025 14:42:15 -0400 Subject: [PATCH] FilterRunner update to better support machine types --- SabreTools.Core/Filter/FilterRunner.cs | 75 +++++++++----------------- 1 file changed, 24 insertions(+), 51 deletions(-) diff --git a/SabreTools.Core/Filter/FilterRunner.cs b/SabreTools.Core/Filter/FilterRunner.cs index 512fd4d3..4b8ca8fa 100644 --- a/SabreTools.Core/Filter/FilterRunner.cs +++ b/SabreTools.Core/Filter/FilterRunner.cs @@ -20,24 +20,23 @@ namespace SabreTools.Core.Filter /// private readonly string[] _datItemTypeNames = TypeHelper.GetDatItemTypeNames(); - /// - /// Set of machine type keys that are logically grouped - /// - /// 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)