public static PresetTransportContainer ExportPreset(Preset export, HBConfiguration config)\r
{\r
PresetTransportContainer container = new PresetTransportContainer();\r
- container.VersionMajor = "0";\r
- container.VersionMinor = "10";\r
- container.VersionMicro = "2";\r
+ container.VersionMajor = Constants.PresetVersionMajor;\r
+ container.VersionMinor = Constants.PresetVersionMinor;\r
+ container.VersionMicro = Constants.PresetVersionMicro;\r
+\r
container.PresetList = new List<HBPreset> { CreateHbPreset(export, config) };\r
\r
return container;\r
}\r
\r
+ /// <summary>\r
+ /// Export a list of Presets.\r
+ /// </summary>\r
+ /// <param name="exportList">A list of presets to export</param>\r
+ /// <param name="config">HB's configuration</param>\r
+ /// <returns>A list of JSON object presets.</returns>\r
+ public static PresetTransportContainer ExportPresets(IEnumerable<Preset> exportList, HBConfiguration config)\r
+ {\r
+ PresetTransportContainer container = new PresetTransportContainer();\r
+ container.VersionMajor = Constants.PresetVersionMajor;\r
+ container.VersionMinor = Constants.PresetVersionMinor;\r
+ container.VersionMicro = Constants.PresetVersionMicro;\r
+\r
+ List<HBPreset> presets = exportList.Select(item => CreateHbPreset(item, config)).ToList();\r
+\r
+ container.PresetList = presets;\r
+\r
+ return container;\r
+ }\r
+\r
/// <summary>\r
/// The create hb preset.\r
/// </summary>\r
/// <returns>\r
/// The <see cref="HBPreset"/>.\r
/// </returns>\r
- private static HBPreset CreateHbPreset(Preset export, HBConfiguration config)\r
+ public static HBPreset CreateHbPreset(Preset export, HBConfiguration config)\r
{\r
HBPreset preset = new HBPreset();\r
\r
+++ /dev/null
-// --------------------------------------------------------------------------------------------------------------------\r
-// <copyright file="PresetContainer.cs" company="HandBrake Project (http://handbrake.fr)">\r
-// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
-// </copyright>\r
-// <summary>\r
-// A container object for presets. This object should not change often as it's designed for preset version tracking.\r
-// </summary>\r
-// --------------------------------------------------------------------------------------------------------------------\r
-\r
-namespace HandBrakeWPF.Services.Presets.Model\r
-{\r
- /// <summary>\r
- /// The preset container.\r
- /// </summary>\r
- public class PresetContainer\r
- {\r
- /// <summary>\r
- /// Initializes a new instance of the <see cref="PresetContainer"/> class.\r
- /// </summary>\r
- /// <param name="version">\r
- /// The version.\r
- /// </param>\r
- /// <param name="presets">\r
- /// The presets.\r
- /// </param>\r
- public PresetContainer(int version, string presets)\r
- {\r
- Version = version;\r
- Presets = presets;\r
- }\r
-\r
- /// <summary>\r
- /// Gets or sets the version of the presets stored in this container.\r
- /// </summary>\r
- public int Version { get; set; }\r
-\r
- /// <summary>\r
- /// Gets or sets the presets. This is a serialised string.\r
- /// </summary>\r
- public string Presets { get; set; }\r
- }\r
-}\r
using HandBrake.ApplicationServices.Model;\r
using HandBrake.ApplicationServices.Utilities;\r
\r
+ using HandBrakeWPF.Factories;\r
using HandBrakeWPF.Model.Picture;\r
using HandBrakeWPF.Properties;\r
using HandBrakeWPF.Services.Encode.Model.Models;\r
using (StreamReader reader = new StreamReader(this.builtInPresetFile))\r
{\r
// New Preset Format.\r
- try\r
- {\r
- var presetList = JsonConvert.DeserializeObject<List<Preset>>(reader.ReadToEnd());\r
+ IList<PresetCategory> presetCategories = JsonConvert.DeserializeObject<IList<PresetCategory>>(reader.ReadToEnd());\r
\r
- foreach (Preset preset in presetList)\r
+ foreach (var item in presetCategories)\r
+ {\r
+ foreach (var hbpreset in item.ChildrenArray)\r
{\r
- preset.IsBuildIn = true; // Older versions did not have this flag so explicitly make sure it is set.\r
+ Preset preset = JsonPresetFactory.ImportPreset(hbpreset);\r
+ preset.Category = item.PresetName;\r
+ preset.IsBuildIn = true;\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.presets.Add(preset);\r
}\r
}\r
- catch (Exception exc)\r
- {\r
- // Do Nothing.\r
- Debug.WriteLine(exc);\r
- }\r
}\r
}\r
}\r
{\r
// New Preset Format.\r
bool createBackup = false;\r
- PresetContainer presetContainer = null;\r
+ PresetTransportContainer presetContainer = null;\r
using (StreamReader reader = new StreamReader(this.userPresetFile))\r
{\r
try\r
{\r
- presetContainer = JsonConvert.DeserializeObject<PresetContainer>(reader.ReadToEnd());\r
+ presetContainer = JsonConvert.DeserializeObject<PresetTransportContainer>(reader.ReadToEnd());\r
}\r
catch (Exception exc)\r
{\r
\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.\r
- if (createBackup || (presetContainer != null && presetContainer.Version < CurrentPresetVersion))\r
+ if (createBackup || (presetContainer.VersionMajor != Constants.PresetVersionMajor || presetContainer.VersionMinor != Constants.PresetVersionMinor || presetContainer.VersionMicro != Constants.PresetVersionMicro))\r
{\r
string fileName = RecoverFromCorruptedPresetFile(this.userPresetFile);\r
this.errorService.ShowMessageBox(\r
}\r
\r
// Load the current presets.\r
- if (presetContainer != null && !string.IsNullOrEmpty(presetContainer.Presets))\r
+ if (presetContainer.PresetList != null)\r
{\r
- JsonSerializerSettings settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore };\r
- List<Preset> list = JsonConvert.DeserializeObject<List<Preset>>(presetContainer.Presets, settings);\r
- foreach (Preset preset in list)\r
+ foreach (var item in presetContainer.PresetList)\r
{\r
+ Preset preset = JsonPresetFactory.ImportPreset(item);\r
+ preset.Category = item.PresetName;\r
+ preset.IsBuildIn = true;\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.presets.Add(preset);\r
}\r
}\r
JsonSerializerSettings settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore };\r
\r
// Built-in Presets\r
+ Dictionary<string, PresetCategory> presetCategories = new Dictionary<string, PresetCategory>();\r
+ foreach (var item in this.presets.Where(p => p.IsBuildIn).ToList())\r
+ {\r
+ HBPreset preset = JsonPresetFactory.CreateHbPreset(item, HBConfigurationFactory.Create());\r
+ if (presetCategories.ContainsKey(item.Category))\r
+ {\r
+ presetCategories[item.Category].ChildrenArray.Add(preset);\r
+ }\r
+ else\r
+ {\r
+ presetCategories[item.Category] = new PresetCategory { ChildrenArray = new List<HBPreset>(), Folder = true, PresetName = item.Category, Type = 0 };\r
+ } \r
+ }\r
\r
using (FileStream strm = new FileStream(this.builtInPresetFile, FileMode.Create, FileAccess.Write))\r
{\r
- string presetsJson = JsonConvert.SerializeObject(this.presets.Where(p => p.IsBuildIn).ToList(), Formatting.Indented, settings);\r
+ string presetsJson = JsonConvert.SerializeObject(presetCategories, Formatting.Indented, settings);\r
using (StreamWriter writer = new StreamWriter(strm))\r
{\r
writer.WriteLine(presetsJson);\r
List<Preset> userPresets = this.presets.Where(p => p.IsBuildIn == false).ToList();\r
string presetsJson = JsonConvert.SerializeObject(userPresets, Formatting.Indented, settings);\r
\r
- PresetContainer container = new PresetContainer(CurrentPresetVersion, presetsJson);\r
- string containerJson = JsonConvert.SerializeObject(container, Formatting.Indented, settings);\r
-\r
using (StreamWriter writer = new StreamWriter(strm))\r
{\r
- writer.WriteLine(containerJson);\r
+ writer.WriteLine(presetsJson);\r
}\r
}\r
}\r