[SabreTools, Filter] Implement new filter, add warnings for invalid inputs

This commit is contained in:
Matt Nadareski
2017-01-11 16:53:22 -08:00
parent 50df38026a
commit 7d1bb820a8
3 changed files with 31 additions and 9 deletions

View File

@@ -118,11 +118,11 @@ namespace SabreTools.Helper.Dats
public bool ItemPasses(DatItem item, Logger logger) public bool ItemPasses(DatItem item, Logger logger)
{ {
// Filter on machine type // Filter on machine type
if (_machineType != MachineType.NULL && item.Machine.MachineType != _machineType) if (_machineType != MachineType.NULL && (item.Machine.MachineType & _machineType) == 0)
{ {
return false; return false;
} }
if (_machineNotType != MachineType.NULL && item.Machine.MachineType == _machineNotType) if (_machineNotType != MachineType.NULL && (item.Machine.MachineType & _machineNotType) != 0)
{ {
return false; return false;
} }
@@ -139,11 +139,11 @@ namespace SabreTools.Helper.Dats
Rom rom = (Rom)item; Rom rom = (Rom)item;
// Filter on status // Filter on status
if (_itemStatus != ItemStatus.NULL && rom.ItemStatus != _itemStatus) if (_itemStatus != ItemStatus.NULL && (rom.ItemStatus & _itemStatus) == 0)
{ {
return false; return false;
} }
if (_itemNotStatus != ItemStatus.NULL && rom.ItemStatus == _itemNotStatus) if (_itemNotStatus != ItemStatus.NULL && (rom.ItemStatus & _itemNotStatus) != 0)
{ {
return false; return false;
} }
@@ -362,11 +362,11 @@ namespace SabreTools.Helper.Dats
Disk rom = (Disk)item; Disk rom = (Disk)item;
// Filter on status // Filter on status
if (_itemStatus != ItemStatus.NULL && rom.ItemStatus != _itemStatus) if (_itemStatus != ItemStatus.NULL && (rom.ItemStatus & _itemStatus) == 0)
{ {
return false; return false;
} }
if (_itemNotStatus != ItemStatus.NULL && rom.ItemStatus == _itemNotStatus) if (_itemNotStatus != ItemStatus.NULL && (rom.ItemStatus & _itemNotStatus) != 0)
{ {
return false; return false;
} }

View File

@@ -840,18 +840,22 @@ Options:
-is=, --status= Include only items with a given status -is=, --status= Include only items with a given status
Include items with one of the supported values: Include items with one of the supported values:
None, Good, BadDump, Nodump, Verified None, Good, BadDump, Nodump, Verified
Multiples of this input are allowed.
-nis=, --not-status= Exclude only items with a given status -nis=, --not-status= Exclude only items with a given status
Exclude items with one of the supported values: Exclude items with one of the supported values:
None, Good, BadDump, Nodump, Verified None, Good, BadDump, Nodump, Verified
Multiples of this input are allowed.
-gt=, --game-type= Include only items with the given game type -gt=, --game-type= Include only items with the given game type
Include items with one of the supported values: Include items with one of the supported values:
None, Bios, Device, Mechanical None, Bios, Device, Mechanical
Multiples of this input are allowed.
-ngt=, --not-gtype= Exclude only items with a given game type -ngt=, --not-gtype= Exclude only items with a given game type
Exclude items with one of the supported values: Exclude items with one of the supported values:
None, Bios, Device, Mechanical None, Bios, Device, Mechanical
Multiples of this input are allowed.
-run, --runnable Include only items that are marked runnable -run, --runnable Include only items that are marked runnable
This allows users to include only verified runnable games This allows users to include only verified runnable games

View File

@@ -541,7 +541,6 @@ namespace SabreTools
switch (forcemerge?.ToLowerInvariant()) switch (forcemerge?.ToLowerInvariant())
{ {
case "none": case "none":
default:
fm = ForceMerging.None; fm = ForceMerging.None;
break; break;
case "split": case "split":
@@ -550,13 +549,15 @@ namespace SabreTools
case "full": case "full":
fm = ForceMerging.Full; fm = ForceMerging.Full;
break; break;
default:
_logger.Warning(forcemerge + " is not a valid merge flag");
break;
} }
ForceNodump fn = ForceNodump.None; ForceNodump fn = ForceNodump.None;
switch (forcend?.ToLowerInvariant()) switch (forcend?.ToLowerInvariant())
{ {
case "none": case "none":
default:
fn = ForceNodump.None; fn = ForceNodump.None;
break; break;
case "obsolete": case "obsolete":
@@ -568,13 +569,15 @@ namespace SabreTools
case "ignore": case "ignore":
fn = ForceNodump.Ignore; fn = ForceNodump.Ignore;
break; break;
default:
_logger.Warning(forcend + " is not a valid nodump flag");
break;
} }
ForcePacking fp = ForcePacking.None; ForcePacking fp = ForcePacking.None;
switch (forcepack?.ToLowerInvariant()) switch (forcepack?.ToLowerInvariant())
{ {
case "none": case "none":
default:
fp = ForcePacking.None; fp = ForcePacking.None;
break; break;
case "zip": case "zip":
@@ -583,6 +586,9 @@ namespace SabreTools
case "unzip": case "unzip":
fp = ForcePacking.Unzip; fp = ForcePacking.Unzip;
break; break;
default:
_logger.Warning(forcepack + " is not a valid packing flag");
break;
} }
// Set the status flag for filtering // Set the status flag for filtering
@@ -606,6 +612,9 @@ namespace SabreTools
case "verified": case "verified":
itemStatus |= ItemStatus.Verified; itemStatus |= ItemStatus.Verified;
break; break;
default:
_logger.Warning(status + " is not a valid status");
break;
} }
} }
@@ -630,6 +639,9 @@ namespace SabreTools
case "verified": case "verified":
itemNotStatus |= ItemStatus.Verified; itemNotStatus |= ItemStatus.Verified;
break; break;
default:
_logger.Warning(status + " is not a valid status");
break;
} }
} }
@@ -653,6 +665,9 @@ namespace SabreTools
case "mechanical": case "mechanical":
machineType |= MachineType.Mechanical; machineType |= MachineType.Mechanical;
break; break;
default:
_logger.Warning(gametype + " is not a valid type");
break;
} }
} }
@@ -676,6 +691,9 @@ namespace SabreTools
case "mechanical": case "mechanical":
machineNotType = MachineType.Mechanical; machineNotType = MachineType.Mechanical;
break; break;
default:
_logger.Warning(gametype + " is not a valid type");
break;
} }
} }