diff --git a/.gitignore b/.gitignore index c70037b5..2be996f7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,9 +8,6 @@ /Deheader/obj /Deheader/obj/Debug /Deheader/obj/Release -/Filter/obj -/Filter/obj/Debug -/Filter/obj/Release /OfflineMerge/obj /OfflineMerge/obj/Debug /OfflineMerge/obj/Release diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index 67c1c047..b4fe4bf0 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -85,11 +85,12 @@ namespace SabreTools bare = false, cascade = false, clean = false, + datprefix = false, dedup = false, diff = false, - gamename = false, disableForce = false, extsplit = false, + filter = false, forceunpack = false, generate = false, genall = false, @@ -118,10 +119,15 @@ namespace SabreTools skip = false, update = false, usegame = true; + bool? nodump = null; + long sgt = -1, + slt = -1, + seq = -1; string addext = "", author = "", category = "", comment = "", + crc = "", date = "", description = "", email = "", @@ -131,14 +137,19 @@ namespace SabreTools forcemerge = "", forcend = "", forcepack = "", + gamename = "", header = "", homepage = "", name = "", manu = "", + md5 = "", outdir = "", postfix = "", prefix = "", repext = "", + romname = "", + romtype = "", + sha1 = "", sources = "", systems = "", root = "", @@ -208,6 +219,10 @@ namespace SabreTools case "--ext-split": extsplit = true; break; + case "-f": + case "--filter": + filter = true; + break; case "-g": case "--generate": generate = true; @@ -218,7 +233,7 @@ namespace SabreTools break; case "-gp": case "--game-prefix": - gamename = true; + datprefix = true; break; case "-hs": case "--hash-split": @@ -248,6 +263,14 @@ namespace SabreTools case "--merge": merge = true; break; + case "-nd": + case "--nodump": + nodump = true; + break; + case "-nnd": + case "--not-nodump": + nodump = false; + break; case "-nr": case "--no-rename": norename = true; @@ -340,6 +363,10 @@ namespace SabreTools { comment = arg.Split('=')[1]; } + else if (arg.StartsWith("-crc=") || arg.StartsWith("--crc=")) + { + crc = arg.Split('=')[1]; + } else if (arg.StartsWith("-da=") || arg.StartsWith("--date=")) { date = arg.Split('=')[1]; @@ -376,6 +403,10 @@ namespace SabreTools { forcepack = arg.Split('=')[1]; } + else if (arg.StartsWith("-gn=") || arg.StartsWith("--game-name=")) + { + gamename = arg.Split('=')[1]; + } else if (arg.StartsWith("-h=") || arg.StartsWith("--header=")) { header = arg.Split('=')[1]; @@ -392,6 +423,10 @@ namespace SabreTools { manu = arg.Split('=')[1]; } + else if (arg.StartsWith("-md5=") || arg.StartsWith("--md5=")) + { + md5 = arg.Split('=')[1]; + } else if (arg.StartsWith("-n=") || arg.StartsWith("--name=")) { name = arg.Split('=')[1]; @@ -408,6 +443,39 @@ namespace SabreTools { prefix = arg.Split('=')[1]; } + else if (arg.StartsWith("-rn=") || arg.StartsWith("--rom-name=")) + { + romname = arg.Split('=')[1]; + } + else if (arg.StartsWith("-rt=") || arg.StartsWith("--rom-type=")) + { + romtype = arg.Split('=')[1]; + } + else if (arg.StartsWith("-seq=") || arg.StartsWith("--equal=")) + { + if (!Int64.TryParse(arg.Split('=')[1], out seq)) + { + seq = -1; + } + } + else if (arg.StartsWith("-sgt=") || arg.StartsWith("--greater=")) + { + if (!Int64.TryParse(arg.Split('=')[1], out sgt)) + { + sgt = -1; + } + } + else if (arg.StartsWith("-sha1=") || arg.StartsWith("--sha1=")) + { + sha1 = arg.Split('=')[1]; + } + else if (arg.StartsWith("-slt=") || arg.StartsWith("--less=")) + { + if (!Int64.TryParse(arg.Split('=')[1], out slt)) + { + slt = -1; + } + } else if (arg.StartsWith("-source=") && sources == "") { sources = arg.Split('=')[1]; @@ -467,7 +535,7 @@ namespace SabreTools } // If more than one switch is enabled, show the help screen - if (!(add ^ extsplit ^ generate ^ genall ^ hashsplit ^ import ^ listsrc ^ listsys ^ (merge || diff) ^ + if (!(add ^ extsplit ^ filter ^ generate ^ genall ^ hashsplit ^ import ^ listsrc ^ listsys ^ (merge || diff) ^ (update || outputCMP || outputRC || outputSD || outputXML || outputMiss || romba) ^ rem ^ stats ^ trim)) { _logger.Error("Only one feature switch is allowed at a time"); @@ -478,7 +546,7 @@ namespace SabreTools // If a switch that requires a filename is set and no file is, show the help screen if (inputs.Count == 0 && (update || (outputMiss || romba) || outputCMP || outputRC || outputSD - || outputXML || extsplit || hashsplit || (merge || diff) || stats || trim)) + || outputXML || filter || extsplit || hashsplit || (merge || diff) || stats || trim)) { _logger.Error("This feature requires at least one input"); Build.Help(); @@ -527,7 +595,7 @@ namespace SabreTools { 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, gamename, romba, tsv, outdir, clean); + postfix, quotes, repext, addext, datprefix, romba, tsv, outdir, clean); } } @@ -601,6 +669,12 @@ 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 9377fe89..d794fb24 100644 --- a/DATabase/DATabase.csproj +++ b/DATabase/DATabase.csproj @@ -105,6 +105,7 @@ + diff --git a/Filter/Filter.cs b/DATabase/Filter.cs similarity index 100% rename from Filter/Filter.cs rename to DATabase/Filter.cs diff --git a/DATabase/Partials/DATabase_Inits.cs b/DATabase/Partials/DATabase_Inits.cs index 10d9ce1c..eaea09a0 100644 --- a/DATabase/Partials/DATabase_Inits.cs +++ b/DATabase/Partials/DATabase_Inits.cs @@ -102,7 +102,7 @@ namespace SabreTools /// Add quotes to each item /// Replace all extensions with another /// Add an extension to all items - /// Add the dat name as a directory prefix + /// Add the dat name as a directory prefix /// Output files in romba format /// Output files in TSV format /// Optional param for output directory @@ -135,7 +135,7 @@ namespace SabreTools bool quotes, string repext, string addext, - bool gamename, + bool datprefix, bool romba, bool tsv, string outdir, @@ -221,7 +221,7 @@ namespace SabreTools Quotes = quotes, RepExt = repext, AddExt = addext, - GameName = gamename, + GameName = datprefix, Romba = romba, TSV = tsv, }; @@ -491,6 +491,61 @@ 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/Filter/App.config b/Filter/App.config deleted file mode 100644 index 88fa4027..00000000 --- a/Filter/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Filter/Filter.csproj b/Filter/Filter.csproj deleted file mode 100644 index 97cbbed3..00000000 --- a/Filter/Filter.csproj +++ /dev/null @@ -1,86 +0,0 @@ - - - - - Debug - AnyCPU - {136AA0D0-9234-4680-B593-A32C0762972E} - Exe - Properties - SabreTools - Filter - v4.5.2 - 512 - true - - - AnyCPU - true - full - false - ..\..\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - ..\..\Release\ - TRACE - prompt - 4 - - - true - ..\..\Debug-x64\ - DEBUG;TRACE - full - x64 - prompt - MinimumRecommendedRules.ruleset - true - - - ..\..\Release-x64\ - TRACE - true - pdbonly - x64 - prompt - MinimumRecommendedRules.ruleset - true - - - - - - - - - - - - - - - - - - - - - {225a1afd-0890-44e8-b779-7502665c23a5} - SabreHelper - - - - - \ No newline at end of file diff --git a/Filter/Properties/AssemblyInfo.cs b/Filter/Properties/AssemblyInfo.cs deleted file mode 100644 index 587dba49..00000000 --- a/Filter/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Filter")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Filter")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("136aa0d0-9234-4680-b593-a32c0762972e")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SabreTools.sln b/SabreTools.sln index 635c559d..46bc1c2a 100644 --- a/SabreTools.sln +++ b/SabreTools.sln @@ -15,8 +15,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DATFromDir", "DATFromDir\DA EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OfflineMerge", "OfflineMerge\OfflineMerge.csproj", "{88310DB9-3B64-4268-AD48-2E0358D4CA5F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Filter", "Filter\Filter.csproj", "{136AA0D0-9234-4680-B593-A32C0762972E}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -70,14 +68,6 @@ Global {88310DB9-3B64-4268-AD48-2E0358D4CA5F}.Release|Any CPU.Build.0 = Release|Any CPU {88310DB9-3B64-4268-AD48-2E0358D4CA5F}.Release|x64.ActiveCfg = Release|x64 {88310DB9-3B64-4268-AD48-2E0358D4CA5F}.Release|x64.Build.0 = Release|x64 - {136AA0D0-9234-4680-B593-A32C0762972E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {136AA0D0-9234-4680-B593-A32C0762972E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {136AA0D0-9234-4680-B593-A32C0762972E}.Debug|x64.ActiveCfg = Debug|x64 - {136AA0D0-9234-4680-B593-A32C0762972E}.Debug|x64.Build.0 = Debug|x64 - {136AA0D0-9234-4680-B593-A32C0762972E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {136AA0D0-9234-4680-B593-A32C0762972E}.Release|Any CPU.Build.0 = Release|Any CPU - {136AA0D0-9234-4680-B593-A32C0762972E}.Release|x64.ActiveCfg = Release|Any CPU - {136AA0D0-9234-4680-B593-A32C0762972E}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE