mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make ItemDictionary responsible for running filters on itself
This commit is contained in:
@@ -158,41 +158,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||||
public void ExecuteFilters(FilterRunner filterRunner)
|
public void ExecuteFilters(FilterRunner filterRunner)
|
||||||
{
|
=> Items.ExecuteFilters(filterRunner);
|
||||||
List<string> 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<DatItem>? items = Items[key];
|
|
||||||
if (items == null)
|
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
|
||||||
return;
|
|
||||||
#else
|
|
||||||
continue;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Filter all items in the current key
|
|
||||||
var newItems = new ConcurrentList<DatItem>();
|
|
||||||
foreach (var item in items)
|
|
||||||
{
|
|
||||||
if (item.PassesFilter(filterRunner))
|
|
||||||
newItems.Add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the value in the key to the new set
|
|
||||||
Items[key] = newItems;
|
|
||||||
|
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
|
||||||
});
|
|
||||||
#else
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
|||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SabreTools.Core;
|
using SabreTools.Core;
|
||||||
|
using SabreTools.Core.Filter;
|
||||||
using SabreTools.DatItems;
|
using SabreTools.DatItems;
|
||||||
using SabreTools.DatItems.Formats;
|
using SabreTools.DatItems.Formats;
|
||||||
using SabreTools.Hashing;
|
using SabreTools.Hashing;
|
||||||
@@ -710,6 +711,51 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Filtering
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Execute all filters in a filter runner on the items in the dictionary
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||||
|
public void ExecuteFilters(FilterRunner filterRunner)
|
||||||
|
{
|
||||||
|
List<string> keys = [.. 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<DatItem>? items = this[key];
|
||||||
|
if (items == null)
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
return;
|
||||||
|
#else
|
||||||
|
continue;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Filter all items in the current key
|
||||||
|
var newItems = new ConcurrentList<DatItem>();
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
if (item.PassesFilter(filterRunner))
|
||||||
|
newItems.Add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the value in the key to the new set
|
||||||
|
this[key] = newItems;
|
||||||
|
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
});
|
||||||
|
#else
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Statistics
|
#region Statistics
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user