]> granicus.if.org Git - handbrake/commitdiff
WinGui: Fix preset updates. Built in presets should now automatically update. It...
authorsr55 <sr55.hb@outlook.com>
Fri, 18 Jan 2019 20:14:44 +0000 (20:14 +0000)
committersr55 <sr55.hb@outlook.com>
Fri, 18 Jan 2019 20:14:59 +0000 (20:14 +0000)
win/CS/HandBrakeWPF/Constants.cs
win/CS/HandBrakeWPF/Services/Presets/PresetService.cs

index 64eae95bda653f7c50e348dd8fea5f7cf9cdab2d..5bb064fb74988c295ea3d562ab155f609bd2b562 100644 (file)
@@ -38,7 +38,7 @@ namespace HandBrakeWPF
         public const string SourceFolderName = "{source_folder_name}";\r
 \r
         /* Preset Versions */\r
-        public const string PresetVersionMajor = "11";\r
+        public const string PresetVersionMajor = "34";\r
         public const string PresetVersionMinor = "0";\r
         public const string PresetVersionMicro = "0";\r
 \r
index ef280b5b7722a294b57506203c1291c6e22c4e36..7a91841d8d242cff274c50fa36576981dd9602b6 100644 (file)
@@ -101,13 +101,6 @@ namespace HandBrakeWPF.Services.Presets
         /// </summary>\r
         public void Load()\r
         {\r
-            // If the preset file doesn't exist. Create it.\r
-            if (!File.Exists(this.presetFile))\r
-            {\r
-                this.UpdateBuiltInPresets();\r
-                return;\r
-            }\r
-\r
             // Load the presets from file\r
             this.LoadPresets();\r
         }\r
@@ -466,7 +459,7 @@ namespace HandBrakeWPF.Services.Presets
         /// </summary>\r
         public void UpdateBuiltInPresets()\r
         {\r
-            // Clear the current built in Presets and now parse the tempory Presets file.\r
+            // Clear the current built in Presets and now parse the temporary Presets file.\r
             this.ClearBuiltIn();\r
 \r
             IList<PresetCategory> presetCategories = HandBrakePresetService.GetBuiltInPresets();\r
@@ -680,17 +673,8 @@ namespace HandBrakeWPF.Services.Presets
                 // If we don't have a presets file. Create one for first load.\r
                 if (!File.Exists(this.presetFile))\r
                 {\r
-                    // If this is a nightly, and we don't have a presets file, try port the main version if it exists.\r
-                    string releasePresetFile = Path.Combine(DirectoryUtilities.GetUserStoragePath(false), "presets.json");\r
-                    if (VersionHelper.IsNightly() && File.Exists(releasePresetFile))\r
-                    {\r
-                        File.Copy(releasePresetFile, DirectoryUtilities.GetUserStoragePath(true));\r
-                    }\r
-                    else\r
-                    {\r
-                        this.UpdateBuiltInPresets();\r
-                        return; // Update built-in presets stores the presets locally, so just return.\r
-                    }\r
+                    this.UpdateBuiltInPresets();\r
+                    return;\r
                 }\r
 \r
                 // Otherwise, we already have a file, so lets try load it.\r
@@ -724,6 +708,7 @@ namespace HandBrakeWPF.Services.Presets
                 // Version Check\r
                 // If we have old presets, or the container wasn't parseable, or we have a version mismatch, backup the user preset file \r
                 // incase something goes wrong and reset built-in presets, then re-save.\r
+                bool ignoreBuildIn = false;\r
                 if (container.VersionMajor != Constants.PresetVersionMajor || container.VersionMinor != Constants.PresetVersionMinor || container.VersionMicro != Constants.PresetVersionMicro)\r
                 {\r
                     string fileName = this.ArchivePresetFile(this.presetFile);\r
@@ -732,9 +717,9 @@ namespace HandBrakeWPF.Services.Presets
                         + Environment.NewLine + Environment.NewLine + Resources.PresetService_ArchiveFile + fileName,\r
                         Resources.PresetService_UnableToLoad,\r
                         MessageBoxButton.OK,\r
-                        MessageBoxImage.Exclamation);\r
+                        MessageBoxImage.Information);\r
                     this.UpdateBuiltInPresets(); // Update built-in presets stores the presets locally, so just return.\r
-                    return;\r
+                    ignoreBuildIn = true;\r
                 }\r
 \r
                 // Force Upgrade of presets\r
@@ -748,54 +733,44 @@ namespace HandBrakeWPF.Services.Presets
                         + Environment.NewLine + Environment.NewLine + Resources.PresetService_ArchiveFile + fileName,\r
                         Resources.PresetService_UnableToLoad,\r
                         MessageBoxButton.OK,\r
-                        MessageBoxImage.Exclamation);\r
+                        MessageBoxImage.Information);\r
                     this.UpdateBuiltInPresets(); // Update built-in presets stores the presets locally, so just return.\r
                     return;\r
                 }\r
 \r
-                // The presets file loaded was OK, so process it.\r
-                foreach (var item in container.PresetList)\r
-                {\r
-                    object deserialisedItem = JsonConvert.DeserializeObject<PresetCategory>(item.ToString());\r
+                this.ProcessPresetList(container, ignoreBuildIn);\r
+            }\r
+            catch (Exception ex)\r
+            {\r
+                Debug.WriteLine(ex);\r
+                this.RecoverFromCorruptedPresetFile(this.presetFile);\r
+                this.UpdateBuiltInPresets();\r
+            }\r
+        }\r
 \r
-                    // Handle Categorised Presets.\r
-                    PresetCategory category = deserialisedItem as PresetCategory;\r
-                    if (category != null && category.Folder)\r
-                    {\r
-                        foreach (HBPreset hbpreset in category.ChildrenArray)\r
-                        {\r
-                            Preset preset = JsonPresetFactory.ImportPreset(hbpreset);\r
-                            \r
-                            // Migration\r
-                            if (category.PresetName == "User Presets")\r
-                            {\r
-                                preset.Category = UserPresetCatgoryName;\r
-                            }\r
-                            else\r
-                            {\r
-                                preset.Category = category.PresetName;\r
-                            }\r
-                            preset.IsBuildIn = hbpreset.Type == 0;\r
+        private void ProcessPresetList(PresetTransportContainer container, bool ignoreOldBuiltIn)\r
+        {\r
+            // The presets file loaded was OK, so process it.\r
+            foreach (var item in container.PresetList)\r
+            {\r
+                object deserialisedItem = JsonConvert.DeserializeObject<PresetCategory>(item.ToString());\r
 \r
-                            // IF we are using Source Max, Set the Max Width / Height values.\r
-                            if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)\r
-                            {\r
-                                preset.Task.MaxWidth = preset.Task.Height;\r
-                                preset.Task.MaxHeight = preset.Task.Width;\r
-                            }\r
+                // Handle Categorised Presets.\r
+                PresetCategory category = deserialisedItem as PresetCategory;\r
+                if (category != null && category.Folder)\r
+                {\r
+                    foreach (HBPreset hbpreset in category.ChildrenArray)\r
+                    {\r
+                        Preset preset = JsonPresetFactory.ImportPreset(hbpreset);\r
 \r
-                            this.Add(preset, true);\r
+                        if (preset.IsBuildIn && ignoreOldBuiltIn)\r
+                        {\r
+                            continue;\r
                         }\r
-                    }\r
 \r
-                    // Uncategorised Presets\r
-                    deserialisedItem = JsonConvert.DeserializeObject<HBPreset>(item.ToString());\r
-                    HBPreset hbPreset = deserialisedItem as HBPreset;\r
-                    if (hbPreset != null && !hbPreset.Folder)\r
-                    {\r
-                        Preset preset = JsonPresetFactory.ImportPreset(hbPreset);\r
-                        preset.Category = UserPresetCatgoryName;\r
-                        preset.IsBuildIn = hbPreset.Type == 1;\r
+                        // Migration\r
+                        preset.Category = category.PresetName == "User Presets" ? UserPresetCatgoryName : category.PresetName;\r
+                        preset.IsBuildIn = hbpreset.Type == 0;\r
 \r
                         // IF we are using Source Max, Set the Max Width / Height values.\r
                         if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)\r
@@ -807,13 +782,27 @@ namespace HandBrakeWPF.Services.Presets
                         this.Add(preset, true);\r
                     }\r
                 }\r
+\r
+                // Uncategorised Presets\r
+                deserialisedItem = JsonConvert.DeserializeObject<HBPreset>(item.ToString());\r
+                HBPreset hbPreset = deserialisedItem as HBPreset;\r
+                if (hbPreset != null && !hbPreset.Folder)\r
+                {\r
+                    Preset preset = JsonPresetFactory.ImportPreset(hbPreset);\r
+                    preset.Category = UserPresetCatgoryName;\r
+                    preset.IsBuildIn = hbPreset.Type == 1;\r
+\r
+                    // IF we are using Source Max, Set the Max Width / Height values.\r
+                    if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)\r
+                    {\r
+                        preset.Task.MaxWidth = preset.Task.Height;\r
+                        preset.Task.MaxHeight = preset.Task.Width;\r
+                    }\r
+\r
+                    this.Add(preset, true);\r
+                }\r
             }\r
-            catch (Exception ex)\r
-            {\r
-                Debug.WriteLine(ex);\r
-                this.RecoverFromCorruptedPresetFile(this.presetFile);\r
-                this.UpdateBuiltInPresets();\r
-            }\r
+\r
         }\r
 \r
         /// <summary>\r