summaryrefslogtreecommitdiffstats
path: root/win/CS
diff options
context:
space:
mode:
authorsr55 <[email protected]>2013-07-20 14:37:53 +0000
committersr55 <[email protected]>2013-07-20 14:37:53 +0000
commita3d27b2e6c41d8d856b935bf55f85c719a850cc3 (patch)
tree7d8d0f3dd753e88907b2df62a4e2a5db47fbe8de /win/CS
parent18611a4004bf4adc61d6923c565e363244ffa2b0 (diff)
WinGui: Update the exception handling code to deal with Component Activation Exceptions, allowing for better error messages. Changed the defaultsettings.xml file to be an embedded resource.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5655 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs20
-rw-r--r--win/CS/HandBrakeWPF/App.xaml.cs34
-rw-r--r--win/CS/HandBrakeWPF/HandBrakeWPF.csproj4
3 files changed, 44 insertions, 14 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
index db7389637..7f40bffff 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
@@ -13,6 +13,7 @@ namespace HandBrake.ApplicationServices.Services
using System.Collections.Specialized;
using System.IO;
using System.Linq;
+ using System.Reflection;
using System.Xml.Serialization;
using HandBrake.ApplicationServices.Collections;
@@ -67,7 +68,7 @@ namespace HandBrake.ApplicationServices.Services
this.userSettings[name] = value;
this.Save();
- this.OnSettingChanged(new SettingChangedEventArgs {Key = name, Value = value});
+ this.OnSettingChanged(new SettingChangedEventArgs { Key = name, Value = value });
}
/// <summary>
@@ -163,7 +164,7 @@ namespace HandBrake.ApplicationServices.Services
SerializableDictionary<string, object> data = (SerializableDictionary<string, object>)serializer.Deserialize(reader);
this.userSettings = data;
}
- }
+ }
else
{
this.userSettings = new SerializableDictionary<string, object>();
@@ -192,7 +193,7 @@ namespace HandBrake.ApplicationServices.Services
}
catch (Exception)
{
- throw new GeneralApplicationException("Unable to load user settings.", "Your user settings file appears to be inaccessible or corrupted. You may have to delete the file and let HandBrake generate a new one.", exc);
+ throw new GeneralApplicationException("Unable to load user settings file: " + this.settingsFile, "Your user settings file appears to be inaccessible or corrupted. You may have to delete the file and let HandBrake generate a new one.", exc);
}
}
}
@@ -205,13 +206,20 @@ namespace HandBrake.ApplicationServices.Services
/// </returns>
private SerializableDictionary<string, object> GetDefaults()
{
- if (File.Exists("defaultsettings.xml"))
+ try
{
- using (StreamReader reader = new StreamReader("defaultsettings.xml"))
+ Assembly assembly = Assembly.GetEntryAssembly();
+ Stream stream = assembly.GetManifestResourceStream("HandBrakeWPF.defaultsettings.xml");
+ if (stream != null)
{
- return (SerializableDictionary<string, object>)serializer.Deserialize(reader);
+ return (SerializableDictionary<string, object>)this.serializer.Deserialize(stream);
}
}
+ catch (Exception exc)
+ {
+ return new SerializableDictionary<string, object>();
+ }
+
return new SerializableDictionary<string, object>();
}
}
diff --git a/win/CS/HandBrakeWPF/App.xaml.cs b/win/CS/HandBrakeWPF/App.xaml.cs
index 1d4434677..8ad696d7f 100644
--- a/win/CS/HandBrakeWPF/App.xaml.cs
+++ b/win/CS/HandBrakeWPF/App.xaml.cs
@@ -108,6 +108,20 @@ namespace HandBrakeWPF
{
this.ShowError(e.Exception.InnerException);
}
+ else if (e.Exception.InnerException != null && e.Exception.InnerException.GetType() == typeof(Castle.MicroKernel.ComponentActivator.ComponentActivatorException))
+ {
+ // Handle Component Activation Exceptions. Can happen when one of the services throws an execption when being constructed.
+ Exception innerException = e.Exception.InnerException.InnerException;
+ if (innerException != null && innerException.InnerException != null &&
+ innerException.InnerException.GetType() == typeof(GeneralApplicationException))
+ {
+ this.ShowError(innerException.InnerException);
+ }
+ else
+ {
+ this.ShowError(innerException);
+ }
+ }
else
{
this.ShowError(e.Exception);
@@ -130,10 +144,10 @@ namespace HandBrakeWPF
if (windowManager != null)
{
ErrorViewModel errorView = new ErrorViewModel();
-
+ GeneralApplicationException applicationException = null;
if (exception.GetType() == typeof(GeneralApplicationException))
{
- GeneralApplicationException applicationException = exception as GeneralApplicationException;
+ applicationException = exception as GeneralApplicationException;
if (applicationException != null)
{
string details = string.Format(
@@ -142,9 +156,7 @@ namespace HandBrakeWPF
Environment.NewLine,
applicationException.Solution,
Environment.NewLine,
- applicationException.ActualException != null
- ? applicationException.ActualException.ToString()
- : "No additional exception information available.");
+ applicationException.ActualException != null ? applicationException.ActualException.ToString() : "No additional exception information available.");
errorView.ErrorMessage = applicationException.Error;
errorView.Solution = applicationException.Solution;
@@ -156,7 +168,17 @@ namespace HandBrakeWPF
errorView.Details = exception.ToString();
}
- windowManager.ShowDialog(errorView);
+ try
+ {
+ windowManager.ShowDialog(errorView);
+ }
+ catch (Exception)
+ {
+ if (applicationException != null)
+ {
+ MessageBox.Show(applicationException.Error + Environment.NewLine + Environment.NewLine + applicationException.Solution, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
}
}
catch (Exception)
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
index cb4f87a9b..1e1bddefa 100644
--- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
+++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
@@ -441,10 +441,10 @@
</Page>
</ItemGroup>
<ItemGroup>
- <Content Include="defaultsettings.xml">
+ <EmbeddedResource Include="defaultsettings.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
- </Content>
+ </EmbeddedResource>
<Resource Include="Views\Images\add40.png" />
<Resource Include="Views\Images\add.png" />
<Resource Include="Views\Images\remove.png" />