summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsr55 <[email protected]>2014-01-21 20:27:57 +0000
committersr55 <[email protected]>2014-01-21 20:27:57 +0000
commit1c5cdd2e5767b3b25df9da740034e1f05a43d271 (patch)
treed6230a366fdb4785faa69974efa3e3a6afb5b713
parent675678a7157fac5c8ad6a69edd21fbf33d263c08 (diff)
WinGui: Make the Preset Plist importer a bit more robust by checking versions and automatically falling back to a value for invalid key/value pairs from old versions.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5988 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/EnumHelper.cs5
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs14
-rw-r--r--win/CS/HandBrakeWPF/Properties/Resources.Designer.cs39
-rw-r--r--win/CS/HandBrakeWPF/Properties/Resources.resx15
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs27
5 files changed, 92 insertions, 8 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/EnumHelper.cs b/win/CS/HandBrake.ApplicationServices/Utilities/EnumHelper.cs
index cc7dfc43e..45988ba60 100644
--- a/win/CS/HandBrake.ApplicationServices/Utilities/EnumHelper.cs
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/EnumHelper.cs
@@ -14,6 +14,7 @@ namespace HandBrake.ApplicationServices.Utilities
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
+ using System.Diagnostics;
using System.Linq;
using System.Reflection;
@@ -91,7 +92,9 @@ namespace HandBrake.ApplicationServices.Utilities
}
}
- throw new ArgumentOutOfRangeException("The Description for the enum was not recognized.");
+ Debug.WriteLine("EnumHelper.GetValue: The Description for the enum was not recognized: " + description);
+
+ return default(T);
}
/// <summary>
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs
index 3ddb1ff51..25c3a1426 100644
--- a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs
@@ -276,13 +276,13 @@ namespace HandBrake.ApplicationServices.Utilities
if (parsed.FastDecode)
{
tune = tune == "none" ? "fastdecode" : tune + ",fastdecode";
- }
- AddEncodeElement(xmlWriter, "x264Tune", "string", tune);
- AddEncodeElement(xmlWriter, "x264UseAdvancedOptions", "integer", parsed.ShowAdvancedTab ? "1" : "0");
- AddEncodeElement(xmlWriter, "qsvPreset", "string", parsed.QsvPreset.ToString().ToLower());
-
- int videoQualityType = 0;
- if (parsed.VideoBitrate != null) videoQualityType = 1;
+ }
+ AddEncodeElement(xmlWriter, "x264Tune", "string", tune);
+ AddEncodeElement(xmlWriter, "x264UseAdvancedOptions", "integer", parsed.ShowAdvancedTab ? "1" : "0");
+ AddEncodeElement(xmlWriter, "qsvPreset", "string", parsed.QsvPreset.ToString().ToLower());
+
+ int videoQualityType = 0;
+ if (parsed.VideoBitrate != null) videoQualityType = 1;
else if (parsed.Quality != null) videoQualityType = 2;
AddEncodeElement(xmlWriter, "VideoQualityType", "integer", videoQualityType.ToString());
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
index 297b6a576..6206412ef 100644
--- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
+++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
@@ -672,6 +672,45 @@ namespace HandBrakeWPF.Properties {
}
/// <summary>
+ /// Looks up a localized string similar to Preset Version.
+ /// </summary>
+ public static string Preset_OldVersion_Header {
+ get {
+ return ResourceManager.GetString("Preset_OldVersion_Header", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to The preset you are trying to import is from a different version of HandBrake.
+ ///Some values may be reset to default as a result.
+ ///
+ ///Do you wish to proceed?.
+ /// </summary>
+ public static string Preset_OldVersion_Message {
+ get {
+ return ResourceManager.GetString("Preset_OldVersion_Message", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Unable to import preset!.
+ /// </summary>
+ public static string Preset_UnableToImport_Header {
+ get {
+ return ResourceManager.GetString("Preset_UnableToImport_Header", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Unable to import the preset as it appears to be corrupted or from an older version of HandBrake..
+ /// </summary>
+ public static string Preset_UnableToImport_Message {
+ get {
+ return ResourceManager.GetString("Preset_UnableToImport_Message", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to The Built-in presets have been reset..
/// </summary>
public static string Presets_ResetComplete {
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx
index afd114c0c..76ddea9ee 100644
--- a/win/CS/HandBrakeWPF/Properties/Resources.resx
+++ b/win/CS/HandBrakeWPF/Properties/Resources.resx
@@ -486,4 +486,19 @@ Your custom presets have not been updated so you may have to re-create these by
<data name="Updated" xml:space="preserve">
<value>Updated</value>
</data>
+ <data name="Preset_OldVersion_Header" xml:space="preserve">
+ <value>Preset Version</value>
+ </data>
+ <data name="Preset_OldVersion_Message" xml:space="preserve">
+ <value>The preset you are trying to import is from a different version of HandBrake.
+Some values may be reset to default as a result.
+
+Do you wish to proceed?</value>
+ </data>
+ <data name="Preset_UnableToImport_Header" xml:space="preserve">
+ <value>Unable to import preset!</value>
+ </data>
+ <data name="Preset_UnableToImport_Message" xml:space="preserve">
+ <value>Unable to import the preset as it appears to be corrupted or from an older version of HandBrake.</value>
+ </data>
</root> \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
index 0499e7157..a531b549c 100644
--- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
@@ -1539,6 +1539,33 @@ namespace HandBrakeWPF.ViewModels
if (!string.IsNullOrEmpty(filename))
{
PList plist = new PList(filename);
+
+ object build;
+ plist.TryGetValue("PresetBuildNumber", out build);
+
+ string buildNumber = build as string;
+ if (buildNumber == null)
+ {
+ MessageBox.Show(
+ Resources.Preset_UnableToImport_Message,
+ Resources.Preset_UnableToImport_Header,
+ MessageBoxButton.YesNo, MessageBoxImage.Question);
+ return;
+ }
+
+ if (buildNumber != userSettingService.GetUserSetting<int>(UserSettingConstants.HandBrakeBuild).ToString(CultureInfo.InvariantCulture))
+ {
+ MessageBoxResult result = MessageBox.Show(
+ Resources.Preset_OldVersion_Message,
+ Resources.Preset_OldVersion_Header,
+ MessageBoxButton.YesNo, MessageBoxImage.Question);
+
+ if (result == MessageBoxResult.No)
+ {
+ return;
+ }
+ }
+
Preset preset = PlistPresetFactory.CreatePreset(plist);
if (this.presetService.CheckIfPresetExists(preset.Name))