From 0946b00075200a77443306ed6d6e8987cc48125f Mon Sep 17 00:00:00 2001 From: Evan Dixon Date: Thu, 2 Mar 2017 09:28:33 -0600 Subject: [PATCH 1/3] Delete settings if corrupt --- PKHeX.WinForms/MainWindow/Main.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index b2985a230..af07b900d 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -11,6 +11,7 @@ using System.Windows.Forms; using PKHeX.Core; using PKHeX.Core.Properties; +using System.Configuration; namespace PKHeX.WinForms { @@ -161,9 +162,18 @@ public Main() ConfigUtil.checkConfig(); loadConfig(out BAKprompt, out showChangelog, out languageID); } - catch (Exception e) + catch (ConfigurationErrorsException e) { - WinFormsUtil.Error("Failed to access settings:" + Environment.NewLine + e.Message, "Please delete corrupt user.config file."); + // Delete the settings if they exist + var settingsFilename = (e.InnerException as ConfigurationErrorsException)?.Filename; + if (File.Exists(settingsFilename)) + { + File.Delete(settingsFilename); + } + else + { + WinFormsUtil.Error("Unable to load settings.", e); + } } CB_MainLanguage.SelectedIndex = languageID; From beed20cfdf957b832875739fa51be54c32011433 Mon Sep 17 00:00:00 2001 From: Evan Dixon Date: Thu, 2 Mar 2017 09:37:54 -0600 Subject: [PATCH 2/3] Reloading settings doesn't work right --- PKHeX.WinForms/MainWindow/Main.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index af07b900d..86a9571c3 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -168,7 +168,21 @@ public Main() var settingsFilename = (e.InnerException as ConfigurationErrorsException)?.Filename; if (File.Exists(settingsFilename)) { - File.Delete(settingsFilename); + if (MessageBox.Show("PKHeX's settings are corrupt. Would you like to reset the settings? (Click Yes to delete the settings or No to close the program.", "PKHeX", MessageBoxButtons.YesNo) == DialogResult.Yes) + { + File.Delete(settingsFilename); + + // This should theoretically work, but has failed in evandixon's testing + // Properties.Settings.Default.Reload(); + + // Instead, restart the application + MessageBox.Show("The settings have been deleted. Please restart PKHeX."); + Process.GetCurrentProcess().Kill(); + } + else + { + Process.GetCurrentProcess().Kill(); + } } else { From 0eda87fdf6f59299c537711d6244c7c4215e3fdd Mon Sep 17 00:00:00 2001 From: Evan Dixon Date: Thu, 2 Mar 2017 09:40:33 -0600 Subject: [PATCH 3/3] Averted potential null reference exception --- PKHeX.WinForms/MainWindow/Main.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index 86a9571c3..48e42282e 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -166,7 +166,7 @@ public Main() { // Delete the settings if they exist var settingsFilename = (e.InnerException as ConfigurationErrorsException)?.Filename; - if (File.Exists(settingsFilename)) + if (!string.IsNullOrEmpty(settingsFilename) && File.Exists(settingsFilename)) { if (MessageBox.Show("PKHeX's settings are corrupt. Would you like to reset the settings? (Click Yes to delete the settings or No to close the program.", "PKHeX", MessageBoxButtons.YesNo) == DialogResult.Yes) {