summaryrefslogtreecommitdiffstats
path: root/win/CS
diff options
context:
space:
mode:
authorsr55 <[email protected]>2012-03-29 20:29:13 +0000
committersr55 <[email protected]>2012-03-29 20:29:13 +0000
commit15c3e5ba568ed34d6a5adc629ced50010c819078 (patch)
tree143c999d557d875770d54f5ae7df1847e2eabc2d /win/CS
parent72997d728bb599ffff1e81c65ff4b44cc646c3f0 (diff)
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
Diffstat (limited to 'win/CS')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs55
-rw-r--r--win/CS/Program.cs4
-rw-r--r--win/CS/frmQueue.cs11
3 files changed, 29 insertions, 41 deletions
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();
- }
}
/// <summary>
@@ -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<string, object> data = (SerializableDictionary<string, object>)serializer.Deserialize(reader);
this.userSettings = data;
-
- // Add any new settings
- SerializableDictionary<string, object> 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<string, object> 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
/// </returns>
private SerializableDictionary<string, object> 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<string, object>)serializer.Deserialize(reader);
- }
+ return (SerializableDictionary<string, object>)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<string, object>();
}
}
}
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
@@ -45,6 +45,11 @@ namespace Handbrake
private readonly IUserSettingService userSettingService = ServiceManager.UserSettingService;
/// <summary>
+ /// Set to true when the window is ready.
+ /// </summary>
+ private bool isInitialised = false;
+
+ /// <summary>
/// Initializes a new instance of the <see cref="frmQueue"/> class.
/// </summary>
/// <param name="q">
@@ -69,6 +74,7 @@ namespace Handbrake
queue.EncodeService.EncodeCompleted += this.queue_EncodeEnded;
drp_completeOption.Text = userSettingService.GetUserSetting<string>(ASUserSettingConstants.WhenCompleteAction);
+ this.isInitialised = true;
}
/// <summary>
@@ -720,7 +726,10 @@ namespace Handbrake
/// </param>
private void CompleteOptionChanged(object sender, EventArgs e)
{
- userSettingService.SetUserSetting(ASUserSettingConstants.WhenCompleteAction, drp_completeOption.Text);
+ if (this.isInitialised)
+ {
+ userSettingService.SetUserSetting(ASUserSettingConstants.WhenCompleteAction, drp_completeOption.Text);
+ }
}
/// <summary>