Add universal changes to RombaSharp

This commit is contained in:
Matt Nadareski
2021-02-03 11:10:19 -08:00
parent b543ceb4e0
commit de481a0570
26 changed files with 167 additions and 48 deletions

View File

@@ -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."; have a current entry in the DAT index.";
Features = new Dictionary<string, SabreTools.Help.Feature>(); Features = new Dictionary<string, SabreTools.Help.Feature>();
// Common Features
AddCommonFeatures();
AddFeature(OnlyNeededFlag); AddFeature(OnlyNeededFlag);
AddFeature(ResumeStringInput); AddFeature(ResumeStringInput);
AddFeature(IncludeZipsInt32Input); // Defaults to 0 AddFeature(IncludeZipsInt32Input); // Defaults to 0

View File

@@ -20,7 +20,18 @@ namespace RombaSharp.Features
{ {
internal class BaseFeature : TopLevel internal class BaseFeature : TopLevel
{ {
#region Private Flag features #region Logging
/// <summary>
/// Logging object
/// </summary>
protected Logger logger = new Logger();
#endregion
#region Features
#region Flag features
internal const string CopyValue = "copy"; internal const string CopyValue = "copy";
internal static SabreTools.Help.Feature CopyFlag 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<string>() { "-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 const string SkipInitialScanValue = "skip-initial-scan";
internal static SabreTools.Help.Feature SkipInitialScanFlag internal static SabreTools.Help.Feature SkipInitialScanFlag
{ {
@@ -115,7 +140,7 @@ namespace RombaSharp.Features
#endregion #endregion
#region Private Int32 features #region Int32 features
internal const string Include7ZipsInt32Value = "include-7zips"; internal const string Include7ZipsInt32Value = "include-7zips";
internal static SabreTools.Help.Feature Include7ZipsInt32Input internal static SabreTools.Help.Feature Include7ZipsInt32Input
@@ -184,7 +209,7 @@ namespace RombaSharp.Features
#endregion #endregion
#region Private Int64 features #region Int64 features
internal const string SizeInt64Value = "size"; internal const string SizeInt64Value = "size";
internal static SabreTools.Help.Feature SizeInt64Input internal static SabreTools.Help.Feature SizeInt64Input
@@ -201,7 +226,7 @@ namespace RombaSharp.Features
#endregion #endregion
#region Private List<String> features #region List<String> features
internal const string DatsListStringValue = "dats"; internal const string DatsListStringValue = "dats";
internal static SabreTools.Help.Feature DatsListStringInput internal static SabreTools.Help.Feature DatsListStringInput
@@ -231,7 +256,7 @@ namespace RombaSharp.Features
#endregion #endregion
#region Private String features #region String features
internal const string BackupStringValue = "backup"; internal const string BackupStringValue = "backup";
internal static SabreTools.Help.Feature BackupStringInput 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<string>() { "-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 const string MissingSha1sStringValue = "missing-sha1s";
internal static SabreTools.Help.Feature MissingSha1sStringInput internal static SabreTools.Help.Feature MissingSha1sStringInput
{ {
@@ -352,6 +392,24 @@ namespace RombaSharp.Features
#endregion #endregion
#endregion // Features
#region Fields
/// <summary>
/// Lowest log level for output
/// </summary>
public LogLevel LogLevel { get; protected set; }
/// <summary>
/// Determines if scripting mode is enabled
/// </summary>
public bool ScriptMode { get; protected set; }
#endregion
#region Settings
// General settings // General settings
internal static string _logdir; // Log folder location internal static string _logdir; // Log folder location
internal static string _tmpdir; // Temp folder location internal static string _tmpdir; // Temp folder location
@@ -374,13 +432,26 @@ namespace RombaSharp.Features
internal const string _config = "config.xml"; internal const string _config = "config.xml";
internal static string _connectionString; internal static string _connectionString;
#endregion
#region Add Feature Groups
/// <summary> /// <summary>
/// Logging object /// Add common features
/// </summary> /// </summary>
protected Logger logger = new Logger(); protected void AddCommonFeatures()
{
AddFeature(ScriptFlag);
AddFeature(LogLevelStringInput);
}
#endregion
public override void ProcessFeatures(Dictionary<string, SabreTools.Help.Feature> features) public override void ProcessFeatures(Dictionary<string, SabreTools.Help.Feature> features)
{ {
LogLevel = GetString(features, LogLevelStringValue).AsLogLevel();
ScriptMode = GetBoolean(features, ScriptValue);
InitializeConfiguration(); InitializeConfiguration();
EnsureDatabase(_db, _connectionString); EnsureDatabase(_db, _connectionString);
} }

View File

@@ -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."; structure according to the original DAT master directory tree structure.";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
AddFeature(OutStringInput); AddFeature(OutStringInput);
AddFeature(FixdatOnlyFlag); AddFeature(FixdatOnlyFlag);
AddFeature(CopyFlag); AddFeature(CopyFlag);

View File

@@ -16,6 +16,9 @@ namespace RombaSharp.Features
_featureType = ParameterType.Flag; _featureType = ParameterType.Flag;
LongDescription = "Cancels current long-running job."; LongDescription = "Cancels current long-running job.";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
} }
public override void ProcessFeatures(Dictionary<string, Feature> features) public override void ProcessFeatures(Dictionary<string, Feature> features)

View File

@@ -19,6 +19,9 @@ namespace RombaSharp.Features
_featureType = ParameterType.Flag; _featureType = ParameterType.Flag;
LongDescription = "Print dat stats."; LongDescription = "Print dat stats.";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
} }
public override void ProcessFeatures(Dictionary<string, Feature> features) public override void ProcessFeatures(Dictionary<string, Feature> features)

View File

@@ -17,6 +17,9 @@ namespace RombaSharp.Features
_featureType = ParameterType.Flag; _featureType = ParameterType.Flag;
LongDescription = "Print db stats."; LongDescription = "Print db stats.";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
} }
public override void ProcessFeatures(Dictionary<string, Feature> features) public override void ProcessFeatures(Dictionary<string, Feature> features)

View File

@@ -22,6 +22,9 @@ namespace RombaSharp.Features
in -old DAT file. Ignores those entries in -old that are not in -new."; in -old DAT file. Ignores those entries in -old that are not in -new.";
this.Features = new Dictionary<string, Feature>(); this.Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
AddFeature(OutStringInput); AddFeature(OutStringInput);
AddFeature(OldStringInput); AddFeature(OldStringInput);
AddFeature(NewStringInput); AddFeature(NewStringInput);

View File

@@ -23,6 +23,9 @@ namespace RombaSharp.Features
LongDescription = "Creates a DAT file for the specified input directory and saves it to the -out filename."; LongDescription = "Creates a DAT file for the specified input directory and saves it to the -out filename.";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
AddFeature(OutStringInput); AddFeature(OutStringInput);
AddFeature(SourceStringInput); AddFeature(SourceStringInput);
AddFeature(NameStringInput); // Defaults to "untitled" AddFeature(NameStringInput); // Defaults to "untitled"

View File

@@ -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."; 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<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
AddFeature(OutStringInput); AddFeature(OutStringInput);
AddFeature(OldStringInput); AddFeature(OldStringInput);
AddFeature(NewStringInput); AddFeature(NewStringInput);

View File

@@ -19,6 +19,9 @@ namespace RombaSharp.Features
_featureType = ParameterType.Flag; _featureType = ParameterType.Flag;
LongDescription = "Exports db to standardized export.csv"; LongDescription = "Exports db to standardized export.csv";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
} }
// TODO: Add ability to say which depot the files are found in // TODO: Add ability to say which depot the files are found in

View File

@@ -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."; 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<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
AddFeature(OutStringInput); AddFeature(OutStringInput);
AddFeature(FixdatOnlyFlag); // Enabled by default AddFeature(FixdatOnlyFlag); // Enabled by default
AddFeature(WorkersInt32Input); AddFeature(WorkersInt32Input);

View File

@@ -21,6 +21,9 @@ namespace RombaSharp.Features
_featureType = ParameterType.Flag; _featureType = ParameterType.Flag;
LongDescription = "Import a database from a formatted CSV file"; LongDescription = "Import a database from a formatted CSV file";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
} }
public override void ProcessFeatures(Dictionary<string, Feature> features) public override void ProcessFeatures(Dictionary<string, Feature> features)

View File

@@ -19,6 +19,9 @@ namespace RombaSharp.Features
LongDescription = "For each specified hash it looks up any available information (dat or rom)."; LongDescription = "For each specified hash it looks up any available information (dat or rom).";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
AddFeature(SizeInt64Input); // Defaults to -1 AddFeature(SizeInt64Input); // Defaults to -1
AddFeature(OutStringInput); AddFeature(OutStringInput);
} }

View File

@@ -16,6 +16,9 @@ namespace RombaSharp.Features
_featureType = ParameterType.Flag; _featureType = ParameterType.Flag;
LongDescription = "Print memory stats."; LongDescription = "Print memory stats.";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
} }
public override void ProcessFeatures(Dictionary<string, Feature> features) public override void ProcessFeatures(Dictionary<string, Feature> features)

View File

@@ -20,6 +20,9 @@ namespace RombaSharp.Features
LongDescription = "Merges specified depot into current depot."; LongDescription = "Merges specified depot into current depot.";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
AddFeature(OnlyNeededFlag); AddFeature(OnlyNeededFlag);
AddFeature(ResumeStringInput); AddFeature(ResumeStringInput);
AddFeature(WorkersInt32Input); AddFeature(WorkersInt32Input);

View File

@@ -21,6 +21,9 @@ namespace RombaSharp.Features
_featureType = ParameterType.Flag; _featureType = ParameterType.Flag;
LongDescription = "For each specified DAT file, create miss and have file"; LongDescription = "For each specified DAT file, create miss and have file";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
} }
public override void ProcessFeatures(Dictionary<string, Feature> features) public override void ProcessFeatures(Dictionary<string, Feature> features)

View File

@@ -16,6 +16,9 @@ namespace RombaSharp.Features
_featureType = ParameterType.Flag; _featureType = ParameterType.Flag;
LongDescription = "Shows progress of the currently running command."; LongDescription = "Shows progress of the currently running command.";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
} }
public override void ProcessFeatures(Dictionary<string, Feature> features) public override void ProcessFeatures(Dictionary<string, Feature> features)

View File

@@ -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."; structure. It also deletes the specified DATs from the DAT index.";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
AddFeature(BackupStringInput); AddFeature(BackupStringInput);
AddFeature(WorkersInt32Input); AddFeature(WorkersInt32Input);
AddFeature(DepotListStringInput); AddFeature(DepotListStringInput);

View File

@@ -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."; structure. It also deletes the specified DATs from the DAT index.";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
AddFeature(WorkersInt32Input); AddFeature(WorkersInt32Input);
AddFeature(DepotListStringInput); AddFeature(DepotListStringInput);
AddFeature(DatsListStringInput); AddFeature(DatsListStringInput);

View File

@@ -30,6 +30,9 @@ accordingly, marking deleted or overwritten dats as orphaned and updating
contents of any changed dats."; contents of any changed dats.";
Features = new Dictionary<string, SabreTools.Help.Feature>(); Features = new Dictionary<string, SabreTools.Help.Feature>();
// Common Features
AddCommonFeatures();
AddFeature(WorkersInt32Input); AddFeature(WorkersInt32Input);
AddFeature(MissingSha1sStringInput); AddFeature(MissingSha1sStringInput);
} }

View File

@@ -25,6 +25,9 @@ namespace RombaSharp.Features
_featureType = ParameterType.Flag; _featureType = ParameterType.Flag;
LongDescription = "Rescan a specific depot to get new information"; LongDescription = "Rescan a specific depot to get new information";
Features = new Dictionary<string, SabreTools.Help.Feature>(); Features = new Dictionary<string, SabreTools.Help.Feature>();
// Common Features
AddCommonFeatures();
} }
public override void ProcessFeatures(Dictionary<string, SabreTools.Help.Feature> features) public override void ProcessFeatures(Dictionary<string, SabreTools.Help.Feature> features)

View File

@@ -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<string>() { "--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<string, Feature>();
}
}
}

View File

@@ -16,6 +16,9 @@ namespace RombaSharp.Features
_featureType = ParameterType.Flag; _featureType = ParameterType.Flag;
LongDescription = "Gracefully shuts down server saving all the cached data."; LongDescription = "Gracefully shuts down server saving all the cached data.";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
} }
public override void ProcessFeatures(Dictionary<string, Feature> features) public override void ProcessFeatures(Dictionary<string, Feature> features)

View File

@@ -17,6 +17,9 @@ namespace RombaSharp.Features
_featureType = ParameterType.Flag; _featureType = ParameterType.Flag;
LongDescription = "Prints version."; LongDescription = "Prints version.";
Features = new Dictionary<string, Feature>(); Features = new Dictionary<string, Feature>();
// Common Features
AddCommonFeatures();
} }
public override void ProcessFeatures(Dictionary<string, Feature> features) public override void ProcessFeatures(Dictionary<string, Feature> features)

View File

@@ -49,24 +49,6 @@ namespace RombaSharp
// Create a new Help object for this program // Create a new Help object for this program
_help = RetrieveHelp(); _help = RetrieveHelp();
// Get the location of the script tag, if it exists
int scriptLocation = (new List<string>(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<string> newargs = new List<string>(args);
newargs.RemoveAt(scriptLocation);
args = newargs.ToArray();
}
// Credits take precidence over all // Credits take precidence over all
if ((new List<string>(args)).Contains("--credits")) if ((new List<string>(args)).Contains("--credits"))
{ {
@@ -116,13 +98,22 @@ namespace RombaSharp
return; 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 // Now process the current feature
Dictionary<string, Feature> features = _help.GetEnabledFeatures(); Dictionary<string, Feature> features = _help.GetEnabledFeatures();
switch (featureName) switch (featureName)
{ {
case DisplayHelpDetailed.Value: case DisplayHelpDetailed.Value:
case DisplayHelp.Value: case DisplayHelp.Value:
case Script.Value:
// No-op as this should be caught // No-op as this should be caught
break; break;
@@ -189,7 +180,6 @@ namespace RombaSharp
// Add all of the features // Add all of the features
help.Add(new DisplayHelp()); help.Add(new DisplayHelp());
help.Add(new DisplayHelpDetailed()); help.Add(new DisplayHelpDetailed());
help.Add(new Script());
help.Add(new Archive()); help.Add(new Archive());
help.Add(new Build()); help.Add(new Build());
help.Add(new Cancel()); help.Add(new Cancel());

View File

@@ -96,6 +96,19 @@ with each flag. Not all features are currently available.
Usage: Usage:
RombaSharp.exe [feature] [options] [filename|dirname] ... 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: Features and Options:
-?, -h, --help Show the built-in help text -?, -h, --help Show the built-in help text