From c3d6f1d6b86e17c2edf5a3ee0e3e150887d08a5d Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 11 Jun 2016 15:07:53 -0700 Subject: [PATCH] [DATabase, RomManipulation] Wrap Filter into Update --- DATabase/DATabase.cs | 13 +- DATabase/DATabase.csproj | 1 - DATabase/Filter.cs | 232 ----------------------- DATabase/Partials/DATabase_Inits.cs | 153 ++++----------- SabreHelper/DatTools/RomManipulation.cs | 237 ++++++++++++++++++++++++ 5 files changed, 274 insertions(+), 362 deletions(-) delete mode 100644 DATabase/Filter.cs diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index 3da53bd1..a309d31b 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -586,14 +586,15 @@ namespace SabreTools ListSystems(); } - // Convert or update a DAT or folder of DATs - else if (update || outputCMP || outputMiss || outputRC || outputSD || outputXML || romba) + // Convert, update, and filter a DAT or folder of DATs + else if (update || outputCMP || outputMiss || outputRC || outputSD || outputXML || romba || filter) { foreach (string input in inputs) { InitUpdate(input, filename, name, description, category, version, date, author, email, homepage, url, comment, header, superdat, forcemerge, forcend, forcepack, outputCMP, outputMiss, outputRC, outputSD, outputXML, usegame, prefix, - postfix, quotes, repext, addext, datprefix, romba, tsv, outdir, clean, dedup); + postfix, quotes, repext, addext, datprefix, romba, tsv, gamename, romname, romtype, sgt, slt, seq, crc, md5, + sha1, nodump, outdir, clean, dedup); } } @@ -664,12 +665,6 @@ namespace SabreTools InitStats(inputs, single); } - // Filter input files - else if (filter) - { - InitFilter(inputs, outdir, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger); - } - // If nothing is set, show the help else { diff --git a/DATabase/DATabase.csproj b/DATabase/DATabase.csproj index 807c81ea..359275e6 100644 --- a/DATabase/DATabase.csproj +++ b/DATabase/DATabase.csproj @@ -105,7 +105,6 @@ - diff --git a/DATabase/Filter.cs b/DATabase/Filter.cs deleted file mode 100644 index d10dc5e0..00000000 --- a/DATabase/Filter.cs +++ /dev/null @@ -1,232 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -using SabreTools.Helper; - -namespace SabreTools -{ - public class Filter - { - // Private instance variables - private string _filename; - private string _outdir; - private string _gamename; - private string _romname; - private string _romtype; - private long _sgt; - private long _slt; - private long _seq; - private string _crc; - private string _md5; - private string _sha1; - private bool? _nodump; - private Logger _logger; - - /// - /// Create a Filter object - /// - /// Name of the file to be parsed - /// Output directory to write the file to - /// Name of the game to match (can use asterisk-partials) - /// Name of the rom to match (can use asterisk-partials) - /// Type of the rom to match - /// Find roms greater than or equal to this size - /// Find roms less than or equal to this size - /// Find roms equal to this size - /// CRC of the rom to match (can use asterisk-partials) - /// MD5 of the rom to match (can use asterisk-partials) - /// SHA-1 of the rom to match (can use asterisk-partials) - /// Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump) - /// Logging object for file and console output - public Filter(string filename, string outdir, string gamename, string romname, string romtype, - long sgt, long slt, long seq, string crc, string md5, string sha1, bool? nodump, Logger logger) - { - _filename = filename; - _outdir = (outdir == "" ? Path.GetDirectoryName(_filename) : outdir); - _gamename = gamename; - _romname = romname; - _romtype = romtype; - _sgt = sgt; - _slt = slt; - _seq = seq; - _crc = crc; - _md5 = md5; - _sha1 = sha1; - _nodump = nodump; - _logger = logger; - } - - /// - /// Process an individual DAT with the given information - /// - /// True if the DAT was output, false otherwise - public bool Process() - { - _logger.User("Processing file: '" + _filename + "'"); - - // Populated the DAT information - DatData datdata = new DatData(); - datdata = RomManipulation.Parse(_filename, 0, 0, datdata, _logger); - - // Now loop through and create a new Rom dictionary using filtered values - Dictionary> dict = new Dictionary>(); - List keys = datdata.Roms.Keys.ToList(); - foreach (string key in keys) - { - List roms = datdata.Roms[key]; - foreach (RomData rom in roms) - { - // Filter on nodump status - if (_nodump == true && !rom.Nodump) - { - continue; - } - if (_nodump == false && rom.Nodump) - { - continue; - } - - // Filter on game name - if (_gamename != "") - { - if (_gamename.StartsWith("*") && _gamename.EndsWith("*") && !rom.Game.ToLowerInvariant().Contains(_gamename.ToLowerInvariant().Replace("*", ""))) - { - continue; - } - else if (_gamename.StartsWith("*") && !rom.Game.EndsWith(_gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - else if (_gamename.EndsWith("*") && !rom.Game.StartsWith(_gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - } - - // Filter on rom name - if (_romname != "") - { - if (_romname.StartsWith("*") && _romname.EndsWith("*") && !rom.Name.ToLowerInvariant().Contains(_romname.ToLowerInvariant().Replace("*", ""))) - { - continue; - } - else if (_romname.StartsWith("*") && !rom.Name.EndsWith(_romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - else if (_romname.EndsWith("*") && !rom.Name.StartsWith(_romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - } - - // Filter on rom type - if (_romtype != "" && rom.Type.ToLowerInvariant() != _romtype.ToLowerInvariant()) - { - continue; - } - - // Filter on rom size - if (_seq != -1 && rom.Size != _seq) - { - continue; - } - else - { - if (_sgt != -1 && rom.Size < _sgt) - { - continue; - } - if (_slt != -1 && rom.Size > _slt) - { - continue; - } - } - - // Filter on crc - if (_crc != "") - { - if (_crc.StartsWith("*") && _crc.EndsWith("*") && !rom.CRC.ToLowerInvariant().Contains(_crc.ToLowerInvariant().Replace("*", ""))) - { - continue; - } - else if (_crc.StartsWith("*") && !rom.CRC.EndsWith(_crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - else if (_crc.EndsWith("*") && !rom.CRC.StartsWith(_crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - } - - // Filter on md5 - if (_md5 != "") - { - if (_md5.StartsWith("*") && _md5.EndsWith("*") && !rom.MD5.ToLowerInvariant().Contains(_md5.ToLowerInvariant().Replace("*", ""))) - { - continue; - } - else if (_md5.StartsWith("*") && !rom.MD5.EndsWith(_md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - else if (_md5.EndsWith("*") && !rom.MD5.StartsWith(_md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - } - - // Filter on sha1 - if (_sha1 != "") - { - if (_sha1.StartsWith("*") && _sha1.EndsWith("*") && !rom.SHA1.ToLowerInvariant().Contains(_sha1.ToLowerInvariant().Replace("*", ""))) - { - continue; - } - else if (_sha1.StartsWith("*") && !rom.SHA1.EndsWith(_sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - else if (_sha1.EndsWith("*") && !rom.SHA1.StartsWith(_sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) - { - continue; - } - } - - // If it made it this far, add the rom to the output dictionary - if (dict.ContainsKey(key)) - { - dict[key].Add(rom); - } - else - { - List temp = new List(); - temp.Add(rom); - dict.Add(key, temp); - } - } - - // Now clean up by removing the old list - datdata.Roms[key] = null; - } - - // Get the correct output values - datdata.FileName = Path.GetFileNameWithoutExtension(datdata.FileName) + " (Filtered)" + Path.GetExtension(datdata.FileName); - datdata.Name += " (Filtered)"; - datdata.Description += " (Filtered)"; - datdata.Roms = dict; - - // Now write the file out if anything is there and return - if (datdata.Roms.Count > 0) - { - return Output.WriteDatfile(datdata, _outdir, _logger); - } - - // Otherwise, we return true because we did all we could - return true; - } - } -} diff --git a/DATabase/Partials/DATabase_Inits.cs b/DATabase/Partials/DATabase_Inits.cs index fbf74631..ec3273d0 100644 --- a/DATabase/Partials/DATabase_Inits.cs +++ b/DATabase/Partials/DATabase_Inits.cs @@ -106,10 +106,21 @@ namespace SabreTools /// Add the dat name as a directory prefix /// Output files in romba format /// Output files in TSV format + /// Name of the game to match (can use asterisk-partials) + /// Name of the rom to match (can use asterisk-partials) + /// Type of the rom to match + /// Find roms greater than or equal to this size + /// Find roms less than or equal to this size + /// Find roms equal to this size + /// CRC of the rom to match (can use asterisk-partials) + /// MD5 of the rom to match (can use asterisk-partials) + /// SHA-1 of the rom to match (can use asterisk-partials) + /// Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump) /// Optional param for output directory /// True to clean the game names to WoD standard, false otherwise (default) /// True to dedupe the roms in the DAT, false otherwise (default) private static void InitUpdate(string input, + /* Normal DAT header info */ string filename, string name, string description, @@ -131,6 +142,8 @@ namespace SabreTools bool outputRC, bool outputSD, bool outputXML, + + /* Missfile-specific DAT info */ bool usegame, string prefix, string postfix, @@ -140,6 +153,20 @@ namespace SabreTools bool datprefix, bool romba, bool tsv, + + /* Filtering info */ + string gamename, + string romname, + string romtype, + long sgt, + long slt, + long seq, + string crc, + string md5, + string sha1, + bool? nodump, + + /* Output DAT info */ string outdir, bool clean, bool dedup) @@ -232,93 +259,34 @@ namespace SabreTools if (outputCMP) { userInputDat.OutputFormat = OutputFormat.ClrMamePro; - InitUpdate(input, userInputDat, outdir, clean); + RomManipulation.Update(input, userInputDat, outdir, clean, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger); } if (outputMiss || romba) { userInputDat.OutputFormat = OutputFormat.MissFile; - InitUpdate(input, userInputDat, outdir, clean); + RomManipulation.Update(input, userInputDat, outdir, clean, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger); } if (outputRC) { userInputDat.OutputFormat = OutputFormat.RomCenter; - InitUpdate(input, userInputDat, outdir, clean); + RomManipulation.Update(input, userInputDat, outdir, clean, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger); } if (outputSD) { userInputDat.OutputFormat = OutputFormat.SabreDat; - InitUpdate(input, userInputDat, outdir, clean); + RomManipulation.Update(input, userInputDat, outdir, clean, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger); } if (outputXML) { userInputDat.OutputFormat = OutputFormat.Xml; - InitUpdate(input, userInputDat, outdir, clean); + RomManipulation.Update(input, userInputDat, outdir, clean, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger); } if (!outputCMP && !(outputMiss || romba) && !outputRC && !outputSD && !outputXML) { - InitUpdate(input, userInputDat, outdir, clean); + RomManipulation.Update(input, userInputDat, outdir, clean, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger); } } - /// - /// Wrap converting and updating DAT file from any format to any format - /// - /// Name of the input file or folder - /// User specified inputs contained in a DatData object - /// Optional param for output directory - /// True to clean the game names to WoD standard, false otherwise (default) - private static void InitUpdate(string inputFileName, DatData datdata, string outputDirectory, bool clean = false) - { - // Clean the input strings - outputDirectory = outputDirectory.Replace("\"", ""); - if (outputDirectory != "") - { - outputDirectory = Path.GetFullPath(outputDirectory) + Path.DirectorySeparatorChar; - } - inputFileName = inputFileName.Replace("\"", ""); - - if (File.Exists(inputFileName)) - { - _logger.User("Converting \"" + Path.GetFileName(inputFileName) + "\""); - datdata = RomManipulation.Parse(inputFileName, 0, 0, datdata, _logger, true, clean); - - // If the extension matches, append ".new" to the filename - string extension = (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); - if (outputDirectory == "" && Path.GetExtension(inputFileName) == extension) - { - datdata.FileName += ".new"; - } - - Output.WriteDatfile(datdata, (outputDirectory == "" ? Path.GetDirectoryName(inputFileName) : outputDirectory), _logger); - } - else if (Directory.Exists(inputFileName)) - { - inputFileName = Path.GetFullPath(inputFileName) + Path.DirectorySeparatorChar; - - foreach (string file in Directory.EnumerateFiles(inputFileName, "*", SearchOption.AllDirectories)) - { - _logger.User("Converting \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\""); - DatData innerDatdata = (DatData)datdata.Clone(); - innerDatdata.Roms = null; - innerDatdata = RomManipulation.Parse(file, 0, 0, innerDatdata, _logger, true, clean); - - // If the extension matches, append ".new" to the filename - string extension = (innerDatdata.OutputFormat == OutputFormat.Xml || innerDatdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); - if (outputDirectory == "" && Path.GetExtension(file) == extension) - { - innerDatdata.FileName += ".new"; - } - - Output.WriteDatfile(innerDatdata, (outputDirectory == "" ? Path.GetDirectoryName(file) : outputDirectory + Path.GetDirectoryName(file).Remove(0, inputFileName.Length - 1)), _logger); - } - } - else - { - _logger.Error("I'm sorry but " + inputFileName + " doesn't exist!"); - } - return; - } - /// /// Wrap trimming and merging a single DAT /// @@ -497,61 +465,6 @@ namespace SabreTools statlog.Close(); } - /// - /// Wrap filtering a DAT or set of DATs - /// - /// List of inputs to be procesed - /// Output directory for new files (optional) - /// Name of the game to match (can use asterisk-partials) - /// Name of the rom to match (can use asterisk-partials) - /// Type of the rom to match - /// Find roms greater than or equal to this size - /// Find roms less than or equal to this size - /// Find roms equal to this size - /// CRC of the rom to match (can use asterisk-partials) - /// MD5 of the rom to match (can use asterisk-partials) - /// SHA-1 of the rom to match (can use asterisk-partials) - /// Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump) - /// Logging object for file and console output - private static void InitFilter(List inputs, string outdir, string gamename, string romname, string romtype, long sgt, - long slt, long seq, string crc, string md5, string sha1, bool? nodump, Logger logger) - { - // Create new Filter objects for each input - Filter filter; - bool success = true; - foreach (string input in inputs) - { - string newinput = Path.GetFullPath(input.Replace("\"", "")); - - if (File.Exists(newinput)) - { - filter = new Filter(newinput, outdir, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger); - success &= filter.Process(); - } - - if (Directory.Exists(newinput)) - { - foreach (string file in Directory.EnumerateFiles(newinput, "*", SearchOption.AllDirectories)) - { - string nestedoutdir = ""; - if (outdir != "") - { - nestedoutdir = outdir + Path.GetDirectoryName(file).Remove(0, newinput.Length); - } - filter = new Filter(file, nestedoutdir, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger); - success &= filter.Process(); - } - } - } - - // If we failed, show the help - if (!success) - { - Console.WriteLine(); - Build.Help(); - } - } - /// /// Wrap adding a new source to the database /// diff --git a/SabreHelper/DatTools/RomManipulation.cs b/SabreHelper/DatTools/RomManipulation.cs index 105b9834..1eb77479 100644 --- a/SabreHelper/DatTools/RomManipulation.cs +++ b/SabreHelper/DatTools/RomManipulation.cs @@ -1687,5 +1687,242 @@ namespace SabreTools.Helper outgame = outgame.TrimStart().TrimEnd(); return outgame; } + + /// + /// Convert, update, and filter a DAT file + /// + /// Name of the input file or folder + /// User specified inputs contained in a DatData object + /// Optional param for output directory + /// True to clean the game names to WoD standard, false otherwise (default) + /// Name of the game to match (can use asterisk-partials) + /// Name of the rom to match (can use asterisk-partials) + /// Type of the rom to match + /// Find roms greater than or equal to this size + /// Find roms less than or equal to this size + /// Find roms equal to this size + /// CRC of the rom to match (can use asterisk-partials) + /// MD5 of the rom to match (can use asterisk-partials) + /// SHA-1 of the rom to match (can use asterisk-partials) + /// Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump) + /// Logging object for console and file output + public static void Update(string inputFileName, DatData datdata, string outputDirectory, bool clean, string gamename, string romname, + string romtype, long sgt, long slt, long seq, string crc, string md5, string sha1, bool? nodump, Logger logger) + { + // Clean the input strings + outputDirectory = outputDirectory.Replace("\"", ""); + if (outputDirectory != "") + { + outputDirectory = Path.GetFullPath(outputDirectory) + Path.DirectorySeparatorChar; + } + inputFileName = inputFileName.Replace("\"", ""); + + if (File.Exists(inputFileName)) + { + logger.User("Processing \"" + Path.GetFileName(inputFileName) + "\""); + datdata = RomManipulation.Parse(inputFileName, 0, 0, datdata, logger, true, clean); + datdata = Filter(datdata, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger); + + // If the extension matches, append ".new" to the filename + string extension = (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); + if (outputDirectory == "" && Path.GetExtension(inputFileName) == extension) + { + datdata.FileName += ".new"; + } + + Output.WriteDatfile(datdata, (outputDirectory == "" ? Path.GetDirectoryName(inputFileName) : outputDirectory), logger); + } + else if (Directory.Exists(inputFileName)) + { + inputFileName = Path.GetFullPath(inputFileName) + Path.DirectorySeparatorChar; + + foreach (string file in Directory.EnumerateFiles(inputFileName, "*", SearchOption.AllDirectories)) + { + logger.User("Processing \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\""); + DatData innerDatdata = (DatData)datdata.Clone(); + innerDatdata.Roms = null; + innerDatdata = RomManipulation.Parse(file, 0, 0, innerDatdata, logger, true, clean); + innerDatdata = Filter(innerDatdata, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger); + + // If the extension matches, append ".new" to the filename + string extension = (innerDatdata.OutputFormat == OutputFormat.Xml || innerDatdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); + if (outputDirectory == "" && Path.GetExtension(file) == extension) + { + innerDatdata.FileName += ".new"; + } + + Output.WriteDatfile(innerDatdata, (outputDirectory == "" ? Path.GetDirectoryName(file) : outputDirectory + Path.GetDirectoryName(file).Remove(0, inputFileName.Length - 1)), logger); + } + } + else + { + logger.Error("I'm sorry but " + inputFileName + " doesn't exist!"); + } + return; + } + + /// + /// Filter an input DAT file + /// + /// User specified inputs contained in a DatData object + /// Name of the game to match (can use asterisk-partials) + /// Name of the rom to match (can use asterisk-partials) + /// Type of the rom to match + /// Find roms greater than or equal to this size + /// Find roms less than or equal to this size + /// Find roms equal to this size + /// CRC of the rom to match (can use asterisk-partials) + /// MD5 of the rom to match (can use asterisk-partials) + /// SHA-1 of the rom to match (can use asterisk-partials) + /// Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump) + /// Logging object for console and file output + /// Returns filtered DatData object + public static DatData Filter(DatData datdata, string gamename, string romname, string romtype, long sgt, long slt, long seq, string crc, string md5, string sha1, bool? nodump, Logger logger) + { + // Now loop through and create a new Rom dictionary using filtered values + Dictionary> dict = new Dictionary>(); + List keys = datdata.Roms.Keys.ToList(); + foreach (string key in keys) + { + List roms = datdata.Roms[key]; + foreach (RomData rom in roms) + { + // Filter on nodump status + if (nodump == true && !rom.Nodump) + { + continue; + } + if (nodump == false && rom.Nodump) + { + continue; + } + + // Filter on game name + if (gamename != "") + { + if (gamename.StartsWith("*") && gamename.EndsWith("*") && !rom.Game.ToLowerInvariant().Contains(gamename.ToLowerInvariant().Replace("*", ""))) + { + continue; + } + else if (gamename.StartsWith("*") && !rom.Game.EndsWith(gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + continue; + } + else if (gamename.EndsWith("*") && !rom.Game.StartsWith(gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + continue; + } + } + + // Filter on rom name + if (romname != "") + { + if (romname.StartsWith("*") && romname.EndsWith("*") && !rom.Name.ToLowerInvariant().Contains(romname.ToLowerInvariant().Replace("*", ""))) + { + continue; + } + else if (romname.StartsWith("*") && !rom.Name.EndsWith(romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + continue; + } + else if (romname.EndsWith("*") && !rom.Name.StartsWith(romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + continue; + } + } + + // Filter on rom type + if (romtype != "" && rom.Type.ToLowerInvariant() != romtype.ToLowerInvariant()) + { + continue; + } + + // Filter on rom size + if (seq != -1 && rom.Size != seq) + { + continue; + } + else + { + if (sgt != -1 && rom.Size < sgt) + { + continue; + } + if (slt != -1 && rom.Size > slt) + { + continue; + } + } + + // Filter on crc + if (crc != "") + { + if (crc.StartsWith("*") && crc.EndsWith("*") && !rom.CRC.ToLowerInvariant().Contains(crc.ToLowerInvariant().Replace("*", ""))) + { + continue; + } + else if (crc.StartsWith("*") && !rom.CRC.EndsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + continue; + } + else if (crc.EndsWith("*") && !rom.CRC.StartsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + continue; + } + } + + // Filter on md5 + if (md5 != "") + { + if (md5.StartsWith("*") && md5.EndsWith("*") && !rom.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", ""))) + { + continue; + } + else if (md5.StartsWith("*") && !rom.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + continue; + } + else if (md5.EndsWith("*") && !rom.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + continue; + } + } + + // Filter on sha1 + if (sha1 != "") + { + if (sha1.StartsWith("*") && sha1.EndsWith("*") && !rom.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", ""))) + { + continue; + } + else if (sha1.StartsWith("*") && !rom.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + continue; + } + else if (sha1.EndsWith("*") && !rom.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)) + { + continue; + } + } + + // If it made it this far, add the rom to the output dictionary + if (dict.ContainsKey(key)) + { + dict[key].Add(rom); + } + else + { + List temp = new List(); + temp.Add(rom); + dict.Add(key, temp); + } + } + + // Now clean up by removing the old list + datdata.Roms[key] = null; + } + + return datdata; + } } }