Exemple #1
0
        /// <summary>
        /// Entry point for the SabreTools application
        /// </summary>
        /// <param name="args">String array representing command line parameters</param>
        public static void Main(string[] args)
        {
            // Perform initial setup and verification
            LoggerImpl.SetFilename("sabretools.log", true);
            LoggerImpl.AppendPrefix   = true;
            LoggerImpl.LowestLogLevel = LogLevel.VERBOSE;
            LoggerImpl.ThrowOnError   = false;
            LoggerImpl.Start();

            // Create a new Help object for this program
            _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("SabreTools");
            }

            // 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
            if ((new List <string>(args)).Contains("--credits"))
            {
                _help.OutputCredits();
                LoggerImpl.Close();
                return;
            }

            // If there's no arguments, show help
            if (args.Length == 0)
            {
                _help.OutputGenericHelp();
                LoggerImpl.Close();
                return;
            }

            // Get the first argument as a feature flag
            string featureName = args[0];

            // Verify that the flag is valid
            if (!_help.TopLevelFlag(featureName))
            {
                logger.User($"'{featureName}' is not valid feature flag");
                _help.OutputIndividualFeature(featureName);
                LoggerImpl.Close();
                return;
            }

            // Get the proper name for the feature
            featureName = _help.GetFeatureName(featureName);

            // Get the associated feature
            BaseFeature feature = _help[featureName] as BaseFeature;

            // If we had the help feature first
            if (featureName == DisplayHelp.Value || featureName == DisplayHelpDetailed.Value)
            {
                feature.ProcessArgs(args, _help);
                LoggerImpl.Close();
                return;
            }

            // Now verify that all other flags are valid
            if (!feature.ProcessArgs(args, _help))
            {
                LoggerImpl.Close();
                return;
            }

            // Now process the current feature
            Dictionary <string, Feature> features = _help.GetEnabledFeatures();

            switch (featureName)
            {
            // No-op as these should be caught
            case DisplayHelp.Value:
            case DisplayHelpDetailed.Value:
            case Script.Value:
                break;

            // Require input verification
            case Batch.Value:
            case DatFromDir.Value:
            case Extract.Value:
            case Restore.Value:
            case Split.Value:
            case Stats.Value:
            case Update.Value:
            case Verify.Value:
                VerifyInputs(feature.Inputs, featureName);
                feature.ProcessFeatures(features);
                break;

            // Requires no input verification
            case Sort.Value:
                feature.ProcessFeatures(features);
                break;

            // If nothing is set, show the help
            default:
                _help.OutputGenericHelp();
                break;
            }

            LoggerImpl.Close();
            return;
        }
Exemple #2
0
        /// <summary>
        /// Entry class for the RombaSharp application
        /// </summary>
        public static void Main(string[] args)
        {
            // Perform initial setup and verification
            LoggerImpl.SetFilename(Path.Combine(PathTool.GetRuntimeDirectory(), "logs", "romba.log"), true);
            LoggerImpl.AppendPrefix   = true;
            LoggerImpl.LowestLogLevel = LogLevel.VERBOSE;
            LoggerImpl.ThrowOnError   = false;
            LoggerImpl.Start();

            // Create a new Help object for this program
            _help = RetrieveHelp();

            // Credits take precidence over all
            if ((new List <string>(args)).Contains("--credits"))
            {
                _help.OutputCredits();
                LoggerImpl.Close();
                return;
            }

            // If there's no arguments, show help
            if (args.Length == 0)
            {
                _help.OutputGenericHelp();
                LoggerImpl.Close();
                return;
            }

            // Get the first argument as a feature flag
            string featureName = args[0];

            // Verify that the flag is valid
            if (!_help.TopLevelFlag(featureName))
            {
                logger.User($"'{featureName}' is not valid feature flag");
                _help.OutputIndividualFeature(featureName);
                LoggerImpl.Close();
                return;
            }

            // Get the proper name for the feature
            featureName = _help.GetFeatureName(featureName);

            // Get the associated feature
            BaseFeature feature = _help[featureName] as BaseFeature;

            // If we had the help feature first
            if (featureName == DisplayHelp.Value || featureName == DisplayHelpDetailed.Value)
            {
                feature.ProcessArgs(args, _help);
                LoggerImpl.Close();
                return;
            }

            // Now verify that all other flags are valid
            if (!feature.ProcessArgs(args, _help))
            {
                LoggerImpl.Close();
                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 <string, Feature> features = _help.GetEnabledFeatures();
            bool success = false;

            switch (featureName)
            {
            case DisplayHelpDetailed.Value:
            case DisplayHelp.Value:
                // No-op as this should be caught
                break;

            // Require input verification
            case Archive.Value:
            case Build.Value:
            case DatStats.Value:
            case Fixdat.Value:
            case Import.Value:
            case Lookup.Value:
            case Merge.Value:
            case Miss.Value:
            case RescanDepots.Value:
                VerifyInputs(feature.Inputs, featureName);
                success = feature.ProcessFeatures(features);
                break;

            // Requires no input verification
            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:
                success = feature.ProcessFeatures(features);
                break;

            // If nothing is set, show the help
            default:
                _help.OutputGenericHelp();
                break;
            }

            // If the feature failed, output help
            if (!success)
            {
                logger.Error("An error occurred during processing!");
                _help.OutputIndividualFeature(featureName);
            }

            LoggerImpl.Close();
            return;
        }
Exemple #3
0
        /// <summary>
        /// Entry point for the SabreTools application
        /// </summary>
        /// <param name="args">String array representing command line parameters</param>
        public static void Main(string[] args)
        {
            // Perform initial setup and verification
            LoggerImpl.SetFilename(Path.Combine(PathTool.GetRuntimeDirectory(), "logs", "sabretools.log"), true);
            LoggerImpl.AppendPrefix   = true;
            LoggerImpl.LowestLogLevel = LogLevel.VERBOSE;
            LoggerImpl.ThrowOnError   = false;
            LoggerImpl.Start();

            // Create a new Help object for this program
            _help = RetrieveHelp();

            // Credits take precidence over all
            if ((new List <string>(args)).Contains("--credits"))
            {
                _help.OutputCredits();
                LoggerImpl.Close();
                return;
            }

            // If there's no arguments, show help
            if (args.Length == 0)
            {
                _help.OutputGenericHelp();
                LoggerImpl.Close();
                return;
            }

            // Get the first argument as a feature flag
            string featureName = args[0];

            // TODO: Remove this block once trimming is no longer needed
            // TODO: Update wiki documentation ONLY after this reaches stable
            // TODO: Re-evaluate feature flags with this change in mind
            featureName = featureName.TrimStart('-');
            if (args[0].StartsWith("-"))
            {
                logger.User($"Feature flags no longer require leading '-' characters");
            }

            // Verify that the flag is valid
            if (!_help.TopLevelFlag(featureName))
            {
                logger.User($"'{featureName}' is not valid feature flag");
                _help.OutputIndividualFeature(featureName);
                LoggerImpl.Close();
                return;
            }

            // Get the proper name for the feature
            featureName = _help.GetFeatureName(featureName);

            // Get the associated feature
            BaseFeature feature = _help[featureName] as BaseFeature;

            // If we had the help feature first
            if (featureName == DisplayHelp.Value || featureName == DisplayHelpDetailed.Value)
            {
                feature.ProcessArgs(args, _help);
                LoggerImpl.Close();
                return;
            }

            // Now verify that all other flags are valid
            if (!feature.ProcessArgs(args, _help))
            {
                LoggerImpl.Close();
                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 <string, Feature> features = _help.GetEnabledFeatures();
            bool success = false;

            switch (featureName)
            {
            // No-op as these should be caught
            case DisplayHelp.Value:
            case DisplayHelpDetailed.Value:
                break;

            // Require input verification
            case Batch.Value:
            case DatFromDir.Value:
            case Extract.Value:
            case Restore.Value:
            case Split.Value:
            case Stats.Value:
            case Update.Value:
            case Verify.Value:
                VerifyInputs(feature.Inputs, feature);
                success = feature.ProcessFeatures(features);
                break;

            // Requires no input verification
            case Sort.Value:
                success = feature.ProcessFeatures(features);
                break;

            // If nothing is set, show the help
            default:
                _help.OutputGenericHelp();
                break;
            }

            // If the feature failed, output help
            if (!success)
            {
                logger.Error("An error occurred during processing!");
                _help.OutputIndividualFeature(featureName);
            }

            LoggerImpl.Close();
            return;
        }