Add per-machine filtering to Batch

This commit is contained in:
Matt Nadareski
2020-09-04 20:57:30 -07:00
parent e2d0dc26b9
commit 4146972afe
4 changed files with 38 additions and 14 deletions

View File

@@ -821,13 +821,18 @@ namespace SabreTools.Library.DatFiles
/// Apply a Filter on the DatFile
/// </summary>
/// <param name="filter">Filter to use</param>
/// <param name="perMachine">True if entire machines are considered, false otherwise (default)</param>
/// <returns>True if the DatFile was filtered, false on error</returns>
public bool ApplyFilter(Filter filter)
public bool ApplyFilter(Filter filter, bool perMachine = false)
{
// If we have a null filter, return false
if (filter == null)
return false;
// If we're filtering per machine, bucket by machine first
if (perMachine)
Items.BucketBy(Field.Machine_Name, DedupeType.None);
try
{
// Loop over every key in the dictionary
@@ -835,6 +840,7 @@ namespace SabreTools.Library.DatFiles
foreach (string key in keys)
{
// For every item in the current key
bool machinePass = true;
List<DatItem> items = Items[key];
foreach (DatItem item in items)
{
@@ -844,7 +850,25 @@ namespace SabreTools.Library.DatFiles
// If the rom doesn't pass the filter, mark for removal
if (!item.PassesFilter(filter))
{
item.Remove = true;
// If we're in machine mode, set and break
if (perMachine)
{
machinePass = false;
break;
}
}
}
// If we didn't pass and we're in machine mode, set all items as remove
if (perMachine && !machinePass)
{
foreach (DatItem item in items)
{
item.Remove = true;
}
}
// Assign back for caution

View File

@@ -513,14 +513,6 @@ namespace SabreTools.Library.DatItems
#endregion
// TODO: Can there be a special filter for machine that says if one item in a machine
// explicitly passes then the machine is included? This will be difficult to attempt to
// implement because technically, you'd want to keep games that don't match a negative
// instead of the inverse. Possible way of doing it would be: filter on machine-level
// things first, then see if any items inside explicitly fail. If ANY fail inside, filter
// out the machine. This would likely have to be an entirely separate flag. A proof
// of concept implementation would be best first, likely living under Filtering of
// the DatFile class.
#region Filtering
/// <summary>

View File

@@ -186,7 +186,7 @@ Options:
Set a header field (if default): set(header.field, value);
Parse new file(s): input(datpath, ...);
Perform a dir2dat: d2d(path, ...);
Filter on a field and value: filter(machine.field|item.field, value, [negate = false]);
Filter on a field and value: filter(machine.field|item.field, value, [negate = false, [perMachine = false]]);
Apply a MAME Extra INI for a field: extra(field, inipath);
Perform a split/merge: merge(split|merged|nonmerged|full|device);
Set game names from description: descname();