diff --git a/SabreTools.DatFiles/DatFile.cs b/SabreTools.DatFiles/DatFile.cs index d6d88db3..223d6070 100644 --- a/SabreTools.DatFiles/DatFile.cs +++ b/SabreTools.DatFiles/DatFile.cs @@ -9,6 +9,7 @@ using SabreTools.Core.Tools; using SabreTools.DatFiles.Formats; using SabreTools.DatItems; using SabreTools.DatItems.Formats; +using SabreTools.Filter; using SabreTools.Hashing; using SabreTools.Logging; @@ -146,6 +147,41 @@ namespace SabreTools.DatFiles #endregion + #region Filtering + + /// + /// Execute all filters in a filter runner on the items in the dictionary + /// + /// Preconfigured filter runner to use + public void ExecuteFilters(FilterRunner filterRunner) + { + List keys = [.. Items.Keys]; +#if NET452_OR_GREATER || NETCOREAPP + Parallel.ForEach(keys, Globals.ParallelOptions, key => +#elif NET40_OR_GREATER + Parallel.ForEach(keys, key => +#else + foreach (var key in keys) +#endif + { + ConcurrentList? items = Items[key]; + if (items == null) +#if NET40_OR_GREATER || NETCOREAPP + return; +#else + continue; +#endif + + // TODO: Implement filtering +#if NET40_OR_GREATER || NETCOREAPP + }); +#else + } +#endif + } + + #endregion + #region Parsing /// diff --git a/SabreTools.DatFiles/ItemDictionary.cs b/SabreTools.DatFiles/ItemDictionary.cs index 410e2692..2fb2a8f3 100644 --- a/SabreTools.DatFiles/ItemDictionary.cs +++ b/SabreTools.DatFiles/ItemDictionary.cs @@ -818,7 +818,11 @@ namespace SabreTools.DatFiles // Get the possibly unsorted list ConcurrentList? sortedlist = this[key]?.ToConcurrentList(); if (sortedlist == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif // Sort the list of items to be consistent DatItem.Sort(ref sortedlist, false); diff --git a/SabreTools.DatFiles/ItemDictionaryDB.cs b/SabreTools.DatFiles/ItemDictionaryDB.cs index b8011d1b..c4b2af61 100644 --- a/SabreTools.DatFiles/ItemDictionaryDB.cs +++ b/SabreTools.DatFiles/ItemDictionaryDB.cs @@ -946,7 +946,11 @@ CREATE TABLE IF NOT EXISTS groups ( { string key = oldkeys[k]; if (this[key] == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif // Now add each of the roms to their respective keys for (int i = 0; i < this[key]!.Count; i++) diff --git a/SabreTools.DatTools/DatFileTool.cs b/SabreTools.DatTools/DatFileTool.cs index 619577c8..8fac61dd 100644 --- a/SabreTools.DatTools/DatFileTool.cs +++ b/SabreTools.DatTools/DatFileTool.cs @@ -43,7 +43,11 @@ namespace SabreTools.DatTools { ConcurrentList? items = datFile.Items[key]; if (items == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif ConcurrentList newItems = []; foreach (DatItem item in items) @@ -119,7 +123,11 @@ namespace SabreTools.DatTools { ConcurrentList? datItems = intDat.Items[key]; if (datItems == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif ConcurrentList newDatItems = []; foreach (DatItem datItem in datItems) @@ -163,7 +171,11 @@ namespace SabreTools.DatTools { ConcurrentList? datItems = intDat.Items[key]; if (datItems == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif ConcurrentList newDatItems = []; foreach (DatItem datItem in datItems) @@ -230,15 +242,27 @@ namespace SabreTools.DatTools { // If the key is null, keep it if (!intDat.Items.TryGetValue(key, out var intList) || intList == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif // If the base DAT doesn't contain the key, keep it if (!datFile.Items.TryGetValue(key, out var list) || list == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif // If the number of items is different, then keep it if (list.Count != intList.Count) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif // Otherwise, compare by name and hash the remaining files bool exactMatch = true; @@ -262,7 +286,11 @@ namespace SabreTools.DatTools { ConcurrentList? datItems = intDat.Items[key]; if (datItems == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif ConcurrentList keepDatItems = []; foreach (DatItem datItem in datItems) diff --git a/SabreTools.DatTools/DatFromDir.cs b/SabreTools.DatTools/DatFromDir.cs index a160cac4..d6f3bd12 100644 --- a/SabreTools.DatTools/DatFromDir.cs +++ b/SabreTools.DatTools/DatFromDir.cs @@ -255,7 +255,11 @@ namespace SabreTools.DatTools { DatItem? datItem = DatItem.Create(baseFile); if (datItem == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif ProcessFileHelper(datFile, item, datItem, basePath, parent); #if NET40_OR_GREATER || NETCOREAPP diff --git a/SabreTools.DatTools/Splitter.cs b/SabreTools.DatTools/Splitter.cs index ed72f493..b2c68b29 100644 --- a/SabreTools.DatTools/Splitter.cs +++ b/SabreTools.DatTools/Splitter.cs @@ -597,7 +597,11 @@ namespace SabreTools.DatTools // If the rom list is empty or null, just skip it if (items == null || items.Count == 0) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif foreach (DatItem item in items) { diff --git a/SabreTools.Filtering/Cleaner.cs b/SabreTools.Filtering/Cleaner.cs index efaa1564..6256a4bf 100644 --- a/SabreTools.Filtering/Cleaner.cs +++ b/SabreTools.Filtering/Cleaner.cs @@ -249,7 +249,11 @@ namespace SabreTools.Filtering { var items = datFile.Items[key]; if (items == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif foreach (DatItem item in items) { @@ -277,7 +281,11 @@ namespace SabreTools.Filtering { var items = datFile.Items[key]; if (items == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif ConcurrentList newItems = []; foreach (DatItem item in items) @@ -420,7 +428,11 @@ namespace SabreTools.Filtering { var items = datFile.Items[key]; if (items == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif for (int i = 0; i < items.Count; i++) { @@ -474,7 +486,11 @@ namespace SabreTools.Filtering { var items = datFile.Items[key]; if (items == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif for (int j = 0; j < items.Count; j++) { diff --git a/SabreTools.Filtering/Remover.cs b/SabreTools.Filtering/Remover.cs index 199f405d..10fd852d 100644 --- a/SabreTools.Filtering/Remover.cs +++ b/SabreTools.Filtering/Remover.cs @@ -121,7 +121,11 @@ namespace SabreTools.Filtering { ConcurrentList? items = datFile.Items[key]; if (items == null) +#if NET40_OR_GREATER || NETCOREAPP return; +#else + continue; +#endif for (int j = 0; j < items.Count; j++) { diff --git a/SabreTools/Features/BaseFeature.cs b/SabreTools/Features/BaseFeature.cs index 36c623fa..8881a6c3 100644 --- a/SabreTools/Features/BaseFeature.cs +++ b/SabreTools/Features/BaseFeature.cs @@ -1786,6 +1786,11 @@ Some special strings that can be used: /// protected Filtering.Filter Filter { get; set; } + /// + /// Preonfigured FilterRunner + /// + protected Filter.FilterRunner FilterRunner { get; set; } + /// /// Pre-configured DatHeader /// @@ -1894,6 +1899,7 @@ Some special strings that can be used: Cleaner = GetCleaner(features); Extras = GetExtras(features); Filter = GetFilter(features); + FilterRunner = GetFilterRunner(features); Header = GetDatHeader(features); LogLevel = GetString(features, LogLevelStringValue).AsLogLevel(); OutputDir = GetString(features, OutputDirStringValue)?.Trim('"'); @@ -2243,6 +2249,22 @@ Some special strings that can be used: return filter; } + /// + /// Get FilterRunner from feature list + /// + private static Filter.FilterRunner GetFilterRunner(Dictionary features) + { + // Populate filters + List filterPairs = GetList(features, FilterListValue); + var filterRunner = new Filter.FilterRunner(filterPairs.ToArray()); + + // TODO: Support this use case somehow + // Include 'of" in game filters + //filter.MachineFilter.IncludeOfInGame = GetBoolean(features, MatchOfTagsValue); + + return filterRunner; + } + /// /// Get Remover from feature list /// diff --git a/SabreTools/Features/DatFromDir.cs b/SabreTools/Features/DatFromDir.cs index 92abc581..d1ea12c7 100644 --- a/SabreTools/Features/DatFromDir.cs +++ b/SabreTools/Features/DatFromDir.cs @@ -101,6 +101,7 @@ namespace SabreTools.Features Extras.ApplyExtras(datdata); Splitter.ApplySplitting(datdata, useTags: false); Filter.ApplyFilters(datdata); + //FilterRunner.Run(datdata); // TODO: Create helper method to run over entire DAT Cleaner.ApplyCleaning(datdata); Remover.ApplyRemovals(datdata);