diff --git a/SabreTools.RedumpLib.Test/ExtensionsTests.cs b/SabreTools.RedumpLib.Test/ExtensionsTests.cs
index 1a37222..cdefe08 100644
--- a/SabreTools.RedumpLib.Test/ExtensionsTests.cs
+++ b/SabreTools.RedumpLib.Test/ExtensionsTests.cs
@@ -15,8 +15,8 @@ namespace SabreTools.RedumpLib.Test
///
/// DiscType values that map to MediaType
///
- private static readonly DiscType?[] _mappableDiscTypes = new DiscType?[]
- {
+ private static readonly DiscType?[] _mappableDiscTypes =
+ [
DiscType.BD25,
DiscType.BD33,
DiscType.BD50,
@@ -35,13 +35,13 @@ namespace SabreTools.RedumpLib.Test
DiscType.NintendoWiiUOpticalDiscSL,
DiscType.UMDSL,
DiscType.UMDDL,
- };
+ ];
///
/// MediaType values that map to DiscType
///
- private static readonly MediaType?[] _mappableMediaTypes = new MediaType?[]
- {
+ private static readonly MediaType?[] _mappableMediaTypes =
+ [
MediaType.BluRay,
MediaType.CDROM,
MediaType.DVD,
@@ -51,7 +51,7 @@ namespace SabreTools.RedumpLib.Test
MediaType.NintendoWiiOpticalDisc,
MediaType.NintendoWiiUOpticalDisc,
MediaType.UMD,
- };
+ ];
///
/// Check that every supported system has some set of MediaTypes supported
@@ -101,9 +101,9 @@ namespace SabreTools.RedumpLib.Test
foreach (DiscType? discType in Enum.GetValues(typeof(DiscType)))
{
if (_mappableDiscTypes.Contains(discType))
- testData.Add(new object?[] { discType, false });
+ testData.Add([discType, false]);
else
- testData.Add(new object?[] { discType, true });
+ testData.Add([discType, true]);
}
return testData;
@@ -118,7 +118,7 @@ namespace SabreTools.RedumpLib.Test
var testData = new List
///
///
- public static string? LongName(this Region? region) => AttributeHelper.GetAttribute(region)?.LongName;
+ public static string? LongName(this Region region)
+ => AttributeHelper.GetAttribute(region)?.LongName;
+
+ ///
+ /// Get the Redump longnames for each known region
+ ///
+ ///
+ ///
+ public static string? LongName(this Region? region)
+ => AttributeHelper.GetAttribute(region)?.LongName;
///
/// Get the Redump shortnames for each known region
///
///
///
- public static string? ShortName(this Region? region) => AttributeHelper.GetAttribute(region)?.ShortName;
+ public static string? ShortName(this Region region)
+ => AttributeHelper.GetAttribute(region)?.ShortName;
+
+ ///
+ /// Get the Redump shortnames for each known region
+ ///
+ ///
+ ///
+ public static string? ShortName(this Region? region)
+ => AttributeHelper.GetAttribute(region)?.ShortName;
///
/// Get the Region enum value for a given string
@@ -1107,25 +1108,15 @@ namespace SabreTools.RedumpLib.Data
public static Region? ToRegion(string region)
{
region = region.ToLowerInvariant();
- var regions = (Region?[])Enum.GetValues(typeof(Region));
+ var regions = (Region[])Enum.GetValues(typeof(Region));
- // Check ISO 3166-1 alpha-2 codes
-#if NET20 || NET35
- var regionMapping = new Dictionary();
- foreach (var r in regions)
- {
- if (r.ShortName() == null)
- continue;
+ int index = Array.FindIndex(regions, r => region == r.ShortName());
+ if (index > -1)
+ return regions[index];
- regionMapping[r.ShortName()?.ToLowerInvariant() ?? string.Empty] = r;
- }
-#else
- Dictionary regionMapping = Array.FindAll(regions, r => r.ShortName() != null)
- .ToDictionary(r => r.ShortName()?.ToLowerInvariant() ?? string.Empty, r => r);
-#endif
-
- if (regionMapping.ContainsKey(region))
- return regionMapping[region];
+ index = Array.FindIndex(regions, r => region == r.LongName());
+ if (index > -1)
+ return regions[index];
return null;
}
@@ -1442,64 +1433,146 @@ namespace SabreTools.RedumpLib.Data
///
///
///
- public static string? LongName(this RedumpSystem? system) => AttributeHelper.GetAttribute(system)?.LongName;
+ public static string? LongName(this RedumpSystem system)
+ => AttributeHelper.GetAttribute(system)?.LongName;
+
+ ///
+ /// Get the Redump longnames for each known system
+ ///
+ ///
+ ///
+ public static string? LongName(this RedumpSystem? system)
+ => AttributeHelper.GetAttribute(system)?.LongName;
///
/// Get the Redump shortnames for each known system
///
///
///
- public static string? ShortName(this RedumpSystem? system) => AttributeHelper.GetAttribute(system)?.ShortName;
+ public static string? ShortName(this RedumpSystem system)
+ => AttributeHelper.GetAttribute(system)?.ShortName;
+
+ ///
+ /// Get the Redump shortnames for each known system
+ ///
+ ///
+ ///
+ public static string? ShortName(this RedumpSystem? system)
+ => AttributeHelper.GetAttribute(system)?.ShortName;
///
/// Determine the category of a system
///
- public static SystemCategory GetCategory(this RedumpSystem? system) => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.Category ?? SystemCategory.NONE;
+ public static SystemCategory GetCategory(this RedumpSystem? system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.Category ?? SystemCategory.NONE;
///
/// Determine if a system is available in Redump yet
///
- public static bool IsAvailable(this RedumpSystem? system) => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.Available ?? false;
+ public static bool IsAvailable(this RedumpSystem system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.Available ?? false;
+
+ ///
+ /// Determine if a system is available in Redump yet
+ ///
+ public static bool IsAvailable(this RedumpSystem? system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.Available ?? false;
///
/// Determine if a system is restricted to dumpers
///
- public static bool IsBanned(this RedumpSystem? system) => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.IsBanned ?? false;
+ public static bool IsBanned(this RedumpSystem system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.IsBanned ?? false;
+
+ ///
+ /// Determine if a system is restricted to dumpers
+ ///
+ public static bool IsBanned(this RedumpSystem? system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.IsBanned ?? false;
///
/// Determine if a system has a CUE pack
///
- public static bool HasCues(this RedumpSystem? system) => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasCues ?? false;
+ public static bool HasCues(this RedumpSystem system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasCues ?? false;
+
+ ///
+ /// Determine if a system has a CUE pack
+ ///
+ public static bool HasCues(this RedumpSystem? system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasCues ?? false;
///
/// Determine if a system has a DAT
///
- public static bool HasDat(this RedumpSystem? system) => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasDat ?? false;
+ public static bool HasDat(this RedumpSystem system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasDat ?? false;
+
+ ///
+ /// Determine if a system has a DAT
+ ///
+ public static bool HasDat(this RedumpSystem? system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasDat ?? false;
///
/// Determine if a system has a decrypted keys pack
///
- public static bool HasDkeys(this RedumpSystem? system) => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasDkeys ?? false;
+ public static bool HasDkeys(this RedumpSystem system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasDkeys ?? false;
+
+ ///
+ /// Determine if a system has a decrypted keys pack
+ ///
+ public static bool HasDkeys(this RedumpSystem? system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasDkeys ?? false;
///
/// Determine if a system has a GDI pack
///
- public static bool HasGdi(this RedumpSystem? system) => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasGdi ?? false;
+ public static bool HasGdi(this RedumpSystem system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasGdi ?? false;
+
+ ///
+ /// Determine if a system has a GDI pack
+ ///
+ public static bool HasGdi(this RedumpSystem? system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasGdi ?? false;
///
/// Determine if a system has a keys pack
///
- public static bool HasKeys(this RedumpSystem? system) => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasKeys ?? false;
+ public static bool HasKeys(this RedumpSystem system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasKeys ?? false;
+
+ ///
+ /// Determine if a system has a keys pack
+ ///
+ public static bool HasKeys(this RedumpSystem? system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasKeys ?? false;
///
/// Determine if a system has an LSD pack
///
- public static bool HasLsd(this RedumpSystem? system) => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasLsd ?? false;
+ public static bool HasLsd(this RedumpSystem system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasLsd ?? false;
+
+ ///
+ /// Determine if a system has an LSD pack
+ ///
+ public static bool HasLsd(this RedumpSystem? system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasLsd ?? false;
///
/// Determine if a system has an SBI pack
///
- public static bool HasSbi(this RedumpSystem? system) => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasSbi ?? false;
+ public static bool HasSbi(this RedumpSystem system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasSbi ?? false;
+
+ ///
+ /// Determine if a system has an SBI pack
+ ///
+ public static bool HasSbi(this RedumpSystem? system)
+ => (AttributeHelper.GetAttribute(system) as SystemAttribute)?.HasSbi ?? false;
///
/// Get the RedumpSystem enum value for a given string
diff --git a/SabreTools.RedumpLib/Web/Packs.cs b/SabreTools.RedumpLib/Web/Packs.cs
index d5d7149..f7fa3db 100644
--- a/SabreTools.RedumpLib/Web/Packs.cs
+++ b/SabreTools.RedumpLib/Web/Packs.cs
@@ -17,7 +17,7 @@ namespace SabreTools.RedumpLib.Web
/// True to use named subfolders to store downloads, false to store directly in the output directory
public static async Task DownloadPacks(RedumpClient rc, string? outDir, bool useSubfolders)
{
- var systems = (RedumpSystem?[])Enum.GetValues(typeof(RedumpSystem));
+ var systems = (RedumpSystem[])Enum.GetValues(typeof(RedumpSystem));
await rc.DownloadPacks(Constants.PackCuesUrl, Array.FindAll(systems, s => s.HasCues()), "CUEs", outDir, useSubfolders ? "cue" : null);
await rc.DownloadPacks(Constants.PackDatfileUrl, Array.FindAll(systems, s => s.HasDat()), "DATs", outDir, useSubfolders ? "dat" : null);
@@ -39,7 +39,10 @@ namespace SabreTools.RedumpLib.Web
/// True to use named subfolders to store downloads, false to store directly in the output directory
public static async Task DownloadPacksForSystem(RedumpClient rc, RedumpSystem? system, string? outDir, bool useSubfolders)
{
- var systemAsArray = new RedumpSystem?[] { system };
+ if (system == null)
+ return false;
+
+ var systemAsArray = new RedumpSystem[] { system.Value };
if (system.HasCues())
await rc.DownloadPacks(Constants.PackCuesUrl, systemAsArray, "CUEs", outDir, useSubfolders ? "cue" : null);
diff --git a/SabreTools.RedumpLib/Web/RedumpClient.cs b/SabreTools.RedumpLib/Web/RedumpClient.cs
index 9f88e81..de62006 100644
--- a/SabreTools.RedumpLib/Web/RedumpClient.cs
+++ b/SabreTools.RedumpLib/Web/RedumpClient.cs
@@ -725,7 +725,7 @@ namespace SabreTools.RedumpLib.Web
/// Base URL to download using
/// Systems to download packs for
/// Name of the pack that is downloading
- public async Task> DownloadPacks(string url, RedumpSystem?[] systems, string title)
+ public async Task> DownloadPacks(string url, RedumpSystem[] systems, string title)
{
var packsDictionary = new Dictionary();
@@ -733,7 +733,7 @@ namespace SabreTools.RedumpLib.Web
foreach (var system in systems)
{
// If the system is invalid, we can't do anything
- if (system == null || !system.IsAvailable())
+ if (!system.IsAvailable())
continue;
// If we didn't have credentials
@@ -748,7 +748,7 @@ namespace SabreTools.RedumpLib.Web
Console.Write($"\r{longName}{new string(' ', Console.BufferWidth - longName!.Length - 1)}");
byte[]? pack = await DownloadSinglePack(url, system);
if (pack != null)
- packsDictionary.Add(system.Value, pack);
+ packsDictionary.Add(system, pack);
}
Console.Write($"\rComplete!{new string(' ', Console.BufferWidth - 10)}");
@@ -765,13 +765,13 @@ namespace SabreTools.RedumpLib.Web
/// Name of the pack that is downloading
/// Output directory to save data to
/// Named subfolder for the pack, used optionally
- public async Task DownloadPacks(string url, RedumpSystem?[] systems, string title, string? outDir, string? subfolder)
+ public async Task DownloadPacks(string url, RedumpSystem[] systems, string title, string? outDir, string? subfolder)
{
Console.WriteLine($"Downloading {title}");
foreach (var system in systems)
{
// If the system is invalid, we can't do anything
- if (system == null || !system.IsAvailable())
+ if (!system.IsAvailable())
continue;
// If we didn't have credentials