Enforce nullability in RombaSharp program

This commit is contained in:
Matt Nadareski
2024-03-06 01:04:51 -05:00
parent fe0dccb8d2
commit d7a317c1aa
27 changed files with 53 additions and 66 deletions

View File

@@ -20,7 +20,7 @@ namespace RombaSharp.Features
public Archive()
{
Name = Value;
Flags = new List<string>() { "archive" };
Flags = ["archive"];
Description = "Adds ROM files from the specified directories to the ROM archive.";
_featureType = ParameterType.Flag;
LongDescription = @"Adds ROM files from the specified directories to the ROM archive.

View File

@@ -552,9 +552,9 @@ CREATE TABLE IF NOT EXISTS dat (
{
// Get a dictionary of filenames that actually exist in the DATRoot, logging which ones are not
#if NET20 || NET35
List<string> datRootDats = Directory.GetFiles(_dats, "*").ToList();
List<string> datRootDats = Directory.GetFiles(_dats!, "*").ToList();
#else
List<string> datRootDats = Directory.EnumerateFiles(_dats, "*", SearchOption.AllDirectories).ToList();
List<string> datRootDats = Directory.EnumerateFiles(_dats!, "*", SearchOption.AllDirectories).ToList();
#endif
List<string> lowerCaseDats = datRootDats.ConvertAll(i => Path.GetFileName(i).ToLowerInvariant());
Dictionary<string, string> foundDats = [];
@@ -785,7 +785,7 @@ CREATE TABLE IF NOT EXISTS dat (
internal void AddDatToDatabase(Rom dat, SqliteConnection dbc)
{
// Get the dat full path
string fullpath = Path.Combine(_dats, (dat.Machine.Name == "dats" ? string.Empty : dat.Machine.Name), dat.Name);
string fullpath = Path.Combine(_dats!, (dat.Machine.Name == "dats" ? string.Empty : dat.Machine.Name)!, dat.Name!);
// Parse the Dat if possible
logger.User($"Adding from '{dat.Name}'");

View File

@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.DatFiles;
using SabreTools.DatTools;
using SabreTools.FileTypes;
@@ -17,7 +16,7 @@ namespace RombaSharp.Features
public Build()
{
Name = Value;
Flags = new List<string>() { "build" };
Flags = ["build"];
Description = "For each specified DAT file it creates the torrentzip files.";
_featureType = ParameterType.Flag;
LongDescription = @"For each specified DAT file it creates the torrentzip files in the specified
@@ -56,7 +55,7 @@ structure according to the original DAT master directory tree structure.";
foreach (string key in foundDats.Keys)
{
// Get the DAT file associated with the key
DatFile datFile = Parser.CreateAndParse(Path.Combine(_dats, foundDats[key]));
DatFile datFile = Parser.CreateAndParse(Path.Combine(_dats!, foundDats[key]));
// Set the depot values
datFile.Header.InputDepot = new DepotInformation(true, 4);

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using SabreTools.Help;
namespace RombaSharp.Features
@@ -11,7 +10,7 @@ namespace RombaSharp.Features
public Cancel()
{
Name = Value;
Flags = new List<string>() { "cancel" };
Flags = ["cancel"];
Description = "Cancels current long-running job";
_featureType = ParameterType.Flag;
LongDescription = "Cancels current long-running job.";

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.IO;
using SabreTools.DatTools;
using SabreTools.Help;
using SabreTools.Reports;
@@ -14,7 +13,7 @@ namespace RombaSharp.Features
public DatStats()
{
Name = Value;
Flags = new List<string>() { "datstats" };
Flags = ["datstats"];
Description = "Prints dat stats.";
_featureType = ParameterType.Flag;
LongDescription = "Print dat stats.";
@@ -32,7 +31,7 @@ namespace RombaSharp.Features
// If we have no inputs listed, we want to use datroot
if (Inputs == null || Inputs.Count == 0)
Inputs = new List<string> { Path.GetFullPath(_dats) };
Inputs = new List<string> { Path.GetFullPath(_dats!) };
// Now output the stats for all inputs
var statistics = Statistics.CalculateStatistics(Inputs, single: true);

View File

@@ -1,7 +1,6 @@
using System.Collections.Generic;
using SabreTools.Help;
using Microsoft.Data.Sqlite;
using SabreTools.Help;
namespace RombaSharp.Features
{
@@ -12,7 +11,7 @@ namespace RombaSharp.Features
public DbStats()
{
Name = Value;
Flags = new List<string>() { "dbstats" };
Flags = ["dbstats"];
Description = "Prints db stats.";
_featureType = ParameterType.Flag;
LongDescription = "Print db stats.";

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.IO;
using SabreTools.DatFiles;
using SabreTools.DatTools;
using SabreTools.Help;
@@ -15,7 +14,7 @@ namespace RombaSharp.Features
public Diffdat()
{
Name = Value;
Flags = new List<string>() { "diffdat" };
Flags = ["diffdat"];
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 file and not

View File

@@ -16,7 +16,7 @@ namespace RombaSharp.Features
public Dir2Dat()
{
Name = Value;
Flags = new List<string>() { "dir2dat" };
Flags = ["dir2dat"];
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.";

View File

@@ -1,6 +1,4 @@
using System.Collections.Generic;
using SabreTools.Help;
using SabreTools.Help;
namespace RombaSharp.Features
{
@@ -11,7 +9,7 @@ namespace RombaSharp.Features
public DisplayHelp()
{
Name = Value;
Flags = new List<string>() { "-?", "-h", "--help" };
Flags = ["-?", "-h", "--help"];
Description = "Show this help";
_featureType = ParameterType.Flag;
LongDescription = "Built-in to most of the programs is a basic help text.";

View File

@@ -1,6 +1,4 @@
using System.Collections.Generic;
using SabreTools.Help;
using SabreTools.Help;
namespace RombaSharp.Features
{
@@ -11,7 +9,7 @@ namespace RombaSharp.Features
public DisplayHelpDetailed()
{
Name = Value;
Flags = new List<string>() { "-??", "-hd", "--help-detailed" };
Flags = ["-??", "-hd", "--help-detailed"];
Description = "Show this detailed help";
_featureType = ParameterType.Flag;
LongDescription = "Display a detailed help text to the screen.";

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.IO;
using SabreTools.DatFiles;
using SabreTools.DatTools;
using SabreTools.Help;
@@ -15,7 +14,7 @@ namespace RombaSharp.Features
public EDiffdat()
{
Name = Value;
Flags = new List<string>() { "ediffdat" };
Flags = ["ediffdat"];
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.";

View File

@@ -1,8 +1,7 @@
using System.Collections.Generic;
using System.IO;
using SabreTools.Help;
using Microsoft.Data.Sqlite;
using SabreTools.Help;
namespace RombaSharp.Features
{
@@ -14,7 +13,7 @@ namespace RombaSharp.Features
public Export()
{
Name = Value;
Flags = new List<string>() { "export" };
Flags = ["export"];
Description = "Exports db to export.csv";
_featureType = ParameterType.Flag;
LongDescription = "Exports db to standardized export.csv";

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using SabreTools.Help;
namespace RombaSharp.Features
@@ -11,7 +10,7 @@ namespace RombaSharp.Features
public Fixdat()
{
Name = Value;
Flags = new List<string>() { "fixdat" };
Flags = ["fixdat"];
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.";

View File

@@ -1,10 +1,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Data.Sqlite;
using SabreTools.Help;
using SabreTools.IO;
using Microsoft.Data.Sqlite;
namespace RombaSharp.Features
{
@@ -16,7 +15,7 @@ namespace RombaSharp.Features
public Import()
{
Name = Value;
Flags = new List<string>() { "import" };
Flags = ["import"];
Description = "Import a database from a formatted CSV file";
_featureType = ParameterType.Flag;
LongDescription = "Import a database from a formatted CSV file";

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using SabreTools.Core;
using SabreTools.Help;
using Microsoft.Data.Sqlite;
@@ -13,7 +12,7 @@ namespace RombaSharp.Features
public Lookup()
{
Name = Value;
Flags = new List<string>() { "lookup" };
Flags = ["lookup"];
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).";

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using SabreTools.Help;
namespace RombaSharp.Features
@@ -11,7 +10,7 @@ namespace RombaSharp.Features
public Memstats()
{
Name = Value;
Flags = new List<string>() { "memstats" };
Flags = ["memstats"];
Description = "Prints memory stats.";
_featureType = ParameterType.Flag;
LongDescription = "Print memory stats.";

View File

@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Help;
using SabreTools.IO;
@@ -14,7 +13,7 @@ namespace RombaSharp.Features
public Merge()
{
Name = Value;
Flags = new List<string>() { "merge" };
Flags = ["merge"];
Description = "Merges depot";
_featureType = ParameterType.Flag;
LongDescription = "Merges specified depot into current depot.";

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.IO;
using SabreTools.DatFiles;
using SabreTools.DatTools;
using SabreTools.Help;
@@ -16,7 +15,7 @@ namespace RombaSharp.Features
public Miss()
{
Name = Value;
Flags = new List<string>() { "miss" };
Flags = ["miss"];
Description = "Create miss and have file";
_featureType = ParameterType.Flag;
LongDescription = "For each specified DAT file, create miss and have file";
@@ -42,7 +41,7 @@ namespace RombaSharp.Features
foreach (string key in foundDats.Keys)
{
// Get the DAT file associated with the key
DatFile datFile = Parser.CreateAndParse(Path.Combine(_dats, foundDats[key]));
DatFile datFile = Parser.CreateAndParse(Path.Combine(_dats!, foundDats[key]));
// Now loop through and see if all of the hash combinations exist in the database
/* ended here */

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using SabreTools.Help;
namespace RombaSharp.Features
@@ -11,7 +10,7 @@ namespace RombaSharp.Features
public Progress()
{
Name = Value;
Flags = new List<string>() { "progress" };
Flags = ["progress"];
Description = "Shows progress of the currently running command.";
_featureType = ParameterType.Flag;
LongDescription = "Shows progress of the currently running command.";

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using SabreTools.Help;
namespace RombaSharp.Features
@@ -11,7 +10,7 @@ namespace RombaSharp.Features
public PurgeBackup()
{
Name = Value;
Flags = new List<string>() { "purge-backup" };
Flags = ["purge-backup"];
Description = "Moves DAT index entries for orphaned DATs.";
_featureType = ParameterType.Flag;
LongDescription = @"Deletes DAT index entries for orphaned DATs and moves ROM files that are no

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using SabreTools.Help;
namespace RombaSharp.Features
@@ -12,7 +11,7 @@ namespace RombaSharp.Features
public PurgeDelete()
{
Name = Value;
Flags = new List<string>() { "purge-delete" };
Flags = ["purge-delete"];
Description = "Deletes DAT index entries for orphaned DATs";
_featureType = ParameterType.Flag;
LongDescription = @"Deletes DAT index entries for orphaned DATs and moves ROM files that are no

View File

@@ -20,7 +20,7 @@ namespace RombaSharp.Features
public RefreshDats()
{
Name = Value;
Flags = new List<string>() { "refresh-dats" };
Flags = ["refresh-dats"];
Description = "Refreshes the DAT index from the files in the DAT master directory tree.";
_featureType = ParameterType.Flag;
LongDescription = @"Refreshes the DAT index from the files in the DAT master directory tree.
@@ -74,8 +74,8 @@ contents of any changed dats.";
datroot.Items.BucketBy(ItemKey.SHA1, DedupeType.None);
// Create a List of dat hashes in the database (SHA-1)
List<string> databaseDats = new List<string>();
List<string> unneeded = new List<string>();
List<string> databaseDats = [];
List<string> unneeded = [];
SqliteConnection dbc = new SqliteConnection(_connectionString);
dbc.Open();

View File

@@ -20,7 +20,7 @@ namespace RombaSharp.Features
public RescanDepots()
{
Name = Value;
Flags = new List<string>() { "depot-rescan" };
Flags = ["depot-rescan"];
Description = "Rescan a specific depot to get new information";
_featureType = ParameterType.Flag;
LongDescription = "Rescan a specific depot to get new information";
@@ -59,7 +59,7 @@ namespace RombaSharp.Features
dbc.Open();
// If we have it, then check for all hashes that are in that depot
List<string> hashes = new List<string>();
List<string> hashes = [];
string query = $"SELECT sha1 FROM sha1 WHERE depot=\"{depotname}\"";
SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteDataReader sldr = slc.ExecuteReader();
@@ -84,7 +84,7 @@ namespace RombaSharp.Features
string md5sha1query = "INSERT OR IGNORE INTO md5sha1 (md5, sha1) VALUES";
// Once we have both, check for any new files
List<string> dupehashes = new List<string>();
List<string> dupehashes = [];
IEnumerable<string> keys = depot.Items.Keys;
foreach (string key in keys)
{
@@ -94,12 +94,12 @@ namespace RombaSharp.Features
foreach (Rom rom in roms)
{
if (hashes.Contains(rom.SHA1))
if (hashes.Contains(rom.SHA1!))
{
dupehashes.Add(rom.SHA1);
hashes.Remove(rom.SHA1);
dupehashes.Add(rom.SHA1!);
hashes.Remove(rom.SHA1!);
}
else if (!dupehashes.Contains(rom.SHA1))
else if (!dupehashes.Contains(rom.SHA1!))
{
if (!string.IsNullOrWhiteSpace(rom.CRC))
crcquery += $" (\"{rom.CRC}\"),";

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using SabreTools.Help;
namespace RombaSharp.Features
@@ -11,7 +10,7 @@ namespace RombaSharp.Features
public Shutdown()
{
Name = Value;
Flags = new List<string>() { "shutdown" };
Flags = ["shutdown"];
Description = "Gracefully shuts down server.";
_featureType = ParameterType.Flag;
LongDescription = "Gracefully shuts down server saving all the cached data.";

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using SabreTools.Core;
using SabreTools.Help;
@@ -12,7 +11,7 @@ namespace RombaSharp.Features
public Version()
{
Name = Value;
Flags = new List<string>() { "version" };
Flags = ["version"];
Description = "Prints version";
_featureType = ParameterType.Flag;
LongDescription = "Prints current program version.";

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using RombaSharp.Features;
using SabreTools.Core;
using SabreTools.Help;

View File

@@ -1,14 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Assembly Properties -->
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.1.2</Version>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>
<Copyright>Copyright (c)2016-2024 Matt Nadareski</Copyright>
<PackageProjectUrl>https://github.com/SabreTools/</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/SabreTools/SabreTools</RepositoryUrl>
</PropertyGroup>