Introduce filter-on-read as first defense

This commit is contained in:
Matt Nadareski
2025-05-02 22:34:38 -04:00
parent 1d2e99b246
commit 8b618cea48
20 changed files with 449 additions and 113 deletions

View File

@@ -1,4 +1,8 @@
#if NET40_OR_GREATER || NETCOREAPP
using System.Threading.Tasks;
#endif
using SabreTools.Core;
using SabreTools.Core.Filter;
using SabreTools.Core.Tools;
using SabreTools.DatItems;
using SabreTools.DatItems.Formats;
@@ -17,7 +21,13 @@ namespace SabreTools.DatFiles
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
internal void ConvertFromMetadata(Models.Metadata.MetadataFile? item, string filename, int indexId, bool keep, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
internal void ConvertFromMetadata(Models.Metadata.MetadataFile? item,
string filename,
int indexId,
bool keep,
bool statsOnly,
FilterRunner? filterRunner)
{
// If the metadata file is invalid, we can't do anything
if (item == null || item.Count == 0)
@@ -35,7 +45,7 @@ namespace SabreTools.DatFiles
// Get the machines from the metadata
var machines = item.ReadItemArray<Models.Metadata.Machine>(Models.Metadata.MetadataFile.MachineKey);
if (machines != null)
ConvertMachines(machines, source, sourceIndex: 0, statsOnly);
ConvertMachines(machines, source, sourceIndex: 0, statsOnly, filterRunner);
}
/// <summary>
@@ -175,17 +185,32 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ConvertMachines(Models.Metadata.Machine[]? items, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ConvertMachines(Models.Metadata.Machine[]? items,
Source source,
long sourceIndex,
bool statsOnly,
FilterRunner? filterRunner)
{
// If the array is invalid, we can't do anything
if (items == null || items.Length == 0)
return;
// Loop through the machines and add
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(items, Core.Globals.ParallelOptions, machine =>
#elif NET40_OR_GREATER
Parallel.ForEach(items, machine =>
#else
foreach (var machine in items)
#endif
{
ConvertMachine(machine, source, sourceIndex, statsOnly);
ConvertMachine(machine, source, sourceIndex, statsOnly, filterRunner);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
}
#endif
}
/// <summary>
@@ -195,12 +220,21 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ConvertMachine(Models.Metadata.Machine? item, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ConvertMachine(Models.Metadata.Machine? item,
Source source,
long sourceIndex,
bool statsOnly,
FilterRunner? filterRunner)
{
// If the machine is invalid, we can't do anything
if (item == null || item.Count == 0)
return;
// If the machine doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
return;
// Create an internal machine and add to the dictionary
var machine = new Machine(item);
// long machineIndex = AddMachineDB(machine);
@@ -209,138 +243,138 @@ namespace SabreTools.DatFiles
if (item.ContainsKey(Models.Metadata.Machine.AdjusterKey))
{
var items = item.ReadItemArray<Models.Metadata.Adjuster>(Models.Metadata.Machine.AdjusterKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.ArchiveKey))
{
var items = item.ReadItemArray<Models.Metadata.Archive>(Models.Metadata.Machine.ArchiveKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.BiosSetKey))
{
var items = item.ReadItemArray<Models.Metadata.BiosSet>(Models.Metadata.Machine.BiosSetKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.ChipKey))
{
var items = item.ReadItemArray<Models.Metadata.Chip>(Models.Metadata.Machine.ChipKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.ConfigurationKey))
{
var items = item.ReadItemArray<Models.Metadata.Configuration>(Models.Metadata.Machine.ConfigurationKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.DeviceKey))
{
var items = item.ReadItemArray<Models.Metadata.Device>(Models.Metadata.Machine.DeviceKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.DeviceRefKey))
{
var items = item.ReadItemArray<Models.Metadata.DeviceRef>(Models.Metadata.Machine.DeviceRefKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.DipSwitchKey))
{
var items = item.ReadItemArray<Models.Metadata.DipSwitch>(Models.Metadata.Machine.DipSwitchKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.DiskKey))
{
var items = item.ReadItemArray<Models.Metadata.Disk>(Models.Metadata.Machine.DiskKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.DisplayKey))
{
var items = item.ReadItemArray<Models.Metadata.Display>(Models.Metadata.Machine.DisplayKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.DriverKey))
{
var items = item.ReadItemArray<Models.Metadata.Driver>(Models.Metadata.Machine.DriverKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.DumpKey))
{
var items = item.ReadItemArray<Models.Metadata.Dump>(Models.Metadata.Machine.DumpKey);
string? machineName = machine.GetName();
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, machineName);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, machineName, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.FeatureKey))
{
var items = item.ReadItemArray<Models.Metadata.Feature>(Models.Metadata.Machine.FeatureKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.InfoKey))
{
var items = item.ReadItemArray<Models.Metadata.Info>(Models.Metadata.Machine.InfoKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.InputKey))
{
var items = item.ReadItemArray<Models.Metadata.Input>(Models.Metadata.Machine.InputKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.MediaKey))
{
var items = item.ReadItemArray<Models.Metadata.Media>(Models.Metadata.Machine.MediaKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.PartKey))
{
var items = item.ReadItemArray<Models.Metadata.Part>(Models.Metadata.Machine.PartKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.PortKey))
{
var items = item.ReadItemArray<Models.Metadata.Port>(Models.Metadata.Machine.PortKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.RamOptionKey))
{
var items = item.ReadItemArray<Models.Metadata.RamOption>(Models.Metadata.Machine.RamOptionKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.ReleaseKey))
{
var items = item.ReadItemArray<Models.Metadata.Release>(Models.Metadata.Machine.ReleaseKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.RomKey))
{
var items = item.ReadItemArray<Models.Metadata.Rom>(Models.Metadata.Machine.RomKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.SampleKey))
{
var items = item.ReadItemArray<Models.Metadata.Sample>(Models.Metadata.Machine.SampleKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.SharedFeatKey))
{
var items = item.ReadItemArray<Models.Metadata.SharedFeat>(Models.Metadata.Machine.SharedFeatKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.SlotKey))
{
var items = item.ReadItemArray<Models.Metadata.Slot>(Models.Metadata.Machine.SlotKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.SoftwareListKey))
{
var items = item.ReadItemArray<Models.Metadata.SoftwareList>(Models.Metadata.Machine.SoftwareListKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.SoundKey))
{
var items = item.ReadItemArray<Models.Metadata.Sound>(Models.Metadata.Machine.SoundKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
if (item.ContainsKey(Models.Metadata.Machine.VideoKey))
{
var items = item.ReadItemArray<Models.Metadata.Video>(Models.Metadata.Machine.VideoKey);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly);
ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner);
}
}
@@ -353,7 +387,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Adjuster[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Adjuster[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -362,12 +397,16 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Adjuster(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
AddItem(datItem, statsOnly);
//AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
//AddItemDB(datItem, machineIndex, sourceIndex, statsOnly, filterRunner);
}
}
@@ -380,7 +419,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Archive[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Archive[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -389,6 +429,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Archive(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -407,7 +451,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.BiosSet[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.BiosSet[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -416,6 +461,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new BiosSet(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -434,7 +483,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Chip[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Chip[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -443,6 +493,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Chip(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -461,7 +515,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Configuration[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Configuration[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -470,6 +525,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Configuration(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -488,7 +547,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Device[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Device[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -497,6 +557,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Device(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -515,7 +579,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.DeviceRef[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.DeviceRef[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -524,6 +589,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new DeviceRef(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -542,7 +611,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.DipSwitch[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.DipSwitch[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -551,6 +621,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new DipSwitch(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -569,7 +643,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Disk[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Disk[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -578,6 +653,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Disk(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -596,7 +675,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Display[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Display[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -605,6 +685,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Display(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -623,7 +707,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Driver[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Driver[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -632,6 +717,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Driver(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -651,8 +740,9 @@ namespace SabreTools.DatFiles
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="machineName">Machine name to use when constructing item names</param>
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
/// TODO: Convert this into a constructor in Rom
private void ProcessItems(Models.Metadata.Dump[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, string? machineName)
private void ProcessItems(Models.Metadata.Dump[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, string? machineName, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -685,6 +775,10 @@ namespace SabreTools.DatFiles
continue;
}
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(rom!))
continue;
string name = $"{machineName}_{index++}{(!string.IsNullOrEmpty(rom!.ReadString(Models.Metadata.Rom.RemarkKey)) ? $" {rom.ReadString(Models.Metadata.Rom.RemarkKey)}" : string.Empty)}";
var datItem = new Rom();
@@ -743,7 +837,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Feature[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Feature[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -752,6 +847,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Feature(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -770,7 +869,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Info[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Info[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -779,6 +879,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Info(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -797,7 +901,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Input[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Input[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -806,6 +911,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Input(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -824,7 +933,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Media[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Media[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -833,6 +943,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Media(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -851,7 +965,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Part[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Part[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -875,6 +990,10 @@ namespace SabreTools.DatFiles
foreach (var rom in roms)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(rom))
continue;
var romItem = new Rom(rom);
romItem.SetFieldValue<DataArea?>(Rom.DataAreaKey, dataAreaItem);
romItem.SetFieldValue<Part?>(Rom.PartKey, partItem);
@@ -899,6 +1018,10 @@ namespace SabreTools.DatFiles
foreach (var disk in disks)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(disk))
continue;
var diskItem = new Disk(disk);
diskItem.SetFieldValue<DiskArea?>(Disk.DiskAreaKey, diskAreaitem);
diskItem.SetFieldValue<Part?>(Disk.PartKey, partItem);
@@ -916,6 +1039,10 @@ namespace SabreTools.DatFiles
{
foreach (var dipSwitch in dipSwitches)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(dipSwitch))
continue;
var dipSwitchItem = new DipSwitch(dipSwitch);
dipSwitchItem.SetFieldValue<Part?>(DipSwitch.PartKey, partItem);
dipSwitchItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
@@ -931,6 +1058,10 @@ namespace SabreTools.DatFiles
{
foreach (var partFeature in partFeatures)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(partFeature))
continue;
var partFeatureItem = new PartFeature(partFeature);
partFeatureItem.SetFieldValue<Part?>(DipSwitch.PartKey, partItem);
partFeatureItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
@@ -952,7 +1083,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Port[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Port[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -961,6 +1093,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Port(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -979,7 +1115,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.RamOption[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.RamOption[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -988,6 +1125,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new RamOption(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -1006,7 +1147,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Release[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Release[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -1015,6 +1157,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Release(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -1033,7 +1179,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Rom[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Rom[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -1042,6 +1189,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Rom(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -1060,7 +1211,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Sample[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Sample[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -1069,6 +1221,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Sample(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -1087,7 +1243,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.SharedFeat[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.SharedFeat[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -1096,6 +1253,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new SharedFeat(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -1114,7 +1275,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Slot[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Slot[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -1123,6 +1285,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Slot(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -1141,7 +1307,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.SoftwareList[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.SoftwareList[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -1150,10 +1317,18 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new SoftwareList(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
AddItem(datItem, statsOnly);
// AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
@@ -1168,7 +1343,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Sound[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Sound[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -1177,6 +1353,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Sound(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
@@ -1195,7 +1375,8 @@ namespace SabreTools.DatFiles
/// <param name="source">Source to use with the converted items</param>
/// <param name="sourceIndex">Index of the Source to use with the converted items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Video[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly)
/// <param name="filterRunner">Optional FilterRunner to filter items on parse</param>
private void ProcessItems(Models.Metadata.Video[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner)
{
// If the array is null or empty, return without processing
if (items == null || items.Length == 0)
@@ -1204,6 +1385,10 @@ namespace SabreTools.DatFiles
// Loop through the items and add
foreach (var item in items)
{
// If the item doesn't pass the filter
if (filterRunner != null && !filterRunner.Run(item))
continue;
var datItem = new Display(item);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);