mirror of
https://github.com/SabreTools/SabreTools.RedumpLib.git
synced 2026-09-22 23:14:52 +00:00
Attempts is more accurate than retry count
This commit is contained in:
@@ -20,8 +20,8 @@ namespace RedumpTool.Features
|
||||
private const string _passwordName = "password";
|
||||
internal readonly StringInput PasswordInput = new(_passwordName, ["-p", "--password"], "Redump password");
|
||||
|
||||
private const string _retryCountName = "retrycount";
|
||||
internal readonly Int32Input RetryCountInput = new(_retryCountName, ["-r", "--retries"], "Number of attempts for web requests");
|
||||
private const string _attemptCountName = "attemptcount";
|
||||
internal readonly Int32Input AttemptCountInput = new(_attemptCountName, ["-a", "--attempts"], "Number of attempts for web requests");
|
||||
|
||||
private const string _usernameName = "username";
|
||||
internal readonly StringInput UsernameInput = new(_usernameName, ["-u", "--username"], "Redump username");
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace RedumpTool.Features
|
||||
Add(OutputInput);
|
||||
Add(UsernameInput);
|
||||
Add(PasswordInput);
|
||||
Add(RetryCountInput);
|
||||
Add(AttemptCountInput);
|
||||
|
||||
// Specific
|
||||
Add(SubfoldersInput);
|
||||
@@ -43,7 +43,7 @@ namespace RedumpTool.Features
|
||||
{
|
||||
// Get values needed more than once
|
||||
string? outputDirectory = OutputInput.Value;
|
||||
int? retryCount = RetryCountInput.Value;
|
||||
int? attemptCount = AttemptCountInput.Value;
|
||||
|
||||
// Output directory validation
|
||||
if (!ValidateAndCreateOutputDirectory(outputDirectory))
|
||||
@@ -55,8 +55,8 @@ namespace RedumpTool.Features
|
||||
|
||||
// Update client properties
|
||||
_client.Debug = DebugInput.Value;
|
||||
if (retryCount != null && retryCount > 0)
|
||||
_client.RetryCount = retryCount.Value;
|
||||
if (attemptCount != null && attemptCount > 0)
|
||||
_client.AttemptCount = attemptCount.Value;
|
||||
|
||||
// Start the processing
|
||||
var processingTask = _client.DownloadPacks(outputDirectory, SubfoldersInput.Value);
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace RedumpTool.Features
|
||||
Add(OutputInput);
|
||||
Add(UsernameInput);
|
||||
Add(PasswordInput);
|
||||
Add(RetryCountInput);
|
||||
Add(AttemptCountInput);
|
||||
|
||||
// Specific
|
||||
Add(QueryInput);
|
||||
@@ -56,7 +56,7 @@ namespace RedumpTool.Features
|
||||
bool onlyList = ListInput.Value;
|
||||
string? outputDirectory = OutputInput.Value;
|
||||
string? queryString = QueryInput.Value;
|
||||
int? retryCount = RetryCountInput.Value;
|
||||
int? attemptCount = AttemptCountInput.Value;
|
||||
|
||||
// Output directory validation
|
||||
if (!onlyList && !ValidateAndCreateOutputDirectory(outputDirectory))
|
||||
@@ -75,8 +75,8 @@ namespace RedumpTool.Features
|
||||
|
||||
// Update client properties
|
||||
_client.Debug = DebugInput.Value;
|
||||
if (retryCount != null && retryCount > 0)
|
||||
_client.RetryCount = retryCount.Value;
|
||||
if (attemptCount != null && attemptCount > 0)
|
||||
_client.AttemptCount = attemptCount.Value;
|
||||
|
||||
// Start the processing
|
||||
Task<List<int>> processingTask;
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace RedumpTool.Features
|
||||
Add(OutputInput);
|
||||
Add(UsernameInput);
|
||||
Add(PasswordInput);
|
||||
Add(RetryCountInput);
|
||||
Add(AttemptCountInput);
|
||||
|
||||
// Specific
|
||||
Add(MinimumInput);
|
||||
@@ -61,7 +61,7 @@ namespace RedumpTool.Features
|
||||
int minId = MinimumInput.Value ?? -1;
|
||||
int maxId = MaximumInput.Value ?? -1;
|
||||
bool onlyNew = OnlyNewInput.Value;
|
||||
int? retryCount = RetryCountInput.Value;
|
||||
int? attemptCount = AttemptCountInput.Value;
|
||||
|
||||
// Output directory validation
|
||||
if (!ValidateAndCreateOutputDirectory(outputDirectory))
|
||||
@@ -80,8 +80,8 @@ namespace RedumpTool.Features
|
||||
|
||||
// Update client properties
|
||||
_client.Debug = DebugInput.Value;
|
||||
if (retryCount != null && retryCount > 0)
|
||||
_client.RetryCount = retryCount.Value;
|
||||
if (attemptCount != null && attemptCount > 0)
|
||||
_client.AttemptCount = attemptCount.Value;
|
||||
|
||||
// Start the processing
|
||||
Task<List<int>> processingTask;
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace RedumpTool.Features
|
||||
Add(OutputInput);
|
||||
Add(UsernameInput);
|
||||
Add(PasswordInput);
|
||||
Add(RetryCountInput);
|
||||
Add(AttemptCountInput);
|
||||
|
||||
// Specific
|
||||
Add(OnlyNewInput);
|
||||
@@ -50,7 +50,7 @@ namespace RedumpTool.Features
|
||||
// Get values needed more than once
|
||||
bool onlyList = ListInput.Value;
|
||||
string? outputDirectory = OutputInput.Value;
|
||||
int? retryCount = RetryCountInput.Value;
|
||||
int? attemptCount = AttemptCountInput.Value;
|
||||
|
||||
// Output directory validation
|
||||
if (!onlyList && !ValidateAndCreateOutputDirectory(outputDirectory))
|
||||
@@ -62,8 +62,8 @@ namespace RedumpTool.Features
|
||||
|
||||
// Update client properties
|
||||
_client.Debug = DebugInput.Value;
|
||||
if (retryCount != null && retryCount > 0)
|
||||
_client.RetryCount = retryCount.Value;
|
||||
if (attemptCount != null && attemptCount > 0)
|
||||
_client.AttemptCount = attemptCount.Value;
|
||||
|
||||
// Start the processing
|
||||
Task<List<int>> processingTask;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace RedumpTool.Features
|
||||
Add(OutputInput);
|
||||
Add(UsernameInput);
|
||||
Add(PasswordInput);
|
||||
Add(RetryCountInput);
|
||||
Add(AttemptCountInput);
|
||||
|
||||
// Specific
|
||||
Add(MinimumInput);
|
||||
@@ -57,7 +57,7 @@ namespace RedumpTool.Features
|
||||
int minId = MinimumInput.Value ?? -1;
|
||||
int maxId = MaximumInput.Value ?? -1;
|
||||
bool onlyNew = OnlyNewInput.Value;
|
||||
int? retryCount = RetryCountInput.Value;
|
||||
int? attemptCount = AttemptCountInput.Value;
|
||||
|
||||
// Output directory validation
|
||||
if (!ValidateAndCreateOutputDirectory(outputDirectory))
|
||||
@@ -76,8 +76,8 @@ namespace RedumpTool.Features
|
||||
|
||||
// Update client properties
|
||||
_client.Debug = DebugInput.Value;
|
||||
if (retryCount != null && retryCount > 0)
|
||||
_client.RetryCount = retryCount.Value;
|
||||
if (attemptCount != null && attemptCount > 0)
|
||||
_client.AttemptCount = attemptCount.Value;
|
||||
|
||||
// Start the processing
|
||||
Task<List<int>> processingTask;
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace RedumpTool
|
||||
Console.WriteLine(" -o <folder>, --output <folder> - Set the base output directory");
|
||||
Console.WriteLine(" -u <username>, --username <username> - Redump username");
|
||||
Console.WriteLine(" -p <pass>, --password <pass> - Redump password");
|
||||
Console.WriteLine(" -r <retries>, --retries <retries> - Number of attempts for web requests");
|
||||
Console.WriteLine(" -a <attempts>, --attempts <attempts> - Number of attempts for web requests");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("site - Download pages and related files from the main site");
|
||||
Console.WriteLine(" -min <MinId>, --minimum <MinId> - Lower bound for page numbers (cannot be used with only new)");
|
||||
|
||||
@@ -34,10 +34,10 @@ namespace SabreTools.RedumpLib.Web
|
||||
public bool Debug { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum retry count for any operation
|
||||
/// Maximum attempt count for any operation
|
||||
/// </summary>
|
||||
/// <remarks>Value has to be greater than 0</remarks>
|
||||
public int RetryCount
|
||||
public int AttemptCount
|
||||
{
|
||||
get;
|
||||
set { field = value < 0 ? 3 : value; }
|
||||
@@ -141,11 +141,11 @@ namespace SabreTools.RedumpLib.Web
|
||||
#endif
|
||||
|
||||
// Attempt to login up as many times as the retry count allows
|
||||
for (int i = 0; i < RetryCount; i++)
|
||||
for (int i = 0; i < AttemptCount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine($"Login attempt {i + 1} of {RetryCount}");
|
||||
Console.WriteLine($"Login attempt {i + 1} of {AttemptCount}");
|
||||
|
||||
// Get the current token from the login page
|
||||
var loginPage = await DownloadString(Constants.LoginUrl);
|
||||
@@ -200,7 +200,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
}
|
||||
}
|
||||
|
||||
Console.Error.WriteLine($"Could not login to Redump in {RetryCount} attempts, continuing without logging in...");
|
||||
Console.Error.WriteLine($"Could not login to Redump in {AttemptCount} attempts, continuing without logging in...");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -216,14 +216,14 @@ namespace SabreTools.RedumpLib.Web
|
||||
public async Task<byte[]?> DownloadData(string uri)
|
||||
{
|
||||
// Only retry a positive number of times
|
||||
if (RetryCount <= 0)
|
||||
if (AttemptCount <= 0)
|
||||
return null;
|
||||
|
||||
for (int i = 0; i < RetryCount; i++)
|
||||
for (int i = 0; i < AttemptCount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Debug) Console.WriteLine($"DEBUG: DownloadData(\"{uri}\"), Attempt {i + 1} of {RetryCount}");
|
||||
if (Debug) Console.WriteLine($"DEBUG: DownloadData(\"{uri}\"), Attempt {i + 1} of {AttemptCount}");
|
||||
#if NET40
|
||||
return await Task.Factory.StartNew(() => _internalClient.DownloadData(uri));
|
||||
#elif NETFRAMEWORK || NETSTANDARD2_0_OR_GREATER
|
||||
@@ -284,14 +284,14 @@ namespace SabreTools.RedumpLib.Web
|
||||
public async Task<string?> DownloadString(string uri)
|
||||
{
|
||||
// Only retry a positive number of times
|
||||
if (RetryCount <= 0)
|
||||
if (AttemptCount <= 0)
|
||||
return null;
|
||||
|
||||
for (int i = 0; i < RetryCount; i++)
|
||||
for (int i = 0; i < AttemptCount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Debug) Console.WriteLine($"DEBUG: DownloadString(\"{uri}\"), Attempt {i + 1} of {RetryCount}");
|
||||
if (Debug) Console.WriteLine($"DEBUG: DownloadString(\"{uri}\"), Attempt {i + 1} of {AttemptCount}");
|
||||
#if NET40
|
||||
return await Task.Factory.StartNew(() => _internalClient.DownloadString(uri));
|
||||
#elif NETFRAMEWORK || NETSTANDARD2_0_OR_GREATER
|
||||
|
||||
Reference in New Issue
Block a user