mirror of
https://github.com/SabreTools/SabreTools.RedumpLib.git
synced 2026-07-08 18:16:25 +00:00
Add database download to packs feature
This commit is contained in:
@@ -18,6 +18,9 @@ namespace RedumpTool.Features
|
||||
|
||||
#region Inputs
|
||||
|
||||
private const string _includeDatabseName = "include-database";
|
||||
internal readonly FlagInput IncludeDatabaseInput = new(_includeDatabseName, ["-b", "--database"], "Include database in downloads");
|
||||
|
||||
private const string _subfoldersName = "subfolders";
|
||||
internal readonly FlagInput SubfoldersInput = new(_subfoldersName, ["-s", "--subfolders"], "Download packs to named subfolders");
|
||||
|
||||
@@ -39,6 +42,7 @@ namespace RedumpTool.Features
|
||||
Add(ForceContinueInput);
|
||||
|
||||
// Specific
|
||||
Add(IncludeDatabaseInput);
|
||||
Add(SubfoldersInput);
|
||||
}
|
||||
|
||||
@@ -55,6 +59,7 @@ namespace RedumpTool.Features
|
||||
bool forceContinue = ForceContinueInput.Value;
|
||||
|
||||
// Get specific values
|
||||
bool includeDatabase = IncludeDatabaseInput.Value;
|
||||
bool useSubfolders = SubfoldersInput.Value;
|
||||
|
||||
// Output directory validation
|
||||
@@ -74,7 +79,7 @@ namespace RedumpTool.Features
|
||||
_client.Login(username, password).Wait();
|
||||
|
||||
// Start the processing
|
||||
var processingTask = _client.DownloadAllPacks(outDir, useSubfolders);
|
||||
var processingTask = _client.DownloadAllPacks(outDir, includeDatabase, useSubfolders);
|
||||
|
||||
// Retrieve the result
|
||||
processingTask.Wait();
|
||||
|
||||
@@ -140,6 +140,7 @@ namespace RedumpTool
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("packs - Download available packs");
|
||||
Console.WriteLine(" -b, --database - Include database in downloads");
|
||||
Console.WriteLine(" -s, --subfolders - Download packs to named subfolders");
|
||||
Console.WriteLine();
|
||||
|
||||
|
||||
@@ -943,6 +943,43 @@ namespace SabreTools.RedumpLib.Web
|
||||
|
||||
#region Download Helpers
|
||||
|
||||
/// <summary>
|
||||
/// Download the database
|
||||
/// </summary>
|
||||
/// <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> DownloadDatabase(string? outDir, string? subfolder = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Debug) Console.WriteLine($"DEBUG: DownloadDatabase(\"{outDir}\", {subfolder})");
|
||||
|
||||
// Determine the database URL
|
||||
string dbUri = UrlBuilder.BuildDownloadsUrl(database: true);
|
||||
|
||||
// If no output directory is defined, use the current directory instead
|
||||
if (string.IsNullOrEmpty(outDir))
|
||||
{
|
||||
if (Debug) Console.WriteLine("DEBUG: Output directory was not provided, setting to current directory");
|
||||
outDir = Environment.CurrentDirectory;
|
||||
}
|
||||
|
||||
// Make the call to get the pack
|
||||
string tempfile = Path.Combine(outDir, "tmp" + Guid.NewGuid().ToString());
|
||||
string? remoteFileName = await DownloadFile(dbUri, tempfile);
|
||||
if (remoteFileName is null)
|
||||
return false;
|
||||
|
||||
MoveOrDelete(tempfile, remoteFileName, outDir!, subfolder);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"An exception has occurred: {ex}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download a single pack
|
||||
/// </summary>
|
||||
@@ -1407,7 +1444,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// Download a set of packs
|
||||
/// </summary>
|
||||
/// <param name="packType">Pack type to use to determine the download URL</param>
|
||||
/// <param name="system">Systems to download packs for</param>
|
||||
/// <param name="systems">Systems to download packs for</param>
|
||||
public async Task<Dictionary<PhysicalSystem, byte[]>> DownloadPacks(PackType packType, PhysicalSystem[] systems)
|
||||
{
|
||||
// Determine if the pack type is valid
|
||||
|
||||
@@ -14,11 +14,15 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// </summary>
|
||||
/// <param name="client">RedumpClient for connectivity</param>
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
/// <param name="includeDatabase">Include database in downloads</param>
|
||||
/// <param name="useSubfolders">True to use named subfolders to store downloads, false to store directly in the output directory</param>
|
||||
public static async Task<bool> DownloadAllPacks(this Client client, string? outDir, bool useSubfolders)
|
||||
public static async Task<bool> DownloadAllPacks(this Client client,
|
||||
string? outDir,
|
||||
bool includeDatabase,
|
||||
bool useSubfolders)
|
||||
{
|
||||
var systems = (PhysicalSystem[])Enum.GetValues(typeof(PhysicalSystem));
|
||||
return await client.DownloadPacksForSystems(systems, outDir, useSubfolders);
|
||||
return await client.DownloadPacksForSystems(systems, outDir, includeDatabase, useSubfolders);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -27,17 +31,19 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="client">RedumpClient for connectivity</param>
|
||||
/// <param name="system">PhysicalSystem to get all possible packs for</param>
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
/// <param name="includeDatabase">Include database in downloads</param>
|
||||
/// <param name="useSubfolders">True to use named subfolders to store downloads, false to store directly in the output directory</param>
|
||||
public static async Task<bool> DownloadPacksForSystem(this Client client,
|
||||
PhysicalSystem? system,
|
||||
string? outDir,
|
||||
bool includeDatabase,
|
||||
bool useSubfolders)
|
||||
{
|
||||
if (system is null)
|
||||
return false;
|
||||
|
||||
var systems = new PhysicalSystem[] { system.Value };
|
||||
return await client.DownloadPacksForSystems(systems, outDir, useSubfolders);
|
||||
return await client.DownloadPacksForSystems(systems, outDir, includeDatabase, useSubfolders);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -46,10 +52,12 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="client">RedumpClient for connectivity</param>
|
||||
/// <param name="systems">Systems to download packs for</param>
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
/// <param name="includeDatabase">Include database in downloads</param>
|
||||
/// <param name="useSubfolders">True to use named subfolders to store downloads, false to store directly in the output directory</param>
|
||||
public static async Task<bool> DownloadPacksForSystems(this Client client,
|
||||
PhysicalSystem[] systems,
|
||||
string? outDir,
|
||||
bool includeDatabase,
|
||||
bool useSubfolders)
|
||||
{
|
||||
Console.WriteLine("Downloading CUEs");
|
||||
@@ -64,6 +72,12 @@ namespace SabreTools.RedumpLib.Web
|
||||
Console.WriteLine("Downloading SBIs");
|
||||
_ = await client.DownloadPacks(PackType.Sbis, systems, outDir, useSubfolders ? "sbi" : null);
|
||||
|
||||
if (includeDatabase)
|
||||
{
|
||||
Console.WriteLine("Downloading database export");
|
||||
_ = await client.DownloadDatabase(outDir, useSubfolders ? "db" : null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user