Support ancient .NET in DatTools

This commit is contained in:
Matt Nadareski
2024-02-29 00:14:16 -05:00
parent af86287af4
commit fc061ae555
11 changed files with 148 additions and 60 deletions

View File

@@ -547,7 +547,11 @@ CREATE TABLE IF NOT EXISTS dat (
internal Dictionary<string, string> GetValidDats(List<string> inputs)
{
// 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();
#else
List<string> datRootDats = Directory.EnumerateFiles(_dats, "*", SearchOption.AllDirectories).ToList();
#endif
List<string> lowerCaseDats = datRootDats.ConvertAll(i => Path.GetFileName(i).ToLowerInvariant());
Dictionary<string, string> foundDats = new Dictionary<string, string>();
foreach (string input in inputs)

View File

@@ -50,7 +50,11 @@ namespace RombaSharp.Features
// Loop over all input directories
foreach (string input in Inputs)
{
#if NET20 || NET35
List<string> depotFiles = Directory.GetFiles(input, "*.gz").ToList();
#else
List<string> depotFiles = Directory.EnumerateFiles(input, "*.gz", SearchOption.AllDirectories).ToList();
#endif
// If we are copying all that is possible but we want to scan first
if (!onlyNeeded && !skipInitialscan)

View File

@@ -55,9 +55,14 @@ namespace SabreTools.DatTools
string filename = inputs[newItem.Source.Index].CurrentPath;
string? rootpath = inputs[newItem.Source.Index].ParentPath;
if (!string.IsNullOrWhiteSpace(rootpath)
if (!string.IsNullOrEmpty(rootpath)
#if NETFRAMEWORK
&& !rootpath!.EndsWith(Path.DirectorySeparatorChar.ToString())
&& !rootpath!.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
#else
&& !rootpath.EndsWith(Path.DirectorySeparatorChar)
&& !rootpath.EndsWith(Path.AltDirectorySeparatorChar))
#endif
{
rootpath += Path.DirectorySeparatorChar.ToString();
}
@@ -343,13 +348,13 @@ namespace SabreTools.DatTools
InternalStopwatch watch = new("Initializing duplicate DAT");
// Fill in any information not in the base DAT
if (string.IsNullOrWhiteSpace(datFile.Header.FileName))
if (string.IsNullOrEmpty(datFile.Header.FileName))
datFile.Header.FileName = "All DATs";
if (string.IsNullOrWhiteSpace(datFile.Header.Name))
if (string.IsNullOrEmpty(datFile.Header.Name))
datFile.Header.Name = "datFile.All DATs";
if (string.IsNullOrWhiteSpace(datFile.Header.Description))
if (string.IsNullOrEmpty(datFile.Header.Description))
datFile.Header.Description = "datFile.All DATs";
string post = " (Duplicates)";
@@ -376,7 +381,11 @@ namespace SabreTools.DatTools
// If the rom list is empty or null, just skip it
if (items == null || items.Count == 0)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
// Loop through and add the items correctly
foreach (DatItem item in items)
@@ -428,13 +437,13 @@ namespace SabreTools.DatTools
InternalStopwatch watch = new("Initializing all individual DATs");
// Fill in any information not in the base DAT
if (string.IsNullOrWhiteSpace(datFile.Header.FileName))
if (string.IsNullOrEmpty(datFile.Header.FileName))
datFile.Header.FileName = "All DATs";
if (string.IsNullOrWhiteSpace(datFile.Header.Name))
if (string.IsNullOrEmpty(datFile.Header.Name))
datFile.Header.Name = "All DATs";
if (string.IsNullOrWhiteSpace(datFile.Header.Description))
if (string.IsNullOrEmpty(datFile.Header.Description))
datFile.Header.Description = "All DATs";
// Loop through each of the inputs and get or create a new DatData object
@@ -481,7 +490,11 @@ namespace SabreTools.DatTools
// If the rom list is empty or null, just skip it
if (items == null || items.Count == 0)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
// Loop through and add the items correctly
foreach (DatItem item in items)
@@ -528,13 +541,13 @@ namespace SabreTools.DatTools
InternalStopwatch watch = new("Initializing no duplicate DAT");
// Fill in any information not in the base DAT
if (string.IsNullOrWhiteSpace(datFile.Header.FileName))
if (string.IsNullOrEmpty(datFile.Header.FileName))
datFile.Header.FileName = "All DATs";
if (string.IsNullOrWhiteSpace(datFile.Header.Name))
if (string.IsNullOrEmpty(datFile.Header.Name))
datFile.Header.Name = "All DATs";
if (string.IsNullOrWhiteSpace(datFile.Header.Description))
if (string.IsNullOrEmpty(datFile.Header.Description))
datFile.Header.Description = "All DATs";
string post = " (No Duplicates)";
@@ -561,7 +574,11 @@ namespace SabreTools.DatTools
// If the rom list is empty or null, just skip it
if (items == null || items.Count == 0)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
// Loop through and add the items correctly
foreach (DatItem item in items)
@@ -692,7 +709,11 @@ namespace SabreTools.DatTools
// If the rom list is empty or null, just skip it
if (items == null || items.Count == 0)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
foreach (DatItem item in items)
{

View File

@@ -58,7 +58,11 @@ namespace SabreTools.DatTools
logger.Verbose($"Folder found: {basePath}");
// Get a list of all files to process
#if NET20 || NET35
List<string> files = Directory.GetFiles(basePath, "*").ToList();
#else
List<string> files = Directory.EnumerateFiles(basePath, "*", SearchOption.AllDirectories).ToList();
#endif
// Loop through and add the file sizes
#if NET452_OR_GREATER || NETCOREAPP
@@ -155,7 +159,7 @@ namespace SabreTools.DatTools
// Process as archive if we're not treating archives as files
#if NETFRAMEWORK
else if ((!asFiles & TreatAsFile.Archive) != 0)
else if ((asFiles & TreatAsFile.Archive) == 0)
#else
else if (!asFiles.HasFlag(TreatAsFile.Archive))
#endif
@@ -430,7 +434,7 @@ namespace SabreTools.DatTools
string? machineName, itemName;
// If the parent is blank, then we have a non-archive file
if (string.IsNullOrWhiteSpace(parent))
if (string.IsNullOrEmpty(parent))
{
// If we have a SuperDAT, we want anything that's not the base path as the game, and the file as the rom
if (datFile.Header.Type == "SuperDAT")
@@ -472,7 +476,7 @@ namespace SabreTools.DatTools
machineName = machineName?.Trim(Path.DirectorySeparatorChar);
itemName = itemName?.Trim(Path.DirectorySeparatorChar) ?? string.Empty;
if (!string.IsNullOrWhiteSpace(machineName) && string.IsNullOrWhiteSpace(itemName))
if (!string.IsNullOrEmpty(machineName) && string.IsNullOrEmpty(itemName))
{
itemName = machineName;
machineName = "Default";
@@ -483,24 +487,24 @@ namespace SabreTools.DatTools
datItem.Machine.Description = machineName;
// If we have a Disk, then the ".chd" extension needs to be removed
if (datItem.ItemType == ItemType.Disk && itemName.EndsWith(".chd"))
if (datItem.ItemType == ItemType.Disk && itemName!.EndsWith(".chd"))
{
itemName = itemName[0..^4];
itemName = itemName.Substring(0, itemName.Length - 4);
}
// If we have a Media, then the extension needs to be removed
else if (datItem.ItemType == ItemType.Media)
{
if (itemName.EndsWith(".dicf"))
itemName = itemName[0..^5];
if (itemName!.EndsWith(".dicf"))
itemName = itemName.Substring(0, itemName.Length - 5);
else if (itemName.EndsWith(".aaru"))
itemName = itemName[0..^5];
itemName = itemName.Substring(0, itemName.Length - 5);
else if (itemName.EndsWith(".aaruformat"))
itemName = itemName[0..^11];
itemName = itemName.Substring(0, itemName.Length - 11);
else if (itemName.EndsWith(".aaruf"))
itemName = itemName[0..^6];
itemName = itemName.Substring(0, itemName.Length - 6);
else if (itemName.EndsWith(".aif"))
itemName = itemName[0..^4];
itemName = itemName.Substring(0, itemName.Length - 4);
}
// Set the item name back

View File

@@ -90,7 +90,7 @@ namespace SabreTools.DatTools
return;
// If the output filename isn't set already, get the internal filename
datFile.Header.FileName = string.IsNullOrWhiteSpace(datFile.Header.FileName)
datFile.Header.FileName = string.IsNullOrEmpty(datFile.Header.FileName)
? (keepext
? Path.GetFileName(currentPath)
: Path.GetFileNameWithoutExtension(currentPath))
@@ -214,7 +214,11 @@ namespace SabreTools.DatTools
return DatFormat.EverdriveSMDB;
// If we have an INI-based DAT
#if NETFRAMEWORK
else if (first.Contains("[") && first.Contains("]"))
#else
else if (first.Contains('[') && first.Contains(']'))
#endif
return DatFormat.RomCenter;
// If we have a listroms DAT
@@ -231,7 +235,11 @@ namespace SabreTools.DatTools
else if (first.Contains("doscenter"))
return DatFormat.DOSCenter;
#if NETFRAMEWORK
else if (first.ToLowerInvariant().Contains("#name;title;emulator;cloneof;year;manufacturer;category;players;rotation;control;status;displaycount;displaytype;altromname;alttitle;extra"))
#else
else if (first.Contains("#Name;Title;Emulator;CloneOf;Year;Manufacturer;Category;Players;Rotation;Control;Status;DisplayCount;DisplayType;AltRomname;AltTitle;Extra", StringComparison.InvariantCultureIgnoreCase))
#endif
return DatFormat.AttractMode;
else
@@ -252,7 +260,7 @@ namespace SabreTools.DatTools
// Find the first line that's not whitespace or an XML comment
string? line = sr.ReadLine()?.ToLowerInvariant()?.Trim();
bool inComment = line?.StartsWith("<!--") ?? false;
while ((string.IsNullOrWhiteSpace(line) || inComment) && !sr.EndOfStream)
while ((string.IsNullOrEmpty(line) || inComment) && !sr.EndOfStream)
{
// Null lines should not happen
if (line == null)
@@ -283,7 +291,7 @@ namespace SabreTools.DatTools
}
// Empty lines are just skipped
else if (string.IsNullOrWhiteSpace(line))
else if (string.IsNullOrEmpty(line))
{
line = sr.ReadLine()?.ToLowerInvariant()?.Trim();
inComment |= line?.StartsWith("<!--") ?? false;

View File

@@ -247,7 +247,11 @@ namespace SabreTools.DatTools
else if (Directory.Exists(input))
{
logger.Verbose($"Checking directory: {input}");
#if NET20 || NET35
foreach (string file in Directory.GetFiles(input, "*"))
#else
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
#endif
{
logger.User($"Checking file: {file}");
bool rebuilt = RebuildGenericHelper(datFile, file, outDir, quickScan, date, inverse, outputFormat, asFiles);

View File

@@ -1,10 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<!-- Assembly Properties -->
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;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>
<RepositoryUrl>https://github.com/SabreTools/SabreTools</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
<ItemGroup>

View File

@@ -45,10 +45,10 @@ namespace SabreTools.DatTools
InternalStopwatch watch = new($"Splitting DAT by extension");
// Make sure all of the extensions don't have a dot at the beginning
var newExtA = extA.Select(s => s.TrimStart('.').ToLowerInvariant());
var newExtA = extA.Select(s => s.TrimStart('.').ToLowerInvariant()).ToArray();
string newExtAString = string.Join(",", newExtA);
var newExtB = extB.Select(s => s.TrimStart('.').ToLowerInvariant());
var newExtB = extB.Select(s => s.TrimStart('.').ToLowerInvariant()).ToArray();
string newExtBString = string.Join(",", newExtB);
// Set all of the appropriate outputs for each of the subsets
@@ -71,9 +71,13 @@ namespace SabreTools.DatTools
foreach (var key in datFile.Items.Keys)
#endif
{
ConcurrentList<DatItem>? items = datFile.Items[key];
var items = datFile.Items[key];
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
foreach (DatItem item in items)
{
@@ -165,15 +169,18 @@ namespace SabreTools.DatTools
foreach (var key in datFile.Items.Keys)
#endif
{
ConcurrentList<DatItem>? items = datFile.Items[key];
var items = datFile.Items[key];
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
foreach (DatItem item in items)
{
// If the file is not a Disk, Media, or Rom, continue
if (item.ItemType != ItemType.Disk && item.ItemType != ItemType.Media && item.ItemType != ItemType.Rom)
return;
continue;
// If the file is a nodump
if ((item.ItemType == ItemType.Rom && (item as Rom)!.ItemStatus == ItemStatus.Nodump)
@@ -183,42 +190,42 @@ namespace SabreTools.DatTools
}
// If the file has a SHA-512
else if ((item.ItemType == ItemType.Rom && !string.IsNullOrWhiteSpace((item as Rom)!.SHA512)))
else if ((item.ItemType == ItemType.Rom && !string.IsNullOrEmpty((item as Rom)!.SHA512)))
{
fieldDats[DatItemField.SHA512].Items.Add(key, item);
}
// If the file has a SHA-384
else if ((item.ItemType == ItemType.Rom && !string.IsNullOrWhiteSpace((item as Rom)!.SHA384)))
else if ((item.ItemType == ItemType.Rom && !string.IsNullOrEmpty((item as Rom)!.SHA384)))
{
fieldDats[DatItemField.SHA384].Items.Add(key, item);
}
// If the file has a SHA-256
else if ((item.ItemType == ItemType.Media && !string.IsNullOrWhiteSpace((item as Media)!.SHA256))
|| (item.ItemType == ItemType.Rom && !string.IsNullOrWhiteSpace((item as Rom)!.SHA256)))
else if ((item.ItemType == ItemType.Media && !string.IsNullOrEmpty((item as Media)!.SHA256))
|| (item.ItemType == ItemType.Rom && !string.IsNullOrEmpty((item as Rom)!.SHA256)))
{
fieldDats[DatItemField.SHA256].Items.Add(key, item);
}
// If the file has a SHA-1
else if ((item.ItemType == ItemType.Disk && !string.IsNullOrWhiteSpace((item as Disk)!.SHA1))
|| (item.ItemType == ItemType.Media && !string.IsNullOrWhiteSpace((item as Media)!.SHA1))
|| (item.ItemType == ItemType.Rom && !string.IsNullOrWhiteSpace((item as Rom)!.SHA1)))
else if ((item.ItemType == ItemType.Disk && !string.IsNullOrEmpty((item as Disk)!.SHA1))
|| (item.ItemType == ItemType.Media && !string.IsNullOrEmpty((item as Media)!.SHA1))
|| (item.ItemType == ItemType.Rom && !string.IsNullOrEmpty((item as Rom)!.SHA1)))
{
fieldDats[DatItemField.SHA1].Items.Add(key, item);
}
// If the file has an MD5
else if ((item.ItemType == ItemType.Disk && !string.IsNullOrWhiteSpace((item as Disk)!.MD5))
|| (item.ItemType == ItemType.Media && !string.IsNullOrWhiteSpace((item as Media)!.MD5))
|| (item.ItemType == ItemType.Rom && !string.IsNullOrWhiteSpace((item as Rom)!.MD5)))
else if ((item.ItemType == ItemType.Disk && !string.IsNullOrEmpty((item as Disk)!.MD5))
|| (item.ItemType == ItemType.Media && !string.IsNullOrEmpty((item as Media)!.MD5))
|| (item.ItemType == ItemType.Rom && !string.IsNullOrEmpty((item as Rom)!.MD5)))
{
fieldDats[DatItemField.MD5].Items.Add(key, item);
}
// If the file has a CRC
else if ((item.ItemType == ItemType.Rom && !string.IsNullOrWhiteSpace((item as Rom)!.CRC)))
else if ((item.ItemType == ItemType.Rom && !string.IsNullOrEmpty((item as Rom)!.CRC)))
{
fieldDats[DatItemField.CRC].Items.Add(key, item);
}
@@ -281,8 +288,11 @@ namespace SabreTools.DatTools
// Clean the input list and set all games to be pathless
ConcurrentList<DatItem>? items = datFile.Items[key];
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
items.ForEach(item => item.Machine.Name = Path.GetFileName(item.Machine.Name));
items.ForEach(item => item.Machine.Description = Path.GetFileName(item.Machine.Description));
@@ -334,16 +344,25 @@ namespace SabreTools.DatTools
string? expName = name?.Replace("/", " - ")?.Replace("\\", " - ");
// Now set the new output values
newDatFile.Header.FileName = WebUtility.HtmlDecode(string.IsNullOrWhiteSpace(name)
#if NET20 || NET35
newDatFile.Header.FileName = string.IsNullOrEmpty(name)
? datFile.Header.FileName
: (shortname
? Path.GetFileName(name)
: expName
);
#else
newDatFile.Header.FileName = WebUtility.HtmlDecode(string.IsNullOrEmpty(name)
? datFile.Header.FileName
: (shortname
? Path.GetFileName(name)
: expName
)
);
#endif
newDatFile.Header.FileName = restore ? $"{datFile.Header.FileName} ({newDatFile.Header.FileName})" : newDatFile.Header.FileName;
newDatFile.Header.Name = $"{datFile.Header.Name} ({expName})";
newDatFile.Header.Description = string.IsNullOrWhiteSpace(datFile.Header.Description) ? newDatFile.Header.Name : $"{datFile.Header.Description} ({expName})";
newDatFile.Header.Description = string.IsNullOrEmpty(datFile.Header.Description) ? newDatFile.Header.Name : $"{datFile.Header.Description} ({expName})";
newDatFile.Header.Type = null;
// Write out the temporary DAT to the proper directory
@@ -382,8 +401,11 @@ namespace SabreTools.DatTools
{
ConcurrentList<DatItem>? items = datFile.Items[key];
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
foreach (DatItem item in items)
{
// If the file is not a Rom, it automatically goes in the "lesser" dat

View File

@@ -72,7 +72,11 @@ namespace SabreTools.DatTools
// If we don't have the first file and the directory has changed, show the previous directory stats and reset
if (lastdir != null && thisdir != lastdir && single)
{
#if NET20 || NET35
dirStats.DisplayName = $"DIR: {lastdir}";
#else
dirStats.DisplayName = $"DIR: {WebUtility.HtmlEncode(lastdir)}";
#endif
dirStats.MachineCount = dirStats.Statistics.GameCount;
stats.Add(dirStats);
dirStats = new DatStatistics
@@ -118,7 +122,11 @@ namespace SabreTools.DatTools
// Add last directory stats
if (single)
{
#if NET20 || NET35
dirStats.DisplayName = $"DIR: {lastdir}";
#else
dirStats.DisplayName = $"DIR: {WebUtility.HtmlEncode(lastdir)}";
#endif
dirStats.MachineCount = dirStats.Statistics.GameCount;
stats.Add(dirStats);
}
@@ -157,7 +165,7 @@ namespace SabreTools.DatTools
}
// Get the proper output file name
if (string.IsNullOrWhiteSpace(reportName))
if (string.IsNullOrEmpty(reportName))
reportName = "report";
// Get the proper output directory name

View File

@@ -146,31 +146,31 @@ namespace SabreTools.DatTools
private static void EnsureHeaderFields(DatFile datFile)
{
// Empty FileName
if (string.IsNullOrWhiteSpace(datFile.Header.FileName))
if (string.IsNullOrEmpty(datFile.Header.FileName))
{
if (string.IsNullOrWhiteSpace(datFile.Header.Name) && string.IsNullOrWhiteSpace(datFile.Header.Description))
if (string.IsNullOrEmpty(datFile.Header.Name) && string.IsNullOrEmpty(datFile.Header.Description))
datFile.Header.FileName = datFile.Header.Name = datFile.Header.Description = "Default";
else if (string.IsNullOrWhiteSpace(datFile.Header.Name) && !string.IsNullOrWhiteSpace(datFile.Header.Description))
else if (string.IsNullOrEmpty(datFile.Header.Name) && !string.IsNullOrEmpty(datFile.Header.Description))
datFile.Header.FileName = datFile.Header.Name = datFile.Header.Description;
else if (!string.IsNullOrWhiteSpace(datFile.Header.Name) && string.IsNullOrWhiteSpace(datFile.Header.Description))
else if (!string.IsNullOrEmpty(datFile.Header.Name) && string.IsNullOrEmpty(datFile.Header.Description))
datFile.Header.FileName = datFile.Header.Description = datFile.Header.Name;
else if (!string.IsNullOrWhiteSpace(datFile.Header.Name) && !string.IsNullOrWhiteSpace(datFile.Header.Description))
else if (!string.IsNullOrEmpty(datFile.Header.Name) && !string.IsNullOrEmpty(datFile.Header.Description))
datFile.Header.FileName = datFile.Header.Description;
}
// Filled FileName
else
{
if (string.IsNullOrWhiteSpace(datFile.Header.Name) && string.IsNullOrWhiteSpace(datFile.Header.Description))
if (string.IsNullOrEmpty(datFile.Header.Name) && string.IsNullOrEmpty(datFile.Header.Description))
datFile.Header.Name = datFile.Header.Description = datFile.Header.FileName;
else if (string.IsNullOrWhiteSpace(datFile.Header.Name) && !string.IsNullOrWhiteSpace(datFile.Header.Description))
else if (string.IsNullOrEmpty(datFile.Header.Name) && !string.IsNullOrEmpty(datFile.Header.Description))
datFile.Header.Name = datFile.Header.Description;
else if (!string.IsNullOrWhiteSpace(datFile.Header.Name) && string.IsNullOrWhiteSpace(datFile.Header.Description))
else if (!string.IsNullOrEmpty(datFile.Header.Name) && string.IsNullOrEmpty(datFile.Header.Description))
datFile.Header.Description = datFile.Header.Name;
}
}

View File

@@ -274,7 +274,7 @@ namespace SabreTools.FileTypes
if (_children == null || _children.Count == 0)
{
_children = [];
#if NETFRAMEWORK
#if NET20 || NET35
foreach (string file in Directory.GetFiles(this.Filename, "*"))
#else
foreach (string file in Directory.EnumerateFiles(this.Filename, "*", SearchOption.TopDirectoryOnly))
@@ -285,7 +285,7 @@ namespace SabreTools.FileTypes
_children.Add(nf);
}
#if NETFRAMEWORK
#if NET20 || NET35
foreach (string dir in Directory.GetDirectories(this.Filename, "*"))
#else
foreach (string dir in Directory.EnumerateDirectories(this.Filename, "*", SearchOption.TopDirectoryOnly))