diff --git a/SabreTools.Core/Filter/FilterRunner.cs b/SabreTools.Core/Filter/FilterRunner.cs index 28cd3aca..948cf7d1 100644 --- a/SabreTools.Core/Filter/FilterRunner.cs +++ b/SabreTools.Core/Filter/FilterRunner.cs @@ -20,6 +20,17 @@ namespace SabreTools.Core.Filter /// private readonly string[] _datItemTypeNames = TypeHelper.GetDatItemTypeNames(); + /// + /// Set of machine type keys that are logically grouped + /// + /// TODO: REMOVE THISWHEN 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) { Filters = filters; @@ -73,6 +84,46 @@ namespace SabreTools.Core.Filter filterDictionary[key].Add(filter); } + // 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 (filterDictionary.ContainsKey(key)) + containsKey = true; + } + + // If at least one exists + if (containsKey) + { + bool matchAny = false; + foreach (string filterKey in _machineTypeKeys) + { + // Skip missing keys + if (!filterDictionary.ContainsKey(filterKey)) + continue; + + foreach (var filter in filterDictionary[filterKey]) + { + matchAny |= filter.Matches(dictionaryBase); + } + } + + // If we don't get a match, it's a failure + if (!matchAny) + return false; + + // Remove the keys from the dictionary + foreach (string key in _machineTypeKeys) + { + filterDictionary.Remove(key); + } + } + } + // Loop through and run each filter in order foreach (var filterKey in filterDictionary.Keys) {