From c430404f5ad78dbdb7c08c8651f8a14026336950 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 24 May 2016 13:17:21 -0700 Subject: [PATCH] Add output redirection --- Filter/Filter.cs | 31 ++++++++++++++++++------------- SabreHelper/Build.cs | 1 + 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Filter/Filter.cs b/Filter/Filter.cs index f32572f7..20a2cee4 100644 --- a/Filter/Filter.cs +++ b/Filter/Filter.cs @@ -9,18 +9,11 @@ using SabreTools.Helper; namespace SabreTools { - /* - Create new tool: Filter, with the following filters available - Game name, Rom name, CRC, MD5, SHA-1 use asterisks as follows(case insensitive): - -crc=*00 (means ends with "00") - -crc=00* (means starts with "00") - -crc=*00* (means contains "00") - -crc=00 (means is "00") - */ public class Filter { // Private instance variables private string _filename; + private string _outdir; private string _gamename; private string _romname; private string _romtype; @@ -37,6 +30,7 @@ namespace SabreTools /// 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 @@ -48,9 +42,11 @@ namespace SabreTools /// 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 gamename, string romname, string romtype, long sgt, long slt, long seq, string crc, string md5, string sha1, bool? nodump, Logger logger) + 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; @@ -84,7 +80,7 @@ namespace SabreTools // First things first, take care of all of the arguments that this could have bool? nodump = null; - string gamename = "", romname = "", romtype = "", crc = "", md5 = "", sha1= ""; + string outdir = "", gamename = "", romname = "", romtype = "", crc = "", md5 = "", sha1= ""; long sgt = -1, slt = -1, seq = -1; List inputs = new List(); foreach (string arg in args) @@ -130,6 +126,10 @@ namespace SabreTools } // String inputs + else if (arg.StartsWith("-out=") || arg.StartsWith("--out=")) + { + outdir = arg.Split('=')[1]; + } else if (arg.StartsWith("-crc=") || arg.StartsWith("--crc=")) { crc = arg.Split('=')[1]; @@ -194,7 +194,7 @@ namespace SabreTools if (File.Exists(newinput)) { - filter = new Filter(newinput, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger); + filter = new Filter(newinput, outdir, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger); success &= filter.Process(); } @@ -202,7 +202,12 @@ namespace SabreTools { foreach (string file in Directory.EnumerateFiles(newinput, "*", SearchOption.AllDirectories)) { - filter = new Filter(file, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger); + 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(); } } @@ -369,7 +374,7 @@ namespace SabreTools datdata.Roms = dict; // Now write the file out and return - return Output.WriteDatfile(datdata, Path.GetDirectoryName(_filename), _logger); + return Output.WriteDatfile(datdata, _outdir, _logger); } } } diff --git a/SabreHelper/Build.cs b/SabreHelper/Build.cs index 422d8a29..e2279c67 100644 --- a/SabreHelper/Build.cs +++ b/SabreHelper/Build.cs @@ -215,6 +215,7 @@ Usage: Filter [options] [inputs] Options: -h, -?, --help Show this help dialog + -out=, --out= Output directory -gn=, --game-name= Game name to be filtered on -rn=, --rom-name= Rom name to be filtered on -rt=, --rom-type= Rom type to be filtered on