Skip to content

Commit 52ff255

Browse files
committed
Better unify common input handling
1 parent c913e66 commit 52ff255

5 files changed

Lines changed: 61 additions & 38 deletions

File tree

RedumpTool/Features/PacksFeature.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,23 @@ public PacksFeature()
4343
/// <inheritdoc/>
4444
public override bool Execute()
4545
{
46-
// Get values needed more than once
47-
string? outputDirectory = OutputInput.Value;
46+
// Get common values
47+
string? outDir = OutputInput.Value;
48+
string username = UsernameInput.Value ?? string.Empty;
49+
string password = PasswordInput.Value ?? string.Empty;
4850
int? attemptCount = AttemptCountInput.Value;
4951
int? timeout = TimeoutInput.Value;
5052

53+
// Get specific values
54+
bool useSubfolders = SubfoldersInput.Value;
55+
5156
// Output directory validation
52-
if (!ValidateAndCreateOutputDirectory(outputDirectory))
57+
if (!ValidateAndCreateOutputDirectory(outDir))
5358
return false;
5459

5560
// Login to Redump, if necessary
5661
if (!_client.LoggedIn)
57-
_client.Login(UsernameInput.Value ?? string.Empty, PasswordInput.Value ?? string.Empty).Wait();
62+
_client.Login(username, password).Wait();
5863

5964
// Update client properties
6065
_client.Debug = DebugInput.Value;
@@ -64,7 +69,7 @@ public override bool Execute()
6469
_client.Timeout = TimeSpan.FromSeconds(timeout.Value);
6570

6671
// Start the processing
67-
var processingTask = _client.DownloadPacks(outputDirectory, SubfoldersInput.Value);
72+
var processingTask = _client.DownloadPacks(outDir, useSubfolders);
6873

6974
// Retrieve the result
7075
processingTask.Wait();

RedumpTool/Features/QueryFeature.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,21 @@ public QueryFeature()
5757
/// <inheritdoc/>
5858
public override bool Execute()
5959
{
60-
// Get values needed more than once
61-
bool onlyList = ListInput.Value;
62-
string? outputDirectory = OutputInput.Value;
63-
string? queryString = QueryInput.Value;
60+
// Get common values
61+
string? outDir = OutputInput.Value;
62+
string username = UsernameInput.Value ?? string.Empty;
63+
string password = PasswordInput.Value ?? string.Empty;
6464
int? attemptCount = AttemptCountInput.Value;
6565
int? timeout = TimeoutInput.Value;
66+
67+
// Get specific values
68+
bool onlyList = ListInput.Value;
69+
string? queryString = QueryInput.Value;
6670
bool quick = QuickSearchInput.Value;
6771
bool convertForwardSlashes = !NoSlashInput.Value;
6872

6973
// Output directory validation
70-
if (!onlyList && !ValidateAndCreateOutputDirectory(outputDirectory))
74+
if (!onlyList && !ValidateAndCreateOutputDirectory(outDir))
7175
return false;
7276

7377
// Query verification (and cleanup)
@@ -79,7 +83,7 @@ public override bool Execute()
7983

8084
// Login to Redump, if necessary
8185
if (!_client.LoggedIn)
82-
_client.Login(UsernameInput.Value ?? string.Empty, PasswordInput.Value ?? string.Empty).Wait();
86+
_client.Login(username, password).Wait();
8387

8488
// Update client properties
8589
_client.Debug = DebugInput.Value;
@@ -95,14 +99,14 @@ public override bool Execute()
9599
if (onlyList)
96100
processingTask = _client.ListSearchResults(queryString, convertForwardSlashes);
97101
else
98-
processingTask = _client.DownloadSearchResults(queryString, outputDirectory, convertForwardSlashes);
102+
processingTask = _client.DownloadSearchResults(queryString, outDir, convertForwardSlashes);
99103
}
100104
else
101105
{
102106
if (onlyList)
103107
processingTask = _client.ListDiscsResults(queryString, convertForwardSlashes);
104108
else
105-
processingTask = _client.DownloadDiscsResults(queryString, outputDirectory, convertForwardSlashes);
109+
processingTask = _client.DownloadDiscsResults(queryString, outDir, convertForwardSlashes);
106110
}
107111

108112
// Retrieve the result

RedumpTool/Features/SiteFeature.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,21 @@ public SiteFeature()
5757
/// <inheritdoc/>
5858
public override bool Execute()
5959
{
60-
// Get values needed more than once
61-
string? outputDirectory = OutputInput.Value;
60+
// Get common values
61+
string? outDir = OutputInput.Value;
62+
string username = UsernameInput.Value ?? string.Empty;
63+
string password = PasswordInput.Value ?? string.Empty;
64+
int? attemptCount = AttemptCountInput.Value;
65+
int? timeout = TimeoutInput.Value;
66+
67+
// Get specific values
6268
int minId = MinimumInput.Value ?? -1;
6369
int maxId = MaximumInput.Value ?? -1;
6470
bool onlyNew = OnlyNewInput.Value;
65-
int? attemptCount = AttemptCountInput.Value;
66-
int? timeout = TimeoutInput.Value;
71+
bool force = ForceInput.Value;
6772

6873
// Output directory validation
69-
if (!ValidateAndCreateOutputDirectory(outputDirectory))
74+
if (!ValidateAndCreateOutputDirectory(outDir))
7075
return false;
7176

7277
// Range verification
@@ -78,7 +83,7 @@ public override bool Execute()
7883

7984
// Login to Redump, if necessary
8085
if (!_client.LoggedIn)
81-
_client.Login(UsernameInput.Value ?? string.Empty, PasswordInput.Value ?? string.Empty).Wait();
86+
_client.Login(username, password).Wait();
8287

8388
// Update client properties
8489
_client.Debug = DebugInput.Value;
@@ -90,9 +95,9 @@ public override bool Execute()
9095
// Start the processing
9196
Task<List<int>> processingTask;
9297
if (onlyNew)
93-
processingTask = _client.DownloadLastModified(outputDirectory, ForceInput.Value);
98+
processingTask = _client.DownloadLastModified(outDir, force);
9499
else
95-
processingTask = _client.DownloadSiteRange(outputDirectory, minId, maxId);
100+
processingTask = _client.DownloadSiteRange(outDir, minId, maxId);
96101

97102
// Retrieve the result
98103
processingTask.Wait();

RedumpTool/Features/UserFeature.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,24 @@ public UserFeature()
4949
/// <inheritdoc/>
5050
public override bool Execute()
5151
{
52-
// Get values needed more than once
53-
bool onlyList = ListInput.Value;
54-
string? outputDirectory = OutputInput.Value;
52+
// Get common values
53+
string? outDir = OutputInput.Value;
54+
string username = UsernameInput.Value ?? string.Empty;
55+
string password = PasswordInput.Value ?? string.Empty;
5556
int? attemptCount = AttemptCountInput.Value;
5657
int? timeout = TimeoutInput.Value;
5758

59+
// Get specific values
60+
bool onlyNew = OnlyNewInput.Value;
61+
bool onlyList = ListInput.Value;
62+
5863
// Output directory validation
59-
if (!onlyList && !ValidateAndCreateOutputDirectory(outputDirectory))
64+
if (!onlyList && !ValidateAndCreateOutputDirectory(outDir))
6065
return false;
6166

6267
// Login to Redump, if necessary
6368
if (!_client.LoggedIn)
64-
_client.Login(UsernameInput.Value ?? string.Empty, PasswordInput.Value ?? string.Empty).Wait();
69+
_client.Login(username, password).Wait();
6570

6671
// Update client properties
6772
_client.Debug = DebugInput.Value;
@@ -73,11 +78,11 @@ public override bool Execute()
7378
// Start the processing
7479
Task<List<int>> processingTask;
7580
if (onlyList)
76-
processingTask = _client.ListUser(UsernameInput.Value);
77-
else if (OnlyNewInput.Value)
78-
processingTask = _client.DownloadUserLastModified(UsernameInput.Value, outputDirectory);
81+
processingTask = _client.ListUser(username);
82+
else if (onlyNew)
83+
processingTask = _client.DownloadUserLastModified(username, outDir);
7984
else
80-
processingTask = _client.DownloadUser(UsernameInput.Value, outputDirectory);
85+
processingTask = _client.DownloadUser(username, outDir);
8186

8287
// Retrieve the result
8388
processingTask.Wait();

RedumpTool/Features/WIPFeature.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,20 @@ public WIPFeature()
5353
/// <inheritdoc/>
5454
public override bool Execute()
5555
{
56-
// Get values needed more than once
57-
string? outputDirectory = OutputInput.Value;
56+
// Get common values
57+
string? outDir = OutputInput.Value;
58+
string username = UsernameInput.Value ?? string.Empty;
59+
string password = PasswordInput.Value ?? string.Empty;
60+
int? attemptCount = AttemptCountInput.Value;
61+
int? timeout = TimeoutInput.Value;
62+
63+
// Get specific values
5864
int minId = MinimumInput.Value ?? -1;
5965
int maxId = MaximumInput.Value ?? -1;
6066
bool onlyNew = OnlyNewInput.Value;
61-
int? attemptCount = AttemptCountInput.Value;
62-
int? timeout = TimeoutInput.Value;
6367

6468
// Output directory validation
65-
if (!ValidateAndCreateOutputDirectory(outputDirectory))
69+
if (!ValidateAndCreateOutputDirectory(outDir))
6670
return false;
6771

6872
// Range verification
@@ -74,7 +78,7 @@ public override bool Execute()
7478

7579
// Login to Redump, if necessary
7680
if (!_client.LoggedIn)
77-
_client.Login(UsernameInput.Value ?? string.Empty, PasswordInput.Value ?? string.Empty).Wait();
81+
_client.Login(username, password).Wait();
7882

7983
// Update client properties
8084
_client.Debug = DebugInput.Value;
@@ -86,9 +90,9 @@ public override bool Execute()
8690
// Start the processing
8791
Task<List<int>> processingTask;
8892
if (onlyNew)
89-
processingTask = _client.DownloadLastSubmitted(outputDirectory);
93+
processingTask = _client.DownloadLastSubmitted(outDir);
9094
else
91-
processingTask = _client.DownloadWIPRange(outputDirectory, minId, maxId);
95+
processingTask = _client.DownloadWIPRange(outDir, minId, maxId);
9296

9397
// Retrieve the result
9498
processingTask.Wait();

0 commit comments

Comments
 (0)