]> granicus.if.org Git - handbrake/commitdiff
WinGui: Completely replace the plist preset import code with the functionality built...
authorsr55 <sr55.hb@outlook.com>
Fri, 26 Jun 2015 20:14:25 +0000 (20:14 +0000)
committersr55 <sr55.hb@outlook.com>
Fri, 26 Jun 2015 20:14:25 +0000 (20:14 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7318 b64f7644-9d1e-0410-96f1-a4d463321fa5

14 files changed:
win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs
win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs
win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/PresetTransportContainer.cs [new file with mode: 0644]
win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs
win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs [deleted file]
win/CS/HandBrakeWPF/HandBrakeWPF.csproj
win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs
win/CS/HandBrakeWPF/Services/Presets/Factories/PlistFactory.cs
win/CS/HandBrakeWPF/Services/Presets/Factories/PlistPresetFactory.cs [deleted file]
win/CS/HandBrakeWPF/Services/Presets/Interfaces/IPresetService.cs
win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
win/CS/HandBrakeWPF/Utilities/PList.cs [deleted file]
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs

index 524729f2094c0fecccb27cff6009032befc2dfc4..1a080047fbc406bb58d0ce01b8e2e38b06263e9d 100644 (file)
     <Compile Include="Interop\Json\Presets\AudioList.cs" />\r
     <Compile Include="Interop\Json\Presets\HBPreset.cs" />\r
     <Compile Include="Interop\Json\Presets\PresetCategory.cs" />\r
+    <Compile Include="Interop\Json\Presets\PresetTransportContainer.cs" />\r
     <Compile Include="Interop\Json\Shared\PAR.cs" />\r
     <Compile Include="Interop\Json\Encode\Audio.cs" />\r
     <Compile Include="Interop\Json\Encode\AudioTrack.cs" />\r
     <Compile Include="Services\Logging\Model\LogMessageType.cs" />\r
     <Compile Include="Services\Scan\EventArgs\ScanCompletedEventArgs.cs" />\r
     <Compile Include="Services\Scan\EventArgs\ScanProgressEventArgs.cs" />\r
-    <Compile Include="Utilities\Converters.cs" />\r
     <Compile Include="Utilities\EnumHelper.cs" />\r
     <Compile Include="Utilities\Execute.cs" />\r
     <Compile Include="Utilities\ExtensionMethods.cs" />\r
index e2610905d823474bd822781092606bcb864baae3..8d4f34e9e2e2cd187379b213be031d5ca7431660 100644 (file)
@@ -14,6 +14,7 @@ namespace HandBrake.ApplicationServices.Interop
     using System.Runtime.InteropServices;\r
 \r
     using HandBrake.ApplicationServices.Interop.HbLib;\r
+    using HandBrake.ApplicationServices.Interop.Helpers;\r
     using HandBrake.ApplicationServices.Interop.Json.Presets;\r
     using HandBrake.ApplicationServices.Services.Logging;\r
     using HandBrake.ApplicationServices.Services.Logging.Model;\r
@@ -43,5 +44,26 @@ namespace HandBrake.ApplicationServices.Interop
 \r
             return presetList;\r
         }\r
+\r
+        /// <summary>\r
+        /// The get preset from file.\r
+        /// </summary>\r
+        /// <param name="filename">\r
+        /// The filename.\r
+        /// </param>\r
+        /// <returns>\r
+        /// The <see cref="PresetCategory"/>.\r
+        /// </returns>\r
+        public static PresetTransportContainer GetPresetFromFile(string filename)\r
+        {\r
+            IntPtr presetStringPointer = HBFunctions.hb_presets_read_file_json(InteropUtilities.ToUtf8PtrFromString(filename));\r
+            string presetJson = Marshal.PtrToStringAnsi(presetStringPointer);\r
+\r
+            LogHelper.LogMessage(new LogMessage(presetJson, LogMessageType.libhb, LogLevel.debug));\r
+\r
+            PresetTransportContainer preset = JsonConvert.DeserializeObject<PresetTransportContainer>(presetJson);\r
+\r
+            return preset;\r
+        }\r
     }\r
 }\r
index 1b68df438ba726d2fe2266cdb22166177c57ec47..d8d8289f17168d02f4d89e785499755ceb223394 100644 (file)
@@ -440,8 +440,8 @@ namespace HandBrake.ApplicationServices.Interop.HbLib
         [DllImport("hb.dll", EntryPoint = "hb_presets_builtin_get_json", CallingConvention = CallingConvention.Cdecl)]\r
         public static extern IntPtr hb_presets_builtin_get_json();\r
 \r
-        // hb_value_t * hb_plist_parse_file(const char *filename);\r
-        [DllImport("hb.dll", EntryPoint = "hb_plist_parse_file", CallingConvention = CallingConvention.Cdecl)]\r
-        public static extern IntPtr hb_plist_parse_file(IntPtr filename);\r
+        //     char       * hb_presets_read_file_json(const char *filename);\r
+        [DllImport("hb.dll", EntryPoint = "hb_presets_read_file_json", CallingConvention = CallingConvention.Cdecl)]\r
+        public static extern IntPtr hb_presets_read_file_json(IntPtr filename);\r
     }\r
 }\r
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/PresetTransportContainer.cs b/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/PresetTransportContainer.cs
new file mode 100644 (file)
index 0000000..8f1dd9e
--- /dev/null
@@ -0,0 +1,41 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="PresetTransportContainer.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
+//   The preset transport container.\r
+//   This is a model for importing the JSON / Plist presets into the GUI.\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrake.ApplicationServices.Interop.Json.Presets\r
+{\r
+    using System.Collections.Generic;\r
+\r
+    /// <summary>\r
+    /// The preset transport container.\r
+    /// This is a model for importing the JSON / Plist presets into the GUI.\r
+    /// </summary>\r
+    public class PresetTransportContainer\r
+    {\r
+        /// <summary>\r
+        /// Gets or sets the children array.\r
+        /// </summary>\r
+        public List<HBPreset> PresetList { get; set; }\r
+\r
+        /// <summary>\r
+        /// Gets or sets the version major.\r
+        /// </summary>\r
+        public string VersionMajor { get; set; }\r
+\r
+        /// <summary>\r
+        /// Gets or sets the version micro.\r
+        /// </summary>\r
+        public string VersionMicro { get; set; }\r
+\r
+        /// <summary>\r
+        /// Gets or sets the version minor.\r
+        /// </summary>\r
+        public string VersionMinor { get; set; }\r
+    }\r
+}\r
index e133492fff3b57f6e248ab25738c17fee3db02bb..8d93668bf1e4302e08fffdf5864c101d4608f917 100644 (file)
@@ -263,7 +263,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories
         {\r
             Video video = new Video();\r
 \r
-            HBVideoEncoder videoEncoder = HandBrakeEncoderHelpers.VideoEncoders.FirstOrDefault(e => e.ShortName == ApplicationServices.Utilities.Converters.GetVideoEncoder(job.VideoEncoder));\r
+            HBVideoEncoder videoEncoder = HandBrakeEncoderHelpers.VideoEncoders.FirstOrDefault(e => e.ShortName == EnumHelper<VideoEncoder>.GetShortName(job.VideoEncoder));\r
             Validate.NotNull(videoEncoder, "Video encoder " + job.VideoEncoder + " not recognized.");\r
             if (videoEncoder != null)\r
             {\r
@@ -336,7 +336,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories
             audio.AudioList = new List<Interop.Json.Encode.AudioTrack>();\r
             foreach (AudioTrack item in job.AudioTracks)\r
             {\r
-                HBAudioEncoder encoder = HandBrakeEncoderHelpers.GetAudioEncoder(ApplicationServices.Utilities.Converters.GetCliAudioEncoder(item.Encoder));\r
+                HBAudioEncoder encoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper<AudioEncoder>.GetShortName(item.Encoder));\r
                 Validate.NotNull(encoder, "Unrecognized audio encoder:" + item.Encoder);\r
 \r
                 HBMixdown mixdown = HandBrakeEncoderHelpers.GetMixdown(EnumHelper<Mixdown>.GetShortName(item.MixDown));\r
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs b/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs
deleted file mode 100644 (file)
index dd38fb2..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------\r
-// <copyright file="Converters.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 class to convert various things to native C# objects\r
-// </summary>\r
-// --------------------------------------------------------------------------------------------------------------------\r
-\r
-namespace HandBrake.ApplicationServices.Utilities\r
-{\r
-    using System;\r
-\r
-    using HandBrake.ApplicationServices.Interop.Model.Encoding;\r
-    using HandBrake.ApplicationServices.Services.Encode.Model.Models;\r
-\r
-    /// <summary>\r
-    /// A class to convert various things to native C# objects\r
-    /// </summary>\r
-    public class Converters\r
-    {\r
-        /**\r
-         * TODO:\r
-         * - Many of these converters can be ditched at a later point. Should be able to model all this within the enums themsevles.\r
-         * \r
-         **/\r
-\r
-        #region Audio\r
-\r
-        /// <summary>\r
-        /// Get the GUI equiv to a CLI mixdown\r
-        /// </summary>\r
-        /// <param name="mixdown">\r
-        /// The Audio Mixdown\r
-        /// </param>\r
-        /// <returns>\r
-        /// The GUI representation of the mixdown\r
-        /// </returns>\r
-        [Obsolete("Use EnumHelper instead")]\r
-        public static Mixdown GetAudioMixDown(string mixdown)\r
-        {\r
-            switch (mixdown.Trim())\r
-            {\r
-                case "Mono":\r
-                    return Mixdown.Mono;\r
-                case "Stereo":\r
-                    return Mixdown.Stereo;\r
-                case "Dolby Surround":\r
-                    return Mixdown.DolbySurround;\r
-                case "Dolby Pro Logic II":\r
-                    return Mixdown.DolbyProLogicII;\r
-                case "5.1 Channels":\r
-                    return Mixdown.FivePoint1Channels;\r
-                case "6.1 Channels":\r
-                    return Mixdown.SixPoint1Channels;\r
-                case "7.1 Channels":\r
-                    return Mixdown.SevenPoint1Channels;\r
-                case "7.1 (5F/2R/LFE)":\r
-                    return Mixdown.Five_2_LFE;\r
-                case "None":\r
-                case "Passthru":\r
-                    return Mixdown.None;\r
-                default:\r
-                    return Mixdown.Auto;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Get the GUI equiv to a GUI audio encoder string\r
-        /// </summary>\r
-        /// <param name="audioEnc">\r
-        /// The Audio Encoder\r
-        /// </param>\r
-        /// <returns>\r
-        /// The GUI representation of that audio encoder\r
-        /// </returns>\r
-        [Obsolete("Use EnumHelper instead")]\r
-        public static AudioEncoder GetAudioEncoder(string audioEnc)\r
-        {\r
-            switch (audioEnc)\r
-            {\r
-                case "AAC (faac)":         \r
-                case "AAC (ffmpeg)":\r
-                case "AAC (avcodec)":\r
-                    return AudioEncoder.ffaac;\r
-                case "AAC (FDK)":\r
-                case "AAC (CoreAudio)":\r
-                    return AudioEncoder.fdkaac;\r
-                case "HE-AAC (FDK)":\r
-                case "HE-AAC (CoreAudio)":\r
-                case "HE-AAC":\r
-                    return AudioEncoder.fdkheaac;\r
-                case "MP3 (lame)":\r
-                case "MP3":\r
-                    return AudioEncoder.Lame;\r
-                case "Vorbis (vorbis)":\r
-                case "Vorbis":\r
-                    return AudioEncoder.Vorbis;\r
-                case "AC3 (ffmpeg)":\r
-                case "AC3":\r
-                    return AudioEncoder.Ac3;\r
-                case "AC3 Passthru":\r
-                    return AudioEncoder.Ac3Passthrough;\r
-                case "DTS Passthru":\r
-                    return AudioEncoder.DtsPassthrough;\r
-                case "DTS-HD Passthru":\r
-                    return AudioEncoder.DtsHDPassthrough;\r
-                case "AAC Passthru":\r
-                    return AudioEncoder.AacPassthru;\r
-                case "MP3 Passthru":\r
-                    return AudioEncoder.Mp3Passthru;\r
-                case "FLAC (ffmpeg)":\r
-                case "FLAC 16-bit":\r
-                    return AudioEncoder.ffflac;\r
-                case "FLAC (24-bit)":\r
-                case "FLAC 24-bit":\r
-                    return AudioEncoder.ffflac24;\r
-                case "TrueHD Passthru":\r
-                    return AudioEncoder.TrueHDPassthrough;\r
-                case "E-AC3 Passthru":\r
-                    return AudioEncoder.EAc3Passthrough;\r
-                case "FLAC Passthru":\r
-                    return AudioEncoder.FlacPassthru;\r
-                case "Auto Passthru":\r
-                    return AudioEncoder.Passthrough;\r
-                default:\r
-                    return AudioEncoder.ffaac;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Get the CLI Audio Encoder name\r
-        /// </summary>\r
-        /// <param name="selectedEncoder">\r
-        /// String The GUI Encode name\r
-        /// </param>\r
-        /// <returns>\r
-        /// String CLI encoder name\r
-        /// </returns>\r
-        public static string GetCliAudioEncoder(AudioEncoder selectedEncoder)\r
-        {\r
-            return EnumHelper<AudioEncoder>.GetShortName(selectedEncoder);\r
-        }\r
-\r
-        #endregion\r
-\r
-        #region Video\r
-\r
-        /// <summary>\r
-        /// Get the Video Encoder for a given string\r
-        /// </summary>\r
-        /// <param name="encoder">\r
-        /// The encoder name\r
-        /// </param>\r
-        /// <returns>\r
-        /// VideoEncoder enum object\r
-        /// </returns>\r
-        public static string GetVideoEncoder(VideoEncoder encoder)\r
-        {\r
-            switch (encoder)\r
-            {\r
-                case VideoEncoder.FFMpeg:\r
-                    return "mpeg4";\r
-                case VideoEncoder.FFMpeg2:\r
-                    return "mpeg2";\r
-                case VideoEncoder.X264:\r
-                    return "x264";\r
-                case VideoEncoder.QuickSync:\r
-                    return "qsv_h264";\r
-                case VideoEncoder.Theora:\r
-                    return "theora";\r
-                case VideoEncoder.X265:\r
-                    return "x265";\r
-                case VideoEncoder.VP8:\r
-                    return "VP8";\r
-                default:\r
-                    return "x264";\r
-            }\r
-        }\r
-\r
-        #endregion\r
-\r
-        #region File Format\r
-\r
-        /// <summary>\r
-        /// Get the OutputFormat Enum for a given string\r
-        /// </summary>\r
-        /// <param name="format">\r
-        /// OutputFormat as a string\r
-        /// </param>\r
-        /// <returns>\r
-        /// An OutputFormat Enum\r
-        /// </returns>\r
-        public static OutputFormat GetFileFormat(string format)\r
-        {\r
-            switch (format.ToLower())\r
-            {\r
-                default:\r
-                    return OutputFormat.Mp4;\r
-                case "m4v":\r
-                    return OutputFormat.Mp4;\r
-                case "mkv":\r
-                    return OutputFormat.Mkv;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Get the OutputFormat Enum for a given string\r
-        /// </summary>\r
-        /// <param name="format">\r
-        /// OutputFormat as a string\r
-        /// </param>\r
-        /// <returns>\r
-        /// An OutputFormat Enum\r
-        /// </returns>\r
-        public static string GetFileFormat(OutputFormat format)\r
-        {\r
-            switch (format)\r
-            {\r
-                default:\r
-                    return "mp4";\r
-                case OutputFormat.Mp4:\r
-                    return "m4v";\r
-                case OutputFormat.Mkv:\r
-                    return "mkv";\r
-            }\r
-        }\r
-\r
-        #endregion\r
-    }\r
-}\r
index 87a26cadec5656d945ba464105ce99bc9983b955..c7ebecb48f36419b7832538b91672046c4fd096b 100644 (file)
       <DesignTime>True</DesignTime>\r
     </Compile>\r
     <Compile Include="Services\Presets\Factories\JsonPresetFactory.cs" />\r
+    <Compile Include="Services\Presets\Factories\PlistFactory.cs" />\r
     <Compile Include="Services\Queue\Interfaces\IQueueProcessor.cs" />\r
-    <Compile Include="Services\Presets\Factories\PlistPresetFactory.cs" />\r
     <Compile Include="Helpers\FileHelper.cs" />\r
     <Compile Include="Services\Presets\Model\Preset.cs" />\r
     <Compile Include="Model\ScanMode.cs" />\r
     <Compile Include="Utilities\DPIAwareness.cs" />\r
     <Compile Include="Utilities\DriveUtilities.cs" />\r
     <Compile Include="Utilities\HandBrakeApp.cs" />\r
-    <Compile Include="Services\Presets\Factories\PlistFactory.cs" />\r
-    <Compile Include="Utilities\PList.cs" />\r
     <Compile Include="Utilities\Win7.cs" />\r
     <Compile Include="ViewModels\CountdownAlertViewModel.cs" />\r
     <Compile Include="ViewModels\Interfaces\ICountdownAlertViewModel.cs" />\r
index 82c5eb32979b718ccce61f920c1d4a2142b13663..a95c9b1eafd6f015a5dad0b7c8c6a4b4eabfb3c0 100644 (file)
@@ -46,7 +46,7 @@ namespace HandBrakeWPF.Services.Presets.Factories
             preset.Name = importedPreset.PresetName;\r
             preset.Description = importedPreset.PresetDescription;\r
             preset.UsePictureFilters = importedPreset.UsesPictureFilters;\r
-            preset.UseDeinterlace = importedPreset.PictureDecombDeinterlace;\r
+            preset.UseDeinterlace = !importedPreset.PictureDecombDeinterlace;\r
             preset.Task = new EncodeTask();\r
 \r
             // Step 1, Create the EncodeTask Object that can be loaded into the UI.\r
index eb38c62adea2c7b829e1c364c6307806264d6f81..d50f23be978ba11cf6f871339f07beb560961815 100644 (file)
@@ -95,25 +95,6 @@ namespace HandBrakeWPF.Services.Presets.Factories
             xmlWriter.WriteEndElement();\r
         }\r
 \r
-        /// <summary>\r
-        /// The get null bool value.\r
-        /// </summary>\r
-        /// <param name="value">\r
-        /// The value.\r
-        /// </param>\r
-        /// <returns>\r
-        /// The System.String.\r
-        /// </returns>\r
-        private static string getNullBoolValue(bool? value)\r
-        {\r
-            if (!value.HasValue)\r
-            {\r
-                return "1";\r
-            }\r
-\r
-            return value.Value ? "1" : "0";\r
-        }\r
-\r
         /// <summary>\r
         /// Add the encode settings to the preset\r
         /// </summary>\r
diff --git a/win/CS/HandBrakeWPF/Services/Presets/Factories/PlistPresetFactory.cs b/win/CS/HandBrakeWPF/Services/Presets/Factories/PlistPresetFactory.cs
deleted file mode 100644 (file)
index d58e111..0000000
+++ /dev/null
@@ -1,440 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------\r
-// <copyright file="PlistPresetFactory.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 Factory to translate a Plist object into a Preset.\r
-// </summary>\r
-// --------------------------------------------------------------------------------------------------------------------\r
-\r
-namespace HandBrakeWPF.Services.Presets.Factories\r
-{\r
-    using System.Collections.Generic;\r
-    using System.Collections.ObjectModel;\r
-    using System.ComponentModel;\r
-    using System.Globalization;\r
-    using System.Linq;\r
-\r
-    using HandBrake.ApplicationServices.Services.Encode.Model;\r
-    using HandBrake.ApplicationServices.Services.Encode.Model.Models;\r
-    using HandBrake.ApplicationServices.Services.Encode.Model.Models.Video;\r
-    using HandBrake.ApplicationServices.Utilities;\r
-    using HandBrake.ApplicationServices.Interop.Model.Encoding;\r
-\r
-    using HandBrakeWPF.Model.Audio;\r
-    using HandBrakeWPF.Model.Subtitles;\r
-    using HandBrakeWPF.Services.Presets;\r
-    using HandBrakeWPF.Services.Presets.Model;\r
-    using HandBrakeWPF.Utilities;\r
-\r
-    using PresetPictureSettingsMode = HandBrakeWPF.Model.Picture.PresetPictureSettingsMode;\r
-\r
-    /// <summary>\r
-    /// A Factory to translate a Plist object into a Preset.\r
-    /// </summary>\r
-    public class PlistPresetFactory\r
-    {\r
-        /// <summary>\r
-        /// The lang list.\r
-        /// </summary>\r
-        private static IDictionary<string, string> langList;\r
-\r
-        /// <summary>\r
-        /// Initializes static members of the <see cref="PlistPresetFactory"/> class. \r
-        /// </summary>\r
-        static PlistPresetFactory()\r
-        {\r
-            IDictionary<string, string> langMap = LanguageUtilities.MapLanguages();\r
-            langList = (from entry in langMap select entry).ToDictionary(pair => pair.Value, pair => pair.Key);\r
-        }\r
-\r
-        /// <summary>\r
-        /// The create preset.\r
-        /// </summary>\r
-        /// <param name="plist">\r
-        /// The plist.\r
-        /// </param>\r
-        /// <returns>\r
-        /// The <see cref="Preset"/>.\r
-        /// </returns>\r
-        public static Preset CreatePreset(PList plist)\r
-        {\r
-            Preset preset = new Preset\r
-                                {\r
-                                    Task = new EncodeTask(),\r
-                                    Category = PresetService.UserPresetCatgoryName,\r
-                                    AudioTrackBehaviours = new AudioBehaviours(),\r
-                                    SubtitleTrackBehaviours = new SubtitleBehaviours()\r
-                                };\r
-\r
-            // Parse the settings out.\r
-            foreach (var item in plist)\r
-            {\r
-                if (item.Key == "AudioList")\r
-                {\r
-                    List<AudioTrack> tracks = ParseAudioTracks(item.Value);\r
-                    preset.Task.AudioTracks = new ObservableCollection<AudioTrack>(tracks);\r
-                }\r
-                else\r
-                {\r
-                    ParseSetting(item, preset);\r
-                }\r
-            }\r
-\r
-            // Handle the PictureDecombDeinterlace key\r
-            if (preset.UseDeinterlace)\r
-            {\r
-                preset.Task.Decomb = Decomb.Off;\r
-                preset.Task.CustomDecomb = string.Empty;\r
-            }\r
-\r
-            // Depending on the selected preset options, we may need to change some settings around.\r
-            // If the user chose not to use fitlers, remove them.\r
-            if (!preset.UsePictureFilters)\r
-            {\r
-                preset.Task.Detelecine = Detelecine.Off;\r
-                preset.Task.Denoise = Denoise.Off;\r
-                preset.Task.Deinterlace = Deinterlace.Off;\r
-                preset.Task.Decomb = Decomb.Off;\r
-                preset.Task.Deblock = 0;\r
-                preset.Task.Grayscale = false;\r
-            }\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
-            return preset;\r
-        }\r
-\r
-        /// <summary>\r
-        /// Parse a setting and set it in the given preset.\r
-        /// </summary>\r
-        /// <param name="kvp">\r
-        /// The kvp setting pair.\r
-        /// </param>\r
-        /// <param name="preset">\r
-        /// The preset object.\r
-        /// </param>\r
-        private static void ParseSetting(KeyValuePair<string, dynamic> kvp, Preset preset)\r
-        {\r
-            switch (kvp.Key)\r
-            {\r
-                // Output Settings\r
-                case "FileFormat":\r
-                    preset.Task.OutputFormat = Converters.GetFileFormat(kvp.Value.Replace("file", string.Empty).Trim());\r
-                    break;\r
-                case "Mp4HttpOptimize":\r
-                    preset.Task.OptimizeMP4 = kvp.Value == 1;\r
-                    break;\r
-                case "Mp4iPodCompatible":\r
-                    preset.Task.IPod5GSupport = kvp.Value == 1;\r
-                    break;\r
-\r
-                // Picture Settings\r
-                case "PictureAutoCrop":\r
-                    preset.Task.HasCropping = kvp.Value != 1;\r
-                    break;\r
-                case "PictureTopCrop":\r
-                    preset.Task.Cropping.Top = kvp.Value;\r
-                    break;\r
-                case "PictureBottomCrop":\r
-                    preset.Task.Cropping.Bottom = kvp.Value;\r
-                    break;\r
-                case "PictureLeftCrop":\r
-                    preset.Task.Cropping.Left = kvp.Value;\r
-                    break;\r
-                case "PictureRightCrop":\r
-                    preset.Task.Cropping.Right = kvp.Value;\r
-                    break;\r
-                case "PictureHeight":\r
-                    preset.Task.Height = kvp.Value == null || kvp.Value == 0 ? null : kvp.Value;\r
-                    break;\r
-                case "PictureWidth":\r
-                    preset.Task.Width = kvp.Value == null || kvp.Value == 0 ? null : kvp.Value;\r
-                    break;\r
-                case "PictureKeepRatio":\r
-                    preset.Task.KeepDisplayAspect = kvp.Value == 1;\r
-                    break;\r
-                case "PicturePAR":\r
-                    preset.Task.Anamorphic = (Anamorphic)kvp.Value;\r
-                    break;\r
-                case "PictureModulus":\r
-                    preset.Task.Modulus = kvp.Value;\r
-                    break;\r
-\r
-                // Filters\r
-                case "PictureDeblock":\r
-                    preset.Task.Deblock = kvp.Value;\r
-                    break;\r
-                case "PictureDecomb":\r
-                    preset.Task.Decomb = (Decomb)kvp.Value;\r
-                    break;\r
-                case "PictureDecombCustom":\r
-                    preset.Task.CustomDecomb = kvp.Value;\r
-                    break;\r
-                case "PictureDecombDeinterlace":\r
-                    preset.UseDeinterlace = kvp.Value == true;\r
-                    break;\r
-                case "PictureDeinterlace":\r
-                    preset.Task.Deinterlace = (Deinterlace)kvp.Value;\r
-                    break;\r
-                case "PictureDeinterlaceCustom":\r
-                    preset.Task.CustomDeinterlace = kvp.Value;\r
-                    break;\r
-                case "PictureDenoise":\r
-                    preset.Task.Denoise = (Denoise)kvp.Value;\r
-                    break;\r
-                case "DenoisePreset":\r
-                    preset.Task.DenoisePreset = (DenoisePreset)kvp.Value; // TODO to be confirmed.\r
-                    break;\r
-                case "DenoiseTune":\r
-                    preset.Task.DenoiseTune = (DenoiseTune)kvp.Value; // TODO to be confirmed.\r
-                    break;\r
-                case "PictureDenoiseCustom":\r
-                    preset.Task.CustomDenoise = kvp.Value;\r
-                    break;\r
-                case "PictureDetelecine":\r
-                    preset.Task.Detelecine = (Detelecine)kvp.Value;\r
-                    break;\r
-                case "PictureDetelecineCustom":\r
-                    preset.Task.CustomDetelecine = kvp.Value;\r
-                    break;\r
-\r
-                // Video Tab\r
-                case "VideoAvgBitrate":\r
-                    if (!string.IsNullOrEmpty(kvp.Value))\r
-                    {\r
-                        preset.Task.VideoBitrate = int.Parse(kvp.Value);\r
-                    }\r
-                    break;\r
-                case "VideoEncoder":\r
-                    preset.Task.VideoEncoder = EnumHelper<VideoEncoder>.GetValue(kvp.Value);\r
-                    break;\r
-                case "VideoFramerate":\r
-                    preset.Task.Framerate = kvp.Value == "Same as source" || string.IsNullOrEmpty(kvp.Value) ? null : double.Parse(kvp.Value, CultureInfo.InvariantCulture);\r
-                    break;\r
-                case "VideoFramerateMode":\r
-                    string parsedValue = kvp.Value;\r
-                    switch (parsedValue)\r
-                    {\r
-                        case "vfr":\r
-                            preset.Task.FramerateMode = FramerateMode.VFR;\r
-                            break;\r
-                        case "cfr":\r
-                            preset.Task.FramerateMode = FramerateMode.CFR;\r
-                            break;\r
-                        default:\r
-                            preset.Task.FramerateMode = FramerateMode.PFR;\r
-                            break;\r
-                    }\r
-                    break;\r
-                case "VideoGrayScale":\r
-                    preset.Task.Grayscale = kvp.Value == true;\r
-                    break;\r
-                case "VideoQualitySlider":\r
-                    preset.Task.Quality = double.Parse(kvp.Value.ToString(), CultureInfo.InvariantCulture);\r
-                    break;\r
-                case "VideoQualityType": // The Type of Quality Mode used\r
-                    preset.Task.VideoEncodeRateType = (VideoEncodeRateType)kvp.Value;\r
-                    break;\r
-                case "VideoTurboTwoPass":\r
-                    preset.Task.TurboFirstPass = kvp.Value == 1;\r
-                    break;\r
-                case "VideoTwoPass":\r
-                    preset.Task.TwoPass = kvp.Value == 1;\r
-                    break;\r
-\r
-                case "VideoOptionExtra":\r
-                    preset.Task.ExtraAdvancedArguments = kvp.Value;\r
-                    break;\r
-                case "VideoLevel":\r
-                    preset.Task.VideoLevel = new VideoLevel(kvp.Value, kvp.Value);\r
-                    break;\r
-                case "VideoProfile":\r
-                    preset.Task.VideoProfile = new VideoProfile(kvp.Value, kvp.Value);\r
-                    break;\r
-                case "VideoPreset":\r
-                    preset.Task.VideoPreset = new VideoPreset(kvp.Value, kvp.Value);\r
-                    break;\r
-                case "VideoTune":\r
-                    string[] split = kvp.Value.ToString().Split(',');\r
-                    foreach (var item in split)\r
-                    {\r
-                        preset.Task.VideoTunes.Add(new VideoTune(item, item));\r
-                    }\r
-                    break;\r
-\r
-                // Chapter Markers Tab\r
-                case "ChapterMarkers":\r
-                    preset.Task.IncludeChapterMarkers = kvp.Value == true;\r
-                    break;\r
-\r
-                // Advanced tab\r
-                case "x264Option":\r
-                case "lavcOption":\r
-                    preset.Task.AdvancedEncoderOptions = kvp.Value;\r
-                    break;\r
-\r
-                // Preset Information\r
-                case "PresetBuildNumber":\r
-                    preset.Version = kvp.Value;\r
-                    break;\r
-                case "PresetDescription":\r
-                    preset.Description = kvp.Value;\r
-                    break;\r
-                case "PresetName":\r
-                    preset.Name = kvp.Value;\r
-                    break;\r
-                case "Type":\r
-                    // preset.Task.Type = kvp.Value; // TODO find out what this is\r
-                    break;\r
-                case "UsesMaxPictureSettings":\r
-                    // TODO Not sure if this is used now!?\r
-                    break;\r
-                case "UsesPictureFilters":\r
-                    preset.UsePictureFilters = kvp.Value == 1;\r
-                    break;\r
-                case "UsesPictureSettings":\r
-                    preset.PictureSettingsMode = (PresetPictureSettingsMode)kvp.Value;\r
-                    break;\r
-\r
-                // Allowed Passthru\r
-                case "AudioAllowAACPass":\r
-                    preset.Task.AllowedPassthruOptions.AudioAllowAACPass = kvp.Value == true;\r
-                    break;\r
-                case "AudioAllowAC3Pass":\r
-                    preset.Task.AllowedPassthruOptions.AudioAllowAC3Pass = kvp.Value == true;\r
-                    break;\r
-                case "AudioAllowDTSHDPass":\r
-                    preset.Task.AllowedPassthruOptions.AudioAllowDTSHDPass = kvp.Value == true;\r
-                    break;\r
-                case "AudioAllowDTSPass":\r
-                    preset.Task.AllowedPassthruOptions.AudioAllowDTSPass = kvp.Value == true;\r
-                    break;\r
-                case "AudioAllowMP3Pass":\r
-                    preset.Task.AllowedPassthruOptions.AudioAllowMP3Pass = kvp.Value == true;\r
-                    break;\r
-                case "AudioEncoderFallback":\r
-                    preset.Task.AllowedPassthruOptions.AudioEncoderFallback = EnumHelper<AudioEncoder>.GetValue(kvp.Value);\r
-                    break;\r
-\r
-                // Audio Defaults\r
-                case "AudioLanguageList":\r
-                    preset.AudioTrackBehaviours.SelectedLangauges = new BindingList<string>(ParseLangaugeCodeList(kvp.Value));\r
-                    break;\r
-                case "AudioSecondaryEncoderMode":\r
-                    break;\r
-                case "AudioTrackSelectionBehavior":\r
-                    preset.AudioTrackBehaviours.SelectedBehaviour = kvp.Value == "all"\r
-                                                                        ? AudioBehaviourModes.AllMatching\r
-                                                                        : kvp.Value == "first"\r
-                                                                              ? AudioBehaviourModes.FirstMatch\r
-                                                                              : AudioBehaviourModes.None;\r
-                    break;\r
-\r
-                // Subtitle Defaults\r
-                case "SubtitleAddForeignAudioSearch":\r
-                    preset.SubtitleTrackBehaviours.AddForeignAudioScanTrack = kvp.Value == true;\r
-                    break;\r
-                case "SubtitleAddCC":\r
-                    preset.SubtitleTrackBehaviours.AddClosedCaptions = kvp.Value == true;\r
-                    break;\r
-                case "SubtitleLanguageList":\r
-                    preset.SubtitleTrackBehaviours.SelectedLangauges = new BindingList<string>(ParseLangaugeCodeList(kvp.Value));\r
-                    break;\r
-                case "SubtitleTrackSelectionBehavior":\r
-                    preset.SubtitleTrackBehaviours.SelectedBehaviour = kvp.Value == "all"\r
-                                                                     ? SubtitleBehaviourModes.AllMatching\r
-                                                                     : kvp.Value == "first"\r
-                                                                           ? SubtitleBehaviourModes.FirstMatch\r
-                                                                           : SubtitleBehaviourModes.None;\r
-                    break;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Parse a number of audio tracks\r
-        /// </summary>\r
-        /// <param name="audioList">\r
-        /// The audio list.\r
-        /// </param>\r
-        /// <returns>\r
-        /// The <see cref="List"/> of audio tracks\r
-        /// </returns>\r
-        private static List<AudioTrack> ParseAudioTracks(IEnumerable<dynamic> audioList)\r
-        {\r
-            return audioList.Select(item => ParseAudioTrackParameters(item)).Cast<AudioTrack>().ToList();\r
-        }\r
-\r
-        /// <summary>\r
-        /// The parse langauge code list.\r
-        /// </summary>\r
-        /// <param name="languages">\r
-        /// The languages.\r
-        /// </param>\r
-        /// <returns>\r
-        /// The <see cref="IEnumerable"/>.\r
-        /// </returns>\r
-        private static IEnumerable<string> ParseLangaugeCodeList(IEnumerable<object> languages)\r
-        {\r
-            List<string> languageCodesList = new List<string>();\r
-            foreach (var item in languages)\r
-            {\r
-                string language;\r
-                if (langList.TryGetValue(item.ToString(), out language))\r
-                {\r
-                    languageCodesList.Add(language);\r
-                }            \r
-            }\r
-\r
-            return languageCodesList;\r
-        }\r
-\r
-        /// <summary>\r
-        /// Parse an audio track's parameters.\r
-        /// </summary>\r
-        /// <param name="audioTrack">\r
-        /// The audio track params\r
-        /// </param>\r
-        /// <returns>\r
-        /// An <see cref="AudioTrack"/> Object\r
-        /// </returns>\r
-        private static AudioTrack ParseAudioTrackParameters(Dictionary<string, dynamic> audioTrack)\r
-        {\r
-            AudioTrack track = new AudioTrack();\r
-            foreach (var item in audioTrack)\r
-            {\r
-                switch (item.Key)\r
-                {\r
-                    case "AudioBitrate":\r
-                        track.Bitrate = int.Parse(item.Value);\r
-                        break;\r
-                    case "AudioEncoder":\r
-                        track.Encoder = Converters.GetAudioEncoder(item.Value.Trim());\r
-                        break;\r
-                    case "AudioMixdown":\r
-                        track.MixDown = Converters.GetAudioMixDown(item.Value.Trim());\r
-                        break;\r
-                    case "AudioSamplerate":\r
-                        track.SampleRate = item.Value == "Auto" ? 0 : double.Parse(item.Value);\r
-                        break;\r
-                    case "AudioTrack":\r
-                        // track.SourceTrack = value; We don't do anything with this one.\r
-                        break;\r
-                    case "AudioTrackDRCSlider":\r
-                        track.DRC = item.Value;\r
-                        break;\r
-                    case "AudioTrackGainSlider":\r
-                        track.Gain = (int)item.Value;\r
-                        break;\r
-                }\r
-            }\r
-\r
-            return track;\r
-        }\r
-    }\r
-}\r
index 9035eae70616606bdb5143175d989fdc8e750879..de76a1af3993bfbbcdf2f5b7c4d43405f38a35ef 100644 (file)
@@ -45,6 +45,14 @@ namespace HandBrakeWPF.Services.Presets.Interfaces
         /// </returns>\r
         bool Add(Preset preset);\r
 \r
+        /// <summary>\r
+        /// The import.\r
+        /// </summary>\r
+        /// <param name="filename">\r
+        /// The filename.\r
+        /// </param>\r
+        void Import(string filename);\r
+\r
         /// <summary>\r
         /// Update a preset\r
         /// </summary>\r
index ec009835886e2923300bcd698652f9f2eed0df9d..c6e3c3e4b00a9543f47d69938e68ba72cd9b4e39 100644 (file)
@@ -21,9 +21,14 @@ namespace HandBrakeWPF.Services.Presets
     using HandBrake.ApplicationServices.Exceptions;\r
     using HandBrake.ApplicationServices.Interop;\r
     using HandBrake.ApplicationServices.Interop.Json.Presets;\r
+    using HandBrake.ApplicationServices.Interop.Model.Encoding;\r
     using HandBrake.ApplicationServices.Services.Encode.Model.Models;\r
     using HandBrake.ApplicationServices.Utilities;\r
 \r
+    using HandBrakeWPF.Model.Audio;\r
+    using HandBrakeWPF.Model.Picture;\r
+    using HandBrakeWPF.Model.Subtitles;\r
+    using HandBrakeWPF.Properties;\r
     using HandBrakeWPF.Services.Interfaces;\r
     using HandBrakeWPF.Services.Presets.Factories;\r
     using HandBrakeWPF.Services.Presets.Interfaces;\r
@@ -161,6 +166,95 @@ namespace HandBrakeWPF.Services.Presets
             return true;\r
         }\r
 \r
+        /// <summary>\r
+        /// The import.\r
+        /// </summary>\r
+        /// <param name="filename">\r
+        /// The filename.\r
+        /// </param>\r
+        public void Import(string filename)\r
+        {\r
+            // TODO needs a tidy up but will do for now.\r
+            if (!string.IsNullOrEmpty(filename))\r
+            {\r
+                PresetTransportContainer container = HandBrakePresetService.GetPresetFromFile(filename);\r
+\r
+                if (container == null || container.PresetList == null || container.PresetList.Count == 0)\r
+                {\r
+                    this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, string.Empty);\r
+                    return;\r
+                }\r
+\r
+                HBPreset hbPreset = container.PresetList.FirstOrDefault();\r
+\r
+                Preset preset = null;\r
+                try\r
+                {\r
+                    preset = JsonPresetFactory.ImportPreset(hbPreset);\r
+                    preset.Category = UserPresetCatgoryName;\r
+                    preset.AudioTrackBehaviours = new AudioBehaviours();\r
+                    preset.SubtitleTrackBehaviours = new SubtitleBehaviours();\r
+\r
+                    // Handle the PictureDecombDeinterlace key\r
+                    if (preset.UseDeinterlace)\r
+                    {\r
+                        preset.Task.Decomb = Decomb.Off;\r
+                        preset.Task.CustomDecomb = string.Empty;\r
+                    }\r
+\r
+                    // Depending on the selected preset options, we may need to change some settings around.\r
+                    // If the user chose not to use fitlers, remove them.\r
+                    if (!preset.UsePictureFilters)\r
+                    {\r
+                        preset.Task.Detelecine = Detelecine.Off;\r
+                        preset.Task.Denoise = Denoise.Off;\r
+                        preset.Task.Deinterlace = Deinterlace.Off;\r
+                        preset.Task.Decomb = Decomb.Off;\r
+                        preset.Task.Deblock = 0;\r
+                        preset.Task.Grayscale = false;\r
+                    }\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
+                catch (Exception exc)\r
+                {\r
+                    this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, exc);\r
+                }\r
+\r
+                if (preset == null)\r
+                {\r
+                    this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, string.Empty);\r
+                    return;\r
+                }\r
+\r
+                // TODO Better version checking.\r
+                \r
+                if (this.CheckIfPresetExists(preset.Name))\r
+                {\r
+                    if (!CanUpdatePreset(preset.Name))\r
+                    {\r
+                        MessageBox.Show(Resources.Main_PresetErrorBuiltInName, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
+                        return;\r
+                    }\r
+\r
+                    MessageBoxResult result = MessageBox.Show(Resources.Main_PresetOverwriteWarning, Resources.Overwrite, MessageBoxButton.YesNo, MessageBoxImage.Warning);\r
+                    if (result == MessageBoxResult.Yes)\r
+                    {\r
+                        Update(preset);\r
+                    }\r
+                }\r
+                else\r
+                {\r
+                    Add(preset);\r
+                }\r
+            }\r
+        }\r
+\r
         /// <summary>\r
         /// Update a preset\r
         /// </summary>\r
diff --git a/win/CS/HandBrakeWPF/Utilities/PList.cs b/win/CS/HandBrakeWPF/Utilities/PList.cs
deleted file mode 100644 (file)
index 1e3c30e..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------\r
-// <copyright file="PList.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 Helper class to parse plist files.\r
-// </summary>\r
-// --------------------------------------------------------------------------------------------------------------------\r
-\r
-namespace HandBrakeWPF.Utilities\r
-{\r
-    using System;\r
-    using System.Collections.Generic;\r
-    using System.Linq;\r
-    using System.Xml.Linq;\r
-\r
-    /// <summary>\r
-    /// A Helper class to parse plist files.\r
-    /// </summary>\r
-    public class PList : Dictionary<string, dynamic>\r
-    {\r
-        #region Constructors and Destructors\r
-\r
-        /// <summary>\r
-        /// Initializes a new instance of the <see cref="PList"/> class.\r
-        /// </summary>\r
-        public PList()\r
-        {\r
-        }\r
-\r
-        /// <summary>\r
-        /// Initializes a new instance of the <see cref="PList"/> class.\r
-        /// </summary>\r
-        /// <param name="file">\r
-        /// The file.\r
-        /// </param>\r
-        public PList(string file)\r
-        {\r
-            this.Load(file);\r
-        }\r
-\r
-        #endregion\r
-\r
-        #region Public Methods\r
-\r
-        /// <summary>\r
-        /// Load a plist file.\r
-        /// </summary>\r
-        /// <param name="file">\r
-        /// The file name / path\r
-        /// </param>\r
-        /// <returns>\r
-        /// True if successful, false otherwise.\r
-        /// </returns>\r
-        public bool Load(string file)\r
-        {\r
-            this.Clear();\r
-\r
-            XDocument doc = XDocument.Load(file);\r
-            XElement plist = doc.Element("plist");\r
-            if (plist != null)\r
-            {\r
-                XElement array = plist.Element("array");\r
-                if (array != null)\r
-                {\r
-                    XElement dict = array.Element("dict");\r
-\r
-                    if (dict != null)\r
-                    {\r
-                        IEnumerable<XElement> dictElements = dict.Elements();\r
-                        this.Parse(this, dictElements);\r
-                        return true;\r
-                    }\r
-                }\r
-            }\r
-\r
-            return false;\r
-        }\r
-\r
-        #endregion\r
-\r
-        #region Methods\r
-\r
-        /// <summary>\r
-        /// Parse a list of elements\r
-        /// </summary>\r
-        /// <param name="dict">\r
-        /// The dict.\r
-        /// </param>\r
-        /// <param name="elements">\r
-        /// The elements.\r
-        /// </param>\r
-        private void Parse(PList dict, IEnumerable<XElement> elements)\r
-        {\r
-            for (int i = 0; i < elements.Count(); i += 2)\r
-            {\r
-                XElement key = elements.ElementAt(i);\r
-                XElement val = elements.ElementAt(i + 1);\r
-\r
-                dict[key.Value] = this.ParseValue(val);\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// The parse array.\r
-        /// </summary>\r
-        /// <param name="elements">\r
-        /// The elements.\r
-        /// </param>\r
-        /// <returns>\r
-        /// The <see cref="List"/>.\r
-        /// </returns>\r
-        private List<dynamic> ParseArray(IEnumerable<XElement> elements)\r
-        {\r
-            return elements.Select(e => this.ParseValue(e)).ToList();\r
-        }\r
-\r
-        /// <summary>\r
-        /// The parse value.\r
-        /// </summary>\r
-        /// <param name="val">\r
-        /// The XElement.\r
-        /// </param>\r
-        /// <returns>\r
-        /// The parsed value object.\r
-        /// </returns>\r
-        private dynamic ParseValue(XElement val)\r
-        {\r
-            switch (val.Name.ToString())\r
-            {\r
-                case "string":\r
-                    return val.Value;\r
-                case "integer":\r
-                    return int.Parse(val.Value);\r
-                case "real":\r
-                    return float.Parse(val.Value);\r
-                case "true":\r
-                    return true;\r
-                case "false":\r
-                    return false;\r
-                case "dict":\r
-                    var plist = new PList();\r
-                    this.Parse(plist, val.Elements());\r
-                    return plist;\r
-                case "array":\r
-                    List<dynamic> list = this.ParseArray(val.Elements());\r
-                    return list;\r
-                default:\r
-                    throw new ArgumentException("This plist file is not supported.");\r
-            }\r
-        }\r
-\r
-        #endregion\r
-    }\r
-}
\ No newline at end of file
index f995b4d2ef6d5b928fbea3ef4b0452e1227a3146..60b0c74a51d0abe8c3937fb953d1f65696e1078d 100644 (file)
@@ -30,6 +30,7 @@ namespace HandBrakeWPF.ViewModels
     using HandBrake.ApplicationServices.Services.Scan.Model;\r
     using HandBrake.ApplicationServices.Utilities;\r
     using HandBrake.ApplicationServices.Interop;\r
+    using HandBrake.ApplicationServices.Interop.Json.Presets;\r
 \r
     using HandBrakeWPF.Commands;\r
     using HandBrakeWPF.EventArgs;\r
@@ -1813,74 +1814,10 @@ namespace HandBrakeWPF.ViewModels
         /// </summary>\r
         public void PresetImport()\r
         {\r
-            OpenFileDialog dialog = new OpenFileDialog() { Filter = "Plist (*.plist)|*.plist", CheckFileExists = true };\r
+            OpenFileDialog dialog = new OpenFileDialog { Filter = "Preset Files|*.json;*.plist", CheckFileExists = true };\r
             dialog.ShowDialog();\r
-            string filename = dialog.FileName;\r
-\r
-            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 != HandBrakeUtils.Build.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 = null;\r
-                try\r
-                {\r
-                    preset = PlistPresetFactory.CreatePreset(plist);\r
-                }\r
-                catch (Exception exc)\r
-                {\r
-                    this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, exc);\r
-                }\r
-\r
-                if (preset != null)\r
-                {\r
-                    if (this.presetService.CheckIfPresetExists(preset.Name))\r
-                    {\r
-                        if (!presetService.CanUpdatePreset(preset.Name))\r
-                        {\r
-                            MessageBox.Show(Resources.Main_PresetErrorBuiltInName, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
-                            return;\r
-                        }\r
-\r
-                        MessageBoxResult result = MessageBox.Show(Resources.Main_PresetOverwriteWarning, Resources.Overwrite, MessageBoxButton.YesNo, MessageBoxImage.Warning);\r
-                        if (result == MessageBoxResult.Yes)\r
-                        {\r
-                            presetService.Update(preset);\r
-                        }\r
-                    }\r
-                    else\r
-                    {\r
-                        presetService.Add(preset);\r
-                    }\r
-                }\r
-\r
-                this.NotifyOfPropertyChange(() => this.Presets);\r
-            }\r
+            this.presetService.Import(dialog.FileName);\r
+            this.NotifyOfPropertyChange(() => this.Presets);\r
         }\r
 \r
         /// <summary>\r