From b543ceb4e029b0958cfad80dd19d2ec5317a8c0e Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 3 Feb 2021 10:48:23 -0800 Subject: [PATCH] Better universal options, fix last commit --- SabreTools.Core/README.1ST | 79 ++++++++--------------------- SabreTools.Core/Tools/Converters.cs | 2 +- SabreTools/Features/BaseFeature.cs | 30 +++++++++++ SabreTools/Features/Batch.cs | 2 +- SabreTools/Features/DatFromDir.cs | 3 +- SabreTools/Features/Extract.cs | 2 +- SabreTools/Features/Restore.cs | 3 ++ SabreTools/Features/Script.cs | 23 --------- SabreTools/Features/Sort.cs | 3 +- SabreTools/Features/Split.cs | 4 +- SabreTools/Features/Stats.cs | 3 ++ SabreTools/Features/Update.cs | 4 +- SabreTools/Features/Verify.cs | 2 +- SabreTools/Program.cs | 27 +++------- 14 files changed, 76 insertions(+), 111 deletions(-) delete mode 100644 SabreTools/Features/Script.cs diff --git a/SabreTools.Core/README.1ST b/SabreTools.Core/README.1ST index 8d99f03e..ab9b4535 100644 --- a/SabreTools.Core/README.1ST +++ b/SabreTools.Core/README.1ST @@ -95,9 +95,9 @@ of other features. The following descriptions are based on what WILL be done with each flag. Not all features are currently available. Usage: - RombaSharp.exe [options] [filename|dirname] ... + RombaSharp.exe [feature] [options] [filename|dirname] ... -Options: +Features and Options: -?, -h, --help Show the built-in help text Built-in to most of the programs is a basic help text @@ -159,21 +159,33 @@ For any command below that includes a `field` of any sort, the name are standard the format will be `item.name` Usage: - SabreTools.exe [options] [filename|dirname] ... + SabreTools.exe [feature] [options] [filename|dirname] ... + +Universal Options: + These parameters can be enabled on any feature except Detailed Help and Help + + -ll=, --log-level= Set the lowest log level for output + Set the lowest log level for output. + Possible values are: Verbose, User, Warning, Error + + -sc, --script Enable script mode (no clear screen) + For times when SabreTools is being used in a scripted environment, the + user may not want the screen to be cleared every time that it is called. + This flag allows the user to skip clearing the screen on run just like if + the console was being redirected. + + -mt=, --threads= Amount of threads to use (default = # cores) + Optionally, set the number of threads to use for the multithreaded + operations. The default is the number of available machine threads; + -1 means unlimited threads created. -Options: +Features and Options: -?, -h, --help Show this help Built-in to most of the programs is a basic help text. -??, -hd, --help-detailed Show this detailed help Display a detailed help text to the screen. - --script Enable script mode (no clear screen) - For times when SabreTools is being used in a scripted environment, the - user may not want the screen to be cleared every time that it is called. - This flag allows the user to skip clearing the screen on run just like if - the console was being redirected. - -bt, --batch Enable batch mode Run a special mode that takes input files as lists of batch commands to run sequentially. Each command has to be its own line and must be followed @@ -205,10 +217,6 @@ Options: date. It will also treat all archives as possible games and add all three hashes (CRC, MD5, SHA-1) for each file. - -ll=, --log-level= Set the lowest log level for output - Set the lowest log level for output. - Possible values are: Verbose, User, Warning, Error - -nm, --skip-md5 Don't include MD5 in output This allows the user to skip calculating the MD5 for each of the files which will speed up the creation of the DAT. @@ -419,11 +427,6 @@ Options: This sets an output folder to be used when the files are created. If a path is not defined, the runtime directory is used instead. - -mt=, --threads= Amount of threads to use (default = # cores) - Optionally, set the number of threads to use for the multithreaded - operations. The default is the number of available machine threads; - -1 means unlimited threads created. - -ex, --extract Extract and remove copier headers This will detect, store, and remove copier headers from a file or folder of files. The headers are backed up and collated by the hash of the @@ -441,10 +444,6 @@ Options: - Nintendo Super Famicom / Super Nintendo Entertainment System - Nintendo Super Famicom / Super Nintendo Entertainment System SPC - -ll=, --log-level= Set the lowest log level for output - Set the lowest log level for output. - Possible values are: Verbose, User, Warning, Error - -out=, --output-dir= Set output directory This sets an output folder to be used when the files are created. If a path is not defined, the runtime directory is used instead. @@ -471,10 +470,6 @@ Options: - Nintendo Super Famicom / Super Nintendo Entertainment System - Nintendo Super Famicom / Super Nintendo Entertainment System SPC - -ll=, --log-level= Set the lowest log level for output - Set the lowest log level for output. - Possible values are: Verbose, User, Warning, Error - -out=, --output-dir= Set output directory This sets an output folder to be used when the files are created. If a path is not defined, the runtime directory is used instead. @@ -484,10 +479,6 @@ Options: file(s). By default all files will be rebuilt to uncompressed folders in the output directory. - -ll=, --log-level= Set the lowest log level for output - Set the lowest log level for output. - Possible values are: Verbose, User, Warning, Error - -dat=, --dat= Input DAT to be used User-supplied DAT for use in all operations. Multiple instances of this flag are allowed. @@ -616,20 +607,11 @@ Options: the files that could not be matched will be output to the output directory. - -mt=, --threads= Amount of threads to use (default = # cores) - Optionally, set the number of threads to use for the multithreaded - operations. The default is the number of available machine threads; - -1 means unlimited threads created. - -sp, --split Split input DATs by a given criteria This feature allows the user to split input DATs by a number of different possible criteria. See the individual input information for details. More than one split type is allowed at a time. - -ll=, --log-level= Set the lowest log level for output - Set the lowest log level for output. - Possible values are: Verbose, User, Warning, Error - -ot=, --output-type= Output DATs to a specified format Add outputting the created DAT to known format. Multiple instances of this flag are allowed. @@ -747,10 +729,6 @@ Options: - Items that include a SHA-512 - Items with Nodump status - -ll=, --log-level= Set the lowest log level for output - Set the lowest log level for output. - Possible values are: Verbose, User, Warning, Error - -srt=, --report-type= Output statistics to a specified format Add outputting the created DAT to known format. Multiple instances of this flag are allowed. @@ -788,10 +766,6 @@ Options: different programs that performed DAT manipulation that work better together. - -ll=, --log-level= Set the lowest log level for output - Set the lowest log level for output. - Possible values are: Verbose, User, Warning, Error - -ot=, --output-type= Output DATs to a specified format Add outputting the created DAT to known format. Multiple instances of this flag are allowed. @@ -1174,11 +1148,6 @@ Options: directory, if set). This flag enables users to write out to the directory that the DATs originated from. - -mt=, --threads= Amount of threads to use (default = # cores) - Optionally, set the number of threads to use for the multithreaded - operations. The default is the number of available machine threads; - -1 means unlimited threads created. - -ve, --verify Verify a folder against DATs When used, this will use an input DAT or set of DATs to blindly check against an input folder. The base of the folder is considered the base @@ -1186,10 +1155,6 @@ Options: within. This will only do a direct verification of the items within and will create a fixdat afterwards for missing files. - -ll=, --log-level= Set the lowest log level for output - Set the lowest log level for output. - Possible values are: Verbose, User, Warning, Error - -dat=, --dat= Input DAT to be used User-supplied DAT for use in all operations. Multiple instances of this flag are allowed. diff --git a/SabreTools.Core/Tools/Converters.cs b/SabreTools.Core/Tools/Converters.cs index 9758ad46..056f2a34 100644 --- a/SabreTools.Core/Tools/Converters.cs +++ b/SabreTools.Core/Tools/Converters.cs @@ -956,7 +956,7 @@ namespace SabreTools.Core.Tools /// LogLevel value corresponding to the string public static LogLevel AsLogLevel(this string logLevel) { - return logLevel.ToLowerInvariant() switch + return logLevel?.ToLowerInvariant() switch { "verbose" => LogLevel.VERBOSE, "user" => LogLevel.USER, diff --git a/SabreTools/Features/BaseFeature.cs b/SabreTools/Features/BaseFeature.cs index c06a8a80..5a6b0058 100644 --- a/SabreTools/Features/BaseFeature.cs +++ b/SabreTools/Features/BaseFeature.cs @@ -828,6 +828,20 @@ namespace SabreTools.Features } } + internal const string ScriptValue = "script"; + internal static Feature ScriptFlag + { + get + { + return new Feature( + ScriptValue, + new List() { "-sc", "--script" }, + "Enable script mode (no clear screen)", + ParameterType.Flag, + "For times when SabreTools is being used in a scripted environment, the user may not want the screen to be cleared every time that it is called. This flag allows the user to skip clearing the screen on run just like if the console was being redirected."); + } + } + internal const string ShortValue = "short"; internal static Feature ShortFlag { @@ -1764,6 +1778,11 @@ Some special strings that can be used: /// Pre-configured Remover /// protected Remover Remover { get; set; } + + /// + /// Determines if scripting mode is enabled + /// + public bool ScriptMode { get; protected set; } /// /// Pre-configured Splitter @@ -1774,6 +1793,16 @@ Some special strings that can be used: #region Add Feature Groups + /// + /// Add common features + /// + protected void AddCommonFeatures() + { + AddFeature(ScriptFlag); + AddFeature(LogLevelStringInput); + AddFeature(ThreadsInt32Input); + } + /// /// Add Filter-specific features /// @@ -1839,6 +1868,7 @@ Some special strings that can be used: LogLevel = GetString(features, LogLevelStringValue).AsLogLevel(); OutputDir = GetString(features, OutputDirStringValue).Trim('"'); Remover = GetRemover(features); + ScriptMode = GetBoolean(features, ScriptValue); Splitter = GetSplitter(features); // Set threading flag, if necessary diff --git a/SabreTools/Features/Batch.cs b/SabreTools/Features/Batch.cs index 2547a072..265fd08c 100644 --- a/SabreTools/Features/Batch.cs +++ b/SabreTools/Features/Batch.cs @@ -46,7 +46,7 @@ Reset the internal state: reset();"; Features = new Dictionary(); // Common Features - AddFeature(LogLevelStringInput); + AddCommonFeatures(); } public override void ProcessFeatures(Dictionary features) diff --git a/SabreTools/Features/DatFromDir.cs b/SabreTools/Features/DatFromDir.cs index 5eb9b27d..a3a56c45 100644 --- a/SabreTools/Features/DatFromDir.cs +++ b/SabreTools/Features/DatFromDir.cs @@ -23,7 +23,7 @@ namespace SabreTools.Features Features = new Dictionary(); // Common Features - AddFeature(LogLevelStringInput); + AddCommonFeatures(); // Hash Features AddFeature(SkipMd5Flag); @@ -50,7 +50,6 @@ namespace SabreTools.Features AddFeature(ExtraIniListInput); AddFilteringFeatures(); AddFeature(OutputDirStringInput); - AddFeature(ThreadsInt32Input); } public override void ProcessFeatures(Dictionary features) diff --git a/SabreTools/Features/Extract.cs b/SabreTools/Features/Extract.cs index bb7a4654..189f97fb 100644 --- a/SabreTools/Features/Extract.cs +++ b/SabreTools/Features/Extract.cs @@ -35,7 +35,7 @@ The following systems have headers that this program can work with: Features = new Dictionary(); // Common Features - AddFeature(LogLevelStringInput); + AddCommonFeatures(); AddFeature(OutputDirStringInput); AddFeature(NoStoreHeaderFlag); diff --git a/SabreTools/Features/Restore.cs b/SabreTools/Features/Restore.cs index c0981584..9b797cd8 100644 --- a/SabreTools/Features/Restore.cs +++ b/SabreTools/Features/Restore.cs @@ -33,6 +33,9 @@ The following systems have headers that this program can work with: - Nintendo Super Famicom / Super Nintendo Entertainment System SPC"; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(OutputDirStringInput); } diff --git a/SabreTools/Features/Script.cs b/SabreTools/Features/Script.cs deleted file mode 100644 index c572ef8d..00000000 --- a/SabreTools/Features/Script.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; - -using SabreTools.Help; - -namespace SabreTools.Features -{ - // TODO: With the introduction of the `--log-level` input, can we create a better way - // to handle "universal" flags? Having script as its own feature is not ideal. - internal class Script : BaseFeature - { - public const string Value = "Script"; - - public Script() - { - Name = Value; - Flags = new List() { "--script" }; - Description = "Enable script mode (no clear screen)"; - _featureType = ParameterType.Flag; - LongDescription = "For times when SabreTools is being used in a scripted environment, the user may not want the screen to be cleared every time that it is called. This flag allows the user to skip clearing the screen on run just like if the console was being redirected."; - Features = new Dictionary(); - } - } -} diff --git a/SabreTools/Features/Sort.cs b/SabreTools/Features/Sort.cs index 7d68fc30..451ab300 100644 --- a/SabreTools/Features/Sort.cs +++ b/SabreTools/Features/Sort.cs @@ -24,7 +24,7 @@ namespace SabreTools.Features Features = new Dictionary(); // Common Features - AddFeature(LogLevelStringInput); + AddCommonFeatures(); AddFeature(DatListInput); AddFeature(OutputDirStringInput); @@ -56,7 +56,6 @@ namespace SabreTools.Features AddFeature(HeaderStringInput); AddInternalSplitFeatures(); AddFeature(UpdateDatFlag); - AddFeature(ThreadsInt32Input); } public override void ProcessFeatures(Dictionary features) diff --git a/SabreTools/Features/Split.cs b/SabreTools/Features/Split.cs index 706123d1..205eaca1 100644 --- a/SabreTools/Features/Split.cs +++ b/SabreTools/Features/Split.cs @@ -24,8 +24,8 @@ namespace SabreTools.Features Features = new Dictionary(); // Common Features - AddFeature(LogLevelStringInput); - + AddCommonFeatures(); + AddFeature(OutputTypeListInput); this[OutputTypeListInput].AddFeature(DeprecatedFlag); AddFeature(OutputDirStringInput); diff --git a/SabreTools/Features/Stats.cs b/SabreTools/Features/Stats.cs index 54c36423..dabd52bb 100644 --- a/SabreTools/Features/Stats.cs +++ b/SabreTools/Features/Stats.cs @@ -32,6 +32,9 @@ The stats that are outputted are as follows: - Items with Nodump status"; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(ReportTypeListInput); AddFeature(FilenameStringInput); AddFeature(OutputDirStringInput); diff --git a/SabreTools/Features/Update.cs b/SabreTools/Features/Update.cs index 48703b2a..94f5bf3c 100644 --- a/SabreTools/Features/Update.cs +++ b/SabreTools/Features/Update.cs @@ -25,6 +25,9 @@ namespace SabreTools.Features LongDescription = "This is the multitool part of the program, allowing for almost every manipulation to a DAT, or set of DATs. This is also a combination of many different programs that performed DAT manipulation that work better together."; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + // Output Formats AddFeature(OutputTypeListInput); this[OutputTypeListInput].AddFeature(PrefixStringInput); @@ -79,7 +82,6 @@ namespace SabreTools.Features AddFilteringFeatures(); AddFeature(OutputDirStringInput); AddFeature(InplaceFlag); - AddFeature(ThreadsInt32Input); } public override void ProcessFeatures(Dictionary features) diff --git a/SabreTools/Features/Verify.cs b/SabreTools/Features/Verify.cs index a596ec32..4c6e3415 100644 --- a/SabreTools/Features/Verify.cs +++ b/SabreTools/Features/Verify.cs @@ -24,7 +24,7 @@ namespace SabreTools.Features Features = new Dictionary(); // Common Features - AddFeature(LogLevelStringInput); + AddCommonFeatures(); AddFeature(DatListInput); AddFeature(DepotFlag); diff --git a/SabreTools/Program.cs b/SabreTools/Program.cs index 7897a97a..134d4b1d 100644 --- a/SabreTools/Program.cs +++ b/SabreTools/Program.cs @@ -42,24 +42,6 @@ namespace SabreTools // Create a new Help object for this program _help = RetrieveHelp(); - // Get the location of the script tag, if it exists - int scriptLocation = (new List(args)).IndexOf("--script"); - - // If output is being redirected or we are in script mode, don't allow clear screens - if (!Console.IsOutputRedirected && scriptLocation == -1) - { - Console.Clear(); - Prepare.SetConsoleHeader("SabreTools"); - } - - // Now we remove the script tag because it messes things up - if (scriptLocation > -1) - { - List newargs = new List(args); - newargs.RemoveAt(scriptLocation); - args = newargs.ToArray(); - } - // Credits take precidence over all if ((new List(args)).Contains("--credits")) { @@ -112,6 +94,13 @@ namespace SabreTools // Set the new log level based on settings LoggerImpl.LowestLogLevel = feature.LogLevel; + // If output is being redirected or we are in script mode, don't allow clear screens + if (!Console.IsOutputRedirected && feature.ScriptMode) + { + Console.Clear(); + Prepare.SetConsoleHeader("SabreTools"); + } + // Now process the current feature Dictionary features = _help.GetEnabledFeatures(); switch (featureName) @@ -119,7 +108,6 @@ namespace SabreTools // No-op as these should be caught case DisplayHelp.Value: case DisplayHelpDetailed.Value: - case Script.Value: break; // Require input verification @@ -172,7 +160,6 @@ namespace SabreTools // Add all of the features help.Add(new DisplayHelp()); help.Add(new DisplayHelpDetailed()); - help.Add(new Script()); help.Add(new Batch()); help.Add(new DatFromDir()); help.Add(new Extract());