2016-10-24 12:58:57 -07:00
|
|
|
|
using System;
|
2016-08-30 15:02:48 -07:00
|
|
|
|
using System.Collections.Generic;
|
2021-01-29 11:06:43 -08:00
|
|
|
|
using System.IO;
|
2020-08-01 13:25:32 -07:00
|
|
|
|
using RombaSharp.Features;
|
2020-12-08 13:23:59 -08:00
|
|
|
|
using SabreTools.Core;
|
2020-12-07 13:57:26 -08:00
|
|
|
|
using SabreTools.Help;
|
2021-01-29 11:06:43 -08:00
|
|
|
|
using SabreTools.IO;
|
2020-12-07 14:29:45 -08:00
|
|
|
|
using SabreTools.Logging;
|
2016-08-30 15:02:48 -07:00
|
|
|
|
|
2017-02-02 15:08:21 -08:00
|
|
|
|
namespace RombaSharp
|
2016-08-30 15:02:48 -07:00
|
|
|
|
{
|
2019-02-08 20:31:07 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Entry class for the RombaSharp application
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// In the database, we want to enable "offline mode". That is, when a user does an operation
|
|
|
|
|
|
/// that needs to read from the depot themselves, if the depot folder cannot be found, the
|
|
|
|
|
|
/// user is prompted to reconnect the depot OR skip that depot entirely.
|
|
|
|
|
|
/// </remarks>
|
2020-08-01 13:25:32 -07:00
|
|
|
|
public class Program
|
2019-02-08 20:31:07 -08:00
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
#region Static Variables
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Help object that determines available functionality
|
|
|
|
|
|
/// </summary>
|
2024-03-05 20:26:38 -05:00
|
|
|
|
private static FeatureSet? _help;
|
2019-02-08 20:31:07 -08:00
|
|
|
|
|
2020-10-07 15:42:30 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Logging object
|
|
|
|
|
|
/// </summary>
|
2023-04-19 16:39:58 -04:00
|
|
|
|
private static readonly Logger logger = new();
|
2020-10-07 15:42:30 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2019-02-08 20:31:07 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Entry class for the RombaSharp application
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Perform initial setup and verification
|
2021-01-29 11:06:43 -08:00
|
|
|
|
LoggerImpl.SetFilename(Path.Combine(PathTool.GetRuntimeDirectory(), "logs", "romba.log"), true);
|
2020-10-07 15:42:30 -07:00
|
|
|
|
LoggerImpl.AppendPrefix = true;
|
|
|
|
|
|
LoggerImpl.LowestLogLevel = LogLevel.VERBOSE;
|
|
|
|
|
|
LoggerImpl.ThrowOnError = false;
|
|
|
|
|
|
LoggerImpl.Start();
|
2019-02-08 20:31:07 -08:00
|
|
|
|
|
|
|
|
|
|
// Create a new Help object for this program
|
2020-08-01 13:25:32 -07:00
|
|
|
|
_help = RetrieveHelp();
|
2019-02-08 20:31:07 -08:00
|
|
|
|
|
|
|
|
|
|
// Credits take precidence over all
|
|
|
|
|
|
if ((new List<string>(args)).Contains("--credits"))
|
|
|
|
|
|
{
|
2023-04-19 16:39:58 -04:00
|
|
|
|
FeatureSet.OutputCredits();
|
2020-10-07 15:42:30 -07:00
|
|
|
|
LoggerImpl.Close();
|
2019-02-08 20:31:07 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If there's no arguments, show help
|
|
|
|
|
|
if (args.Length == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
_help.OutputGenericHelp();
|
2020-10-07 15:42:30 -07:00
|
|
|
|
LoggerImpl.Close();
|
2019-02-08 20:31:07 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the first argument as a feature flag
|
2020-06-10 22:37:19 -07:00
|
|
|
|
string featureName = args[0];
|
2019-02-08 20:31:07 -08:00
|
|
|
|
|
|
|
|
|
|
// Verify that the flag is valid
|
2020-06-10 22:37:19 -07:00
|
|
|
|
if (!_help.TopLevelFlag(featureName))
|
2019-02-08 20:31:07 -08:00
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.User($"'{featureName}' is not valid feature flag");
|
2020-06-10 22:37:19 -07:00
|
|
|
|
_help.OutputIndividualFeature(featureName);
|
2020-10-07 15:42:30 -07:00
|
|
|
|
LoggerImpl.Close();
|
2019-02-08 20:31:07 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
// Get the proper name for the feature
|
|
|
|
|
|
featureName = _help.GetFeatureName(featureName);
|
|
|
|
|
|
|
|
|
|
|
|
// Get the associated feature
|
2024-03-05 20:26:38 -05:00
|
|
|
|
BaseFeature? feature = _help[featureName] as BaseFeature;
|
2019-02-08 20:31:07 -08:00
|
|
|
|
|
|
|
|
|
|
// If we had the help feature first
|
2020-08-01 13:25:32 -07:00
|
|
|
|
if (featureName == DisplayHelp.Value || featureName == DisplayHelpDetailed.Value)
|
2019-02-08 20:31:07 -08:00
|
|
|
|
{
|
2024-03-05 20:26:38 -05:00
|
|
|
|
feature!.ProcessArgs(args, _help);
|
2020-10-07 15:42:30 -07:00
|
|
|
|
LoggerImpl.Close();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
return;
|
2019-02-08 20:31:07 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Now verify that all other flags are valid
|
2024-03-05 20:26:38 -05:00
|
|
|
|
if (!feature!.ProcessArgs(args, _help))
|
2019-02-08 20:31:07 -08:00
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
LoggerImpl.Close();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
return;
|
2019-02-08 20:31:07 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-03 11:10:19 -08:00
|
|
|
|
// 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");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
// Now process the current feature
|
2024-03-05 20:26:38 -05:00
|
|
|
|
Dictionary<string, Feature?> features = _help.GetEnabledFeatures();
|
2021-03-19 20:52:11 -07:00
|
|
|
|
bool success = false;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
switch (featureName)
|
2019-02-08 20:31:07 -08:00
|
|
|
|
{
|
2020-08-01 13:25:32 -07:00
|
|
|
|
case DisplayHelpDetailed.Value:
|
|
|
|
|
|
case DisplayHelp.Value:
|
2019-02-08 20:31:07 -08:00
|
|
|
|
// No-op as this should be caught
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
|
|
|
|
|
// Require input verification
|
2020-08-01 13:25:32 -07:00
|
|
|
|
case Archive.Value:
|
2020-10-07 15:42:30 -07:00
|
|
|
|
case Build.Value:
|
2020-08-01 13:25:32 -07:00
|
|
|
|
case DatStats.Value:
|
|
|
|
|
|
case Fixdat.Value:
|
|
|
|
|
|
case Import.Value:
|
|
|
|
|
|
case Lookup.Value:
|
|
|
|
|
|
case Merge.Value:
|
|
|
|
|
|
case Miss.Value:
|
|
|
|
|
|
case RescanDepots.Value:
|
2020-06-10 22:37:19 -07:00
|
|
|
|
VerifyInputs(feature.Inputs, featureName);
|
2021-03-19 20:52:11 -07:00
|
|
|
|
success = feature.ProcessFeatures(features);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// Requires no input verification
|
2020-08-01 13:25:32 -07:00
|
|
|
|
case Cancel.Value:
|
|
|
|
|
|
case DbStats.Value:
|
|
|
|
|
|
case Diffdat.Value:
|
|
|
|
|
|
case Dir2Dat.Value:
|
|
|
|
|
|
case EDiffdat.Value:
|
|
|
|
|
|
case Export.Value:
|
|
|
|
|
|
case Memstats.Value:
|
|
|
|
|
|
case Progress.Value:
|
|
|
|
|
|
case PurgeBackup.Value:
|
|
|
|
|
|
case PurgeDelete.Value:
|
|
|
|
|
|
case RefreshDats.Value:
|
|
|
|
|
|
case Shutdown.Value:
|
|
|
|
|
|
case Features.Version.Value:
|
2021-03-19 20:52:11 -07:00
|
|
|
|
success = feature.ProcessFeatures(features);
|
2019-02-08 20:31:07 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-02-08 20:31:07 -08:00
|
|
|
|
// If nothing is set, show the help
|
|
|
|
|
|
default:
|
|
|
|
|
|
_help.OutputGenericHelp();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-19 20:52:11 -07:00
|
|
|
|
// If the feature failed, output help
|
|
|
|
|
|
if (!success)
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.Error("An error occurred during processing!");
|
|
|
|
|
|
_help.OutputIndividualFeature(featureName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-07 15:42:30 -07:00
|
|
|
|
LoggerImpl.Close();
|
2019-02-08 20:31:07 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-01 13:25:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Generate a Help object for this program
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>Populated Help object</returns>
|
2020-12-08 17:05:08 -08:00
|
|
|
|
private static FeatureSet RetrieveHelp()
|
2020-08-01 13:25:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Create and add the header to the Help object
|
|
|
|
|
|
string barrier = "-----------------------------------------";
|
2023-04-19 16:39:58 -04:00
|
|
|
|
List<string> helpHeader = new()
|
2020-08-01 13:25:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
"RombaSharp - C# port of the Romba rom management tool",
|
|
|
|
|
|
barrier,
|
|
|
|
|
|
"Usage: RombaSharp [option] [filename|dirname] ...",
|
|
|
|
|
|
string.Empty
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Create the base help object with header
|
2023-04-19 16:39:58 -04:00
|
|
|
|
FeatureSet help = new(helpHeader);
|
2020-08-01 13:25:32 -07:00
|
|
|
|
|
|
|
|
|
|
// Add all of the features
|
|
|
|
|
|
help.Add(new DisplayHelp());
|
|
|
|
|
|
help.Add(new DisplayHelpDetailed());
|
|
|
|
|
|
help.Add(new Archive());
|
2020-10-07 15:42:30 -07:00
|
|
|
|
help.Add(new Build());
|
2020-08-01 13:25:32 -07:00
|
|
|
|
help.Add(new Cancel());
|
|
|
|
|
|
help.Add(new DatStats());
|
|
|
|
|
|
help.Add(new DbStats());
|
|
|
|
|
|
help.Add(new Diffdat());
|
|
|
|
|
|
help.Add(new Dir2Dat());
|
|
|
|
|
|
help.Add(new EDiffdat());
|
|
|
|
|
|
help.Add(new Export());
|
|
|
|
|
|
help.Add(new Fixdat());
|
|
|
|
|
|
help.Add(new Import());
|
|
|
|
|
|
help.Add(new Lookup());
|
|
|
|
|
|
help.Add(new Memstats());
|
|
|
|
|
|
help.Add(new Merge());
|
|
|
|
|
|
help.Add(new Miss());
|
|
|
|
|
|
help.Add(new PurgeBackup());
|
|
|
|
|
|
help.Add(new PurgeDelete());
|
|
|
|
|
|
help.Add(new RefreshDats());
|
|
|
|
|
|
help.Add(new RescanDepots());
|
|
|
|
|
|
help.Add(new Progress());
|
|
|
|
|
|
help.Add(new Shutdown());
|
|
|
|
|
|
help.Add(new Features.Version());
|
|
|
|
|
|
|
|
|
|
|
|
return help;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Verify that there are inputs, show help otherwise
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="inputs">List of inputs</param>
|
|
|
|
|
|
/// <param name="feature">Name of the current feature</param>
|
2019-02-08 20:31:07 -08:00
|
|
|
|
private static void VerifyInputs(List<string> inputs, string feature)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (inputs.Count == 0)
|
|
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Error("This feature requires at least one input");
|
2024-03-05 20:26:38 -05:00
|
|
|
|
_help?.OutputIndividualFeature(feature);
|
2019-02-08 20:31:07 -08:00
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-08-30 15:02:48 -07:00
|
|
|
|
}
|