Files
SabreTools.RedumpLib/RedumpTool/Features/PacksFeature.cs

93 lines
3.0 KiB
C#
Raw Permalink Normal View History

2026-02-27 09:58:05 -05:00
using System;
2026-02-26 22:54:53 -05:00
using SabreTools.CommandLine.Inputs;
2026-06-21 22:49:04 -04:00
using SabreTools.RedumpLib.Web;
2026-02-26 22:54:53 -05:00
namespace RedumpTool.Features
{
internal sealed class PacksFeature : BaseFeature
{
#region Feature Definition
public const string DisplayName = "packs";
private static readonly string[] _flags = ["packs"];
private const string _description = "Download available packs";
#endregion
#region Inputs
2026-07-08 13:41:44 -04:00
private const string _includeDatabseName = "include-database";
internal readonly FlagInput IncludeDatabaseInput = new(_includeDatabseName, ["-b", "--database"], "Include database in downloads");
2026-02-26 22:54:53 -05:00
private const string _subfoldersName = "subfolders";
internal readonly FlagInput SubfoldersInput = new(_subfoldersName, ["-s", "--subfolders"], "Download packs to named subfolders");
#endregion
public PacksFeature()
: base(DisplayName, _flags, _description)
{
RequiresInputs = false;
// Common
Add(DebugInput);
Add(OutputInput);
Add(UsernameInput);
Add(PasswordInput);
Add(AttemptCountInput);
2026-02-27 09:58:05 -05:00
Add(TimeoutInput);
Add(ForceDownloadInput);
Add(ForceContinueInput);
2026-02-26 22:54:53 -05:00
// Specific
2026-07-08 13:41:44 -04:00
Add(IncludeDatabaseInput);
2026-02-26 22:54:53 -05:00
Add(SubfoldersInput);
}
/// <inheritdoc/>
public override bool Execute()
{
2026-02-27 11:14:05 -05:00
// Get common values
string? outDir = OutputInput.Value;
string? username = UsernameInput.Value;
string? password = PasswordInput.Value;
int? attemptCount = AttemptCountInput.Value;
2026-02-27 09:58:05 -05:00
int? timeout = TimeoutInput.Value;
bool forceDownload = ForceDownloadInput.Value;
bool forceContinue = ForceContinueInput.Value;
2026-02-26 22:54:53 -05:00
2026-02-27 11:14:05 -05:00
// Get specific values
2026-07-08 13:41:44 -04:00
bool includeDatabase = IncludeDatabaseInput.Value;
2026-02-27 11:14:05 -05:00
bool useSubfolders = SubfoldersInput.Value;
2026-02-26 22:54:53 -05:00
// Output directory validation
2026-02-27 11:14:05 -05:00
if (!ValidateAndCreateOutputDirectory(outDir))
2026-02-26 22:54:53 -05:00
return false;
2026-07-04 22:40:53 -04:00
// Update redump.info client properties
_client.Debug = DebugInput.Value;
if (attemptCount != null && attemptCount > 0)
_client.AttemptCount = attemptCount.Value;
if (timeout != null && timeout > 0)
_client.Timeout = TimeSpan.FromSeconds(timeout.Value);
_client.Overwrite = forceDownload;
_client.IgnoreErrors = forceContinue;
// Login to redump.info, if necessary
_client.Login(username, password).Wait();
// Start the processing
2026-07-08 13:41:44 -04:00
var processingTask = _client.DownloadAllPacks(outDir, includeDatabase, useSubfolders);
2026-07-04 22:40:53 -04:00
// Retrieve the result
processingTask.Wait();
return processingTask.Result;
2026-02-26 22:54:53 -05:00
}
/// <inheritdoc/>
public override bool VerifyInputs() => true;
}
}