From 15c3e5ba568ed34d6a5adc629ced50010c819078 Mon Sep 17 00:00:00 2001 From: sr55 Date: Thu, 29 Mar 2012 20:29:13 +0000 Subject: WinGui: More refactoring of user settings / exception handling for the user setting service. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4557 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Services/UserSettingService.cs | 55 +++++++--------------- win/CS/Program.cs | 4 +- win/CS/frmQueue.cs | 11 ++++- 3 files changed, 29 insertions(+), 41 deletions(-) (limited to 'win/CS') diff --git a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs index 9419efefc..c3feaefa8 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs @@ -9,7 +9,6 @@ namespace HandBrake.ApplicationServices.Services using System.Collections.Specialized; using System.IO; using System.Linq; - using System.Windows.Forms; using System.Xml.Serialization; using HandBrake.ApplicationServices.Collections; @@ -42,10 +41,6 @@ namespace HandBrake.ApplicationServices.Services public UserSettingService() { this.Load(); - if (userSettings == null || userSettings.Count == 0) - { - this.userSettings = this.GetDefaults(); - } } /// @@ -133,39 +128,36 @@ namespace HandBrake.ApplicationServices.Services { try { + // Load up the users current settings file. if (File.Exists(this.settingsFile)) { using (StreamReader reader = new StreamReader(this.settingsFile)) { SerializableDictionary data = (SerializableDictionary)serializer.Deserialize(reader); this.userSettings = data; - - // Add any new settings - SerializableDictionary defaults = this.GetDefaults(); - foreach (var item in defaults.Where(item => !this.userSettings.Keys.Contains(item.Key))) - { - this.userSettings.Add(item.Key, item.Value); - } } + } + // Add any missing / new settings + SerializableDictionary defaults = this.GetDefaults(); + foreach (var item in defaults.Where(item => !this.userSettings.Keys.Contains(item.Key))) + { + this.userSettings.Add(item.Key, item.Value); this.Save(); } } - catch (Exception exc) + catch (Exception) { - this.userSettings = this.GetDefaults(); try { + this.userSettings = this.GetDefaults(); this.Save(); } catch (Exception) - { + { } - - throw new GeneralApplicationException( - "HandBrake has detected corruption in the settings file. User settings will now be reset to defaults.", - "Please restart HandBrake before continuing.", - exc); + + throw; } } @@ -177,29 +169,14 @@ namespace HandBrake.ApplicationServices.Services /// private SerializableDictionary GetDefaults() { - try + if (File.Exists("defaultsettings.xml")) { - string defaults = Path.Combine(Application.StartupPath, "defaultsettings.xml"); - if (File.Exists(defaults)) + using (StreamReader reader = new StreamReader("defaultsettings.xml")) { - using (StreamReader reader = new StreamReader(defaults)) - { - return (SerializableDictionary)serializer.Deserialize(reader); - } + return (SerializableDictionary)serializer.Deserialize(reader); } - - throw new GeneralApplicationException( - "User default settings file is missing. This install of HandBrake may be corrupted.", - "Try re-installing HandBrake.", - null); - } - catch (Exception exc) - { - throw new GeneralApplicationException( - "User default settings file is missing or inaccessible. This install of HandBrake may be corrupted.", - "Try re-installing HandBrake.", - exc); } + return new SerializableDictionary(); } } } diff --git a/win/CS/Program.cs b/win/CS/Program.cs index 48d2f7562..178973994 100644 --- a/win/CS/Program.cs +++ b/win/CS/Program.cs @@ -98,7 +98,9 @@ namespace Handbrake { window.Setup( applicationException.Error + Environment.NewLine + applicationException.Solution, - e.ExceptionObject + "\n\n ---- \n\n" + applicationException.ActualException); + e.ExceptionObject + "\n\n ---- \n\n" + applicationException.ActualException + + Environment.NewLine + "-----" + Environment.NewLine + + applicationException.ActualException.InnerException); } } else diff --git a/win/CS/frmQueue.cs b/win/CS/frmQueue.cs index c7117068f..f5fb75071 100644 --- a/win/CS/frmQueue.cs +++ b/win/CS/frmQueue.cs @@ -44,6 +44,11 @@ namespace Handbrake /// private readonly IUserSettingService userSettingService = ServiceManager.UserSettingService; + /// + /// Set to true when the window is ready. + /// + private bool isInitialised = false; + /// /// Initializes a new instance of the class. /// @@ -69,6 +74,7 @@ namespace Handbrake queue.EncodeService.EncodeCompleted += this.queue_EncodeEnded; drp_completeOption.Text = userSettingService.GetUserSetting(ASUserSettingConstants.WhenCompleteAction); + this.isInitialised = true; } /// @@ -720,7 +726,10 @@ namespace Handbrake /// private void CompleteOptionChanged(object sender, EventArgs e) { - userSettingService.SetUserSetting(ASUserSettingConstants.WhenCompleteAction, drp_completeOption.Text); + if (this.isInitialised) + { + userSettingService.SetUserSetting(ASUserSettingConstants.WhenCompleteAction, drp_completeOption.Text); + } } /// -- cgit v1.2.3