[SabreTools, Filter] Add support for filtering on machine type

This commit is contained in:
Matt Nadareski
2017-01-08 23:09:31 -08:00
parent 37b6a4303d
commit a4ed865650
5 changed files with 103 additions and 13 deletions

View File

@@ -359,6 +359,12 @@ namespace SabreTools.Helper.Data
helptext.Add(" -nis=, --not-status= Exclude items with a given status");
helptext.Add(" Supported values are:");
helptext.Add(" None, Good, BadDump, Nodump, Verified");
helptext.Add(" -gt=, --game-type= Include only games with a given type");
helptext.Add(" Supported values are:");
helptext.Add(" None, Bios, Device, Mechanical");
helptext.Add(" -ngt=, --not-gtype= Exclude only games with a given type");
helptext.Add(" Supported values are:");
helptext.Add(" None, Bios, Device, Mechanical");
helptext.Add(" -out= Output directory (overridden by --inplace)");
helptext.Add(" -mt={4} Amount of threads to use (-1 unlimted)");

View File

@@ -25,6 +25,8 @@ namespace SabreTools.Helper.Dats
private string _notSha1;
private ItemStatus _itemStatus;
private ItemStatus _itemNotStatus;
private MachineType _machineType;
private MachineType _machineNotType;
#endregion
@@ -65,17 +67,19 @@ namespace SabreTools.Helper.Dats
/// <param name="md5">MD5 of the rom to match (can use asterisk-partials)</param>
/// <param name="sha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
/// <param name="itemStatus">Select roms with the given status</param>
/// <param name="machineType">Select games with the given type</param>
/// <param name="notgamename">Name of the game to match (can use asterisk-partials)</param>
/// <param name="notromname">Name of the rom to match (can use asterisk-partials)</param>
/// <param name="notromtype">Type of the rom to match</param>
/// <param name="notcrc">CRC of the rom to match (can use asterisk-partials)</param>
/// <param name="notmd5">MD5 of the rom to match (can use asterisk-partials)</param>
/// <param name="notsha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
/// <param name="itemNotStatus">Select roms with the given status</param>
/// <param name="itemNotStatus">Select roms without the given status</param>
/// <param name="machineNotType">Select games without the given type</param>
public Filter(string gamename, string romname, string romtype, long sgt,
long slt, long seq, string crc, string md5, string sha1, ItemStatus itemStatus,
string notgamename, string notromname, string notromtype, string notcrc, string notmd5,
string notsha1, ItemStatus itemNotStatus)
MachineType machineType, string notgamename, string notromname, string notromtype,
string notcrc, string notmd5, string notsha1, ItemStatus itemNotStatus, MachineType machineNotType)
{
_gameName = gamename;
_notGameName = notgamename;
@@ -94,6 +98,8 @@ namespace SabreTools.Helper.Dats
_notSha1 = notsha1;
_itemStatus = itemStatus;
_itemNotStatus = itemNotStatus;
_machineType = machineType;
_machineNotType = machineNotType;
}
/// <summary>
@@ -119,6 +125,16 @@ namespace SabreTools.Helper.Dats
return false;
}
// Filter on machine type
if (_machineType != MachineType.NULL && rom.Machine.MachineType != _machineType)
{
return false;
}
if (_machineNotType != MachineType.NULL && rom.Machine.MachineType == _machineNotType)
{
return false;
}
// Filter on rom size
if (_sizeEqualTo != -1 && rom.Size != _sizeEqualTo)
{

View File

@@ -825,9 +825,17 @@ Options:
None, Good, BadDump, Nodump, Verified
-nis=, --not-status= Exclude only items with a given status
Include items with one of the supported values:
Exclude items with one of the supported values:
None, Good, BadDump, Nodump, Verified
-gt=, --game-type= Include only items with the given game type
Include items with one of the supported values:
None, Bios, Device, Mechanical
-ngt=, --not-gtype= Exclude only items with a given game type
Exclude items with one of the supported values:
None, Bios, Device, Mechanical
-out= Set the name of the output directory
This sets an output folder to be used when the files are created. If a path
is not defined, the application directory is used instead.

View File

@@ -389,7 +389,7 @@ namespace SabreTools
/// <summary>
/// Wrap converting and updating DAT file from any format to any format
/// </summary>
/// <param name="input">List of input filenames</param>
/// <param name="inputs">List of input filenames</param>
/// /* Normal DAT header info */
/// <param name="filename">New filename</param>
/// <param name="name">New name</param>
@@ -437,13 +437,15 @@ namespace SabreTools
/// <param name="md5">MD5 of the rom to match (can use asterisk-partials)</param>
/// <param name="sha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
/// <param name="status">Select roms with the given item status</param>
/// <param name="gametype">Select games with the given type</param>
/// <param name="notgamename">Name of the game to match (can use asterisk-partials)</param>
/// <param name="notromname">Name of the rom to match (can use asterisk-partials)</param>
/// <param name="notromtype">Type of the rom to match</param>
/// <param name="notcrc">CRC of the rom to match (can use asterisk-partials)</param>
/// <param name="notmd5">MD5 of the rom to match (can use asterisk-partials)</param>
/// <param name="notsha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
/// <param name="notstatus">Select roms with the given item status</param>
/// <param name="notstatus">Select roms without the given item status</param>
/// <param name="notgametype">Select games without the given type</param>
/// /* Trimming info */
/// <param name="trim">True if we are supposed to trim names to NTFS length, false otherwise</param>
/// <param name="single">True if all games should be replaced by '!', false otherwise</param>
@@ -506,6 +508,7 @@ namespace SabreTools
string md5,
string sha1,
string status,
string gametype,
string notgamename,
string notromname,
string notromtype,
@@ -513,6 +516,7 @@ namespace SabreTools
string notmd5,
string notsha1,
string notstatus,
string notgametype,
/* Trimming info */
bool trim,
@@ -619,6 +623,44 @@ namespace SabreTools
break;
}
// Set the machine type flag for filtering
MachineType machineType = MachineType.NULL;
switch(gametype?.ToLowerInvariant())
{
case "none":
machineType = MachineType.None;
break;
case "bios":
machineType = MachineType.Bios;
break;
case "device":
machineType = MachineType.Device;
break;
case "mech":
case "mechanical":
machineType = MachineType.Mechanical;
break;
}
// Set the not machine type flag for filtering
MachineType machineNotType = MachineType.NULL;
switch (gametype?.ToLowerInvariant())
{
case "none":
machineNotType = MachineType.None;
break;
case "bios":
machineNotType = MachineType.Bios;
break;
case "device":
machineNotType = MachineType.Device;
break;
case "mech":
case "mechanical":
machineNotType = MachineType.Mechanical;
break;
}
// Normalize the extensions
addext = (addext == "" || addext.StartsWith(".") ? addext : "." + addext);
repext = (repext == "" || repext.StartsWith(".") ? repext : "." + repext);
@@ -689,8 +731,8 @@ namespace SabreTools
};
// Create the Filter object to be used
Filter filter = new Filter(gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus,
notgamename, notromname, notromtype, notcrc, notmd5, notsha1, itemNotStatus);
Filter filter = new Filter(gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, machineType,
notgamename, notromname, notromtype, notcrc, notmd5, notsha1, itemNotStatus, machineNotType);
userInputDat.DetermineUpdateType(inputs, outDir, merge, diffMode, inplace, skip, bare, clean, softlist,
filter, trim, single, root, maxDegreeOfParallelism, _logger);

View File

@@ -127,12 +127,14 @@ namespace SabreTools
forcend = "",
forcepack = "",
gamename = "",
gametype = "",
header = null,
homepage = null,
md5 = "",
name = null,
notcrc = null,
notgamename = null,
notgametype = "",
notmd5 = null,
notromname = null,
notromtype = null,
@@ -540,6 +542,10 @@ namespace SabreTools
case "--game-name":
gamename = args[++i];
break;
case "-gt":
case "--game-type":
gametype = args[++i];
break;
case "-gz":
case "--gz":
if (!Int32.TryParse(args[++i], out gz))
@@ -579,6 +585,10 @@ namespace SabreTools
case "--not-game":
notgamename = args[++i];
break;
case "-ngt":
case "--not-gtype":
notgametype = args[++i];
break;
case "-nis":
case "--not-status":
notstatus = args[++i];
@@ -765,6 +775,10 @@ namespace SabreTools
case "--game-name":
gamename = split[1];
break;
case "-gt":
case "--game-type":
gametype = split[1];
break;
case "-gz":
case "--gz":
if (!Int32.TryParse(split[1], out gz))
@@ -804,6 +818,10 @@ namespace SabreTools
case "--not-game":
notgamename = split[1];
break;
case "-ngt":
case "--not-gtype":
notgametype = split[1];
break;
case "-nis":
case "--not-status":
notstatus = split[1];
@@ -1038,8 +1056,8 @@ namespace SabreTools
InitUpdate(inputs, filename, name, description, rootdir, category, version, date, author, email, homepage, url, comment, header,
superdat, forcemerge, forcend, forcepack, excludeOf, datFormat, usegame, prefix,
postfix, quotes, repext, addext, remext, datPrefix, romba, merge, diffMode, inplace, skip, removeDateFromAutomaticName,
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, status,
notgamename, notromname, notromtype, notcrc, notmd5, notsha1, notstatus,
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, status, gametype,
notgamename, notromname, notromtype, notcrc, notmd5, notsha1, notstatus, notgametype,
trim, single, root, outDir, cleanGameNames, softlist, dedup, maxParallelism);
}