mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatItem, Filter] Abstract out Filter again
This commit is contained in:
@@ -792,24 +792,14 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="bare">True if the date should not be appended to the default name, false otherwise [OBSOLETE]</param>
|
||||
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
||||
/// <param name="softlist">True to allow SL DATs to have game names used instead of descriptions, false otherwise (default)</param>
|
||||
/// <param name="gamename">Name of the game to match (can use asterisk-partials)</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="romtype">Type of the rom to match</param>
|
||||
/// <param name="sgt">Find roms greater than or equal to this size</param>
|
||||
/// <param name="slt">Find roms less than or equal to this size</param>
|
||||
/// <param name="seq">Find roms equal to this size</param>
|
||||
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <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="filter">Filter object to be passed to the DatItem level</param>
|
||||
/// <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>
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
||||
/// <param name="logger">Logging object for console and file output</param>
|
||||
public void DetermineUpdateType(List<string> inputFileNames, string outDir, bool merge, DiffMode diff, bool inplace, bool skip,
|
||||
bool bare, bool clean, bool softlist, string gamename, string romname, string romtype, long sgt, long slt, long seq, string crc,
|
||||
string md5, string sha1, ItemStatus itemStatus, bool trim, bool single, string root, int maxDegreeOfParallelism, Logger logger)
|
||||
bool bare, bool clean, bool softlist, Filter filter, bool trim, bool single, string root, int maxDegreeOfParallelism, Logger logger)
|
||||
{
|
||||
// If we're in merging or diffing mode, use the full list of inputs
|
||||
if (merge || diff != 0)
|
||||
@@ -862,8 +852,7 @@ namespace SabreTools.Helper.Dats
|
||||
|
||||
// Create a dictionary of all ROMs from the input DATs
|
||||
List<DatFile> datHeaders = PopulateUserData(newInputFileNames, inplace, clean, softlist,
|
||||
outDir, gamename, romname, romtype, sgt, slt, seq,
|
||||
crc, md5, sha1, itemStatus, trim, single, root, maxDegreeOfParallelism, logger);
|
||||
outDir, filter, trim, single, root, maxDegreeOfParallelism, logger);
|
||||
|
||||
// Modify the Dictionary if necessary and output the results
|
||||
if (diff != 0 && diff < DiffMode.Cascade)
|
||||
@@ -884,8 +873,7 @@ namespace SabreTools.Helper.Dats
|
||||
// Otherwise, loop through all of the inputs individually
|
||||
else
|
||||
{
|
||||
Update(inputFileNames, outDir, clean, softlist, gamename, romname, romtype, sgt, slt, seq,
|
||||
crc, md5, sha1, itemStatus, trim, single, root, maxDegreeOfParallelism, logger);
|
||||
Update(inputFileNames, outDir, clean, softlist, filter, trim, single, root, maxDegreeOfParallelism, logger);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -893,16 +881,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// <summary>
|
||||
/// Populate the user DatData object from the input files
|
||||
/// </summary>
|
||||
/// <param name="gamename">Name of the game to match (can use asterisk-partials)</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="romtype">Type of the rom to match</param>
|
||||
/// <param name="sgt">Find roms greater than or equal to this size</param>
|
||||
/// <param name="slt">Find roms less than or equal to this size</param>
|
||||
/// <param name="seq">Find roms equal to this size</param>
|
||||
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <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="filter">Filter object to be passed to the DatItem level</param>
|
||||
/// <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>
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
@@ -910,8 +889,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="logger">Logging object for console and file output</param>
|
||||
/// <returns>List of DatData objects representing headers</returns>
|
||||
private List<DatFile> PopulateUserData(List<string> inputs, bool inplace, bool clean, bool softlist, string outDir,
|
||||
string gamename, string romname, string romtype, long sgt, long slt, long seq, string crc,
|
||||
string md5, string sha1, ItemStatus itemStatus, bool trim, bool single, string root, int maxDegreeOfParallelism, Logger logger)
|
||||
Filter filter, bool trim, bool single, string root, int maxDegreeOfParallelism, Logger logger)
|
||||
{
|
||||
DatFile[] datHeaders = new DatFile[inputs.Count];
|
||||
DateTime start = DateTime.Now;
|
||||
@@ -931,8 +909,7 @@ namespace SabreTools.Helper.Dats
|
||||
MergeRoms = MergeRoms,
|
||||
};
|
||||
|
||||
datHeaders[i].Parse(input.Split('¬')[0], i, 0, gamename, romname, romtype, sgt, slt, seq,
|
||||
crc, md5, sha1, itemStatus, trim, single, root, logger, true, clean, softlist);
|
||||
datHeaders[i].Parse(input.Split('¬')[0], i, 0, filter, trim, single, root, logger, true, clean, softlist);
|
||||
});
|
||||
|
||||
logger.User("Processing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
|
||||
@@ -1294,24 +1271,14 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="bare">True if the date should not be appended to the default name, false otherwise [OBSOLETE]</param>
|
||||
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
||||
/// <param name="softlist">True to allow SL DATs to have game names used instead of descriptions, false otherwise (default)</param>
|
||||
/// <param name="gamename">Name of the game to match (can use asterisk-partials)</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="romtype">Type of the rom to match</param>
|
||||
/// <param name="sgt">Find roms greater than or equal to this size</param>
|
||||
/// <param name="slt">Find roms less than or equal to this size</param>
|
||||
/// <param name="seq">Find roms equal to this size</param>
|
||||
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <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="filter">Filter object to be passed to the DatItem level</param>
|
||||
/// <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>
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
||||
/// <param name="logger">Logging object for console and file output</param>
|
||||
public void Update(List<string> inputFileNames, string outDir, bool clean, bool softlist, string gamename, string romname,
|
||||
string romtype, long sgt, long slt, long seq, string crc, string md5, string sha1, ItemStatus itemStatus, bool trim,
|
||||
bool single, string root, int maxDegreeOfParallelism, Logger logger)
|
||||
public void Update(List<string> inputFileNames, string outDir, bool clean, bool softlist, Filter filter,
|
||||
bool trim, bool single, string root, int maxDegreeOfParallelism, Logger logger)
|
||||
{
|
||||
Parallel.ForEach(inputFileNames,
|
||||
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
|
||||
@@ -1327,8 +1294,7 @@ namespace SabreTools.Helper.Dats
|
||||
{
|
||||
DatFile innerDatdata = (DatFile)CloneHeader();
|
||||
logger.User("Processing \"" + Path.GetFileName(inputFileName) + "\"");
|
||||
innerDatdata.Parse(inputFileName, 0, 0, gamename, romname,
|
||||
romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single,
|
||||
innerDatdata.Parse(inputFileName, 0, 0, filter, trim, single,
|
||||
root, logger, true, clean, softlist,
|
||||
keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0));
|
||||
|
||||
@@ -1349,7 +1315,7 @@ namespace SabreTools.Helper.Dats
|
||||
logger.User("Processing \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\"");
|
||||
DatFile innerDatdata = (DatFile)Clone();
|
||||
innerDatdata.Files = null;
|
||||
innerDatdata.Parse(file, 0, 0, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus,
|
||||
innerDatdata.Parse(file, 0, 0, filter,
|
||||
trim, single, root, logger, true, clean, softlist,
|
||||
keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0));
|
||||
|
||||
@@ -1385,7 +1351,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="keepext">True if original extension should be kept, false otherwise (default)</param>
|
||||
public void Parse(string filename, int sysid, int srcid, Logger logger, bool keep = false, bool clean = false, bool softlist = false, bool keepext = false)
|
||||
{
|
||||
Parse(filename, sysid, srcid, null, null, null, -1, -1, -1, null, null, null, ItemStatus.NULL, false, false, "", logger, keep, clean, softlist, keepext);
|
||||
Parse(filename, sysid, srcid, new Filter(), false, false, "", logger, keep, clean, softlist, keepext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1394,16 +1360,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="sysid">System ID for the DAT</param>
|
||||
/// <param name="srcid">Source ID for the DAT</param>
|
||||
/// <param name="gamename">Name of the game to match (can use asterisk-partials)</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="romtype">Type of the rom to match</param>
|
||||
/// <param name="sgt">Find roms greater than or equal to this size</param>
|
||||
/// <param name="slt">Find roms less than or equal to this size</param>
|
||||
/// <param name="seq">Find roms equal to this size</param>
|
||||
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <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="filter">Filter object for passing to the DatItem level</param>
|
||||
/// <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>
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
@@ -1419,16 +1376,7 @@ namespace SabreTools.Helper.Dats
|
||||
int srcid,
|
||||
|
||||
// Rom filtering
|
||||
string gamename,
|
||||
string romname,
|
||||
string romtype,
|
||||
long sgt,
|
||||
long slt,
|
||||
long seq,
|
||||
string crc,
|
||||
string md5,
|
||||
string sha1,
|
||||
ItemStatus itemStatus,
|
||||
Filter filter,
|
||||
|
||||
// Rom renaming
|
||||
bool trim,
|
||||
@@ -1470,25 +1418,25 @@ namespace SabreTools.Helper.Dats
|
||||
{
|
||||
case DatFormat.ClrMamePro:
|
||||
case DatFormat.DOSCenter:
|
||||
ParseCMP(filename, sysid, srcid, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, logger, keep, clean);
|
||||
ParseCMP(filename, sysid, srcid, filter, trim, single, root, logger, keep, clean);
|
||||
break;
|
||||
case DatFormat.Logiqx:
|
||||
case DatFormat.OfflineList:
|
||||
case DatFormat.SabreDat:
|
||||
case DatFormat.SoftwareList:
|
||||
ParseGenericXML(filename, sysid, srcid, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, logger, keep, clean, softlist);
|
||||
ParseGenericXML(filename, sysid, srcid, filter, trim, single, root, logger, keep, clean, softlist);
|
||||
break;
|
||||
case DatFormat.RedumpMD5:
|
||||
ParseRedumpMD5(filename, sysid, srcid, romname, md5, trim, single, root, logger, clean);
|
||||
ParseRedumpMD5(filename, sysid, srcid, filter, trim, single, root, logger, clean);
|
||||
break;
|
||||
case DatFormat.RedumpSFV:
|
||||
ParseRedumpSFV(filename, sysid, srcid, romname, crc, trim, single, root, logger, clean);
|
||||
ParseRedumpSFV(filename, sysid, srcid, filter, trim, single, root, logger, clean);
|
||||
break;
|
||||
case DatFormat.RedumpSHA1:
|
||||
ParseRedumpSHA1(filename, sysid, srcid, romname, sha1, trim, single, root, logger, clean);
|
||||
ParseRedumpSHA1(filename, sysid, srcid, filter, trim, single, root, logger, clean);
|
||||
break;
|
||||
case DatFormat.RomCenter:
|
||||
ParseRC(filename, sysid, srcid, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, logger, clean);
|
||||
ParseRC(filename, sysid, srcid, filter, trim, single, root, logger, clean);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
@@ -1501,16 +1449,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="sysid">System ID for the DAT</param>
|
||||
/// <param name="srcid">Source ID for the DAT</param>
|
||||
/// <param name="gamename">Name of the game to match (can use asterisk-partials)</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="romtype">Type of the rom to match</param>
|
||||
/// <param name="sgt">Find roms greater than or equal to this size</param>
|
||||
/// <param name="slt">Find roms less than or equal to this size</param>
|
||||
/// <param name="seq">Find roms equal to this size</param>
|
||||
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <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="filter">Filter object for passing to the DatItem level</param>
|
||||
/// <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>
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
@@ -1524,16 +1463,7 @@ namespace SabreTools.Helper.Dats
|
||||
int srcid,
|
||||
|
||||
// Rom filtering
|
||||
string gamename,
|
||||
string romname,
|
||||
string romtype,
|
||||
long sgt,
|
||||
long slt,
|
||||
long seq,
|
||||
string crc,
|
||||
string md5,
|
||||
string sha1,
|
||||
ItemStatus itemStatus,
|
||||
Filter filter,
|
||||
|
||||
// Rom renaming
|
||||
bool trim,
|
||||
@@ -2047,7 +1977,7 @@ namespace SabreTools.Helper.Dats
|
||||
|
||||
// Now process and add the rom
|
||||
string key = "";
|
||||
ParseAddHelper(item, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(item, filter, trim, single, root, clean, logger, out key);
|
||||
}
|
||||
// If the line is anything but a rom or disk and we're in a block
|
||||
else if (Regex.IsMatch(line, Constants.ItemPatternCMP) && block)
|
||||
@@ -2209,16 +2139,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="sysid">System ID for the DAT</param>
|
||||
/// <param name="srcid">Source ID for the DAT</param>
|
||||
/// <param name="gamename">Name of the game to match (can use asterisk-partials)</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="romtype">Type of the rom to match</param>
|
||||
/// <param name="sgt">Find roms greater than or equal to this size</param>
|
||||
/// <param name="slt">Find roms less than or equal to this size</param>
|
||||
/// <param name="seq">Find roms equal to this size</param>
|
||||
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <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="filter">Filter object for passing to the DatItem level</param>
|
||||
/// <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>
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
@@ -2233,16 +2154,7 @@ namespace SabreTools.Helper.Dats
|
||||
int srcid,
|
||||
|
||||
// Rom filtering
|
||||
string gamename,
|
||||
string romname,
|
||||
string romtype,
|
||||
long sgt,
|
||||
long slt,
|
||||
long seq,
|
||||
string crc,
|
||||
string md5,
|
||||
string sha1,
|
||||
ItemStatus itemStatus,
|
||||
Filter filter,
|
||||
|
||||
// Rom renaming
|
||||
bool trim,
|
||||
@@ -2288,7 +2200,7 @@ namespace SabreTools.Helper.Dats
|
||||
Rom rom = new Rom("null", tempgame);
|
||||
|
||||
// Now process and add the rom
|
||||
ParseAddHelper(rom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(rom, filter, trim, single, root, clean, logger, out key);
|
||||
}
|
||||
|
||||
// Regardless, end the current folder
|
||||
@@ -2790,7 +2702,7 @@ namespace SabreTools.Helper.Dats
|
||||
};
|
||||
|
||||
// Now process and add the rom
|
||||
ParseAddHelper(olrom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(olrom, filter, trim, single, root, clean, logger, out key);
|
||||
break;
|
||||
|
||||
// For Software List only
|
||||
@@ -2872,7 +2784,7 @@ namespace SabreTools.Helper.Dats
|
||||
};
|
||||
|
||||
// Now process and add the rom
|
||||
ParseAddHelper(relrom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(relrom, filter, trim, single, root, clean, logger, out key);
|
||||
|
||||
subreader.Read();
|
||||
break;
|
||||
@@ -2915,7 +2827,7 @@ namespace SabreTools.Helper.Dats
|
||||
};
|
||||
|
||||
// Now process and add the rom
|
||||
ParseAddHelper(biosrom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(biosrom, filter, trim, single, root, clean, logger, out key);
|
||||
|
||||
subreader.Read();
|
||||
break;
|
||||
@@ -2943,7 +2855,7 @@ namespace SabreTools.Helper.Dats
|
||||
};
|
||||
|
||||
// Now process and add the rom
|
||||
ParseAddHelper(archiverom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(archiverom, filter, trim, single, root, clean, logger, out key);
|
||||
|
||||
subreader.Read();
|
||||
break;
|
||||
@@ -2971,7 +2883,7 @@ namespace SabreTools.Helper.Dats
|
||||
};
|
||||
|
||||
// Now process and add the rom
|
||||
ParseAddHelper(samplerom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(samplerom, filter, trim, single, root, clean, logger, out key);
|
||||
|
||||
subreader.Read();
|
||||
break;
|
||||
@@ -3107,7 +3019,7 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
|
||||
// Now process and add the rom
|
||||
ParseAddHelper(inrom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(inrom, filter, trim, single, root, clean, logger, out key);
|
||||
|
||||
subreader.Read();
|
||||
break;
|
||||
@@ -3279,7 +3191,7 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
|
||||
// Now process and add the rom
|
||||
ParseAddHelper(rom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(rom, filter, trim, single, root, clean, logger, out key);
|
||||
|
||||
xtr.Read();
|
||||
break;
|
||||
@@ -3306,8 +3218,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="sysid">System ID for the DAT</param>
|
||||
/// <param name="srcid">Source ID for the DAT</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="md5">MD5 of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="filter">Filter object for passing to the DatItem level</param>
|
||||
/// <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>
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
@@ -3320,8 +3231,7 @@ namespace SabreTools.Helper.Dats
|
||||
int srcid,
|
||||
|
||||
// Rom filtering
|
||||
string romname,
|
||||
string md5,
|
||||
Filter filter,
|
||||
|
||||
// Rom renaming
|
||||
bool trim,
|
||||
@@ -3358,7 +3268,7 @@ namespace SabreTools.Helper.Dats
|
||||
|
||||
// Now process and add the rom
|
||||
string key = "";
|
||||
ParseAddHelper(rom, null, romname, null, -1, -1, -1, null, md5, null, ItemStatus.NULL, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(rom, filter, trim, single, root, clean, logger, out key);
|
||||
}
|
||||
|
||||
sr.Dispose();
|
||||
@@ -3370,8 +3280,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="sysid">System ID for the DAT</param>
|
||||
/// <param name="srcid">Source ID for the DAT</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="filter">Filter object for passing to the DatItem level</param>
|
||||
/// <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>
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
@@ -3384,8 +3293,7 @@ namespace SabreTools.Helper.Dats
|
||||
int srcid,
|
||||
|
||||
// Rom filtering
|
||||
string romname,
|
||||
string crc,
|
||||
Filter filter,
|
||||
|
||||
// Rom renaming
|
||||
bool trim,
|
||||
@@ -3422,7 +3330,7 @@ namespace SabreTools.Helper.Dats
|
||||
|
||||
// Now process and add the rom
|
||||
string key = "";
|
||||
ParseAddHelper(rom, null, romname, null, -1, -1, -1, crc, null, null, ItemStatus.NULL, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(rom, filter, trim, single, root, clean, logger, out key);
|
||||
}
|
||||
|
||||
sr.Dispose();
|
||||
@@ -3434,8 +3342,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="sysid">System ID for the DAT</param>
|
||||
/// <param name="srcid">Source ID for the DAT</param>
|
||||
/// <param name="romname">Name 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="filter">Filter object for passing to the DatItem level</param>
|
||||
/// <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>
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
@@ -3448,8 +3355,7 @@ namespace SabreTools.Helper.Dats
|
||||
int srcid,
|
||||
|
||||
// Rom filtering
|
||||
string romname,
|
||||
string sha1,
|
||||
Filter filter,
|
||||
|
||||
// Rom renaming
|
||||
bool trim,
|
||||
@@ -3486,7 +3392,7 @@ namespace SabreTools.Helper.Dats
|
||||
|
||||
// Now process and add the rom
|
||||
string key = "";
|
||||
ParseAddHelper(rom, null, romname, null, -1, -1, -1, null, null, sha1, ItemStatus.NULL, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(rom, filter, trim, single, root, clean, logger, out key);
|
||||
}
|
||||
|
||||
sr.Dispose();
|
||||
@@ -3498,16 +3404,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="sysid">System ID for the DAT</param>
|
||||
/// <param name="srcid">Source ID for the DAT</param>
|
||||
/// <param name="gamename">Name of the game to match (can use asterisk-partials)</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="romtype">Type of the rom to match</param>
|
||||
/// <param name="sgt">Find roms greater than or equal to this size</param>
|
||||
/// <param name="slt">Find roms less than or equal to this size</param>
|
||||
/// <param name="seq">Find roms equal to this size</param>
|
||||
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <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="filter">Filter object for passing to the DatItem level</param>
|
||||
/// <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>
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
@@ -3520,16 +3417,7 @@ namespace SabreTools.Helper.Dats
|
||||
int srcid,
|
||||
|
||||
// Rom filtering
|
||||
string gamename,
|
||||
string romname,
|
||||
string romtype,
|
||||
long sgt,
|
||||
long slt,
|
||||
long seq,
|
||||
string crc,
|
||||
string md5,
|
||||
string sha1,
|
||||
ItemStatus itemStatus,
|
||||
Filter filter,
|
||||
|
||||
// Rom renaming
|
||||
bool trim,
|
||||
@@ -3680,7 +3568,7 @@ namespace SabreTools.Helper.Dats
|
||||
|
||||
// Now process and add the rom
|
||||
string key = "";
|
||||
ParseAddHelper(rom, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, clean, logger, out key);
|
||||
ParseAddHelper(rom, filter, trim, single, root, clean, logger, out key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3692,22 +3580,12 @@ namespace SabreTools.Helper.Dats
|
||||
/// Add a rom to the Dat after checking
|
||||
/// </summary>
|
||||
/// <param name="item">Item data to check against</param>
|
||||
/// <param name="gamename">Name of the game to match (can use asterisk-partials)</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="romtype">Type of the rom to match</param>
|
||||
/// <param name="sgt">Find roms greater than or equal to this size</param>
|
||||
/// <param name="slt">Find roms less than or equal to this size</param>
|
||||
/// <param name="seq">Find roms equal to this size</param>
|
||||
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <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="filter">Filter object for passing to the DatItem level</param>
|
||||
/// <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>
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
/// <param name="logger">Logger object for console and/or file output</param>
|
||||
private void ParseAddHelper(DatItem item, string gamename, string romname, string romtype, long sgt, long slt,
|
||||
long seq, string crc, string md5, string sha1, ItemStatus itemStatus, bool trim, bool single, string root, bool clean, Logger logger, out string key)
|
||||
private void ParseAddHelper(DatItem item, Filter filter, bool trim, bool single, string root, bool clean, Logger logger, out string key)
|
||||
{
|
||||
key = "";
|
||||
|
||||
@@ -3782,7 +3660,7 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
|
||||
// If the rom passes the filter, include it
|
||||
if (item.Filter(gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, logger))
|
||||
if (filter.ItemPasses(item, logger))
|
||||
{
|
||||
// If we are in single game mode, rename all games
|
||||
if (single)
|
||||
|
||||
@@ -228,321 +228,6 @@ namespace SabreTools.Helper.Dats
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a rom should be included based on filters
|
||||
/// </summary>
|
||||
/// <param name="gamename">Name of the game to match (can use asterisk-partials)</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="romtype">Type of the rom to match</param>
|
||||
/// <param name="sgt">Find roms greater than or equal to this size</param>
|
||||
/// <param name="slt">Find roms less than or equal to this size</param>
|
||||
/// <param name="seq">Find roms equal to this size</param>
|
||||
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <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="logger">Logging object for console and file output</param>
|
||||
/// <returns>Returns true if it should be included, false otherwise</returns>
|
||||
public bool Filter(string gamename, string romname, string romtype, long sgt,
|
||||
long slt, long seq, string crc, string md5, string sha1, ItemStatus itemStatus, Logger logger)
|
||||
{
|
||||
// Take care of Rom and Disk specific differences
|
||||
if (Type == ItemType.Rom)
|
||||
{
|
||||
Rom rom = (Rom)this;
|
||||
|
||||
// Filter on status
|
||||
if (itemStatus != ItemStatus.NULL)
|
||||
{
|
||||
if (itemStatus == ItemStatus.NotNodump && rom.ItemStatus == ItemStatus.Nodump)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (itemStatus != ItemStatus.NotNodump && rom.ItemStatus != itemStatus)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on rom size
|
||||
if (seq != -1 && rom.Size != seq)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sgt != -1 && rom.Size < sgt)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (slt != -1 && rom.Size > slt)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on crc
|
||||
if (!String.IsNullOrEmpty(crc))
|
||||
{
|
||||
if (crc.StartsWith("*") && crc.EndsWith("*"))
|
||||
{
|
||||
if (!rom.CRC.ToLowerInvariant().Contains(crc.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (crc.StartsWith("*"))
|
||||
{
|
||||
if (!rom.CRC.EndsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (crc.EndsWith("*"))
|
||||
{
|
||||
if (!rom.CRC.StartsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.CRC, crc, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on md5
|
||||
if (!String.IsNullOrEmpty(md5))
|
||||
{
|
||||
if (md5.StartsWith("*") && md5.EndsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (md5.StartsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (md5.EndsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.MD5, md5, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on sha1
|
||||
if (!String.IsNullOrEmpty(sha1))
|
||||
{
|
||||
if (sha1.StartsWith("*") && sha1.EndsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (sha1.StartsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (sha1.EndsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.SHA1, sha1, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Type == ItemType.Disk)
|
||||
{
|
||||
Disk rom = (Disk)this;
|
||||
|
||||
// Filter on status
|
||||
if (itemStatus != ItemStatus.NULL && rom.ItemStatus != itemStatus)
|
||||
{
|
||||
if (itemStatus == ItemStatus.NotNodump && rom.ItemStatus == ItemStatus.Nodump)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (itemStatus != ItemStatus.NotNodump && rom.ItemStatus != itemStatus)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on md5
|
||||
if (!String.IsNullOrEmpty(md5))
|
||||
{
|
||||
if (md5.StartsWith("*") && md5.EndsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (md5.StartsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (md5.EndsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.MD5, md5, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on sha1
|
||||
if (!String.IsNullOrEmpty(sha1))
|
||||
{
|
||||
if (sha1.StartsWith("*") && sha1.EndsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (sha1.StartsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (sha1.EndsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.SHA1, sha1, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on game name
|
||||
if (!String.IsNullOrEmpty(gamename))
|
||||
{
|
||||
if (gamename.StartsWith("*") && gamename.EndsWith("*"))
|
||||
{
|
||||
if (!Machine.Name.ToLowerInvariant().Contains(gamename.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (gamename.StartsWith("*"))
|
||||
{
|
||||
if (!Machine.Name.EndsWith(gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (gamename.EndsWith("*"))
|
||||
{
|
||||
if (!Machine.Name.StartsWith(gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(Machine.Name, gamename, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on rom name
|
||||
if (!String.IsNullOrEmpty(romname))
|
||||
{
|
||||
if (romname.StartsWith("*") && romname.EndsWith("*"))
|
||||
{
|
||||
if (!Name.ToLowerInvariant().Contains(romname.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (romname.StartsWith("*"))
|
||||
{
|
||||
if (!Name.EndsWith(romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (romname.EndsWith("*"))
|
||||
{
|
||||
if (!Name.StartsWith(romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(Name, romname, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on rom type
|
||||
if (String.IsNullOrEmpty(romtype) && Type != ItemType.Rom && Type != ItemType.Disk)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(romtype) && !String.Equals(Type.ToString(), romtype, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a DAT contains the given rom
|
||||
/// </summary>
|
||||
|
||||
374
SabreTools.Helper/Dats/Filter.cs
Normal file
374
SabreTools.Helper/Dats/Filter.cs
Normal file
@@ -0,0 +1,374 @@
|
||||
using System;
|
||||
|
||||
using SabreTools.Helper.Data;
|
||||
|
||||
namespace SabreTools.Helper.Dats
|
||||
{
|
||||
public class Filter
|
||||
{
|
||||
#region Private instance variables
|
||||
|
||||
private string _gameName;
|
||||
private string _romName;
|
||||
private string _romType;
|
||||
private long _sizeGreaterThanOrEqual;
|
||||
private long _sizeLessThanOrEqual;
|
||||
private long _sizeEqualTo;
|
||||
private string _crc;
|
||||
private string _md5;
|
||||
private string _sha1;
|
||||
private ItemStatus _itemStatus;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Create an empty Filter object
|
||||
/// </summary>
|
||||
public Filter()
|
||||
{
|
||||
_gameName = null;
|
||||
_romName = null;
|
||||
_romType = null;
|
||||
_sizeGreaterThanOrEqual = -1;
|
||||
_sizeLessThanOrEqual = -1;
|
||||
_sizeEqualTo = -1;
|
||||
_crc = null;
|
||||
_md5 = null;
|
||||
_sha1 = null;
|
||||
_itemStatus = ItemStatus.NULL;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a populated Filter object
|
||||
/// </summary>
|
||||
/// <param name="gamename">Name of the game to match (can use asterisk-partials)</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="romtype">Type of the rom to match</param>
|
||||
/// <param name="sgt">Find roms greater than or equal to this size</param>
|
||||
/// <param name="slt">Find roms less than or equal to this size</param>
|
||||
/// <param name="seq">Find roms equal to this size</param>
|
||||
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <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>
|
||||
public Filter(string gamename, string romname, string romtype, long sgt,
|
||||
long slt, long seq, string crc, string md5, string sha1, ItemStatus itemStatus)
|
||||
{
|
||||
_gameName = gamename;
|
||||
_romName = romname;
|
||||
_romType = romtype;
|
||||
_sizeGreaterThanOrEqual = sgt;
|
||||
_sizeLessThanOrEqual = slt;
|
||||
_sizeEqualTo = seq;
|
||||
_crc = crc;
|
||||
_md5 = md5;
|
||||
_sha1 = sha1;
|
||||
_itemStatus = itemStatus;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check to see if a DatItem passes the filter
|
||||
/// </summary>
|
||||
/// <param name="item">DatItem to check</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
/// <returns>True if the file passed the filter, false otherwise</returns>
|
||||
public bool ItemPasses(DatItem item, Logger logger)
|
||||
{
|
||||
// Take care of Rom and Disk specific differences
|
||||
if (item.Type == ItemType.Rom)
|
||||
{
|
||||
Rom rom = (Rom)item;
|
||||
|
||||
// Filter on status
|
||||
if (_itemStatus != ItemStatus.NULL)
|
||||
{
|
||||
if (_itemStatus == ItemStatus.NotNodump && rom.ItemStatus == ItemStatus.Nodump)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (_itemStatus != ItemStatus.NotNodump && rom.ItemStatus != _itemStatus)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on rom size
|
||||
if (_sizeEqualTo != -1 && rom.Size != _sizeEqualTo)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_sizeGreaterThanOrEqual != -1 && rom.Size < _sizeGreaterThanOrEqual)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_sizeLessThanOrEqual != -1 && rom.Size > _sizeLessThanOrEqual)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on _crc
|
||||
if (!String.IsNullOrEmpty(_crc))
|
||||
{
|
||||
if (_crc.StartsWith("*") && _crc.EndsWith("*"))
|
||||
{
|
||||
if (!rom.CRC.ToLowerInvariant().Contains(_crc.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_crc.StartsWith("*"))
|
||||
{
|
||||
if (!rom.CRC.EndsWith(_crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_crc.EndsWith("*"))
|
||||
{
|
||||
if (!rom.CRC.StartsWith(_crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.CRC, _crc, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on _md5
|
||||
if (!String.IsNullOrEmpty(_md5))
|
||||
{
|
||||
if (_md5.StartsWith("*") && _md5.EndsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.ToLowerInvariant().Contains(_md5.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_md5.StartsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.EndsWith(_md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_md5.EndsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.StartsWith(_md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.MD5, _md5, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on _sha1
|
||||
if (!String.IsNullOrEmpty(_sha1))
|
||||
{
|
||||
if (_sha1.StartsWith("*") && _sha1.EndsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.ToLowerInvariant().Contains(_sha1.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_sha1.StartsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.EndsWith(_sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_sha1.EndsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.StartsWith(_sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.SHA1, _sha1, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (item.Type == ItemType.Disk)
|
||||
{
|
||||
Disk rom = (Disk)item;
|
||||
|
||||
// Filter on status
|
||||
if (_itemStatus != ItemStatus.NULL && rom.ItemStatus != _itemStatus)
|
||||
{
|
||||
if (_itemStatus == ItemStatus.NotNodump && rom.ItemStatus == ItemStatus.Nodump)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (_itemStatus != ItemStatus.NotNodump && rom.ItemStatus != _itemStatus)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on _md5
|
||||
if (!String.IsNullOrEmpty(_md5))
|
||||
{
|
||||
if (_md5.StartsWith("*") && _md5.EndsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.ToLowerInvariant().Contains(_md5.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_md5.StartsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.EndsWith(_md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_md5.EndsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.StartsWith(_md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.MD5, _md5, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on _sha1
|
||||
if (!String.IsNullOrEmpty(_sha1))
|
||||
{
|
||||
if (_sha1.StartsWith("*") && _sha1.EndsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.ToLowerInvariant().Contains(_sha1.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_sha1.StartsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.EndsWith(_sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_sha1.EndsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.StartsWith(_sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.SHA1, _sha1, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on game name
|
||||
if (!String.IsNullOrEmpty(_gameName))
|
||||
{
|
||||
if (_gameName.StartsWith("*") && _gameName.EndsWith("*"))
|
||||
{
|
||||
if (!item.Machine.Name.ToLowerInvariant().Contains(_gameName.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_gameName.StartsWith("*"))
|
||||
{
|
||||
if (!item.Machine.Name.EndsWith(_gameName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_gameName.EndsWith("*"))
|
||||
{
|
||||
if (!item.Machine.Name.StartsWith(_gameName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(item.Machine.Name, _gameName, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on rom name
|
||||
if (!String.IsNullOrEmpty(_romName))
|
||||
{
|
||||
if (_romName.StartsWith("*") && _romName.EndsWith("*"))
|
||||
{
|
||||
if (!item.Name.ToLowerInvariant().Contains(_romName.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_romName.StartsWith("*"))
|
||||
{
|
||||
if (!item.Name.EndsWith(_romName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_romName.EndsWith("*"))
|
||||
{
|
||||
if (!item.Name.StartsWith(_romName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(item.Name, _romName, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on rom type
|
||||
if (String.IsNullOrEmpty(_romType) && item.Type != ItemType.Rom && item.Type != ItemType.Disk)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(_romType) && !String.Equals(item.Type.ToString(), _romType, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Data\Constants.cs" />
|
||||
<Compile Include="Data\Flags.cs" />
|
||||
<Compile Include="Dats\Filter.cs" />
|
||||
<Compile Include="External\NaturalSort\NaturalComparer.cs" />
|
||||
<Compile Include="External\NaturalSort\NaturalReversedComparer.cs" />
|
||||
<Compile Include="External\OptimizedCRC.cs" />
|
||||
|
||||
@@ -640,8 +640,11 @@ namespace SabreTools
|
||||
Romba = romba,
|
||||
};
|
||||
|
||||
// Create the Filter object to be used
|
||||
Filter filter = new Filter(gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus);
|
||||
|
||||
userInputDat.DetermineUpdateType(inputs, outDir, merge, diffMode, inplace, skip, bare, clean, softlist,
|
||||
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, itemStatus, trim, single, root, maxDegreeOfParallelism, _logger);
|
||||
filter, trim, single, root, maxDegreeOfParallelism, _logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user