Better unify common input handling

This commit is contained in:
Matt Nadareski
2026-02-27 11:14:05 -05:00
parent c913e667c8
commit 52ff255941
5 changed files with 63 additions and 40 deletions

View File

@@ -43,18 +43,23 @@ namespace RedumpTool.Features
/// <inheritdoc/>
public override bool Execute()
{
// Get values needed more than once
string? outputDirectory = OutputInput.Value;
// Get common values
string? outDir = OutputInput.Value;
string username = UsernameInput.Value ?? string.Empty;
string password = PasswordInput.Value ?? string.Empty;
int? attemptCount = AttemptCountInput.Value;
int? timeout = TimeoutInput.Value;
// Get specific values
bool useSubfolders = SubfoldersInput.Value;
// Output directory validation
if (!ValidateAndCreateOutputDirectory(outputDirectory))
if (!ValidateAndCreateOutputDirectory(outDir))
return false;
// Login to Redump, if necessary
if (!_client.LoggedIn)
_client.Login(UsernameInput.Value ?? string.Empty, PasswordInput.Value ?? string.Empty).Wait();
_client.Login(username, password).Wait();
// Update client properties
_client.Debug = DebugInput.Value;
@@ -64,7 +69,7 @@ namespace RedumpTool.Features
_client.Timeout = TimeSpan.FromSeconds(timeout.Value);
// Start the processing
var processingTask = _client.DownloadPacks(outputDirectory, SubfoldersInput.Value);
var processingTask = _client.DownloadPacks(outDir, useSubfolders);
// Retrieve the result
processingTask.Wait();

View File

@@ -57,17 +57,21 @@ namespace RedumpTool.Features
/// <inheritdoc/>
public override bool Execute()
{
// Get values needed more than once
bool onlyList = ListInput.Value;
string? outputDirectory = OutputInput.Value;
string? queryString = QueryInput.Value;
// Get common values
string? outDir = OutputInput.Value;
string username = UsernameInput.Value ?? string.Empty;
string password = PasswordInput.Value ?? string.Empty;
int? attemptCount = AttemptCountInput.Value;
int? timeout = TimeoutInput.Value;
// Get specific values
bool onlyList = ListInput.Value;
string? queryString = QueryInput.Value;
bool quick = QuickSearchInput.Value;
bool convertForwardSlashes = !NoSlashInput.Value;
// Output directory validation
if (!onlyList && !ValidateAndCreateOutputDirectory(outputDirectory))
if (!onlyList && !ValidateAndCreateOutputDirectory(outDir))
return false;
// Query verification (and cleanup)
@@ -79,7 +83,7 @@ namespace RedumpTool.Features
// Login to Redump, if necessary
if (!_client.LoggedIn)
_client.Login(UsernameInput.Value ?? string.Empty, PasswordInput.Value ?? string.Empty).Wait();
_client.Login(username, password).Wait();
// Update client properties
_client.Debug = DebugInput.Value;
@@ -95,14 +99,14 @@ namespace RedumpTool.Features
if (onlyList)
processingTask = _client.ListSearchResults(queryString, convertForwardSlashes);
else
processingTask = _client.DownloadSearchResults(queryString, outputDirectory, convertForwardSlashes);
processingTask = _client.DownloadSearchResults(queryString, outDir, convertForwardSlashes);
}
else
{
if (onlyList)
processingTask = _client.ListDiscsResults(queryString, convertForwardSlashes);
else
processingTask = _client.DownloadDiscsResults(queryString, outputDirectory, convertForwardSlashes);
processingTask = _client.DownloadDiscsResults(queryString, outDir, convertForwardSlashes);
}
// Retrieve the result

View File

@@ -57,16 +57,21 @@ namespace RedumpTool.Features
/// <inheritdoc/>
public override bool Execute()
{
// Get values needed more than once
string? outputDirectory = OutputInput.Value;
int minId = MinimumInput.Value ?? -1;
int maxId = MaximumInput.Value ?? -1;
bool onlyNew = OnlyNewInput.Value;
// Get common values
string? outDir = OutputInput.Value;
string username = UsernameInput.Value ?? string.Empty;
string password = PasswordInput.Value ?? string.Empty;
int? attemptCount = AttemptCountInput.Value;
int? timeout = TimeoutInput.Value;
// Get specific values
int minId = MinimumInput.Value ?? -1;
int maxId = MaximumInput.Value ?? -1;
bool onlyNew = OnlyNewInput.Value;
bool force = ForceInput.Value;
// Output directory validation
if (!ValidateAndCreateOutputDirectory(outputDirectory))
if (!ValidateAndCreateOutputDirectory(outDir))
return false;
// Range verification
@@ -78,7 +83,7 @@ namespace RedumpTool.Features
// Login to Redump, if necessary
if (!_client.LoggedIn)
_client.Login(UsernameInput.Value ?? string.Empty, PasswordInput.Value ?? string.Empty).Wait();
_client.Login(username, password).Wait();
// Update client properties
_client.Debug = DebugInput.Value;
@@ -90,9 +95,9 @@ namespace RedumpTool.Features
// Start the processing
Task<List<int>> processingTask;
if (onlyNew)
processingTask = _client.DownloadLastModified(outputDirectory, ForceInput.Value);
processingTask = _client.DownloadLastModified(outDir, force);
else
processingTask = _client.DownloadSiteRange(outputDirectory, minId, maxId);
processingTask = _client.DownloadSiteRange(outDir, minId, maxId);
// Retrieve the result
processingTask.Wait();

View File

@@ -49,19 +49,24 @@ namespace RedumpTool.Features
/// <inheritdoc/>
public override bool Execute()
{
// Get values needed more than once
bool onlyList = ListInput.Value;
string? outputDirectory = OutputInput.Value;
// Get common values
string? outDir = OutputInput.Value;
string username = UsernameInput.Value ?? string.Empty;
string password = PasswordInput.Value ?? string.Empty;
int? attemptCount = AttemptCountInput.Value;
int? timeout = TimeoutInput.Value;
// Get specific values
bool onlyNew = OnlyNewInput.Value;
bool onlyList = ListInput.Value;
// Output directory validation
if (!onlyList && !ValidateAndCreateOutputDirectory(outputDirectory))
if (!onlyList && !ValidateAndCreateOutputDirectory(outDir))
return false;
// Login to Redump, if necessary
if (!_client.LoggedIn)
_client.Login(UsernameInput.Value ?? string.Empty, PasswordInput.Value ?? string.Empty).Wait();
_client.Login(username, password).Wait();
// Update client properties
_client.Debug = DebugInput.Value;
@@ -73,11 +78,11 @@ namespace RedumpTool.Features
// Start the processing
Task<List<int>> processingTask;
if (onlyList)
processingTask = _client.ListUser(UsernameInput.Value);
else if (OnlyNewInput.Value)
processingTask = _client.DownloadUserLastModified(UsernameInput.Value, outputDirectory);
processingTask = _client.ListUser(username);
else if (onlyNew)
processingTask = _client.DownloadUserLastModified(username, outDir);
else
processingTask = _client.DownloadUser(UsernameInput.Value, outputDirectory);
processingTask = _client.DownloadUser(username, outDir);
// Retrieve the result
processingTask.Wait();

View File

@@ -53,16 +53,20 @@ namespace RedumpTool.Features
/// <inheritdoc/>
public override bool Execute()
{
// Get values needed more than once
string? outputDirectory = OutputInput.Value;
int minId = MinimumInput.Value ?? -1;
int maxId = MaximumInput.Value ?? -1;
bool onlyNew = OnlyNewInput.Value;
// Get common values
string? outDir = OutputInput.Value;
string username = UsernameInput.Value ?? string.Empty;
string password = PasswordInput.Value ?? string.Empty;
int? attemptCount = AttemptCountInput.Value;
int? timeout = TimeoutInput.Value;
// Get specific values
int minId = MinimumInput.Value ?? -1;
int maxId = MaximumInput.Value ?? -1;
bool onlyNew = OnlyNewInput.Value;
// Output directory validation
if (!ValidateAndCreateOutputDirectory(outputDirectory))
if (!ValidateAndCreateOutputDirectory(outDir))
return false;
// Range verification
@@ -74,7 +78,7 @@ namespace RedumpTool.Features
// Login to Redump, if necessary
if (!_client.LoggedIn)
_client.Login(UsernameInput.Value ?? string.Empty, PasswordInput.Value ?? string.Empty).Wait();
_client.Login(username, password).Wait();
// Update client properties
_client.Debug = DebugInput.Value;
@@ -86,9 +90,9 @@ namespace RedumpTool.Features
// Start the processing
Task<List<int>> processingTask;
if (onlyNew)
processingTask = _client.DownloadLastSubmitted(outputDirectory);
processingTask = _client.DownloadLastSubmitted(outDir);
else
processingTask = _client.DownloadWIPRange(outputDirectory, minId, maxId);
processingTask = _client.DownloadWIPRange(outDir, minId, maxId);
// Retrieve the result
processingTask.Wait();