diff --git a/RombaSharp/Features/BaseFeature.cs b/RombaSharp/Features/BaseFeature.cs index 2e7be328..78d0c901 100644 --- a/RombaSharp/Features/BaseFeature.cs +++ b/RombaSharp/Features/BaseFeature.cs @@ -547,7 +547,11 @@ CREATE TABLE IF NOT EXISTS dat ( internal Dictionary GetValidDats(List inputs) { // Get a dictionary of filenames that actually exist in the DATRoot, logging which ones are not +#if NET20 || NET35 + List datRootDats = Directory.GetFiles(_dats, "*").ToList(); +#else List datRootDats = Directory.EnumerateFiles(_dats, "*", SearchOption.AllDirectories).ToList(); +#endif List lowerCaseDats = datRootDats.ConvertAll(i => Path.GetFileName(i).ToLowerInvariant()); Dictionary foundDats = new Dictionary(); foreach (string input in inputs) diff --git a/RombaSharp/Features/Merge.cs b/RombaSharp/Features/Merge.cs index 13b02a06..5427073b 100644 --- a/RombaSharp/Features/Merge.cs +++ b/RombaSharp/Features/Merge.cs @@ -50,7 +50,11 @@ namespace RombaSharp.Features // Loop over all input directories foreach (string input in Inputs) { +#if NET20 || NET35 + List depotFiles = Directory.GetFiles(input, "*.gz").ToList(); +#else List 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) diff --git a/SabreTools.DatTools/DatFileTool.cs b/SabreTools.DatTools/DatFileTool.cs index f6f247bd..619577c8 100644 --- a/SabreTools.DatTools/DatFileTool.cs +++ b/SabreTools.DatTools/DatFileTool.cs @@ -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) { diff --git a/SabreTools.DatTools/DatFromDir.cs b/SabreTools.DatTools/DatFromDir.cs index d779a643..3f1144f3 100644 --- a/SabreTools.DatTools/DatFromDir.cs +++ b/SabreTools.DatTools/DatFromDir.cs @@ -58,7 +58,11 @@ namespace SabreTools.DatTools logger.Verbose($"Folder found: {basePath}"); // Get a list of all files to process +#if NET20 || NET35 + List files = Directory.GetFiles(basePath, "*").ToList(); +#else List 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 diff --git a/SabreTools.DatTools/Parser.cs b/SabreTools.DatTools/Parser.cs index 6a3bfdb8..b87fd91e 100644 --- a/SabreTools.DatTools/Parser.cs +++ b/SabreTools.DatTools/Parser.cs @@ -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)) @@ -100,7 +100,7 @@ namespace SabreTools.DatTools DatFormat currentPathFormat = GetDatFormat(currentPath); datFile.Header.DatFormat = datFile.Header.DatFormat == 0 ? currentPathFormat : datFile.Header.DatFormat; datFile.Items.SetBucketedBy(ItemKey.CRC); // Setting this because it can reduce issues later - + InternalStopwatch watch = new($"Parsing '{currentPath}' into internal DAT"); // Now parse the correct type of DAT @@ -134,7 +134,7 @@ namespace SabreTools.DatTools // Check if file exists if (!File.Exists(filename)) return 0; - + // Some formats should only require the extension to know switch (ext) { @@ -200,7 +200,7 @@ namespace SabreTools.DatTools else if ((second.StartsWith(" - net6.0;net8.0 + + net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64 + false + false latest enable + true true + 1.1.2 + + + Matt Nadareski + Copyright (c)2016-2024 Matt Nadareski + https://github.com/SabreTools/ + https://github.com/SabreTools/SabreTools + git diff --git a/SabreTools.DatTools/Splitter.cs b/SabreTools.DatTools/Splitter.cs index fea00c71..7d1ea39f 100644 --- a/SabreTools.DatTools/Splitter.cs +++ b/SabreTools.DatTools/Splitter.cs @@ -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? 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? 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? 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? 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 diff --git a/SabreTools.DatTools/Statistics.cs b/SabreTools.DatTools/Statistics.cs index c388dd1d..b20c9858 100644 --- a/SabreTools.DatTools/Statistics.cs +++ b/SabreTools.DatTools/Statistics.cs @@ -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 diff --git a/SabreTools.DatTools/Writer.cs b/SabreTools.DatTools/Writer.cs index 7bfae591..7042d983 100644 --- a/SabreTools.DatTools/Writer.cs +++ b/SabreTools.DatTools/Writer.cs @@ -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; } } diff --git a/SabreTools.FileTypes/Folder.cs b/SabreTools.FileTypes/Folder.cs index bd7dc46f..2465d550 100644 --- a/SabreTools.FileTypes/Folder.cs +++ b/SabreTools.FileTypes/Folder.cs @@ -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))