diff --git a/RombaSharp/Features/Archive.cs b/RombaSharp/Features/Archive.cs index 49cf5217..83eb7891 100644 --- a/RombaSharp/Features/Archive.cs +++ b/RombaSharp/Features/Archive.cs @@ -45,9 +45,11 @@ have a current entry in the DAT index."; AddFeature(NoDbFlag); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get the archive scanning level // TODO: Remove usage @@ -201,6 +203,8 @@ have a current entry in the DAT index."; outDir: _depots.Keys.ToList()[0], outputFormat: OutputFormat.TorrentGzipRomba, asFiles: TreatAsFile.NonArchive); + + return true; } } } diff --git a/RombaSharp/Features/BaseFeature.cs b/RombaSharp/Features/BaseFeature.cs index 68adc8a0..e13af8c8 100644 --- a/RombaSharp/Features/BaseFeature.cs +++ b/RombaSharp/Features/BaseFeature.cs @@ -447,13 +447,14 @@ Possible values are: Verbose, User, Warning, Error"); #endregion - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { LogLevel = GetString(features, LogLevelStringValue).AsLogLevel(); ScriptMode = GetBoolean(features, ScriptValue); InitializeConfiguration(); EnsureDatabase(_db, _connectionString); + return true; } /// diff --git a/RombaSharp/Features/Build.cs b/RombaSharp/Features/Build.cs index 8409bd9f..00998563 100644 --- a/RombaSharp/Features/Build.cs +++ b/RombaSharp/Features/Build.cs @@ -35,9 +35,11 @@ structure according to the original DAT master directory tree structure."; AddFeature(SubworkersInt32Input); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags bool copy = GetBoolean(features, CopyValue); @@ -74,6 +76,8 @@ structure according to the original DAT master directory tree structure."; outDir: outputFolder, outputFormat: copy ? OutputFormat.TorrentGzipRomba : OutputFormat.TorrentZip); } + + return true; } } } diff --git a/RombaSharp/Features/Cancel.cs b/RombaSharp/Features/Cancel.cs index 562cc972..a25fa2b3 100644 --- a/RombaSharp/Features/Cancel.cs +++ b/RombaSharp/Features/Cancel.cs @@ -21,10 +21,14 @@ namespace RombaSharp.Features AddCommonFeatures(); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; + logger.User("This feature is not yet implemented: cancel"); + return true; } } } diff --git a/RombaSharp/Features/DatStats.cs b/RombaSharp/Features/DatStats.cs index 537ae920..349e4bd1 100644 --- a/RombaSharp/Features/DatStats.cs +++ b/RombaSharp/Features/DatStats.cs @@ -24,9 +24,11 @@ namespace RombaSharp.Features AddCommonFeatures(); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // If we have no inputs listed, we want to use datroot if (Inputs == null || Inputs.Count == 0) @@ -41,6 +43,8 @@ namespace RombaSharp.Features baddumpCol: true, nodumpCol: true, StatReportFormat.Textfile); + + return true; } } } diff --git a/RombaSharp/Features/DbStats.cs b/RombaSharp/Features/DbStats.cs index 564b5f42..85e8ff68 100644 --- a/RombaSharp/Features/DbStats.cs +++ b/RombaSharp/Features/DbStats.cs @@ -22,9 +22,11 @@ namespace RombaSharp.Features AddCommonFeatures(); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; SqliteConnection dbc = new SqliteConnection(_connectionString); dbc.Open(); @@ -51,6 +53,7 @@ namespace RombaSharp.Features slc.Dispose(); dbc.Dispose(); + return true; } } } diff --git a/RombaSharp/Features/Diffdat.cs b/RombaSharp/Features/Diffdat.cs index d7b0abd1..6d40c43a 100644 --- a/RombaSharp/Features/Diffdat.cs +++ b/RombaSharp/Features/Diffdat.cs @@ -32,9 +32,11 @@ in -old DAT file. Ignores those entries in -old that are not in -new."; AddFeature(DescriptionStringInput); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags string name = GetString(features, NameStringValue); @@ -50,13 +52,13 @@ in -old DAT file. Ignores those entries in -old that are not in -new."; if (!File.Exists(olddat)) { logger.Error($"File '{olddat}' does not exist!"); - return; + return false; } if (!File.Exists(newdat)) { logger.Error($"File '{newdat}' does not exist!"); - return; + return false; } // Create the encapsulating datfile @@ -69,6 +71,7 @@ in -old DAT file. Ignores those entries in -old that are not in -new."; DatFile intDat = Parser.CreateAndParse(newdat); DatFileTool.DiffAgainst(datfile, intDat, false); Writer.Write(intDat, outdat); + return true; } } } diff --git a/RombaSharp/Features/Dir2Dat.cs b/RombaSharp/Features/Dir2Dat.cs index d87ec687..3b1942c5 100644 --- a/RombaSharp/Features/Dir2Dat.cs +++ b/RombaSharp/Features/Dir2Dat.cs @@ -32,9 +32,11 @@ namespace RombaSharp.Features AddFeature(DescriptionStringInput); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags string name = GetString(features, NameStringValue); @@ -49,7 +51,7 @@ namespace RombaSharp.Features if (!Directory.Exists(source)) { logger.Error($"File '{source}' does not exist!"); - return; + return false; } // Create and write the encapsulating datfile @@ -58,6 +60,7 @@ namespace RombaSharp.Features datfile.Header.Description = description; DatFromDir.PopulateFromDir(datfile, source, asFiles: TreatAsFile.NonArchive, hashes: Hash.Standard); Writer.Write(datfile, outdat); + return true; } } } diff --git a/RombaSharp/Features/EDiffdat.cs b/RombaSharp/Features/EDiffdat.cs index 5047561d..97baa108 100644 --- a/RombaSharp/Features/EDiffdat.cs +++ b/RombaSharp/Features/EDiffdat.cs @@ -29,9 +29,11 @@ namespace RombaSharp.Features AddFeature(NewStringInput); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags string olddat = GetString(features, OldStringValue); @@ -45,13 +47,13 @@ namespace RombaSharp.Features if (!File.Exists(olddat)) { logger.Error($"File '{olddat}' does not exist!"); - return; + return false; } if (!File.Exists(newdat)) { logger.Error($"File '{newdat}' does not exist!"); - return; + return false; } // Create the encapsulating datfile @@ -61,6 +63,7 @@ namespace RombaSharp.Features DatFile intDat = Parser.CreateAndParse(newdat); DatFileTool.DiffAgainst(datfile, intDat, false); Writer.Write(intDat, outdat); + return true; } } } diff --git a/RombaSharp/Features/Export.cs b/RombaSharp/Features/Export.cs index 5170fe80..f3d01a9b 100644 --- a/RombaSharp/Features/Export.cs +++ b/RombaSharp/Features/Export.cs @@ -25,9 +25,11 @@ namespace RombaSharp.Features } // TODO: Add ability to say which depot the files are found in - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; SqliteConnection dbc = new SqliteConnection(_connectionString); dbc.Open(); @@ -69,6 +71,7 @@ namespace RombaSharp.Features slc.Dispose(); sw.Dispose(); dbc.Dispose(); + return true; } } } diff --git a/RombaSharp/Features/Fixdat.cs b/RombaSharp/Features/Fixdat.cs index 1da5a361..e6fee5a5 100644 --- a/RombaSharp/Features/Fixdat.cs +++ b/RombaSharp/Features/Fixdat.cs @@ -26,9 +26,11 @@ namespace RombaSharp.Features AddFeature(SubworkersInt32Input); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags // Inputs @@ -38,6 +40,7 @@ namespace RombaSharp.Features string outdat = GetString(features, OutStringValue); logger.Error("This feature is not yet implemented: fixdat"); + return true; } } } diff --git a/RombaSharp/Features/Import.cs b/RombaSharp/Features/Import.cs index 7f276baf..bc9b36e9 100644 --- a/RombaSharp/Features/Import.cs +++ b/RombaSharp/Features/Import.cs @@ -26,9 +26,12 @@ namespace RombaSharp.Features AddCommonFeatures(); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; + logger.Error("This feature is not yet implemented: import"); // First ensure the inputs and database connection @@ -121,6 +124,7 @@ namespace RombaSharp.Features slc.Dispose(); dbc.Dispose(); + return true; } } } diff --git a/RombaSharp/Features/Lookup.cs b/RombaSharp/Features/Lookup.cs index 0fde1228..90fadcb3 100644 --- a/RombaSharp/Features/Lookup.cs +++ b/RombaSharp/Features/Lookup.cs @@ -26,9 +26,11 @@ namespace RombaSharp.Features AddFeature(OutStringInput); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags long size = GetInt64(features, SizeInt64Value); @@ -123,6 +125,7 @@ namespace RombaSharp.Features } dbc.Dispose(); + return true; } } } diff --git a/RombaSharp/Features/Memstats.cs b/RombaSharp/Features/Memstats.cs index 75425f4f..d1084120 100644 --- a/RombaSharp/Features/Memstats.cs +++ b/RombaSharp/Features/Memstats.cs @@ -21,10 +21,14 @@ namespace RombaSharp.Features AddCommonFeatures(); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; + logger.User("This feature is not yet implemented: memstats"); + return true; } } } diff --git a/RombaSharp/Features/Merge.cs b/RombaSharp/Features/Merge.cs index 4335b268..13b02a06 100644 --- a/RombaSharp/Features/Merge.cs +++ b/RombaSharp/Features/Merge.cs @@ -30,9 +30,11 @@ namespace RombaSharp.Features } // TODO: Add way of specifying "current depot" since that's what Romba relies on - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags bool onlyNeeded = GetBoolean(features, OnlyNeededValue); @@ -74,6 +76,8 @@ namespace RombaSharp.Features } } + + return true; } } } diff --git a/RombaSharp/Features/Miss.cs b/RombaSharp/Features/Miss.cs index fdbeac8b..b3d9e5ea 100644 --- a/RombaSharp/Features/Miss.cs +++ b/RombaSharp/Features/Miss.cs @@ -26,9 +26,11 @@ namespace RombaSharp.Features AddCommonFeatures(); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Verify the filenames Dictionary foundDats = GetValidDats(Inputs); @@ -47,6 +49,7 @@ namespace RombaSharp.Features } logger.Error("This feature is not yet implemented: miss"); + return true; } } } diff --git a/RombaSharp/Features/Progress.cs b/RombaSharp/Features/Progress.cs index f1336414..b2978841 100644 --- a/RombaSharp/Features/Progress.cs +++ b/RombaSharp/Features/Progress.cs @@ -21,10 +21,14 @@ namespace RombaSharp.Features AddCommonFeatures(); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; + logger.User("This feature is not yet implemented: progress"); + return true; } } } diff --git a/RombaSharp/Features/PurgeBackup.cs b/RombaSharp/Features/PurgeBackup.cs index 6f104fd3..7bb6a54e 100644 --- a/RombaSharp/Features/PurgeBackup.cs +++ b/RombaSharp/Features/PurgeBackup.cs @@ -31,9 +31,11 @@ structure. It also deletes the specified DATs from the DAT index."; AddFeature(LogOnlyFlag); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags bool logOnly = GetBoolean(features, LogOnlyValue); @@ -43,6 +45,7 @@ structure. It also deletes the specified DATs from the DAT index."; List depot = GetList(features, DepotListStringValue); logger.Error("This feature is not yet implemented: purge-backup"); + return true; } } } diff --git a/RombaSharp/Features/PurgeDelete.cs b/RombaSharp/Features/PurgeDelete.cs index 592ac648..46b9f7e1 100644 --- a/RombaSharp/Features/PurgeDelete.cs +++ b/RombaSharp/Features/PurgeDelete.cs @@ -31,9 +31,11 @@ structure. It also deletes the specified DATs from the DAT index."; AddFeature(LogOnlyFlag); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags bool logOnly = GetBoolean(features, LogOnlyValue); @@ -42,6 +44,7 @@ structure. It also deletes the specified DATs from the DAT index."; List depot = GetList(features, DepotListStringValue); logger.Error("This feature is not yet implemented: purge-delete"); + return true; } } } diff --git a/RombaSharp/Features/RefreshDats.cs b/RombaSharp/Features/RefreshDats.cs index 7bd1f779..c8ac8e30 100644 --- a/RombaSharp/Features/RefreshDats.cs +++ b/RombaSharp/Features/RefreshDats.cs @@ -37,9 +37,11 @@ contents of any changed dats."; AddFeature(MissingSha1sStringInput); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags int workers = GetInt32(features, WorkersInt32Value); @@ -139,6 +141,7 @@ contents of any changed dats."; } dbc.Dispose(); + return true; } } } diff --git a/RombaSharp/Features/RescanDepots.cs b/RombaSharp/Features/RescanDepots.cs index 9c319320..4b056566 100644 --- a/RombaSharp/Features/RescanDepots.cs +++ b/RombaSharp/Features/RescanDepots.cs @@ -30,9 +30,12 @@ namespace RombaSharp.Features AddCommonFeatures(); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; + logger.Error("This feature is not yet implemented: rescan-depots"); foreach (string depotname in Inputs) @@ -41,14 +44,14 @@ namespace RombaSharp.Features if (!_depots.ContainsKey(depotname)) { logger.User($"'{depotname}' is not a recognized depot. Please add it to your configuration file and try again"); - return; + return false; } // Then check that the depot is online if (!Directory.Exists(depotname)) { logger.User($"'{depotname}' does not appear to be online. Please check its status and try again"); - return; + return false; } // Open the database connection @@ -165,6 +168,8 @@ WHERE sha1.sha1 IN "; slc.Dispose(); dbc.Dispose(); } + + return true; } } } diff --git a/RombaSharp/Features/Shutdown.cs b/RombaSharp/Features/Shutdown.cs index 2972f0e6..eeec1fa7 100644 --- a/RombaSharp/Features/Shutdown.cs +++ b/RombaSharp/Features/Shutdown.cs @@ -21,10 +21,14 @@ namespace RombaSharp.Features AddCommonFeatures(); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; + logger.User("This feature is not yet implemented: shutdown"); + return true; } } } diff --git a/RombaSharp/Features/Version.cs b/RombaSharp/Features/Version.cs index 4c946143..273c7245 100644 --- a/RombaSharp/Features/Version.cs +++ b/RombaSharp/Features/Version.cs @@ -22,10 +22,14 @@ namespace RombaSharp.Features AddCommonFeatures(); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; + logger.User($"RombaSharp version: {Prepare.Version}"); + return true; } } } diff --git a/RombaSharp/Program.cs b/RombaSharp/Program.cs index 0db331c8..5e228339 100644 --- a/RombaSharp/Program.cs +++ b/RombaSharp/Program.cs @@ -110,6 +110,7 @@ namespace RombaSharp // Now process the current feature Dictionary features = _help.GetEnabledFeatures(); + bool success = false; switch (featureName) { case DisplayHelpDetailed.Value: @@ -128,7 +129,7 @@ namespace RombaSharp case Miss.Value: case RescanDepots.Value: VerifyInputs(feature.Inputs, featureName); - feature.ProcessFeatures(features); + success = feature.ProcessFeatures(features); break; // Requires no input verification @@ -145,7 +146,7 @@ namespace RombaSharp case RefreshDats.Value: case Shutdown.Value: case Features.Version.Value: - feature.ProcessFeatures(features); + success = feature.ProcessFeatures(features); break; // If nothing is set, show the help @@ -154,6 +155,13 @@ namespace RombaSharp break; } + // If the feature failed, output help + if (!success) + { + logger.Error("An error occurred during processing!"); + _help.OutputIndividualFeature(featureName); + } + LoggerImpl.Close(); return; } diff --git a/SabreTools.Help/TopLevel.cs b/SabreTools.Help/TopLevel.cs index c354a33b..c0d88ab0 100644 --- a/SabreTools.Help/TopLevel.cs +++ b/SabreTools.Help/TopLevel.cs @@ -82,7 +82,8 @@ namespace SabreTools.Help /// /// Process and extract variables based on current feature /// - public virtual void ProcessFeatures(Dictionary features) { } + /// True if execution was successful, false otherwise + public virtual bool ProcessFeatures(Dictionary features) => true; #endregion diff --git a/SabreTools/Features/BaseFeature.cs b/SabreTools/Features/BaseFeature.cs index 51ae232d..5d54c15b 100644 --- a/SabreTools/Features/BaseFeature.cs +++ b/SabreTools/Features/BaseFeature.cs @@ -1853,7 +1853,7 @@ Some special strings that can be used: #endregion - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // Generic feature flags Cleaner = GetCleaner(features); @@ -1869,6 +1869,12 @@ Some special strings that can be used: // Set threading flag, if necessary if (features.ContainsKey(ThreadsInt32Value)) Globals.MaxThreads = GetInt32(features, ThreadsInt32Value); + + // Failure conditions + if (Header == null) + return false; + + return true; } #region Protected Specific Extraction diff --git a/SabreTools/Features/Batch.cs b/SabreTools/Features/Batch.cs index 54969dd0..4cf9303b 100644 --- a/SabreTools/Features/Batch.cs +++ b/SabreTools/Features/Batch.cs @@ -51,9 +51,11 @@ Reset the internal state: reset();"; AddCommonFeatures(); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Try to read each input as a batch run file foreach (string path in Inputs) @@ -62,6 +64,8 @@ Reset the internal state: reset();"; ProcessScript(path); watch.Stop(); } + + return true; } /// diff --git a/SabreTools/Features/DatFromDir.cs b/SabreTools/Features/DatFromDir.cs index 5870e1a4..bf8f14aa 100644 --- a/SabreTools/Features/DatFromDir.cs +++ b/SabreTools/Features/DatFromDir.cs @@ -53,9 +53,11 @@ namespace SabreTools.Features AddFeature(OutputDirStringInput); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags bool addBlankFiles = GetBoolean(features, AddBlankFilesValue); @@ -113,6 +115,8 @@ namespace SabreTools.Features } } } + + return true; } } } diff --git a/SabreTools/Features/Extract.cs b/SabreTools/Features/Extract.cs index e488b820..ea19c391 100644 --- a/SabreTools/Features/Extract.cs +++ b/SabreTools/Features/Extract.cs @@ -41,9 +41,11 @@ The following systems have headers that this program can work with: AddFeature(NoStoreHeaderFlag); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags bool nostore = GetBoolean(features, NoStoreHeaderValue); @@ -54,6 +56,8 @@ The following systems have headers that this program can work with: { DetectTransformStore(file.CurrentPath, OutputDir, nostore); } + + return true; } /// diff --git a/SabreTools/Features/Restore.cs b/SabreTools/Features/Restore.cs index f18e696f..951d7190 100644 --- a/SabreTools/Features/Restore.cs +++ b/SabreTools/Features/Restore.cs @@ -39,9 +39,11 @@ The following systems have headers that this program can work with: AddFeature(OutputDirStringInput); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get only files from the inputs List files = PathTool.GetFilesOnly(Inputs); @@ -49,6 +51,8 @@ The following systems have headers that this program can work with: { RestoreHeader(file.CurrentPath, OutputDir); } + + return true; } /// diff --git a/SabreTools/Features/Sort.cs b/SabreTools/Features/Sort.cs index c7f676c4..f1357027 100644 --- a/SabreTools/Features/Sort.cs +++ b/SabreTools/Features/Sort.cs @@ -58,9 +58,11 @@ namespace SabreTools.Features AddFeature(UpdateDatFlag); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags TreatAsFile asFiles = GetTreatAsFiles(features); @@ -161,6 +163,8 @@ namespace SabreTools.Features Writer.Write(datdata, OutputDir); } } + + return true; } } } diff --git a/SabreTools/Features/Split.cs b/SabreTools/Features/Split.cs index 01c11318..5020a893 100644 --- a/SabreTools/Features/Split.cs +++ b/SabreTools/Features/Split.cs @@ -44,14 +44,19 @@ namespace SabreTools.Features AddFeature(TypeFlag); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); - SplittingMode splittingMode = GetSplittingMode(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; - // If we somehow have the "none" split type, return + // Get the splitting mode + SplittingMode splittingMode = GetSplittingMode(features); if (splittingMode == SplittingMode.None) - return; + { + logger.Error("No valid splitting mode found!"); + return false; + } // Get only files from the inputs List files = PathTool.GetFilesOnly(Inputs, appendparent: true); @@ -155,6 +160,8 @@ namespace SabreTools.Features watch.Stop(); } } + + return true; } } } diff --git a/SabreTools/Features/Stats.cs b/SabreTools/Features/Stats.cs index f2b87806..8f67991a 100644 --- a/SabreTools/Features/Stats.cs +++ b/SabreTools/Features/Stats.cs @@ -43,9 +43,11 @@ The stats that are outputted are as follows: AddFeature(IndividualFlag); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; string filename = Header.FileName; if (Path.GetFileName(filename) != filename) @@ -66,6 +68,8 @@ The stats that are outputted are as follows: GetBoolean(features, BaddumpColumnValue), GetBoolean(features, NodumpColumnValue), GetStatReportFormat(features)); + + return true; } } } diff --git a/SabreTools/Features/Update.cs b/SabreTools/Features/Update.cs index d2da31aa..1bb54264 100644 --- a/SabreTools/Features/Update.cs +++ b/SabreTools/Features/Update.cs @@ -84,9 +84,11 @@ namespace SabreTools.Features AddFeature(InplaceFlag); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get feature flags var updateDatItemFields = GetUpdateDatItemFields(features); @@ -171,7 +173,7 @@ namespace SabreTools.Features Writer.Write(datFile, realOutDir, overwrite: GetBoolean(features, InplaceValue)); }); - return; + return true; } // Reverse inputs if we're in a required mode @@ -346,6 +348,8 @@ namespace SabreTools.Features Writer.Write(userInputDat, OutputDir); } + + return true; } } } diff --git a/SabreTools/Features/Verify.cs b/SabreTools/Features/Verify.cs index bb2a3d5d..828a7533 100644 --- a/SabreTools/Features/Verify.cs +++ b/SabreTools/Features/Verify.cs @@ -41,9 +41,11 @@ namespace SabreTools.Features AddFilteringFeatures(); } - public override void ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { - base.ProcessFeatures(features); + // If the base fails, just fail out + if (!base.ProcessFeatures(features)) + return false; // Get a list of files from the input datfiles var datfiles = GetList(features, DatListValue); @@ -148,6 +150,8 @@ namespace SabreTools.Features Writer.WriteStatsToConsole(datdata); Writer.Write(datdata, OutputDir); } + + return true; } } } diff --git a/SabreTools/Program.cs b/SabreTools/Program.cs index 994eab89..5db8aa1b 100644 --- a/SabreTools/Program.cs +++ b/SabreTools/Program.cs @@ -110,6 +110,7 @@ namespace SabreTools // Now process the current feature Dictionary features = _help.GetEnabledFeatures(); + bool success = false; switch (featureName) { // No-op as these should be caught @@ -127,12 +128,12 @@ namespace SabreTools case Update.Value: case Verify.Value: VerifyInputs(feature.Inputs, feature); - feature.ProcessFeatures(features); + success = feature.ProcessFeatures(features); break; // Requires no input verification case Sort.Value: - feature.ProcessFeatures(features); + success = feature.ProcessFeatures(features); break; // If nothing is set, show the help @@ -141,6 +142,13 @@ namespace SabreTools break; } + // If the feature failed, output help + if (!success) + { + logger.Error("An error occurred during processing!"); + _help.OutputIndividualFeature(featureName); + } + LoggerImpl.Close(); return; } @@ -193,13 +201,6 @@ namespace SabreTools _help.OutputIndividualFeature(feature.Name); Environment.Exit(0); } - - if (feature.Header == null) - { - logger.Error("Please check for errors in parameters"); - _help.OutputIndividualFeature(feature.Name); - Environment.Exit(0); - } } } }