Allow setting the timeout directly

This commit is contained in:
Matt Nadareski
2026-02-27 08:44:03 -05:00
parent 7f0b9f9fb8
commit 9204a8a5fc

View File

@@ -38,11 +38,6 @@ namespace SabreTools.RedumpLib.Web
/// </summary>
public int RetryCount { get; }
/// <summary>
/// Maximum number of seconds for a retry
/// </summary>
public int TimeoutSeconds { get; }
/// <summary>
/// Internal client for interaction
/// </summary>
@@ -57,7 +52,7 @@ namespace SabreTools.RedumpLib.Web
/// <summary>
/// Constructor
/// </summary>
public RedumpClient(int retryCount = 3, int timeoutSeconds = 30)
public RedumpClient(int timeoutSeconds = 30, int retryCount = 3)
{
// Ensure there are a positive number of retries
if (retryCount <= 0)
@@ -68,12 +63,33 @@ namespace SabreTools.RedumpLib.Web
timeoutSeconds = 30;
RetryCount = retryCount;
TimeoutSeconds = timeoutSeconds;
#if NETFRAMEWORK || NETSTANDARD2_0_OR_GREATER
_internalClient = new CookieWebClient() { Timeout = TimeSpan.FromSeconds(TimeoutSeconds) };
_internalClient = new CookieWebClient() { Timeout = TimeSpan.FromSeconds(timeoutSeconds) };
#else
_internalClient = new HttpClient(new HttpClientHandler { UseCookies = true }) { Timeout = TimeSpan.FromSeconds(TimeoutSeconds) };
_internalClient = new HttpClient(new HttpClientHandler { UseCookies = true }) { Timeout = TimeSpan.FromSeconds(timeoutSeconds) };
#endif
}
/// <summary>
/// Constructor
/// </summary>
public RedumpClient(TimeSpan timeout, int retryCount = 3)
{
// Ensure there are a positive number of retries
if (retryCount <= 0)
retryCount = 3;
// Ensure a positive timespan
if (timeout <= TimeSpan.Zero)
timeout = TimeSpan.FromSeconds(30);
RetryCount = retryCount;
#if NETFRAMEWORK || NETSTANDARD2_0_OR_GREATER
_internalClient = new CookieWebClient() { Timeout = timeout };
#else
_internalClient = new HttpClient(new HttpClientHandler { UseCookies = true }) { Timeout = timeout };
#endif
}