From de481a057085ce3f907468c88f15e7d36790629e Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 3 Feb 2021 11:10:19 -0800 Subject: [PATCH] Add universal changes to RombaSharp --- RombaSharp/Features/Archive.cs | 3 + RombaSharp/Features/BaseFeature.cs | 85 ++++++++++++++++++++++++++--- RombaSharp/Features/Build.cs | 3 + RombaSharp/Features/Cancel.cs | 3 + RombaSharp/Features/DatStats.cs | 3 + RombaSharp/Features/DbStats.cs | 3 + RombaSharp/Features/Diffdat.cs | 3 + RombaSharp/Features/Dir2Dat.cs | 3 + RombaSharp/Features/EDiffdat.cs | 3 + RombaSharp/Features/Export.cs | 3 + RombaSharp/Features/Fixdat.cs | 3 + RombaSharp/Features/Import.cs | 3 + RombaSharp/Features/Lookup.cs | 3 + RombaSharp/Features/Memstats.cs | 3 + RombaSharp/Features/Merge.cs | 3 + RombaSharp/Features/Miss.cs | 3 + RombaSharp/Features/Progress.cs | 3 + RombaSharp/Features/PurgeBackup.cs | 3 + RombaSharp/Features/PurgeDelete.cs | 3 + RombaSharp/Features/RefreshDats.cs | 3 + RombaSharp/Features/RescanDepots.cs | 3 + RombaSharp/Features/Script.cs | 21 ------- RombaSharp/Features/Shutdown.cs | 3 + RombaSharp/Features/Version.cs | 3 + RombaSharp/Program.cs | 30 ++++------ SabreTools.Core/README.1ST | 13 +++++ 26 files changed, 167 insertions(+), 48 deletions(-) delete mode 100644 RombaSharp/Features/Script.cs diff --git a/RombaSharp/Features/Archive.cs b/RombaSharp/Features/Archive.cs index 688690e4..49cf5217 100644 --- a/RombaSharp/Features/Archive.cs +++ b/RombaSharp/Features/Archive.cs @@ -31,6 +31,9 @@ If -only-needed is set, only those files are put in the ROM archive that have a current entry in the DAT index."; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(OnlyNeededFlag); AddFeature(ResumeStringInput); AddFeature(IncludeZipsInt32Input); // Defaults to 0 diff --git a/RombaSharp/Features/BaseFeature.cs b/RombaSharp/Features/BaseFeature.cs index f9dd8196..68adc8a0 100644 --- a/RombaSharp/Features/BaseFeature.cs +++ b/RombaSharp/Features/BaseFeature.cs @@ -20,7 +20,18 @@ namespace RombaSharp.Features { internal class BaseFeature : TopLevel { - #region Private Flag features + #region Logging + + /// + /// Logging object + /// + protected Logger logger = new Logger(); + + #endregion + + #region Features + + #region Flag features internal const string CopyValue = "copy"; internal static SabreTools.Help.Feature CopyFlag @@ -87,6 +98,20 @@ namespace RombaSharp.Features } } + internal const string ScriptValue = "script"; + internal static SabreTools.Help.Feature ScriptFlag + { + get + { + return new SabreTools.Help.Feature( + ScriptValue, + new List() { "-sc", "--script" }, + "Enable script mode (no clear screen)", + ParameterType.Flag, + "For times when RombaSharp 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 SkipInitialScanValue = "skip-initial-scan"; internal static SabreTools.Help.Feature SkipInitialScanFlag { @@ -115,7 +140,7 @@ namespace RombaSharp.Features #endregion - #region Private Int32 features + #region Int32 features internal const string Include7ZipsInt32Value = "include-7zips"; internal static SabreTools.Help.Feature Include7ZipsInt32Input @@ -184,7 +209,7 @@ namespace RombaSharp.Features #endregion - #region Private Int64 features + #region Int64 features internal const string SizeInt64Value = "size"; internal static SabreTools.Help.Feature SizeInt64Input @@ -201,7 +226,7 @@ namespace RombaSharp.Features #endregion - #region Private List features + #region List features internal const string DatsListStringValue = "dats"; internal static SabreTools.Help.Feature DatsListStringInput @@ -231,7 +256,7 @@ namespace RombaSharp.Features #endregion - #region Private String features + #region String features internal const string BackupStringValue = "backup"; internal static SabreTools.Help.Feature BackupStringInput @@ -259,6 +284,21 @@ namespace RombaSharp.Features } } + internal const string LogLevelStringValue = "log-level"; + internal static SabreTools.Help.Feature LogLevelStringInput + { + get + { + return new SabreTools.Help.Feature( + LogLevelStringValue, + new List() { "-ll", "--log-level" }, + "Set the lowest log level for output", + ParameterType.String, + longDescription: @"Set the lowest log level for output. +Possible values are: Verbose, User, Warning, Error"); + } + } + internal const string MissingSha1sStringValue = "missing-sha1s"; internal static SabreTools.Help.Feature MissingSha1sStringInput { @@ -352,6 +392,24 @@ namespace RombaSharp.Features #endregion + #endregion // Features + + #region Fields + + /// + /// Lowest log level for output + /// + public LogLevel LogLevel { get; protected set; } + + /// + /// Determines if scripting mode is enabled + /// + public bool ScriptMode { get; protected set; } + + #endregion + + #region Settings + // General settings internal static string _logdir; // Log folder location internal static string _tmpdir; // Temp folder location @@ -374,13 +432,26 @@ namespace RombaSharp.Features internal const string _config = "config.xml"; internal static string _connectionString; + #endregion + + #region Add Feature Groups + /// - /// Logging object + /// Add common features /// - protected Logger logger = new Logger(); + protected void AddCommonFeatures() + { + AddFeature(ScriptFlag); + AddFeature(LogLevelStringInput); + } + + #endregion public override void ProcessFeatures(Dictionary features) { + LogLevel = GetString(features, LogLevelStringValue).AsLogLevel(); + ScriptMode = GetBoolean(features, ScriptValue); + InitializeConfiguration(); EnsureDatabase(_db, _connectionString); } diff --git a/RombaSharp/Features/Build.cs b/RombaSharp/Features/Build.cs index 10f65d00..8409bd9f 100644 --- a/RombaSharp/Features/Build.cs +++ b/RombaSharp/Features/Build.cs @@ -25,6 +25,9 @@ output dir. The files will be placed in the specified location using a folder structure according to the original DAT master directory tree structure."; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(OutStringInput); AddFeature(FixdatOnlyFlag); AddFeature(CopyFlag); diff --git a/RombaSharp/Features/Cancel.cs b/RombaSharp/Features/Cancel.cs index 3273436c..562cc972 100644 --- a/RombaSharp/Features/Cancel.cs +++ b/RombaSharp/Features/Cancel.cs @@ -16,6 +16,9 @@ namespace RombaSharp.Features _featureType = ParameterType.Flag; LongDescription = "Cancels current long-running job."; Features = new Dictionary(); + + // Common Features + AddCommonFeatures(); } public override void ProcessFeatures(Dictionary features) diff --git a/RombaSharp/Features/DatStats.cs b/RombaSharp/Features/DatStats.cs index 0d6a1f4d..2f936fc6 100644 --- a/RombaSharp/Features/DatStats.cs +++ b/RombaSharp/Features/DatStats.cs @@ -19,6 +19,9 @@ namespace RombaSharp.Features _featureType = ParameterType.Flag; LongDescription = "Print dat stats."; Features = new Dictionary(); + + // Common Features + AddCommonFeatures(); } public override void ProcessFeatures(Dictionary features) diff --git a/RombaSharp/Features/DbStats.cs b/RombaSharp/Features/DbStats.cs index 8738ffb0..564b5f42 100644 --- a/RombaSharp/Features/DbStats.cs +++ b/RombaSharp/Features/DbStats.cs @@ -17,6 +17,9 @@ namespace RombaSharp.Features _featureType = ParameterType.Flag; LongDescription = "Print db stats."; Features = new Dictionary(); + + // Common Features + AddCommonFeatures(); } public override void ProcessFeatures(Dictionary features) diff --git a/RombaSharp/Features/Diffdat.cs b/RombaSharp/Features/Diffdat.cs index c1b5b325..d7b0abd1 100644 --- a/RombaSharp/Features/Diffdat.cs +++ b/RombaSharp/Features/Diffdat.cs @@ -22,6 +22,9 @@ namespace RombaSharp.Features in -old DAT file. Ignores those entries in -old that are not in -new."; this.Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(OutStringInput); AddFeature(OldStringInput); AddFeature(NewStringInput); diff --git a/RombaSharp/Features/Dir2Dat.cs b/RombaSharp/Features/Dir2Dat.cs index 0f741bf3..d87ec687 100644 --- a/RombaSharp/Features/Dir2Dat.cs +++ b/RombaSharp/Features/Dir2Dat.cs @@ -23,6 +23,9 @@ namespace RombaSharp.Features LongDescription = "Creates a DAT file for the specified input directory and saves it to the -out filename."; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(OutStringInput); AddFeature(SourceStringInput); AddFeature(NameStringInput); // Defaults to "untitled" diff --git a/RombaSharp/Features/EDiffdat.cs b/RombaSharp/Features/EDiffdat.cs index 33ee8997..5047561d 100644 --- a/RombaSharp/Features/EDiffdat.cs +++ b/RombaSharp/Features/EDiffdat.cs @@ -21,6 +21,9 @@ namespace RombaSharp.Features LongDescription = @"Creates a DAT file with those entries that are in -new DAT files and not in -old DAT files. Ignores those entries in -old that are not in -new."; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(OutStringInput); AddFeature(OldStringInput); AddFeature(NewStringInput); diff --git a/RombaSharp/Features/Export.cs b/RombaSharp/Features/Export.cs index ca55cd43..5170fe80 100644 --- a/RombaSharp/Features/Export.cs +++ b/RombaSharp/Features/Export.cs @@ -19,6 +19,9 @@ namespace RombaSharp.Features _featureType = ParameterType.Flag; LongDescription = "Exports db to standardized export.csv"; Features = new Dictionary(); + + // Common Features + AddCommonFeatures(); } // TODO: Add ability to say which depot the files are found in diff --git a/RombaSharp/Features/Fixdat.cs b/RombaSharp/Features/Fixdat.cs index 35cfe97f..1da5a361 100644 --- a/RombaSharp/Features/Fixdat.cs +++ b/RombaSharp/Features/Fixdat.cs @@ -17,6 +17,9 @@ namespace RombaSharp.Features LongDescription = @"For each specified DAT file it creates a fix DAT with the missing entries for that DAT. If nothing is missing it doesn't create a fix DAT for that particular DAT."; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(OutStringInput); AddFeature(FixdatOnlyFlag); // Enabled by default AddFeature(WorkersInt32Input); diff --git a/RombaSharp/Features/Import.cs b/RombaSharp/Features/Import.cs index 678e091d..7f276baf 100644 --- a/RombaSharp/Features/Import.cs +++ b/RombaSharp/Features/Import.cs @@ -21,6 +21,9 @@ namespace RombaSharp.Features _featureType = ParameterType.Flag; LongDescription = "Import a database from a formatted CSV file"; Features = new Dictionary(); + + // Common Features + AddCommonFeatures(); } public override void ProcessFeatures(Dictionary features) diff --git a/RombaSharp/Features/Lookup.cs b/RombaSharp/Features/Lookup.cs index 24bb18be..0fde1228 100644 --- a/RombaSharp/Features/Lookup.cs +++ b/RombaSharp/Features/Lookup.cs @@ -19,6 +19,9 @@ namespace RombaSharp.Features LongDescription = "For each specified hash it looks up any available information (dat or rom)."; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(SizeInt64Input); // Defaults to -1 AddFeature(OutStringInput); } diff --git a/RombaSharp/Features/Memstats.cs b/RombaSharp/Features/Memstats.cs index 0b946d9b..75425f4f 100644 --- a/RombaSharp/Features/Memstats.cs +++ b/RombaSharp/Features/Memstats.cs @@ -16,6 +16,9 @@ namespace RombaSharp.Features _featureType = ParameterType.Flag; LongDescription = "Print memory stats."; Features = new Dictionary(); + + // Common Features + AddCommonFeatures(); } public override void ProcessFeatures(Dictionary features) diff --git a/RombaSharp/Features/Merge.cs b/RombaSharp/Features/Merge.cs index d5fbe1d3..4335b268 100644 --- a/RombaSharp/Features/Merge.cs +++ b/RombaSharp/Features/Merge.cs @@ -20,6 +20,9 @@ namespace RombaSharp.Features LongDescription = "Merges specified depot into current depot."; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(OnlyNeededFlag); AddFeature(ResumeStringInput); AddFeature(WorkersInt32Input); diff --git a/RombaSharp/Features/Miss.cs b/RombaSharp/Features/Miss.cs index 2b0eba55..fdbeac8b 100644 --- a/RombaSharp/Features/Miss.cs +++ b/RombaSharp/Features/Miss.cs @@ -21,6 +21,9 @@ namespace RombaSharp.Features _featureType = ParameterType.Flag; LongDescription = "For each specified DAT file, create miss and have file"; Features = new Dictionary(); + + // Common Features + AddCommonFeatures(); } public override void ProcessFeatures(Dictionary features) diff --git a/RombaSharp/Features/Progress.cs b/RombaSharp/Features/Progress.cs index 4a39443b..f1336414 100644 --- a/RombaSharp/Features/Progress.cs +++ b/RombaSharp/Features/Progress.cs @@ -16,6 +16,9 @@ namespace RombaSharp.Features _featureType = ParameterType.Flag; LongDescription = "Shows progress of the currently running command."; Features = new Dictionary(); + + // Common Features + AddCommonFeatures(); } public override void ProcessFeatures(Dictionary features) diff --git a/RombaSharp/Features/PurgeBackup.cs b/RombaSharp/Features/PurgeBackup.cs index efb3689a..6f104fd3 100644 --- a/RombaSharp/Features/PurgeBackup.cs +++ b/RombaSharp/Features/PurgeBackup.cs @@ -21,6 +21,9 @@ a folder structure according to the original DAT master directory tree structure. It also deletes the specified DATs from the DAT index."; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(BackupStringInput); AddFeature(WorkersInt32Input); AddFeature(DepotListStringInput); diff --git a/RombaSharp/Features/PurgeDelete.cs b/RombaSharp/Features/PurgeDelete.cs index 7cb14f98..592ac648 100644 --- a/RombaSharp/Features/PurgeDelete.cs +++ b/RombaSharp/Features/PurgeDelete.cs @@ -22,6 +22,9 @@ a folder structure according to the original DAT master directory tree structure. It also deletes the specified DATs from the DAT index."; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(WorkersInt32Input); AddFeature(DepotListStringInput); AddFeature(DatsListStringInput); diff --git a/RombaSharp/Features/RefreshDats.cs b/RombaSharp/Features/RefreshDats.cs index 84b73988..7bd1f779 100644 --- a/RombaSharp/Features/RefreshDats.cs +++ b/RombaSharp/Features/RefreshDats.cs @@ -30,6 +30,9 @@ accordingly, marking deleted or overwritten dats as orphaned and updating contents of any changed dats."; Features = new Dictionary(); + // Common Features + AddCommonFeatures(); + AddFeature(WorkersInt32Input); AddFeature(MissingSha1sStringInput); } diff --git a/RombaSharp/Features/RescanDepots.cs b/RombaSharp/Features/RescanDepots.cs index 7f6bf7f7..9c319320 100644 --- a/RombaSharp/Features/RescanDepots.cs +++ b/RombaSharp/Features/RescanDepots.cs @@ -25,6 +25,9 @@ namespace RombaSharp.Features _featureType = ParameterType.Flag; LongDescription = "Rescan a specific depot to get new information"; Features = new Dictionary(); + + // Common Features + AddCommonFeatures(); } public override void ProcessFeatures(Dictionary features) diff --git a/RombaSharp/Features/Script.cs b/RombaSharp/Features/Script.cs deleted file mode 100644 index 16a6a8a8..00000000 --- a/RombaSharp/Features/Script.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; - -using SabreTools.Help; - -namespace RombaSharp.Features -{ - 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 RombaSharp 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/RombaSharp/Features/Shutdown.cs b/RombaSharp/Features/Shutdown.cs index 20477773..2972f0e6 100644 --- a/RombaSharp/Features/Shutdown.cs +++ b/RombaSharp/Features/Shutdown.cs @@ -16,6 +16,9 @@ namespace RombaSharp.Features _featureType = ParameterType.Flag; LongDescription = "Gracefully shuts down server saving all the cached data."; Features = new Dictionary(); + + // Common Features + AddCommonFeatures(); } public override void ProcessFeatures(Dictionary features) diff --git a/RombaSharp/Features/Version.cs b/RombaSharp/Features/Version.cs index 1019d09f..4c946143 100644 --- a/RombaSharp/Features/Version.cs +++ b/RombaSharp/Features/Version.cs @@ -17,6 +17,9 @@ namespace RombaSharp.Features _featureType = ParameterType.Flag; LongDescription = "Prints version."; Features = new Dictionary(); + + // Common Features + AddCommonFeatures(); } public override void ProcessFeatures(Dictionary features) diff --git a/RombaSharp/Program.cs b/RombaSharp/Program.cs index 5b26ebbb..0db331c8 100644 --- a/RombaSharp/Program.cs +++ b/RombaSharp/Program.cs @@ -49,24 +49,6 @@ namespace RombaSharp // 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("RombaSharp"); - } - - // 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")) { @@ -116,13 +98,22 @@ namespace RombaSharp return; } + // 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) { case DisplayHelpDetailed.Value: case DisplayHelp.Value: - case Script.Value: // No-op as this should be caught break; @@ -189,7 +180,6 @@ namespace RombaSharp // Add all of the features help.Add(new DisplayHelp()); help.Add(new DisplayHelpDetailed()); - help.Add(new Script()); help.Add(new Archive()); help.Add(new Build()); help.Add(new Cancel()); diff --git a/SabreTools.Core/README.1ST b/SabreTools.Core/README.1ST index ab9b4535..176d1270 100644 --- a/SabreTools.Core/README.1ST +++ b/SabreTools.Core/README.1ST @@ -96,6 +96,19 @@ with each flag. Not all features are currently available. Usage: RombaSharp.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. Features and Options: -?, -h, --help Show the built-in help text