From 3c0d190dc33da155fad540608c8a190037fee961 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 5 Mar 2024 20:26:38 -0500 Subject: [PATCH] Add nullability to the two programs (not enforced) --- RombaSharp/Features/Archive.cs | 15 ++-- RombaSharp/Features/BaseFeature.cs | 33 +++++---- RombaSharp/Features/Build.cs | 8 +- RombaSharp/Features/Cancel.cs | 4 +- RombaSharp/Features/DatStats.cs | 4 +- RombaSharp/Features/DbStats.cs | 12 +-- RombaSharp/Features/Diffdat.cs | 18 ++--- RombaSharp/Features/Dir2Dat.cs | 16 ++-- RombaSharp/Features/DisplayHelp.cs | 2 +- RombaSharp/Features/DisplayHelpDetailed.cs | 2 +- RombaSharp/Features/EDiffdat.cs | 14 ++-- RombaSharp/Features/Export.cs | 4 +- RombaSharp/Features/Fixdat.cs | 6 +- RombaSharp/Features/Import.cs | 8 +- RombaSharp/Features/Lookup.cs | 12 +-- RombaSharp/Features/Memstats.cs | 4 +- RombaSharp/Features/Merge.cs | 6 +- RombaSharp/Features/Miss.cs | 4 +- RombaSharp/Features/Progress.cs | 4 +- RombaSharp/Features/PurgeBackup.cs | 6 +- RombaSharp/Features/PurgeDelete.cs | 4 +- RombaSharp/Features/RefreshDats.cs | 8 +- RombaSharp/Features/RescanDepots.cs | 11 ++- RombaSharp/Features/Shutdown.cs | 4 +- RombaSharp/Features/Version.cs | 4 +- RombaSharp/Program.cs | 12 +-- RombaSharp/RombaSharp.csproj | 1 + SabreTools.DatTools/Statistics.cs | 6 +- SabreTools.Help/TopLevel.cs | 22 +++--- SabreTools/Features/BaseFeature.cs | 85 ++++++++-------------- SabreTools/Features/DatFromDir.cs | 7 +- SabreTools/Features/DisplayHelp.cs | 2 +- SabreTools/Features/DisplayHelpDetailed.cs | 2 +- SabreTools/Features/Extract.cs | 4 +- SabreTools/Features/Restore.cs | 4 +- SabreTools/Features/Sort.cs | 12 +-- SabreTools/Features/Split.cs | 14 ++-- SabreTools/Features/Stats.cs | 4 +- SabreTools/Features/Update.cs | 66 ++++++++--------- SabreTools/Features/Verify.cs | 36 +++++---- SabreTools/Features/Version.cs | 4 +- SabreTools/Program.cs | 2 +- SabreTools/SabreTools.csproj | 1 + 43 files changed, 238 insertions(+), 259 deletions(-) diff --git a/RombaSharp/Features/Archive.cs b/RombaSharp/Features/Archive.cs index b406c14a..ae12f269 100644 --- a/RombaSharp/Features/Archive.cs +++ b/RombaSharp/Features/Archive.cs @@ -29,7 +29,7 @@ Unpacked files will be stored as individual entries. Prior to unpacking a zip file, the external SHA1 is checked against the DAT index. 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(); + Features = []; // Common Features AddCommonFeatures(); @@ -45,7 +45,7 @@ have a current entry in the DAT index."; AddFeature(NoDbFlag); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) @@ -93,7 +93,10 @@ have a current entry in the DAT index."; foreach (string key in df.Items.Keys) { - ConcurrentList datItems = df.Items[key]; + ConcurrentList? datItems = df.Items[key]; + if (datItems == null) + continue; + foreach (Rom rom in datItems) { // If we care about if the file exists, check the databse first @@ -117,7 +120,7 @@ have a current entry in the DAT index."; if (!string.IsNullOrWhiteSpace(rom.SHA1)) { - sha1query += $" (\"{rom.SHA1}\", \"{_depots.Keys.ToList()[0]}\"),"; + sha1query += $" (\"{rom.SHA1}\", \"{_depots!.Keys.ToList()[0]}\"),"; if (!string.IsNullOrWhiteSpace(rom.CRC)) crcsha1query += $" (\"{rom.CRC}\", \"{rom.SHA1}\"),"; @@ -144,7 +147,7 @@ have a current entry in the DAT index."; if (!string.IsNullOrWhiteSpace(rom.SHA1)) { - sha1query += $" (\"{rom.SHA1}\", \"{_depots.Keys.ToList()[0]}\"),"; + sha1query += $" (\"{rom.SHA1}\", \"{_depots!.Keys.ToList()[0]}\"),"; if (!string.IsNullOrWhiteSpace(rom.CRC)) crcsha1query += $" (\"{rom.CRC}\", \"{rom.SHA1}\"),"; @@ -200,7 +203,7 @@ have a current entry in the DAT index."; Rebuilder.RebuildGeneric( need, onlyDirs, - outDir: _depots.Keys.ToList()[0], + outDir: _depots!.Keys.ToList()[0], outputFormat: OutputFormat.TorrentGzipRomba, asFiles: TreatAsFile.NonArchive); diff --git a/RombaSharp/Features/BaseFeature.cs b/RombaSharp/Features/BaseFeature.cs index eff3d02a..3fb2037a 100644 --- a/RombaSharp/Features/BaseFeature.cs +++ b/RombaSharp/Features/BaseFeature.cs @@ -411,26 +411,26 @@ Possible values are: Verbose, User, Warning, Error"); #region Settings // General settings - internal static string _logdir; // Log folder location - internal static string _tmpdir; // Temp folder location - internal static string _webdir; // Web frontend location - internal static string _baddir; // Fail-to-unpack file folder location + internal static string? _logdir; // Log folder location + internal static string? _tmpdir; // Temp folder location + internal static string? _webdir; // Web frontend location + internal static string? _baddir; // Fail-to-unpack file folder location internal static int _verbosity; // Verbosity of the output internal static int _cores; // Forced CPU cores // DatRoot settings - internal static string _dats; // DatRoot folder location - internal static string _db; // Database name + internal static string? _dats; // DatRoot folder location + internal static string? _db; // Database name // Depot settings - internal static Dictionary> _depots; // Folder location, Max size + internal static Dictionary>? _depots; // Folder location, Max size // Server settings internal static int _port; // Web server port // Other internal variables internal const string _config = "config.xml"; - internal static string _connectionString; + internal static string? _connectionString; #endregion @@ -447,7 +447,7 @@ Possible values are: Verbose, User, Warning, Error"); #endregion - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { LogLevel = GetString(features, LogLevelStringValue).AsEnumValue(); ScriptMode = GetBoolean(features, ScriptValue); @@ -462,8 +462,12 @@ Possible values are: Verbose, User, Warning, Error"); /// /// Name of the databse /// Connection string for SQLite - public void EnsureDatabase(string db, string connectionString) + public void EnsureDatabase(string? db, string? connectionString) { + // Missing database or connection string can't work + if (db == null || connectionString == null) + return; + // Make sure the file exists if (!System.IO.File.Exists(db)) System.IO.File.Create(db); @@ -559,8 +563,9 @@ CREATE TABLE IF NOT EXISTS dat ( if (lowerCaseDats.Contains(input.ToLowerInvariant())) { string fullpath = Path.GetFullPath(datRootDats[lowerCaseDats.IndexOf(input.ToLowerInvariant())]); - string sha1 = TextHelper.ByteArrayToString(BaseFile.GetInfo(fullpath, hashes: [HashType.SHA1]).SHA1); - foundDats.Add(sha1, fullpath); + string? sha1 = TextHelper.ByteArrayToString(BaseFile.GetInfo(fullpath, hashes: [HashType.SHA1])?.SHA1); + if (sha1 != null) + foundDats.Add(sha1, fullpath); } else { @@ -787,7 +792,7 @@ CREATE TABLE IF NOT EXISTS dat ( DatFile tempdat = Parser.CreateAndParse(fullpath); // If the Dat wasn't empty, add the information - SqliteCommand slc = null; + SqliteCommand? slc = null; string crcquery = "INSERT OR IGNORE INTO crc (crc) VALUES"; string md5query = "INSERT OR IGNORE INTO md5 (md5) VALUES"; string sha1query = "INSERT OR IGNORE INTO sha1 (sha1) VALUES"; @@ -798,7 +803,7 @@ CREATE TABLE IF NOT EXISTS dat ( bool hasItems = false; foreach (string romkey in tempdat.Items.Keys) { - foreach (DatItem datItem in tempdat.Items[romkey]) + foreach (DatItem datItem in tempdat.Items[romkey]!) { logger.Verbose($"Checking and adding file '{datItem.GetName() ?? string.Empty}'"); diff --git a/RombaSharp/Features/Build.cs b/RombaSharp/Features/Build.cs index 00998563..6e194a43 100644 --- a/RombaSharp/Features/Build.cs +++ b/RombaSharp/Features/Build.cs @@ -23,7 +23,7 @@ namespace RombaSharp.Features LongDescription = @"For each specified DAT file it creates the torrentzip files in the specified 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(); + Features = []; // Common Features AddCommonFeatures(); @@ -35,7 +35,7 @@ structure according to the original DAT master directory tree structure."; AddFeature(SubworkersInt32Input); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) @@ -43,7 +43,7 @@ structure according to the original DAT master directory tree structure."; // Get feature flags bool copy = GetBoolean(features, CopyValue); - string outdat = GetString(features, OutStringValue); + string? outdat = GetString(features, OutStringValue); // Verify the filenames Dictionary foundDats = GetValidDats(Inputs); @@ -67,7 +67,7 @@ structure according to the original DAT master directory tree structure."; outputFolder.Ensure(create: true); // Get all online depots - List onlineDepots = _depots.Where(d => d.Value.Item2).Select(d => d.Key).ToList(); + List onlineDepots = _depots!.Where(d => d.Value.Item2).Select(d => d.Key).ToList(); // Now scan all of those depots and rebuild Rebuilder.RebuildDepot( diff --git a/RombaSharp/Features/Cancel.cs b/RombaSharp/Features/Cancel.cs index a25fa2b3..55ef5668 100644 --- a/RombaSharp/Features/Cancel.cs +++ b/RombaSharp/Features/Cancel.cs @@ -15,13 +15,13 @@ namespace RombaSharp.Features Description = "Cancels current long-running job"; _featureType = ParameterType.Flag; LongDescription = "Cancels current long-running job."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/RombaSharp/Features/DatStats.cs b/RombaSharp/Features/DatStats.cs index 349e4bd1..376c4d96 100644 --- a/RombaSharp/Features/DatStats.cs +++ b/RombaSharp/Features/DatStats.cs @@ -18,13 +18,13 @@ namespace RombaSharp.Features Description = "Prints dat stats."; _featureType = ParameterType.Flag; LongDescription = "Print dat stats."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/RombaSharp/Features/DbStats.cs b/RombaSharp/Features/DbStats.cs index 85e8ff68..ee601a75 100644 --- a/RombaSharp/Features/DbStats.cs +++ b/RombaSharp/Features/DbStats.cs @@ -16,13 +16,13 @@ namespace RombaSharp.Features Description = "Prints db stats."; _featureType = ParameterType.Flag; LongDescription = "Print db stats."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) @@ -34,22 +34,22 @@ namespace RombaSharp.Features // Total number of CRCs string query = "SELECT COUNT(*) FROM crc"; SqliteCommand slc = new SqliteCommand(query, dbc); - logger.User($"Total CRCs: {(long)slc.ExecuteScalar()}"); + logger.User($"Total CRCs: {(long)slc.ExecuteScalar()!}"); // Total number of MD5s query = "SELECT COUNT(*) FROM md5"; slc = new SqliteCommand(query, dbc); - logger.User($"Total MD5s: {(long)slc.ExecuteScalar()}"); + logger.User($"Total MD5s: {(long)slc.ExecuteScalar()!}"); // Total number of SHA1s query = "SELECT COUNT(*) FROM sha1"; slc = new SqliteCommand(query, dbc); - logger.User($"Total SHA1s: {(long)slc.ExecuteScalar()}"); + logger.User($"Total SHA1s: {(long)slc.ExecuteScalar()!}"); // Total number of DATs query = "SELECT COUNT(*) FROM dat"; slc = new SqliteCommand(query, dbc); - logger.User($"Total DATs: {(long)slc.ExecuteScalar()}"); + logger.User($"Total DATs: {(long)slc.ExecuteScalar()!}"); slc.Dispose(); dbc.Dispose(); diff --git a/RombaSharp/Features/Diffdat.cs b/RombaSharp/Features/Diffdat.cs index 6d40c43a..935d5c27 100644 --- a/RombaSharp/Features/Diffdat.cs +++ b/RombaSharp/Features/Diffdat.cs @@ -20,7 +20,7 @@ namespace RombaSharp.Features _featureType = ParameterType.Flag; LongDescription = @"Creates a DAT file with those entries that are in -new DAT file and not in -old DAT file. Ignores those entries in -old that are not in -new."; - this.Features = new Dictionary(); + this.Features = []; // Common Features AddCommonFeatures(); @@ -32,21 +32,21 @@ in -old DAT file. Ignores those entries in -old that are not in -new."; AddFeature(DescriptionStringInput); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) return false; // Get feature flags - string name = GetString(features, NameStringValue); - string description = GetString(features, DescriptionStringValue); - string newdat = GetString(features, NewStringValue); - string olddat = GetString(features, OldStringValue); - string outdat = GetString(features, OutStringValue); + string? name = GetString(features, NameStringValue); + string? description = GetString(features, DescriptionStringValue); + string? newdat = GetString(features, NewStringValue); + string? olddat = GetString(features, OldStringValue); + string? outdat = GetString(features, OutStringValue); // Ensure the output directory - outdat.Ensure(create: true); + outdat = outdat?.Ensure(create: true); // Check that all required files exist if (!File.Exists(olddat)) @@ -70,7 +70,7 @@ in -old DAT file. Ignores those entries in -old that are not in -new."; // Diff against the new datfile DatFile intDat = Parser.CreateAndParse(newdat); DatFileTool.DiffAgainst(datfile, intDat, false); - Writer.Write(intDat, outdat); + Writer.Write(intDat, outdat!); return true; } } diff --git a/RombaSharp/Features/Dir2Dat.cs b/RombaSharp/Features/Dir2Dat.cs index ee43debe..0f80b353 100644 --- a/RombaSharp/Features/Dir2Dat.cs +++ b/RombaSharp/Features/Dir2Dat.cs @@ -20,7 +20,7 @@ namespace RombaSharp.Features Description = "Creates a DAT file for the specified input directory and saves it to the -out filename."; _featureType = ParameterType.Flag; LongDescription = "Creates a DAT file for the specified input directory and saves it to the -out filename."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); @@ -31,20 +31,20 @@ namespace RombaSharp.Features AddFeature(DescriptionStringInput); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) return false; // Get feature flags - string name = GetString(features, NameStringValue); - string description = GetString(features, DescriptionStringValue); - string source = GetString(features, SourceStringValue); - string outdat = GetString(features, OutStringValue); + string? name = GetString(features, NameStringValue); + string? description = GetString(features, DescriptionStringValue); + string? source = GetString(features, SourceStringValue); + string? outdat = GetString(features, OutStringValue); // Ensure the output directory - outdat.Ensure(create: true); + outdat = outdat?.Ensure(create: true); // Check that all required directories exist if (!Directory.Exists(source)) @@ -58,7 +58,7 @@ namespace RombaSharp.Features datfile.Header.Name = string.IsNullOrWhiteSpace(name) ? "untitled" : name; datfile.Header.Description = description; DatFromDir.PopulateFromDir(datfile, source, asFiles: TreatAsFile.NonArchive, hashes: [HashType.CRC32, HashType.MD5, HashType.SHA1]); - Writer.Write(datfile, outdat); + Writer.Write(datfile, outdat!); return true; } } diff --git a/RombaSharp/Features/DisplayHelp.cs b/RombaSharp/Features/DisplayHelp.cs index 0ad5c33e..8e28e3c2 100644 --- a/RombaSharp/Features/DisplayHelp.cs +++ b/RombaSharp/Features/DisplayHelp.cs @@ -15,7 +15,7 @@ namespace RombaSharp.Features Description = "Show this help"; _featureType = ParameterType.Flag; LongDescription = "Built-in to most of the programs is a basic help text."; - Features = new Dictionary(); + Features = []; } public override bool ProcessArgs(string[] args, FeatureSet help) diff --git a/RombaSharp/Features/DisplayHelpDetailed.cs b/RombaSharp/Features/DisplayHelpDetailed.cs index d54119f9..9a647ec8 100644 --- a/RombaSharp/Features/DisplayHelpDetailed.cs +++ b/RombaSharp/Features/DisplayHelpDetailed.cs @@ -15,7 +15,7 @@ namespace RombaSharp.Features Description = "Show this detailed help"; _featureType = ParameterType.Flag; LongDescription = "Display a detailed help text to the screen."; - Features = new Dictionary(); + Features = []; } public override bool ProcessArgs(string[] args, FeatureSet help) diff --git a/RombaSharp/Features/EDiffdat.cs b/RombaSharp/Features/EDiffdat.cs index 97baa108..d2a81da1 100644 --- a/RombaSharp/Features/EDiffdat.cs +++ b/RombaSharp/Features/EDiffdat.cs @@ -19,7 +19,7 @@ namespace RombaSharp.Features Description = "Creates a DAT file with those entries that are in -new DAT."; _featureType = ParameterType.Flag; 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(); + Features = []; // Common Features AddCommonFeatures(); @@ -29,19 +29,19 @@ namespace RombaSharp.Features AddFeature(NewStringInput); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) return false; // Get feature flags - string olddat = GetString(features, OldStringValue); - string outdat = GetString(features, OutStringValue); - string newdat = GetString(features, NewStringValue); + string? olddat = GetString(features, OldStringValue); + string? outdat = GetString(features, OutStringValue); + string? newdat = GetString(features, NewStringValue); // Ensure the output directory - outdat.Ensure(create: true); + outdat = outdat?.Ensure(create: true); // Check that all required files exist if (!File.Exists(olddat)) @@ -62,7 +62,7 @@ namespace RombaSharp.Features // Diff against the new datfile DatFile intDat = Parser.CreateAndParse(newdat); DatFileTool.DiffAgainst(datfile, intDat, false); - Writer.Write(intDat, outdat); + Writer.Write(intDat, outdat!); return true; } } diff --git a/RombaSharp/Features/Export.cs b/RombaSharp/Features/Export.cs index f3d01a9b..b929dd69 100644 --- a/RombaSharp/Features/Export.cs +++ b/RombaSharp/Features/Export.cs @@ -18,14 +18,14 @@ namespace RombaSharp.Features Description = "Exports db to export.csv"; _featureType = ParameterType.Flag; LongDescription = "Exports db to standardized export.csv"; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); } // TODO: Add ability to say which depot the files are found in - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/RombaSharp/Features/Fixdat.cs b/RombaSharp/Features/Fixdat.cs index e6fee5a5..a3b94056 100644 --- a/RombaSharp/Features/Fixdat.cs +++ b/RombaSharp/Features/Fixdat.cs @@ -15,7 +15,7 @@ namespace RombaSharp.Features Description = "For each specified DAT file it creates a fix DAT."; _featureType = ParameterType.Flag; 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(); + Features = []; // Common Features AddCommonFeatures(); @@ -26,7 +26,7 @@ namespace RombaSharp.Features AddFeature(SubworkersInt32Input); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) @@ -37,7 +37,7 @@ namespace RombaSharp.Features bool fixdatOnly = GetBoolean(features, FixdatOnlyValue); int subworkers = GetInt32(features, SubworkersInt32Value); int workers = GetInt32(features, WorkersInt32Value); - string outdat = GetString(features, OutStringValue); + 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 bc9b36e9..02dbcba5 100644 --- a/RombaSharp/Features/Import.cs +++ b/RombaSharp/Features/Import.cs @@ -20,13 +20,13 @@ namespace RombaSharp.Features Description = "Import a database from a formatted CSV file"; _featureType = ParameterType.Flag; LongDescription = "Import a database from a formatted CSV file"; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) @@ -46,7 +46,7 @@ namespace RombaSharp.Features StreamReader sr = new StreamReader(File.OpenRead(input)); // The first line should be the hash header - string line = sr.ReadLine(); + string? line = sr.ReadLine(); if (line != "CRC,MD5,SHA-1") // ,Depot { logger.Error($"{input} is not a valid export file"); @@ -63,7 +63,7 @@ namespace RombaSharp.Features // For each line until we hit a blank line... while (!sr.EndOfStream && line != string.Empty) { - line = sr.ReadLine(); + line = sr.ReadLine() ?? string.Empty; string[] hashes = line.Split(','); // Loop through the parsed entries diff --git a/RombaSharp/Features/Lookup.cs b/RombaSharp/Features/Lookup.cs index 90fadcb3..27a6fa74 100644 --- a/RombaSharp/Features/Lookup.cs +++ b/RombaSharp/Features/Lookup.cs @@ -17,7 +17,7 @@ namespace RombaSharp.Features Description = "For each specified hash it looks up any available information."; _featureType = ParameterType.Flag; LongDescription = "For each specified hash it looks up any available information (dat or rom)."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); @@ -26,7 +26,7 @@ namespace RombaSharp.Features AddFeature(OutStringInput); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) @@ -34,12 +34,12 @@ namespace RombaSharp.Features // Get feature flags long size = GetInt64(features, SizeInt64Value); - string outdat = GetString(features, OutStringValue); + string? outdat = GetString(features, OutStringValue); // First, try to figure out what type of hash each is by length and clean it - List crc = new List(); - List md5 = new List(); - List sha1 = new List(); + List crc = []; + List md5 = []; + List sha1 = []; foreach (string input in Inputs) { if (input.Length == Constants.CRCLength) diff --git a/RombaSharp/Features/Memstats.cs b/RombaSharp/Features/Memstats.cs index d1084120..60918bde 100644 --- a/RombaSharp/Features/Memstats.cs +++ b/RombaSharp/Features/Memstats.cs @@ -15,13 +15,13 @@ namespace RombaSharp.Features Description = "Prints memory stats."; _featureType = ParameterType.Flag; LongDescription = "Print memory stats."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/RombaSharp/Features/Merge.cs b/RombaSharp/Features/Merge.cs index 5427073b..27980246 100644 --- a/RombaSharp/Features/Merge.cs +++ b/RombaSharp/Features/Merge.cs @@ -18,7 +18,7 @@ namespace RombaSharp.Features Description = "Merges depot"; _featureType = ParameterType.Flag; LongDescription = "Merges specified depot into current depot."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); @@ -30,7 +30,7 @@ namespace RombaSharp.Features } // TODO: Add way of specifying "current depot" since that's what Romba relies on - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) @@ -40,7 +40,7 @@ namespace RombaSharp.Features bool onlyNeeded = GetBoolean(features, OnlyNeededValue); bool skipInitialscan = GetBoolean(features, SkipInitialScanValue); int workers = GetInt32(features, WorkersInt32Value); - string resume = GetString(features, ResumeStringValue); + string? resume = GetString(features, ResumeStringValue); logger.Error("This feature is not yet implemented: merge"); diff --git a/RombaSharp/Features/Miss.cs b/RombaSharp/Features/Miss.cs index b3d9e5ea..1dbcba8f 100644 --- a/RombaSharp/Features/Miss.cs +++ b/RombaSharp/Features/Miss.cs @@ -20,13 +20,13 @@ namespace RombaSharp.Features Description = "Create miss and have file"; _featureType = ParameterType.Flag; LongDescription = "For each specified DAT file, create miss and have file"; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/RombaSharp/Features/Progress.cs b/RombaSharp/Features/Progress.cs index b2978841..bd62c2eb 100644 --- a/RombaSharp/Features/Progress.cs +++ b/RombaSharp/Features/Progress.cs @@ -15,13 +15,13 @@ namespace RombaSharp.Features Description = "Shows progress of the currently running command."; _featureType = ParameterType.Flag; LongDescription = "Shows progress of the currently running command."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/RombaSharp/Features/PurgeBackup.cs b/RombaSharp/Features/PurgeBackup.cs index 7bb6a54e..277d20da 100644 --- a/RombaSharp/Features/PurgeBackup.cs +++ b/RombaSharp/Features/PurgeBackup.cs @@ -19,7 +19,7 @@ longer associated with any current DATs to the specified backup folder. The files will be placed in the backup location using 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(); + Features = []; // Common Features AddCommonFeatures(); @@ -31,7 +31,7 @@ structure. It also deletes the specified DATs from the DAT index."; AddFeature(LogOnlyFlag); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) @@ -40,7 +40,7 @@ structure. It also deletes the specified DATs from the DAT index."; // Get feature flags bool logOnly = GetBoolean(features, LogOnlyValue); int workers = GetInt32(features, WorkersInt32Value); - string backup = GetString(features, BackupStringValue); + string? backup = GetString(features, BackupStringValue); List dats = GetList(features, DatsListStringValue); List depot = GetList(features, DepotListStringValue); diff --git a/RombaSharp/Features/PurgeDelete.cs b/RombaSharp/Features/PurgeDelete.cs index 46b9f7e1..c196ef62 100644 --- a/RombaSharp/Features/PurgeDelete.cs +++ b/RombaSharp/Features/PurgeDelete.cs @@ -20,7 +20,7 @@ longer associated with any current DATs to the specified backup folder. The files will be placed in the backup location using 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(); + Features = []; // Common Features AddCommonFeatures(); @@ -31,7 +31,7 @@ structure. It also deletes the specified DATs from the DAT index."; AddFeature(LogOnlyFlag); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/RombaSharp/Features/RefreshDats.cs b/RombaSharp/Features/RefreshDats.cs index a0bf6b8d..22898e70 100644 --- a/RombaSharp/Features/RefreshDats.cs +++ b/RombaSharp/Features/RefreshDats.cs @@ -27,7 +27,7 @@ namespace RombaSharp.Features Detects any changes in the DAT master directory tree and updates the DAT index accordingly, marking deleted or overwritten dats as orphaned and updating contents of any changed dats."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); @@ -36,7 +36,7 @@ contents of any changed dats."; AddFeature(MissingSha1sStringInput); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) @@ -44,7 +44,7 @@ contents of any changed dats."; // Get feature flags int workers = GetInt32(features, WorkersInt32Value); - string missingSha1s = GetString(features, MissingSha1sStringValue); + string? missingSha1s = GetString(features, MissingSha1sStringValue); // Make sure the db is set if (string.IsNullOrWhiteSpace(_db)) @@ -112,7 +112,7 @@ contents of any changed dats."; watch.Start("Adding new DAT information"); foreach (string key in datroot.Items.Keys) { - foreach (Rom value in datroot.Items[key]) + foreach (Rom value in datroot.Items[key]!) { AddDatToDatabase(value, dbc); } diff --git a/RombaSharp/Features/RescanDepots.cs b/RombaSharp/Features/RescanDepots.cs index 41427e94..4d1a4a05 100644 --- a/RombaSharp/Features/RescanDepots.cs +++ b/RombaSharp/Features/RescanDepots.cs @@ -24,13 +24,13 @@ namespace RombaSharp.Features Description = "Rescan a specific depot to get new information"; _featureType = ParameterType.Flag; LongDescription = "Rescan a specific depot to get new information"; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) @@ -41,7 +41,7 @@ namespace RombaSharp.Features foreach (string depotname in Inputs) { // Check that it's a valid depot first - if (!_depots.ContainsKey(depotname)) + if (!_depots!.ContainsKey(depotname)) { logger.User($"'{depotname}' is not a recognized depot. Please add it to your configuration file and try again"); return false; @@ -88,7 +88,10 @@ namespace RombaSharp.Features IEnumerable keys = depot.Items.Keys; foreach (string key in keys) { - ConcurrentList roms = depot.Items[key]; + ConcurrentList? roms = depot.Items[key]; + if (roms == null) + continue; + foreach (Rom rom in roms) { if (hashes.Contains(rom.SHA1)) diff --git a/RombaSharp/Features/Shutdown.cs b/RombaSharp/Features/Shutdown.cs index eeec1fa7..636b78f5 100644 --- a/RombaSharp/Features/Shutdown.cs +++ b/RombaSharp/Features/Shutdown.cs @@ -15,13 +15,13 @@ namespace RombaSharp.Features Description = "Gracefully shuts down server."; _featureType = ParameterType.Flag; LongDescription = "Gracefully shuts down server saving all the cached data."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/RombaSharp/Features/Version.cs b/RombaSharp/Features/Version.cs index a9a649b2..587dcc1b 100644 --- a/RombaSharp/Features/Version.cs +++ b/RombaSharp/Features/Version.cs @@ -16,13 +16,13 @@ namespace RombaSharp.Features Description = "Prints version"; _featureType = ParameterType.Flag; LongDescription = "Prints current program version."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/RombaSharp/Program.cs b/RombaSharp/Program.cs index e8bda3d7..fd4a1bec 100644 --- a/RombaSharp/Program.cs +++ b/RombaSharp/Program.cs @@ -25,7 +25,7 @@ namespace RombaSharp /// /// Help object that determines available functionality /// - private static FeatureSet _help; + private static FeatureSet? _help; /// /// Logging object @@ -81,18 +81,18 @@ namespace RombaSharp featureName = _help.GetFeatureName(featureName); // Get the associated feature - BaseFeature feature = _help[featureName] as BaseFeature; + BaseFeature? feature = _help[featureName] as BaseFeature; // If we had the help feature first if (featureName == DisplayHelp.Value || featureName == DisplayHelpDetailed.Value) { - feature.ProcessArgs(args, _help); + feature!.ProcessArgs(args, _help); LoggerImpl.Close(); return; } // Now verify that all other flags are valid - if (!feature.ProcessArgs(args, _help)) + if (!feature!.ProcessArgs(args, _help)) { LoggerImpl.Close(); return; @@ -109,7 +109,7 @@ namespace RombaSharp } // Now process the current feature - Dictionary features = _help.GetEnabledFeatures(); + Dictionary features = _help.GetEnabledFeatures(); bool success = false; switch (featureName) { @@ -224,7 +224,7 @@ namespace RombaSharp if (inputs.Count == 0) { logger.Error("This feature requires at least one input"); - _help.OutputIndividualFeature(feature); + _help?.OutputIndividualFeature(feature); Environment.Exit(0); } } diff --git a/RombaSharp/RombaSharp.csproj b/RombaSharp/RombaSharp.csproj index 839bfb2e..9e2c4a12 100644 --- a/RombaSharp/RombaSharp.csproj +++ b/RombaSharp/RombaSharp.csproj @@ -5,6 +5,7 @@ net6.0;net8.0 win-x86;win-x64;linux-x64;osx-x64 latest + enable Matt Nadareski Copyright (c)2016-2024 Matt Nadareski MIT diff --git a/SabreTools.DatTools/Statistics.cs b/SabreTools.DatTools/Statistics.cs index dcb236c5..603bfd92 100644 --- a/SabreTools.DatTools/Statistics.cs +++ b/SabreTools.DatTools/Statistics.cs @@ -153,7 +153,7 @@ namespace SabreTools.DatTools public static bool Write( List stats, string reportName, - string outDir, + string? outDir, bool baddumpCol, bool nodumpCol, StatReportFormat statDatFormat, @@ -171,12 +171,12 @@ namespace SabreTools.DatTools reportName = "report"; // Get the proper output directory name - outDir = outDir.Ensure(); + outDir = outDir?.Ensure(); InternalStopwatch watch = new($"Writing out report data to '{outDir}'"); // Get the dictionary of desired output report names - Dictionary outfiles = CreateOutStatsNames(outDir, statDatFormat, reportName); + Dictionary outfiles = CreateOutStatsNames(outDir!, statDatFormat, reportName); try { diff --git a/SabreTools.Help/TopLevel.cs b/SabreTools.Help/TopLevel.cs index 4df08930..661ab9c6 100644 --- a/SabreTools.Help/TopLevel.cs +++ b/SabreTools.Help/TopLevel.cs @@ -16,7 +16,7 @@ namespace SabreTools.Help /// /// List of files, directories, and potential wildcard paths /// - public List Inputs = new(); + public List Inputs = []; #endregion @@ -87,7 +87,7 @@ namespace SabreTools.Help /// Process and extract variables based on current feature /// /// True if execution was successful, false otherwise - public virtual bool ProcessFeatures(Dictionary features) => true; + public virtual bool ProcessFeatures(Dictionary features) => true; #endregion @@ -96,7 +96,7 @@ namespace SabreTools.Help /// /// Get boolean value from nullable feature /// - protected static bool GetBoolean(Dictionary features, string key) + protected static bool GetBoolean(Dictionary features, string key) { if (!features.ContainsKey(key)) return false; @@ -107,45 +107,45 @@ namespace SabreTools.Help /// /// Get int value from nullable feature /// - protected static int GetInt32(Dictionary features, string key) + protected static int GetInt32(Dictionary features, string key) { if (!features.ContainsKey(key)) return Int32.MinValue; - return features[key].GetInt32Value(); + return features[key]!.GetInt32Value(); } /// /// Get long value from nullable feature /// - protected static long GetInt64(Dictionary features, string key) + protected static long GetInt64(Dictionary features, string key) { if (!features.ContainsKey(key)) return Int64.MinValue; - return features[key].GetInt64Value(); + return features[key]!.GetInt64Value(); } /// /// Get list value from nullable feature /// - protected static List GetList(Dictionary features, string key) + protected static List GetList(Dictionary features, string key) { if (!features.ContainsKey(key)) return []; - return features[key].GetListValue() ?? []; + return features[key]!.GetListValue() ?? []; } /// /// Get string value from nullable feature /// - protected static string? GetString(Dictionary features, string key) + protected static string? GetString(Dictionary features, string key) { if (!features.ContainsKey(key)) return null; - return features[key].GetStringValue(); + return features[key]!.GetStringValue(); } #endregion diff --git a/SabreTools/Features/BaseFeature.cs b/SabreTools/Features/BaseFeature.cs index a293022e..cd80a11b 100644 --- a/SabreTools/Features/BaseFeature.cs +++ b/SabreTools/Features/BaseFeature.cs @@ -1774,28 +1774,23 @@ Some special strings that can be used: /// /// Preconfigured Cleaner /// - protected Cleaner Cleaner { get; set; } + protected Cleaner? Cleaner { get; set; } /// /// Preconfigured ExtraIni set /// - protected ExtraIni Extras { get; set; } - - /// - /// Preconfigured Filter - /// - protected Filtering.Filter Filter { get; set; } + protected ExtraIni? Extras { get; set; } /// /// Preonfigured FilterRunner /// - protected Filter.FilterRunner FilterRunner { get; set; } + protected Filter.FilterRunner? FilterRunner { get; set; } /// /// Pre-configured DatHeader /// /// Public because it's an indicator something went wrong - public DatHeader Header { get; set; } + public DatHeader? Header { get; set; } /// /// Lowest log level for output @@ -1805,12 +1800,12 @@ Some special strings that can be used: /// /// Output directory /// - protected string OutputDir { get; set; } + protected string? OutputDir { get; set; } /// /// Pre-configured Remover /// - protected Remover Remover { get; set; } + protected Remover? Remover { get; set; } /// /// Determines if scripting mode is enabled @@ -1820,7 +1815,7 @@ Some special strings that can be used: /// /// Pre-configured Splitter /// - protected Filtering.Splitter Splitter { get; set; } + protected Filtering.Splitter? Splitter { get; set; } #endregion @@ -1873,7 +1868,7 @@ Some special strings that can be used: // Header Filters AddFeature(ExcludeFieldListInput); AddFeature(OneGamePerRegionFlag); - this[OneGamePerRegionFlag].AddFeature(RegionListInput); + this[OneGamePerRegionFlag]!.AddFeature(RegionListInput); AddFeature(OneRomPerGameFlag); AddFeature(SceneDateStripFlag); } @@ -1893,12 +1888,11 @@ Some special strings that can be used: #endregion - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // Generic feature flags Cleaner = GetCleaner(features); Extras = GetExtras(features); - Filter = GetFilter(features); FilterRunner = GetFilterRunner(features); Header = GetDatHeader(features); LogLevel = GetString(features, LogLevelStringValue).AsEnumValue(); @@ -1923,7 +1917,7 @@ Some special strings that can be used: /// /// Get include from scan from feature list /// - protected static HashType[] GetIncludeInScan(Dictionary features) + protected static HashType[] GetIncludeInScan(Dictionary features) { List includeInScan = []; @@ -1952,7 +1946,7 @@ Some special strings that can be used: /// /// Get OutputFormat from feature list /// - protected static OutputFormat GetOutputFormat(Dictionary features) + protected static OutputFormat GetOutputFormat(Dictionary features) { if (GetBoolean(features, TarValue)) return OutputFormat.TapeArchive; @@ -1981,7 +1975,7 @@ Some special strings that can be used: /// /// Get SkipFileType from feature list /// - protected static SkipFileType GetSkipFileType(Dictionary features) + protected static SkipFileType GetSkipFileType(Dictionary features) { if (GetBoolean(features, SkipArchivesValue)) return SkipFileType.Archive; @@ -1994,7 +1988,7 @@ Some special strings that can be used: /// /// Get SplittingMode from feature list /// - protected static SplittingMode GetSplittingMode(Dictionary features) + protected static SplittingMode GetSplittingMode(Dictionary features) { SplittingMode splittingMode = SplittingMode.None; @@ -2017,7 +2011,7 @@ Some special strings that can be used: /// /// Get StatReportFormat from feature list /// - protected static StatReportFormat GetStatReportFormat(Dictionary features) + protected static StatReportFormat GetStatReportFormat(Dictionary features) { StatReportFormat statDatFormat = StatReportFormat.None; @@ -2032,7 +2026,7 @@ Some special strings that can be used: /// /// Get TreatAsFiles from feature list /// - protected static TreatAsFile GetTreatAsFiles(Dictionary features) + protected static TreatAsFile GetTreatAsFiles(Dictionary features) { TreatAsFile asFiles = 0x00; if (GetBoolean(features, AaruFormatsAsFilesValue)) @@ -2048,13 +2042,13 @@ Some special strings that can be used: /// /// Get update Machine fields from feature list /// - protected static List GetUpdateMachineFields(Dictionary features) + protected static List GetUpdateMachineFields(Dictionary features) { List updateFields = []; foreach (string fieldName in GetList(features, UpdateFieldListValue)) { (string? itemType, string? key) = SabreTools.Filter.FilterParser.ParseFilterId(fieldName); - if (itemType == Models.Metadata.MetadataFile.MachineKey) + if (itemType == Models.Metadata.MetadataFile.MachineKey && key != null) updateFields.Add(key); } @@ -2064,13 +2058,13 @@ Some special strings that can be used: /// /// Get update DatItem fields from feature list /// - protected static Dictionary> GetUpdateDatItemFields(Dictionary features) + protected static Dictionary> GetUpdateDatItemFields(Dictionary features) { Dictionary> updateFields = []; foreach (string fieldName in GetList(features, UpdateFieldListValue)) { (string? itemType, string? key) = SabreTools.Filter.FilterParser.ParseFilterId(fieldName); - if (itemType != Models.Metadata.MetadataFile.HeaderKey && itemType != Models.Metadata.MetadataFile.MachineKey) + if (itemType != null && itemType != Models.Metadata.MetadataFile.HeaderKey && itemType != Models.Metadata.MetadataFile.MachineKey && key != null) { if (!updateFields.ContainsKey(itemType)) updateFields[itemType] = []; @@ -2085,7 +2079,7 @@ Some special strings that can be used: /// /// Get UpdateMode from feature list /// - protected static UpdateMode GetUpdateMode(Dictionary features) + protected static UpdateMode GetUpdateMode(Dictionary features) { UpdateMode updateMode = UpdateMode.None; @@ -2129,7 +2123,7 @@ Some special strings that can be used: /// /// Get Cleaner from feature list /// - private static Cleaner GetCleaner(Dictionary features) + private static Cleaner GetCleaner(Dictionary features) { Cleaner cleaner = new() { @@ -2153,10 +2147,10 @@ Some special strings that can be used: /// /// Get DatHeader from feature list /// - private DatHeader GetDatHeader(Dictionary features) + private DatHeader? GetDatHeader(Dictionary features) { // TODO: Sort this by region, like the actual header - DatHeader datHeader = new() + var datHeader = new DatHeader() { AddExtension = GetString(features, AddExtensionStringValue), Author = GetString(features, AuthorStringValue), @@ -2217,7 +2211,7 @@ Some special strings that can be used: /// /// Get DedupeType from feature list /// - private static DedupeType GetDedupeType(Dictionary features) + private static DedupeType GetDedupeType(Dictionary features) { if (GetBoolean(features, DedupValue)) return DedupeType.Full; @@ -2230,38 +2224,17 @@ Some special strings that can be used: /// /// Get ExtraIni from feature list /// - private static ExtraIni GetExtras(Dictionary features) + private static ExtraIni GetExtras(Dictionary features) { ExtraIni extraIni = new(); extraIni.PopulateFromList(GetList(features, ExtraIniListValue)); return extraIni; } - /// - /// Get Filter from feature list - /// - private static Filtering.Filter GetFilter(Dictionary features) - { - Filtering.Filter filter = new() - { - DatItemFilter = new DatItemFilter(), - MachineFilter = new MachineFilter(), - }; - - // Populate filters - List filterPairs = GetList(features, FilterListValue); - filter.PopulateFiltersFromList(filterPairs); - - // Include 'of" in game filters - filter.MachineFilter.IncludeOfInGame = GetBoolean(features, MatchOfTagsValue); - - return filter; - } - /// /// Get FilterRunner from feature list /// - private static Filter.FilterRunner GetFilterRunner(Dictionary features) + private static Filter.FilterRunner GetFilterRunner(Dictionary features) { // Populate filters List filterPairs = GetList(features, FilterListValue); @@ -2277,7 +2250,7 @@ Some special strings that can be used: /// /// Get Remover from feature list /// - private static Remover GetRemover(Dictionary features) + private static Remover GetRemover(Dictionary features) { Remover remover = new(); @@ -2291,7 +2264,7 @@ Some special strings that can be used: /// /// Get Splitter from feature list /// - private static Filtering.Splitter GetSplitter(Dictionary features) + private static Filtering.Splitter GetSplitter(Dictionary features) { Filtering.Splitter splitter = new() { @@ -2303,7 +2276,7 @@ Some special strings that can be used: /// /// Get SplitType from feature list /// - private static MergingFlag GetSplitType(Dictionary features) + private static MergingFlag GetSplitType(Dictionary features) { MergingFlag splitType = MergingFlag.None; if (GetBoolean(features, DatDeviceNonMergedValue)) diff --git a/SabreTools/Features/DatFromDir.cs b/SabreTools/Features/DatFromDir.cs index 86337ce1..335e6fe1 100644 --- a/SabreTools/Features/DatFromDir.cs +++ b/SabreTools/Features/DatFromDir.cs @@ -38,9 +38,9 @@ namespace SabreTools.Features AddFeature(ArchivesAsFilesFlag); AddFeature(ChdsAsFilesFlag); AddFeature(OutputTypeListInput); - this[OutputTypeListInput].AddFeature(DeprecatedFlag); + this[OutputTypeListInput]!.AddFeature(DeprecatedFlag); AddFeature(RombaFlag); - this[RombaFlag].AddFeature(RombaDepthInt32Input); + this[RombaFlag]!.AddFeature(RombaDepthInt32Input); AddFeature(SkipArchivesFlag); AddFeature(SkipFilesFlag); AddHeaderFeatures(); @@ -100,8 +100,7 @@ namespace SabreTools.Features // Perform additional processing steps Extras.ApplyExtras(datdata); Splitter.ApplySplitting(datdata, useTags: false); - Filter.ApplyFilters(datdata); - // datdata.ExecuteFilters(FilterRunner); // TODO: Replace Filter.ApplyFilters with this + datdata.ExecuteFilters(FilterRunner); Cleaner.ApplyCleaning(datdata); Remover.ApplyRemovals(datdata); diff --git a/SabreTools/Features/DisplayHelp.cs b/SabreTools/Features/DisplayHelp.cs index 1e3d3c78..c84fed2e 100644 --- a/SabreTools/Features/DisplayHelp.cs +++ b/SabreTools/Features/DisplayHelp.cs @@ -15,7 +15,7 @@ namespace SabreTools.Features Description = "Show this help"; _featureType = ParameterType.Flag; LongDescription = "Built-in to most of the programs is a basic help text."; - Features = new Dictionary(); + Features = []; } public override bool ProcessArgs(string[] args, FeatureSet help) diff --git a/SabreTools/Features/DisplayHelpDetailed.cs b/SabreTools/Features/DisplayHelpDetailed.cs index deaf4f80..77860c90 100644 --- a/SabreTools/Features/DisplayHelpDetailed.cs +++ b/SabreTools/Features/DisplayHelpDetailed.cs @@ -15,7 +15,7 @@ namespace SabreTools.Features Description = "Show this detailed help"; _featureType = ParameterType.Flag; LongDescription = "Display a detailed help text to the screen."; - Features = new Dictionary(); + Features = []; } public override bool ProcessArgs(string[] args, FeatureSet help) diff --git a/SabreTools/Features/Extract.cs b/SabreTools/Features/Extract.cs index f18974b0..455d3e50 100644 --- a/SabreTools/Features/Extract.cs +++ b/SabreTools/Features/Extract.cs @@ -32,7 +32,7 @@ The following systems have headers that this program can work with: - Nintendo Famicom Disk System - Nintendo Super Famicom / Super Nintendo Entertainment System - Nintendo Super Famicom / Super Nintendo Entertainment System SPC"; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); @@ -41,7 +41,7 @@ The following systems have headers that this program can work with: AddFeature(NoStoreHeaderFlag); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/SabreTools/Features/Restore.cs b/SabreTools/Features/Restore.cs index 63d960ae..7c5ef39c 100644 --- a/SabreTools/Features/Restore.cs +++ b/SabreTools/Features/Restore.cs @@ -31,7 +31,7 @@ The following systems have headers that this program can work with: - Nintendo Famicom Disk System - Nintendo Super Famicom / Super Nintendo Entertainment System - Nintendo Super Famicom / Super Nintendo Entertainment System SPC"; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); @@ -39,7 +39,7 @@ The following systems have headers that this program can work with: AddFeature(OutputDirStringInput); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/SabreTools/Features/Sort.cs b/SabreTools/Features/Sort.cs index 88346095..b15a65db 100644 --- a/SabreTools/Features/Sort.cs +++ b/SabreTools/Features/Sort.cs @@ -21,7 +21,7 @@ namespace SabreTools.Features Description = "Sort inputs by a set of DATs"; _featureType = ParameterType.Flag; LongDescription = "This feature allows the user to quickly rebuild based on a supplied DAT file(s). By default all files will be rebuilt to uncompressed folders in the output directory."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); @@ -29,7 +29,7 @@ namespace SabreTools.Features AddFeature(DatListInput); AddFeature(OutputDirStringInput); AddFeature(DepotFlag); - this[DepotFlag].AddFeature(DepotDepthInt32Input); + this[DepotFlag]!.AddFeature(DepotDepthInt32Input); AddFeature(DeleteFlag); AddFeature(InverseFlag); AddFeature(QuickFlag); @@ -42,13 +42,13 @@ namespace SabreTools.Features AddFeature(Torrent7zipFlag); AddFeature(TarFlag); AddFeature(TorrentGzipFlag); - this[TorrentGzipFlag].AddFeature(RombaFlag); - this[TorrentGzipFlag][RombaFlag].AddFeature(RombaDepthInt32Input); + this[TorrentGzipFlag]!.AddFeature(RombaFlag); + this[TorrentGzipFlag][RombaFlag]!.AddFeature(RombaDepthInt32Input); //AddFeature(SharedInputs.TorrentLrzipFlag); //AddFeature(SharedInputs.TorrentLz4Flag); //AddFeature(SharedInputs.TorrentRarFlag); //AddFeature(SharedInputs.TorrentXzFlag); - //this[SharedInputs.TorrentXzFlag].AddFeature(SharedInputs.RombaFlag); + //this[SharedInputs.TorrentXzFlag]!.AddFeature(SharedInputs.RombaFlag); AddFeature(TorrentZipFlag); //AddFeature(SharedInputs.TorrentZpaqFlag); //AddFeature(SharedInputs.TorrentZstdFlag); @@ -58,7 +58,7 @@ namespace SabreTools.Features AddFeature(UpdateDatFlag); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/SabreTools/Features/Split.cs b/SabreTools/Features/Split.cs index 8b46b320..59a40a86 100644 --- a/SabreTools/Features/Split.cs +++ b/SabreTools/Features/Split.cs @@ -26,20 +26,20 @@ namespace SabreTools.Features AddCommonFeatures(); AddFeature(OutputTypeListInput); - this[OutputTypeListInput].AddFeature(DeprecatedFlag); + this[OutputTypeListInput]!.AddFeature(DeprecatedFlag); AddFeature(OutputDirStringInput); AddFeature(InplaceFlag); AddFeature(ExtensionFlag); - this[ExtensionFlag].AddFeature(ExtaListInput); - this[ExtensionFlag].AddFeature(ExtbListInput); + this[ExtensionFlag]!.AddFeature(ExtaListInput); + this[ExtensionFlag]!.AddFeature(ExtbListInput); AddFeature(HashFlag); AddFeature(LevelFlag); - this[LevelFlag].AddFeature(ShortFlag); - this[LevelFlag].AddFeature(BaseFlag); + this[LevelFlag]!.AddFeature(ShortFlag); + this[LevelFlag]!.AddFeature(BaseFlag); AddFeature(SizeFlag); - this[SizeFlag].AddFeature(RadixInt64Input); + this[SizeFlag]!.AddFeature(RadixInt64Input); AddFeature(TotalSizeFlag); - this[TotalSizeFlag].AddFeature(ChunkSizeInt64Input); + this[TotalSizeFlag]!.AddFeature(ChunkSizeInt64Input); AddFeature(TypeFlag); } diff --git a/SabreTools/Features/Stats.cs b/SabreTools/Features/Stats.cs index 8f67991a..3e20f39d 100644 --- a/SabreTools/Features/Stats.cs +++ b/SabreTools/Features/Stats.cs @@ -30,7 +30,7 @@ The stats that are outputted are as follows: - Items that include a SHA-384 - Items that include a SHA-512 - Items with Nodump status"; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); @@ -43,7 +43,7 @@ The stats that are outputted are as follows: AddFeature(IndividualFlag); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/SabreTools/Features/Update.cs b/SabreTools/Features/Update.cs index 94a9add5..9fdef34d 100644 --- a/SabreTools/Features/Update.cs +++ b/SabreTools/Features/Update.cs @@ -29,17 +29,17 @@ namespace SabreTools.Features // Output Formats AddFeature(OutputTypeListInput); - this[OutputTypeListInput].AddFeature(PrefixStringInput); - this[OutputTypeListInput].AddFeature(PostfixStringInput); - this[OutputTypeListInput].AddFeature(QuotesFlag); - this[OutputTypeListInput].AddFeature(RomsFlag); - this[OutputTypeListInput].AddFeature(GamePrefixFlag); - this[OutputTypeListInput].AddFeature(AddExtensionStringInput); - this[OutputTypeListInput].AddFeature(ReplaceExtensionStringInput); - this[OutputTypeListInput].AddFeature(RemoveExtensionsFlag); - this[OutputTypeListInput].AddFeature(RombaFlag); - this[OutputTypeListInput][RombaFlag].AddFeature(RombaDepthInt32Input); - this[OutputTypeListInput].AddFeature(DeprecatedFlag); + this[OutputTypeListInput]!.AddFeature(PrefixStringInput); + this[OutputTypeListInput]!.AddFeature(PostfixStringInput); + this[OutputTypeListInput]!.AddFeature(QuotesFlag); + this[OutputTypeListInput]!.AddFeature(RomsFlag); + this[OutputTypeListInput]!.AddFeature(GamePrefixFlag); + this[OutputTypeListInput]!.AddFeature(AddExtensionStringInput); + this[OutputTypeListInput]!.AddFeature(ReplaceExtensionStringInput); + this[OutputTypeListInput]!.AddFeature(RemoveExtensionsFlag); + this[OutputTypeListInput]!.AddFeature(RombaFlag); + this[OutputTypeListInput][RombaFlag]!.AddFeature(RombaDepthInt32Input); + this[OutputTypeListInput]!.AddFeature(DeprecatedFlag); AddHeaderFeatures(); AddFeature(KeepEmptyGamesFlag); @@ -48,35 +48,35 @@ namespace SabreTools.Features AddFeature(DescriptionAsNameFlag); AddInternalSplitFeatures(); AddFeature(TrimFlag); - this[TrimFlag].AddFeature(RootDirStringInput); + this[TrimFlag]!.AddFeature(RootDirStringInput); AddFeature(SingleSetFlag); AddFeature(DedupFlag); AddFeature(GameDedupFlag); AddFeature(MergeFlag); - this[MergeFlag].AddFeature(NoAutomaticDateFlag); + this[MergeFlag]!.AddFeature(NoAutomaticDateFlag); AddFeature(DiffAllFlag); - this[DiffAllFlag].AddFeature(NoAutomaticDateFlag); + this[DiffAllFlag]!.AddFeature(NoAutomaticDateFlag); AddFeature(DiffDuplicatesFlag); - this[DiffDuplicatesFlag].AddFeature(NoAutomaticDateFlag); + this[DiffDuplicatesFlag]!.AddFeature(NoAutomaticDateFlag); AddFeature(DiffIndividualsFlag); - this[DiffIndividualsFlag].AddFeature(NoAutomaticDateFlag); + this[DiffIndividualsFlag]!.AddFeature(NoAutomaticDateFlag); AddFeature(DiffNoDuplicatesFlag); - this[DiffNoDuplicatesFlag].AddFeature(NoAutomaticDateFlag); + this[DiffNoDuplicatesFlag]!.AddFeature(NoAutomaticDateFlag); AddFeature(DiffAgainstFlag); - this[DiffAgainstFlag].AddFeature(BaseDatListInput); - this[DiffAgainstFlag].AddFeature(ByGameFlag); + this[DiffAgainstFlag]!.AddFeature(BaseDatListInput); + this[DiffAgainstFlag]!.AddFeature(ByGameFlag); AddFeature(BaseReplaceFlag); - this[BaseReplaceFlag].AddFeature(BaseDatListInput); - this[BaseReplaceFlag].AddFeature(UpdateFieldListInput); - this[BaseReplaceFlag][UpdateFieldListInput].AddFeature(OnlySameFlag); + this[BaseReplaceFlag]!.AddFeature(BaseDatListInput); + this[BaseReplaceFlag]!.AddFeature(UpdateFieldListInput); + this[BaseReplaceFlag][UpdateFieldListInput]!.AddFeature(OnlySameFlag); AddFeature(ReverseBaseReplaceFlag); - this[ReverseBaseReplaceFlag].AddFeature(BaseDatListInput); - this[ReverseBaseReplaceFlag].AddFeature(UpdateFieldListInput); - this[ReverseBaseReplaceFlag][UpdateFieldListInput].AddFeature(OnlySameFlag); + this[ReverseBaseReplaceFlag]!.AddFeature(BaseDatListInput); + this[ReverseBaseReplaceFlag]!.AddFeature(UpdateFieldListInput); + this[ReverseBaseReplaceFlag][UpdateFieldListInput]!.AddFeature(OnlySameFlag); AddFeature(DiffCascadeFlag); - this[DiffCascadeFlag].AddFeature(SkipFirstOutputFlag); + this[DiffCascadeFlag]!.AddFeature(SkipFirstOutputFlag); AddFeature(DiffReverseCascadeFlag); - this[DiffReverseCascadeFlag].AddFeature(SkipFirstOutputFlag); + this[DiffReverseCascadeFlag]!.AddFeature(SkipFirstOutputFlag); AddFeature(ExtraIniListInput); AddFilteringFeatures(); AddFeature(OutputDirStringInput); @@ -174,8 +174,7 @@ namespace SabreTools.Features // Perform additional processing steps Extras.ApplyExtras(datFile); Splitter.ApplySplitting(datFile, useTags: false); - Filter.ApplyFilters(datFile); - // datFile.ExecuteFilters(FilterRunner); // TODO: Replace Filter.ApplyFilters with this + datFile.ExecuteFilters(FilterRunner); Cleaner.ApplyCleaning(datFile); Remover.ApplyRemovals(datFile); @@ -218,8 +217,7 @@ namespace SabreTools.Features // Perform additional processing steps Extras.ApplyExtras(userInputDat); Splitter.ApplySplitting(userInputDat, useTags: false); - Filter.ApplyFilters(userInputDat); - // userInputDat.ExecuteFilters(FilterRunner); // TODO: Replace Filter.ApplyFilters with this + userInputDat.ExecuteFilters(FilterRunner); Cleaner.ApplyCleaning(userInputDat); Remover.ApplyRemovals(userInputDat); @@ -348,8 +346,7 @@ namespace SabreTools.Features // Perform additional processing steps Extras.ApplyExtras(repDat); Splitter.ApplySplitting(repDat, useTags: false); - Filter.ApplyFilters(repDat); - // repDat.ExecuteFilters(FilterRunner); // TODO: Replace Filter.ApplyFilters with this + repDat.ExecuteFilters(FilterRunner); Cleaner.ApplyCleaning(repDat); Remover.ApplyRemovals(repDat); @@ -385,8 +382,7 @@ namespace SabreTools.Features // Perform additional processing steps Extras.ApplyExtras(repDat); Splitter.ApplySplitting(repDat, useTags: false); - Filter.ApplyFilters(repDat); - // repDat.ExecuteFilters(FilterRunner); // TODO: Replace Filter.ApplyFilters with this + repDat.ExecuteFilters(FilterRunner); Cleaner.ApplyCleaning(repDat); Remover.ApplyRemovals(repDat); diff --git a/SabreTools/Features/Verify.cs b/SabreTools/Features/Verify.cs index 8879343a..236dae8e 100644 --- a/SabreTools/Features/Verify.cs +++ b/SabreTools/Features/Verify.cs @@ -20,14 +20,14 @@ namespace SabreTools.Features Description = "Verify a folder against DATs"; _featureType = ParameterType.Flag; LongDescription = "When used, this will use an input DAT or set of DATs to blindly check against an input folder. The base of the folder is considered the base for the combined DATs and games are either the directories or archives within. This will only do a direct verification of the items within and will create a fixdat afterwards for missing files."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); AddFeature(DatListInput); AddFeature(DepotFlag); - this[DepotFlag].AddFeature(DepotDepthInt32Input); + this[DepotFlag]!.AddFeature(DepotDepthInt32Input); AddFeature(OutputDirStringInput); AddFeature(HashOnlyFlag); AddFeature(QuickFlag); @@ -40,7 +40,7 @@ namespace SabreTools.Features AddFilteringFeatures(); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) @@ -65,15 +65,14 @@ namespace SabreTools.Features Parser.ParseInto(datdata, datfile, int.MaxValue, keep: true); // Perform additional processing steps - Extras.ApplyExtras(datdata); - Splitter.ApplySplitting(datdata, useTags: true); - Filter.ApplyFilters(datdata); - // datdata.ExecuteFilters(FilterRunner); // TODO: Replace Filter.ApplyFilters with this - Cleaner.ApplyCleaning(datdata); - Remover.ApplyRemovals(datdata); + Extras!.ApplyExtras(datdata); + Splitter!.ApplySplitting(datdata, useTags: true); + datdata.ExecuteFilters(FilterRunner!); + Cleaner!.ApplyCleaning(datdata); + Remover!.ApplyRemovals(datdata); // Set depot information - datdata.Header.InputDepot = Header.InputDepot?.Clone() as DepotInformation; + datdata.Header.InputDepot = Header!.InputDepot?.Clone() as DepotInformation; // If we have overridden the header skipper, set it now if (!string.IsNullOrEmpty(Header.HeaderSkipper)) @@ -98,7 +97,7 @@ namespace SabreTools.Features // Now write out if there are any items left Writer.WriteStatsToConsole(datdata); - Writer.Write(datdata, OutputDir); + Writer.Write(datdata, OutputDir!); } } // Otherwise, process all DATs into the same output @@ -114,15 +113,14 @@ namespace SabreTools.Features } // Perform additional processing steps - Extras.ApplyExtras(datdata); - Splitter.ApplySplitting(datdata, useTags: true); - Filter.ApplyFilters(datdata); - // datdata.ExecuteFilters(FilterRunner); // TODO: Replace Filter.ApplyFilters with this - Cleaner.ApplyCleaning(datdata); - Remover.ApplyRemovals(datdata); + Extras!.ApplyExtras(datdata); + Splitter!.ApplySplitting(datdata, useTags: true); + datdata.ExecuteFilters(FilterRunner!); + Cleaner!.ApplyCleaning(datdata); + Remover!.ApplyRemovals(datdata); // Set depot information - datdata.Header.InputDepot = Header.InputDepot?.Clone() as DepotInformation; + datdata.Header.InputDepot = Header!.InputDepot?.Clone() as DepotInformation; // If we have overridden the header skipper, set it now if (!string.IsNullOrEmpty(Header.HeaderSkipper)) @@ -149,7 +147,7 @@ namespace SabreTools.Features // Now write out if there are any items left Writer.WriteStatsToConsole(datdata); - Writer.Write(datdata, OutputDir); + Writer.Write(datdata, OutputDir!); } return true; diff --git a/SabreTools/Features/Version.cs b/SabreTools/Features/Version.cs index d0b5d10d..44eee607 100644 --- a/SabreTools/Features/Version.cs +++ b/SabreTools/Features/Version.cs @@ -16,13 +16,13 @@ namespace SabreTools.Features Description = "Prints version"; _featureType = ParameterType.Flag; LongDescription = "Prints current program version."; - Features = new Dictionary(); + Features = []; // Common Features AddCommonFeatures(); } - public override bool ProcessFeatures(Dictionary features) + public override bool ProcessFeatures(Dictionary features) { // If the base fails, just fail out if (!base.ProcessFeatures(features)) diff --git a/SabreTools/Program.cs b/SabreTools/Program.cs index 505715e1..927c4cd5 100644 --- a/SabreTools/Program.cs +++ b/SabreTools/Program.cs @@ -109,7 +109,7 @@ namespace SabreTools } // Now process the current feature - Dictionary features = _help.GetEnabledFeatures(); + Dictionary features = _help.GetEnabledFeatures(); bool success = false; switch (featureName) { diff --git a/SabreTools/SabreTools.csproj b/SabreTools/SabreTools.csproj index 3d420b01..31eeb92e 100644 --- a/SabreTools/SabreTools.csproj +++ b/SabreTools/SabreTools.csproj @@ -5,6 +5,7 @@ net6.0;net8.0 win-x86;win-x64;linux-x64;osx-x64 latest + enable Matt Nadareski Copyright (c)2016-2024 Matt Nadareski MIT