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

200 lines
7.5 KiB
C#
Raw Permalink Normal View History

2026-02-26 22:54:53 -05:00
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SabreTools.CommandLine.Inputs;
using SabreTools.RedumpLib.Data;
2026-06-21 22:49:04 -04:00
using SabreTools.RedumpLib.Web;
2026-02-26 22:54:53 -05:00
namespace RedumpTool.Features
{
2026-07-08 10:18:51 -04:00
internal sealed class QueueFeature : BaseFeature
2026-02-26 22:54:53 -05:00
{
#region Feature Definition
2026-07-08 10:18:51 -04:00
public const string DisplayName = "queue";
2026-02-26 22:54:53 -05:00
2026-07-08 10:18:51 -04:00
private static readonly string[] _flags = ["queue"];
2026-02-26 22:54:53 -05:00
2026-07-08 10:18:51 -04:00
private const string _description = "Download pages and related files from the submission queue";
2026-02-26 22:54:53 -05:00
#endregion
#region Inputs
2026-07-08 12:42:07 -04:00
private const string _discIdName = "disc-id";
internal readonly Int32Input DiscIDInput = new(_discIdName, ["--disc-id"], "Add disc ID to filter");
private const string _isDiscHistoryName = "is-disc-history";
internal readonly BooleanInput IsDiscHistoryInput = new(_isDiscHistoryName, ["--is-disc-history"], "Add disc history status to filter [true, false]");
2026-02-26 22:54:53 -05:00
private const string _maximumName = "maximum";
2026-03-03 15:20:27 -05:00
internal readonly Int32Input MaximumInput = new(_maximumName, ["-max", "--maximum"], "Upper bound for page numbers (incompatible with --onlynew)");
2026-02-26 22:54:53 -05:00
private const string _minimumName = "minimum";
2026-03-03 15:20:27 -05:00
internal readonly Int32Input MinimumInput = new(_minimumName, ["-min", "--minimum"], "Lower bound for page numbers (incompatible with --onlynew)");
2026-02-26 22:54:53 -05:00
private const string _limitName = "limit";
internal readonly Int32Input LimitInput = new(_limitName, ["--limit"], "Limit number of retrieved result pages");
2026-07-08 12:50:18 -04:00
private const string _listName = "list";
internal readonly FlagInput ListInput = new(_listName, ["-l", "--list"], "Only list the page IDs for the filters");
2026-07-08 12:42:07 -04:00
private const string _orderName = "order";
internal readonly StringInput OrderInput = new(_orderName, ["--order"], "Add sort order to filter [asc, desc]");
private const string _sortName = "sort";
internal readonly StringInput SortInput = new(_sortName, ["--sort"], "Add sort category to filter [title, added, region, system, version, edition, language, serial, status, modified]");
private const string _statusName = "status";
internal readonly StringInput StatusInput = new(_statusName, ["--status"], "Add status to filter [grey, red, yellow, blue, green]");
private const string _submitterName = "submitter";
internal readonly StringInput SubmitterInput = new(_submitterName, ["--submitter"], "Add submitter to filter");
private const string _subTypeName = "sub-type";
internal readonly StringInput SubTypeInput = new(_subTypeName, ["--sub-type"], "Add submission type to filter [edit, new disc, verification]");
private const string _systemName = "system";
internal readonly StringInput SystemInput = new(_systemName, ["--system"], "Add system to filter");
2026-02-26 22:54:53 -05:00
#endregion
2026-07-08 10:18:51 -04:00
public QueueFeature()
2026-02-26 22:54:53 -05:00
: 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
Add(LimitInput);
2026-07-08 12:50:18 -04:00
Add(ListInput);
2026-02-26 22:54:53 -05:00
Add(MinimumInput);
Add(MaximumInput);
2026-07-08 12:42:07 -04:00
// Filter
Add(DiscIDInput);
Add(IsDiscHistoryInput);
Add(OrderInput);
Add(SortInput);
Add(StatusInput);
Add(SubmitterInput);
Add(SubTypeInput);
Add(SystemInput);
2026-02-26 22:54:53 -05:00
}
/// <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;
2026-02-27 11:14:05 -05:00
int? attemptCount = AttemptCountInput.Value;
int? timeout = TimeoutInput.Value;
bool forceDownload = ForceDownloadInput.Value;
bool forceContinue = ForceContinueInput.Value;
2026-02-27 11:14:05 -05:00
// Get specific values
int limit = LimitInput.Value ?? -1;
2026-07-08 12:42:07 -04:00
int? minId = MinimumInput.Value;
int? maxId = MaximumInput.Value;
2026-07-08 12:50:18 -04:00
bool onlyList = ListInput.Value;
2026-07-08 12:42:07 -04:00
// Get filter values
long? discId = DiscIDInput.Value;
bool? isDiscHistory = IsDiscHistoryInput.Value;
SortDirection? order = OrderInput.Value.ToSortDirection();
SortCategory? sort = SortInput.Value.ToSortCategory();
DumpStatus? status = StatusInput.Value.ToDumpStatus();
string? submitter = SubmitterInput.Value;
SubmissionType? subType = SubTypeInput.Value.ToSubmissionType();
PhysicalSystem? system = SystemInput.Value.ToPhysicalSystem();
2026-02-26 22:54:53 -05:00
// Output directory validation
2026-07-08 12:50:18 -04:00
if (!onlyList && !ValidateAndCreateOutputDirectory(outDir))
2026-02-26 22:54:53 -05:00
return false;
// Range verification
2026-07-08 12:42:07 -04:00
if ((minId is null) ^ (maxId is null))
{
Console.WriteLine("Both a maximum and minimum ID are required");
return false;
}
else if (minId is not null && minId < 0)
{
Console.WriteLine($"{minId} is an invalid minimum ID");
return false;
}
else if (maxId is not null && maxId < 0)
2026-02-26 22:54:53 -05:00
{
2026-07-08 12:42:07 -04:00
Console.WriteLine($"{maxId} is an invalid maximum ID");
2026-02-26 22:54:53 -05:00
return false;
}
2026-07-04 22:40:53 -04:00
// Update redump.info 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
Task<List<int>> processingTask;
2026-07-08 12:50:18 -04:00
if ((minId is null || maxId is null) && onlyList)
{
processingTask = _client.ListQueueResults(
discId,
isDiscHistory,
order,
sort,
status,
submitter,
subType,
system,
limit);
2026-07-08 12:50:18 -04:00
}
else if ((minId is null || maxId is null) && !onlyList)
2026-07-08 12:42:07 -04:00
{
processingTask = _client.DownloadQueueResults(outDir,
discId,
isDiscHistory,
order,
sort,
status,
submitter,
subType,
system,
limit);
2026-07-08 12:42:07 -04:00
}
2026-02-26 22:54:53 -05:00
else
2026-07-08 12:42:07 -04:00
{
2026-07-08 12:50:18 -04:00
processingTask = _client.DownloadQueueRange(outDir, minId!.Value, maxId!.Value);
2026-07-08 12:42:07 -04:00
}
2026-07-04 22:40:53 -04:00
// Retrieve the result
processingTask.Wait();
var processedIds = processingTask.Result;
// Display the processed IDs
return PrintProcessedIds(processedIds);
2026-02-26 22:54:53 -05:00
}
/// <inheritdoc/>
public override bool VerifyInputs() => true;
}
}