From 64f60004c4e4cb893bcdb690ecb98c6d80177b54 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 30 Dec 2020 15:00:52 -0800 Subject: [PATCH] Error messages on Redump errors --- MPF.Check/Program.cs | 7 +++++-- MPF.Library/Utilities/DumpEnvironment.cs | 14 +++++++++++++- MPF.Library/Web/RedumpWebClient.cs | 12 +++++++----- MPF/Windows/OptionsWindow.xaml.cs | 7 +++++-- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/MPF.Check/Program.cs b/MPF.Check/Program.cs index 380ea900..96ec680c 100644 --- a/MPF.Check/Program.cs +++ b/MPF.Check/Program.cs @@ -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!"); } } diff --git a/MPF.Library/Utilities/DumpEnvironment.cs b/MPF.Library/Utilities/DumpEnvironment.cs index 4ae6f1d4..3c973dc3 100644 --- a/MPF.Library/Utilities/DumpEnvironment.cs +++ b/MPF.Library/Utilities/DumpEnvironment.cs @@ -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 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()) { diff --git a/MPF.Library/Web/RedumpWebClient.cs b/MPF.Library/Web/RedumpWebClient.cs index 3569ecaf..a91d2025 100644 --- a/MPF.Library/Web/RedumpWebClient.cs +++ b/MPF.Library/Web/RedumpWebClient.cs @@ -310,8 +310,8 @@ namespace MPF.Web /// /// Redump username /// Redump password - /// True if the user could be logged in, false otherwise, false otherwise - public bool Login(string username, string password) + /// True if the user could be logged in, false otherwise, null on error + 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 /// /// Query string to attempt to search for - /// All disc IDs for the given query, empty on error + /// All disc IDs for the given query, null on error public List ListSearchResults(string query) { List ids = new List(); @@ -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 /// /// Username to check discs for - /// All disc IDs for the given user, empty on error + /// All disc IDs for the given user, null on error public List ListUser(string username) { List ids = new List(); @@ -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; diff --git a/MPF/Windows/OptionsWindow.xaml.cs b/MPF/Windows/OptionsWindow.xaml.cs index ae2c7ab6..b3cde288 100644 --- a/MPF/Windows/OptionsWindow.xaml.cs +++ b/MPF/Windows/OptionsWindow.xaml.cs @@ -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); } }