mirror of
https://github.com/SabreTools/SabreTools.RedumpLib.git
synced 2026-09-22 06:54:32 +00:00
Start making URLs less visible
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -1020,58 +1020,6 @@ namespace SabreTools.RedumpLib.Web
|
||||
|
||||
#region Helpers
|
||||
|
||||
/// <summary>
|
||||
/// Download a set of packs
|
||||
/// </summary>
|
||||
/// <param name="url">Base URL to download using</param>
|
||||
/// <param name="system">Systems to download packs for</param>
|
||||
public async Task<Dictionary<RedumpSystem, byte[]>> DownloadPacks(string url, RedumpSystem[] systems)
|
||||
{
|
||||
var packsDictionary = new Dictionary<RedumpSystem, byte[]>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download a set of packs
|
||||
/// </summary>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download a set of packs
|
||||
/// </summary>
|
||||
/// <param name="url">Base URL to download using</param>
|
||||
/// <param name="systems">Systems to download packs for</param>
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
/// <param name="subfolder">Named subfolder for the pack, used optionally</param>
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download a set of packs
|
||||
/// </summary>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert the pack type to a base URL
|
||||
/// </summary>
|
||||
/// <param name="packType"></param>
|
||||
/// <returns></returns>
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move a tempfile to a new name unless it aleady exists, in which case, delete the tempfile
|
||||
/// </summary>
|
||||
@@ -1292,6 +1184,47 @@ namespace SabreTools.RedumpLib.Web
|
||||
File.Move(tempfile, Path.Combine(outDir, newfile));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert the pack type to a base URL
|
||||
/// </summary>
|
||||
/// <param name="packType">Pack type to use to determine the download URL</param>
|
||||
/// <returns>Base URL for downloading a pack type, null on error</returns>
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a pack is available for a given system
|
||||
/// </summary>
|
||||
/// <param name="packType">Pack type to use to determine the support status</param>
|
||||
/// <param name="system">Systems to determine pack availability for</param>
|
||||
/// <returns>True if the pack is available for a system, false otherwise</returns>
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user