diff --git a/RedumpTool/Features/PacksFeature.cs b/RedumpTool/Features/PacksFeature.cs
index 5be45e4..7e0563b 100644
--- a/RedumpTool/Features/PacksFeature.cs
+++ b/RedumpTool/Features/PacksFeature.cs
@@ -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();
diff --git a/RedumpTool/Program.cs b/RedumpTool/Program.cs
index ade5789..e62631e 100644
--- a/RedumpTool/Program.cs
+++ b/RedumpTool/Program.cs
@@ -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();
diff --git a/SabreTools.RedumpLib/Web/Client.cs b/SabreTools.RedumpLib/Web/Client.cs
index a58b0e6..4b9347f 100644
--- a/SabreTools.RedumpLib/Web/Client.cs
+++ b/SabreTools.RedumpLib/Web/Client.cs
@@ -943,6 +943,43 @@ namespace SabreTools.RedumpLib.Web
#region Download Helpers
+ ///
+ /// Download the database
+ ///
+ /// Output directory to save data to
+ /// Named subfolder for the pack, used optionally
+ public async Task 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;
+ }
+ }
+
///
/// Download a single pack
///
@@ -1407,7 +1444,7 @@ namespace SabreTools.RedumpLib.Web
/// Download a set of packs
///
/// Pack type to use to determine the download URL
- /// Systems to download packs for
+ /// Systems to download packs for
public async Task> DownloadPacks(PackType packType, PhysicalSystem[] systems)
{
// Determine if the pack type is valid
diff --git a/SabreTools.RedumpLib/Web/Packs.cs b/SabreTools.RedumpLib/Web/Packs.cs
index 2146c9f..6f167bd 100644
--- a/SabreTools.RedumpLib/Web/Packs.cs
+++ b/SabreTools.RedumpLib/Web/Packs.cs
@@ -14,11 +14,15 @@ namespace SabreTools.RedumpLib.Web
///
/// RedumpClient for connectivity
/// Output directory to save data to
+ /// Include database in downloads
/// True to use named subfolders to store downloads, false to store directly in the output directory
- public static async Task DownloadAllPacks(this Client client, string? outDir, bool useSubfolders)
+ public static async Task 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);
}
///
@@ -27,17 +31,19 @@ namespace SabreTools.RedumpLib.Web
/// RedumpClient for connectivity
/// PhysicalSystem to get all possible packs for
/// Output directory to save data to
+ /// Include database in downloads
/// True to use named subfolders to store downloads, false to store directly in the output directory
public static async Task 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);
}
///
@@ -46,10 +52,12 @@ namespace SabreTools.RedumpLib.Web
/// RedumpClient for connectivity
/// Systems to download packs for
/// Output directory to save data to
+ /// Include database in downloads
/// True to use named subfolders to store downloads, false to store directly in the output directory
public static async Task 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;
}
}