Error messages on Redump errors

This commit is contained in:
Matt Nadareski
2020-12-30 15:00:52 -08:00
parent 020c063177
commit 64f60004c4
4 changed files with 30 additions and 10 deletions

View File

@@ -131,10 +131,13 @@ namespace MPF.Check
{
using (RedumpWebClient wc = new RedumpWebClient())
{
if (wc.Login(username, password))
bool? loggedIn = wc.Login(username, password);
if (loggedIn == true)
Console.WriteLine("Redump username and password accepted!");
else
else if (loggedIn == false)
Console.WriteLine("Redump username and password denied!");
else
Console.WriteLine("An error occurred validating your crendentials!");
}
}

View File

@@ -682,7 +682,12 @@ namespace MPF.Utilities
using (RedumpWebClient wc = new RedumpWebClient())
{
// Login to Redump
if (wc.Login(this.Username, this.Password))
bool? loggedIn = wc.Login(this.Username, this.Password);
if (loggedIn == null)
{
resultProgress?.Report(Result.Failure("There was an unknown error connecting to Redump"));
}
else if (loggedIn == true)
{
// Loop through all of the hashdata to find matching IDs
resultProgress?.Report(Result.Success("Finding disc matches on Redump..."));
@@ -694,6 +699,13 @@ namespace MPF.Utilities
// Get all matching IDs for the track
List<int> newIds = wc.ListSearchResults(sha1);
// If we got null back, there was an error
if (newIds == null)
{
resultProgress?.Report(Result.Failure("There was an unknown error retrieving information from Redump"));
break;
}
// If no IDs match any track, then we don't match a disc at all
if (!newIds.Any())
{

View File

@@ -310,8 +310,8 @@ namespace MPF.Web
/// </summary>
/// <param name="username">Redump username</param>
/// <param name="password">Redump password</param>
/// <returns>True if the user could be logged in, false otherwise, false otherwise</returns>
public bool Login(string username, string password)
/// <returns>True if the user could be logged in, false otherwise, null on error</returns>
public bool? Login(string username, string password)
{
// Credentials verification
if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
@@ -359,7 +359,7 @@ namespace MPF.Web
catch (Exception ex)
{
Console.WriteLine($"An exception occurred while trying to log in: {ex}");
return false;
return null;
}
}
@@ -941,7 +941,7 @@ namespace MPF.Web
/// List the disc IDs associated with a given quicksearch query
/// </summary>
/// <param name="query">Query string to attempt to search for</param>
/// <returns>All disc IDs for the given query, empty on error</returns>
/// <returns>All disc IDs for the given query, null on error</returns>
public List<int> ListSearchResults(string query)
{
List<int> ids = new List<int>();
@@ -972,6 +972,7 @@ namespace MPF.Web
catch (Exception ex)
{
Console.WriteLine($"An exception occurred while trying to log in: {ex}");
return null;
}
return ids;
@@ -981,7 +982,7 @@ namespace MPF.Web
/// List the disc IDs associated with the given user
/// </summary>
/// <param name="username">Username to check discs for</param>
/// <returns>All disc IDs for the given user, empty on error</returns>
/// <returns>All disc IDs for the given user, null on error</returns>
public List<int> ListUser(string username)
{
List<int> ids = new List<int>();
@@ -1007,6 +1008,7 @@ namespace MPF.Web
catch (Exception ex)
{
Console.WriteLine($"An exception occurred while trying to log in: {ex}");
return null;
}
return ids;

View File

@@ -181,10 +181,13 @@ namespace MPF.Windows
{
using (RedumpWebClient wc = new RedumpWebClient())
{
if (wc.Login(RedumpUsernameTextBox.Text, RedumpPasswordBox.Password))
bool? loggedIn = wc.Login(RedumpUsernameTextBox.Text, RedumpPasswordBox.Password);
if (loggedIn == true)
System.Windows.MessageBox.Show("Redump login credentials accepted!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
else
else if (loggedIn == false)
System.Windows.MessageBox.Show("Redump login credentials denied!", "Failure", MessageBoxButton.OK, MessageBoxImage.Error);
else
System.Windows.MessageBox.Show("Error validating credentials!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}