]> granicus.if.org Git - handbrake/commitdiff
WinGui: Make the Preset Plist importer a bit more robust by checking versions and...
authorsr55 <sr55.hb@outlook.com>
Tue, 21 Jan 2014 20:27:57 +0000 (20:27 +0000)
committersr55 <sr55.hb@outlook.com>
Tue, 21 Jan 2014 20:27:57 +0000 (20:27 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5988 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrake.ApplicationServices/Utilities/EnumHelper.cs
win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs
win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
win/CS/HandBrakeWPF/Properties/Resources.resx
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs

index cc7dfc43e110c5646902348145b7670d06f17ac1..45988ba60a560a35033f70a0cd1df1b70491ef26 100644 (file)
@@ -14,6 +14,7 @@ namespace HandBrake.ApplicationServices.Utilities
     using System.Collections.ObjectModel;\r
     using System.ComponentModel;\r
     using System.ComponentModel.DataAnnotations;\r
+    using System.Diagnostics;\r
     using System.Linq;\r
     using System.Reflection;\r
 \r
@@ -91,7 +92,9 @@ namespace HandBrake.ApplicationServices.Utilities
                 }\r
             }\r
 \r
-            throw new ArgumentOutOfRangeException("The Description for the enum was not recognized.");\r
+            Debug.WriteLine("EnumHelper.GetValue: The Description for the enum was not recognized: " + description);\r
+\r
+            return default(T);\r
         }\r
 \r
         /// <summary>\r
index 3ddb1ff51b84842936c371588b587773d05c5e1d..25c3a14269656db231e49da641e7387d5f1cf809 100644 (file)
@@ -276,13 +276,13 @@ namespace HandBrake.ApplicationServices.Utilities
             if (parsed.FastDecode)\r
             {\r
                 tune = tune == "none" ? "fastdecode" : tune + ",fastdecode";\r
-            }
-            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;
+            }\r
+            AddEncodeElement(xmlWriter, "x264Tune", "string", tune);\r
+            AddEncodeElement(xmlWriter, "x264UseAdvancedOptions", "integer", parsed.ShowAdvancedTab ? "1" : "0");\r
+            AddEncodeElement(xmlWriter, "qsvPreset", "string", parsed.QsvPreset.ToString().ToLower());\r
+\r
+            int videoQualityType = 0;\r
+            if (parsed.VideoBitrate != null) videoQualityType = 1;\r
             else if (parsed.Quality != null) videoQualityType = 2;\r
 \r
             AddEncodeElement(xmlWriter, "VideoQualityType", "integer", videoQualityType.ToString());\r
index 297b6a5760198c01edfbc6ebb1719697e0121183..6206412ef86afe2b74df5b1cd83204597a3d9144 100644 (file)
@@ -671,6 +671,45 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to Preset Version.\r
+        /// </summary>\r
+        public static string Preset_OldVersion_Header {\r
+            get {\r
+                return ResourceManager.GetString("Preset_OldVersion_Header", resourceCulture);\r
+            }\r
+        }\r
+        \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to The preset you are trying to import is from a different version of HandBrake. \r
+        ///Some values may be reset to default as a result. \r
+        ///\r
+        ///Do you wish to proceed?.\r
+        /// </summary>\r
+        public static string Preset_OldVersion_Message {\r
+            get {\r
+                return ResourceManager.GetString("Preset_OldVersion_Message", resourceCulture);\r
+            }\r
+        }\r
+        \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to Unable to import preset!.\r
+        /// </summary>\r
+        public static string Preset_UnableToImport_Header {\r
+            get {\r
+                return ResourceManager.GetString("Preset_UnableToImport_Header", resourceCulture);\r
+            }\r
+        }\r
+        \r
+        /// <summary>\r
+        ///   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..\r
+        /// </summary>\r
+        public static string Preset_UnableToImport_Message {\r
+            get {\r
+                return ResourceManager.GetString("Preset_UnableToImport_Message", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to The Built-in presets have been reset..\r
         /// </summary>\r
index afd114c0c95d90d5a552c8223f511e1e1f6bd618..76ddea9ee747a3c626ad6dc7255074f5eb620b1a 100644 (file)
@@ -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">\r
     <value>Updated</value>\r
   </data>\r
+  <data name="Preset_OldVersion_Header" xml:space="preserve">\r
+    <value>Preset Version</value>\r
+  </data>\r
+  <data name="Preset_OldVersion_Message" xml:space="preserve">\r
+    <value>The preset you are trying to import is from a different version of HandBrake. \r
+Some values may be reset to default as a result. \r
+\r
+Do you wish to proceed?</value>\r
+  </data>\r
+  <data name="Preset_UnableToImport_Header" xml:space="preserve">\r
+    <value>Unable to import preset!</value>\r
+  </data>\r
+  <data name="Preset_UnableToImport_Message" xml:space="preserve">\r
+    <value>Unable to import the preset as it appears to be corrupted or from an older version of HandBrake.</value>\r
+  </data>\r
 </root>
\ No newline at end of file
index 0499e7157cb40149d3a4b6280d4fcad460484415..a531b549c9a6866a94d69dada20354fdb87e3528 100644 (file)
@@ -1539,6 +1539,33 @@ namespace HandBrakeWPF.ViewModels
             if (!string.IsNullOrEmpty(filename))\r
             {\r
                 PList plist = new PList(filename);\r
+\r
+                object build;\r
+                plist.TryGetValue("PresetBuildNumber", out build);\r
+\r
+                string buildNumber = build as string;\r
+                if (buildNumber == null)\r
+                {\r
+                    MessageBox.Show(\r
+                        Resources.Preset_UnableToImport_Message,\r
+                        Resources.Preset_UnableToImport_Header,\r
+                        MessageBoxButton.YesNo, MessageBoxImage.Question);\r
+                    return;\r
+                }\r
+\r
+                if (buildNumber != userSettingService.GetUserSetting<int>(UserSettingConstants.HandBrakeBuild).ToString(CultureInfo.InvariantCulture))\r
+                {\r
+                    MessageBoxResult result = MessageBox.Show(\r
+                        Resources.Preset_OldVersion_Message,\r
+                        Resources.Preset_OldVersion_Header,\r
+                        MessageBoxButton.YesNo, MessageBoxImage.Question);\r
+\r
+                    if (result == MessageBoxResult.No)\r
+                    {\r
+                        return;\r
+                    }\r
+                }\r
+\r
                 Preset preset = PlistPresetFactory.CreatePreset(plist);\r
 \r
                 if (this.presetService.CheckIfPresetExists(preset.Name))\r