diff --git a/SabreTools.RedumpLib/Web/Packs.cs b/SabreTools.RedumpLib/Web/Packs.cs
index 9ee6005..3bfb956 100644
--- a/SabreTools.RedumpLib/Web/Packs.cs
+++ b/SabreTools.RedumpLib/Web/Packs.cs
@@ -20,25 +20,25 @@ namespace SabreTools.RedumpLib.Web
var systems = (RedumpSystem[])Enum.GetValues(typeof(RedumpSystem));
Console.WriteLine("Downloading CUEs");
- await client.DownloadPacks(Constants.PackCuesUrl, Array.FindAll(systems, s => s.HasCues()), outDir, useSubfolders ? "cue" : null);
+ await client.DownloadPacks(PackType.Cuesheets, systems, outDir, useSubfolders ? "cue" : null);
Console.WriteLine("Downloading DATs");
- await client.DownloadPacks(Constants.PackDatfileUrl, Array.FindAll(systems, s => s.HasDat()), outDir, useSubfolders ? "dat" : null);
+ await client.DownloadPacks(PackType.Datfile, systems, outDir, useSubfolders ? "dat" : null);
Console.WriteLine("Downloading Decrypted KEYS");
- await client.DownloadPacks(Constants.PackDkeysUrl, Array.FindAll(systems, s => s.HasDkeys()), outDir, useSubfolders ? "dkey" : null);
+ await client.DownloadPacks(PackType.DecryptedKeys, systems, outDir, useSubfolders ? "dkey" : null);
Console.WriteLine("Downloading GDIs");
- await client.DownloadPacks(Constants.PackGdiUrl, Array.FindAll(systems, s => s.HasGdi()), outDir, useSubfolders ? "gdi" : null);
+ await client.DownloadPacks(PackType.Gdis, systems, outDir, useSubfolders ? "gdi" : null);
Console.WriteLine("Downloading KEYS");
- await client.DownloadPacks(Constants.PackKeysUrl, Array.FindAll(systems, s => s.HasKeys()), outDir, useSubfolders ? "keys" : null);
+ await client.DownloadPacks(PackType.Keys, systems, outDir, useSubfolders ? "keys" : null);
Console.WriteLine("Downloading LSD");
- await client.DownloadPacks(Constants.PackLsdUrl, Array.FindAll(systems, s => s.HasLsd()), outDir, useSubfolders ? "lsd" : null);
+ await client.DownloadPacks(PackType.Lsds, systems, outDir, useSubfolders ? "lsd" : null);
Console.WriteLine("Downloading SBIs");
- await client.DownloadPacks(Constants.PackSbiUrl, Array.FindAll(systems, s => s.HasSbi()), outDir, useSubfolders ? "sbi" : null);
+ await client.DownloadPacks(PackType.Sbis, systems, outDir, useSubfolders ? "sbi" : null);
return true;
}
@@ -63,43 +63,43 @@ namespace SabreTools.RedumpLib.Web
if (system.HasCues())
{
Console.WriteLine("Downloading CUEs");
- await client.DownloadPacks(Constants.PackCuesUrl, systemAsArray, outDir, useSubfolders ? "cue" : null);
+ await client.DownloadPacks(PackType.Cuesheets, systemAsArray, outDir, useSubfolders ? "cue" : null);
}
if (system.HasDat())
{
Console.WriteLine("Downloading DATs");
- await client.DownloadPacks(Constants.PackDatfileUrl, systemAsArray, outDir, useSubfolders ? "dat" : null);
+ await client.DownloadPacks(PackType.Datfile, systemAsArray, outDir, useSubfolders ? "dat" : null);
}
if (system.HasDkeys())
{
Console.WriteLine("Downloading Decrypted KEYS");
- await client.DownloadPacks(Constants.PackDkeysUrl, systemAsArray, outDir, useSubfolders ? "dkey" : null);
+ await client.DownloadPacks(PackType.DecryptedKeys, systemAsArray, outDir, useSubfolders ? "dkey" : null);
}
if (system.HasGdi())
{
Console.WriteLine("Downloading GDIs");
- await client.DownloadPacks(Constants.PackGdiUrl, systemAsArray, outDir, useSubfolders ? "gdi" : null);
+ await client.DownloadPacks(PackType.Gdis, systemAsArray, outDir, useSubfolders ? "gdi" : null);
}
if (system.HasKeys())
{
Console.WriteLine("Downloading KEYS");
- await client.DownloadPacks(Constants.PackKeysUrl, systemAsArray, outDir, useSubfolders ? "keys" : null);
+ await client.DownloadPacks(PackType.Keys, systemAsArray, outDir, useSubfolders ? "keys" : null);
}
if (system.HasLsd())
{
Console.WriteLine("Downloading LSD");
- await client.DownloadPacks(Constants.PackLsdUrl, systemAsArray, outDir, useSubfolders ? "lsd" : null);
+ await client.DownloadPacks(PackType.Lsds, systemAsArray, outDir, useSubfolders ? "lsd" : null);
}
if (system.HasSbi())
{
Console.WriteLine("Downloading SBIs");
- await client.DownloadPacks(Constants.PackSbiUrl, systemAsArray, outDir, useSubfolders ? "sbi" : null);
+ await client.DownloadPacks(PackType.Sbis, systemAsArray, outDir, useSubfolders ? "sbi" : null);
}
return true;
diff --git a/SabreTools.RedumpLib/Web/RedumpClient.cs b/SabreTools.RedumpLib/Web/RedumpClient.cs
index b086d3c..d925ab1 100644
--- a/SabreTools.RedumpLib/Web/RedumpClient.cs
+++ b/SabreTools.RedumpLib/Web/RedumpClient.cs
@@ -1020,58 +1020,6 @@ namespace SabreTools.RedumpLib.Web
#region Helpers
- ///
- /// Download a set of packs
- ///
- /// Base URL to download using
- /// Systems to download packs for
- public async Task> DownloadPacks(string url, RedumpSystem[] systems)
- {
- var packsDictionary = new Dictionary();
- foreach (var system in systems)
- {
- // If the system is invalid, we can't do anything
- if (!system.IsAvailable())
- {
- if (Debug) Console.WriteLine($"DEBUG: {system} is not marked as available on Redump, skipping...");
- continue;
- }
-
- // If we didn't have credentials
- if (!_loggedIn && system.IsBanned())
- {
- if (Debug) Console.WriteLine($"DEBUG: {system} requires a user login to access, skipping...");
- continue;
- }
-
- // If the system is unknown, we can't do anything
- string? longName = system.LongName();
- if (string.IsNullOrEmpty(longName))
- {
- if (Debug) Console.WriteLine($"DEBUG: {system} is not a recognized system, skipping...");
- continue;
- }
-
- if (Debug)
- Console.WriteLine(longName);
- else
- Console.Write($"\r{longName}{new string(' ', Console.BufferWidth - longName!.Length - 1)}");
-
- byte[]? pack = await DownloadSinglePack(url, system);
- if (pack is not null)
- packsDictionary.Add(system, pack);
- }
-
- if (Debug)
- Console.WriteLine("Complete!");
- else
- Console.Write($"\rComplete!{new string(' ', Console.BufferWidth - 10)}");
-
- Console.WriteLine();
-
- return packsDictionary;
- }
-
///
/// Download a set of packs
///
@@ -1083,7 +1031,7 @@ namespace SabreTools.RedumpLib.Web
string? baseUrl = PackTypeToBaseUrl(packType);
if (baseUrl is null)
{
- if (Debug) Console.Error.WriteLine($"'{packType}' is not a recognized pack type, skipping...");
+ if (Debug) Console.Error.WriteLine($"DEBUG: {packType} is not a recognized pack type, skipping...");
return [];
}
@@ -1112,6 +1060,13 @@ namespace SabreTools.RedumpLib.Web
continue;
}
+ // If the pack is not supported for the system
+ if (!PackTypeToAvailable(packType, system))
+ {
+ if (Debug) Console.WriteLine($"DEBUG: {packType} is not available for {system}, skipping...");
+ continue;
+ }
+
if (Debug)
Console.WriteLine(longName);
else
@@ -1132,56 +1087,6 @@ namespace SabreTools.RedumpLib.Web
return packsDictionary;
}
- ///
- /// Download a set of packs
- ///
- /// Base URL to download using
- /// Systems to download packs for
- /// Output directory to save data to
- /// Named subfolder for the pack, used optionally
- public async Task DownloadPacks(string url, RedumpSystem[] systems, string? outDir, string? subfolder)
- {
- foreach (var system in systems)
- {
- // If the system is invalid, we can't do anything
- if (!system.IsAvailable())
- {
- if (Debug) Console.WriteLine($"DEBUG: {system} is not marked as available on Redump, skipping...");
- continue;
- }
-
- // If we didn't have credentials
- if (!_loggedIn && system.IsBanned())
- {
- if (Debug) Console.WriteLine($"DEBUG: {system} requires a user login to access, skipping...");
- continue;
- }
-
- // If the system is unknown, we can't do anything
- string? longName = system.LongName();
- if (string.IsNullOrEmpty(longName))
- {
- if (Debug) Console.WriteLine($"DEBUG: {system} is not a recognized system, skipping...");
- continue;
- }
-
- if (Debug)
- Console.WriteLine(longName);
- else
- Console.Write($"\r{longName}{new string(' ', Console.BufferWidth - longName!.Length - 1)}");
-
- await DownloadSinglePack(url, system, outDir, subfolder);
- }
-
- if (Debug)
- Console.WriteLine("Complete!");
- else
- Console.Write($"\rComplete!{new string(' ', Console.BufferWidth - 10)}");
-
- Console.WriteLine();
- return true;
- }
-
///
/// Download a set of packs
///
@@ -1195,7 +1100,7 @@ namespace SabreTools.RedumpLib.Web
string? baseUrl = PackTypeToBaseUrl(packType);
if (baseUrl is null)
{
- if (Debug) Console.Error.WriteLine($"'{packType}' is not a recognized pack type, skipping...");
+ if (Debug) Console.Error.WriteLine($"DEBUG: {packType} is not a recognized pack type, skipping...");
return false;
}
@@ -1223,6 +1128,13 @@ namespace SabreTools.RedumpLib.Web
continue;
}
+ // If the pack is not supported for the system
+ if (!PackTypeToAvailable(packType, system))
+ {
+ if (Debug) Console.WriteLine($"DEBUG: {packType} is not available for {system}, skipping...");
+ continue;
+ }
+
if (Debug)
Console.WriteLine(longName);
else
@@ -1240,26 +1152,6 @@ namespace SabreTools.RedumpLib.Web
return true;
}
- ///
- /// Convert the pack type to a base URL
- ///
- ///
- ///
- private static string? PackTypeToBaseUrl(PackType packType)
- {
- return packType switch
- {
- PackType.Cuesheets => Constants.PackCuesUrl,
- PackType.Datfile => Constants.PackDatfileUrl,
- PackType.DecryptedKeys => Constants.PackDkeysUrl,
- PackType.Gdis => Constants.PackGdiUrl,
- PackType.Keys => Constants.PackKeysUrl,
- PackType.Lsds => Constants.PackLsdUrl,
- PackType.Sbis => Constants.PackSbiUrl,
- _ => null,
- };
- }
-
///
/// Move a tempfile to a new name unless it aleady exists, in which case, delete the tempfile
///
@@ -1292,6 +1184,47 @@ namespace SabreTools.RedumpLib.Web
File.Move(tempfile, Path.Combine(outDir, newfile));
}
+ ///
+ /// Convert the pack type to a base URL
+ ///
+ /// Pack type to use to determine the download URL
+ /// Base URL for downloading a pack type, null on error
+ private static string? PackTypeToBaseUrl(PackType packType)
+ {
+ return packType switch
+ {
+ PackType.Cuesheets => Constants.PackCuesUrl,
+ PackType.Datfile => Constants.PackDatfileUrl,
+ PackType.DecryptedKeys => Constants.PackDkeysUrl,
+ PackType.Gdis => Constants.PackGdiUrl,
+ PackType.Keys => Constants.PackKeysUrl,
+ PackType.Lsds => Constants.PackLsdUrl,
+ PackType.Sbis => Constants.PackSbiUrl,
+ _ => null,
+ };
+ }
+
+ ///
+ /// Determine if a pack is available for a given system
+ ///
+ /// Pack type to use to determine the support status
+ /// Systems to determine pack availability for
+ /// True if the pack is available for a system, false otherwise
+ private static bool PackTypeToAvailable(PackType packType, RedumpSystem system)
+ {
+ return packType switch
+ {
+ PackType.Cuesheets => system.HasCues(),
+ PackType.Datfile => system.HasDat(),
+ PackType.DecryptedKeys => system.HasDkeys(),
+ PackType.Gdis => system.HasGdi(),
+ PackType.Keys => system.HasKeys(),
+ PackType.Lsds => system.HasLsd(),
+ PackType.Sbis => system.HasSbi(),
+ _ => false,
+ };
+ }
+
#endregion
}
}