Consolidate Redump login testing

This commit is contained in:
Matt Nadareski
2022-04-12 12:01:26 -07:00
parent 661d2440f2
commit f4c4c21a10
4 changed files with 33 additions and 34 deletions

View File

@@ -51,7 +51,9 @@ namespace MPF.Check
protectionProgress.ProgressChanged += ProgressUpdated;
// Validate the supplied credentials
ValidateCredentials(options);
(bool? _, string message) = RedumpWebClient.ValidateCredentials(options?.RedumpUsername, options?.RedumpPassword);
if (!string.IsNullOrWhiteSpace(message))
Console.WriteLine(message);
// Loop through all the rest of the args
for (int i = startIndex; i < args.Length; i++)
@@ -170,28 +172,5 @@ namespace MPF.Check
{
Console.WriteLine($"{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}");
}
/// <summary>
/// Validate supplied credentials
/// </summary>
/// TODO: Move to a common location
private static void ValidateCredentials(Options options)
{
// If options are invalid or we're missing something key, just return
if (string.IsNullOrWhiteSpace(options?.RedumpUsername) || string.IsNullOrWhiteSpace(options?.RedumpPassword))
return;
// Try logging in with the supplied credentials otherwise
using (RedumpWebClient wc = new RedumpWebClient())
{
bool? loggedIn = wc.Login(options.RedumpUsername, options.RedumpPassword);
if (loggedIn == true)
Console.WriteLine("Redump username and password accepted!");
else if (loggedIn == false)
Console.WriteLine("Redump username and password denied!");
else
Console.WriteLine("An error occurred validating your crendentials!");
}
}
}
}