]> granicus.if.org Git - handbrake/commitdiff
WinGui: Initial work to overhaul the plist import code.
authorsr55 <sr55.hb@outlook.com>
Sat, 27 Oct 2012 19:54:23 +0000 (19:54 +0000)
committersr55 <sr55.hb@outlook.com>
Sat, 27 Oct 2012 19:54:23 +0000 (19:54 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5039 b64f7644-9d1e-0410-96f1-a4d463321fa5

14 files changed:
win/CS/HandBrake.ApplicationServices/Factories/PlistPresetFactory.cs [new file with mode: 0644]
win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
win/CS/HandBrake.ApplicationServices/Model/Preset.cs
win/CS/HandBrake.ApplicationServices/Model/PresetPictureSettingsMode.cs
win/CS/HandBrake.ApplicationServices/Utilities/PList.cs [new file with mode: 0644]
win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Anamorphic.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Decomb.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Deinterlace.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Denoise.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Detelecine.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/VideoEncodeRateType.cs
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
win/CS/HandBrakeWPF/Views/MainView.xaml

diff --git a/win/CS/HandBrake.ApplicationServices/Factories/PlistPresetFactory.cs b/win/CS/HandBrake.ApplicationServices/Factories/PlistPresetFactory.cs
new file mode 100644 (file)
index 0000000..f07f0aa
--- /dev/null
@@ -0,0 +1,336 @@
+// --------------------------------------------------------------------------------------------------------------------\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 HandBrake.ApplicationServices.Factories\r
+{\r
+    using System.Collections.Generic;\r
+    using System.Collections.ObjectModel;\r
+    using System.Globalization;\r
+    using System.Linq;\r
+\r
+    using HandBrake.ApplicationServices.Model;\r
+    using HandBrake.ApplicationServices.Model.Encoding;\r
+    using HandBrake.ApplicationServices.Services;\r
+    using HandBrake.ApplicationServices.Utilities;\r
+    using HandBrake.Interop.Model.Encoding;\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 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 { Task = new EncodeTask(), Category = PresetService.UserPresetCatgoryName };\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
+\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 "Mp4LargeFile":\r
+                    preset.Task.LargeFile = 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;\r
+                    break;\r
+                case "PictureWidth":\r
+                    preset.Task.Width = 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
+\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 == 1;\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 "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
+                    preset.Task.VideoBitrate = int.Parse(kvp.Value);\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" ? 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 == 1;\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
+                // Chapter Markers Tab\r
+                case "ChapterMarkers":\r
+                    preset.Task.IncludeChapterMarkers = kvp.Value == 1;\r
+                    break;\r
+\r
+                // Advanced x264 tab\r
+                case "x264Option":\r
+                    if (preset.Task.VideoEncoder == VideoEncoder.X264) // TODO Temp fix until a better solution is found.\r
+                    {\r
+                        preset.Task.AdvancedEncoderOptions = kvp.Value;\r
+                    }\r
+                    break;\r
+\r
+                case "lavcOption":\r
+                    if (preset.Task.VideoEncoder != VideoEncoder.X264) // TODO Temp fix until a better solution is found.\r
+                    {\r
+                        preset.Task.AdvancedEncoderOptions = kvp.Value;\r
+                    }\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 == 1;\r
+                    break;\r
+                case "AudioAllowAC3Pass":\r
+                    preset.Task.AllowedPassthruOptions.AudioAllowAC3Pass = kvp.Value == 1;\r
+                    break;\r
+                case "AudioAllowDTSHDPass":\r
+                    preset.Task.AllowedPassthruOptions.AudioAllowDTSHDPass = kvp.Value == 1;\r
+                    break;\r
+                case "AudioAllowDTSPass":\r
+                    preset.Task.AllowedPassthruOptions.AudioAllowDTSPass = kvp.Value == 1;\r
+                    break;\r
+                case "AudioAllowMP3Pass":\r
+                    preset.Task.AllowedPassthruOptions.AudioAllowMP3Pass = kvp.Value == 1;\r
+                    break;\r
+                case "AudioEncoderFallback":\r
+                    preset.Task.AllowedPassthruOptions.AudioEncoderFallback = EnumHelper<AudioEncoder>.GetValue(kvp.Value);\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
+        /// 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, CultureInfo.InvariantCulture);\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 = double.Parse(item.Value.ToString(), CultureInfo.InvariantCulture);\r
+                        break;\r
+                    case "AudioTrackGainSlider":\r
+                        track.Gain = int.Parse(item.Value.ToString(), CultureInfo.InvariantCulture);\r
+                        break;\r
+                }\r
+            }\r
+\r
+            return track;\r
+        }\r
+    }\r
+}\r
index af024c7e81f2f8b8b86c06425ddfdbf215a841d0..6730e2d6696e7212bb792b0ba941d09aef16a50e 100644 (file)
@@ -57,6 +57,7 @@
       <SpecificVersion>False</SpecificVersion>\r
       <HintPath>..\libraries\caliburn\Castle.Windsor.dll</HintPath>\r
     </Reference>\r
+    <Reference Include="Microsoft.CSharp" />\r
     <Reference Include="PresentationCore" />\r
     <Reference Include="PresentationFramework" />\r
     <Reference Include="System" />\r
@@ -89,6 +90,7 @@
     <Compile Include="EventArgs\ScanCompletedEventArgs.cs" />\r
     <Compile Include="EventArgs\ScanProgressEventArgs.cs" />\r
     <Compile Include="Extensions\StringExtensions.cs" />\r
+    <Compile Include="Factories\PlistPresetFactory.cs" />\r
     <Compile Include="Isolation\BackgroundServiceConnector.cs" />\r
     <Compile Include="Isolation\IsolatedEncodeService.cs" />\r
     <Compile Include="Isolation\IsolatedScanService.cs" />\r
     <Compile Include="Utilities\Converters.cs" />\r
     <Compile Include="Utilities\EnumHelper.cs" />\r
     <Compile Include="Utilities\InteropModelCreator.cs" />\r
+    <Compile Include="Utilities\PList.cs" />\r
+    <Compile Include="Utilities\PlistUtility.cs" />\r
     <Compile Include="Utilities\SystemInfo.cs" />\r
     <Compile Include="Utilities\Win32.cs" />\r
     <Compile Include="Utilities\Win7.cs" />\r
     <Compile Include="Utilities\CharCodesUtilities.cs" />\r
     <Compile Include="Utilities\GeneralUtilities.cs" />\r
     <Compile Include="Utilities\LanguageUtilities.cs" />\r
-    <Compile Include="Utilities\PlistUtility.cs" />\r
     <Compile Include="Utilities\QueryGeneratorUtility.cs" />\r
     <Compile Include="Utilities\QueryParserUtility.cs" />\r
   </ItemGroup>\r
index 128bf5c219cc7ba74f331270f15b4836c6238053..7003ca2c7abffb076701321fea631e2ea53d2bbb 100644 (file)
@@ -69,6 +69,11 @@ namespace HandBrake.ApplicationServices.Model
         /// </summary>\r
         public PresetPictureSettingsMode PictureSettingsMode { get; set; }\r
 \r
+        /// <summary>\r
+        /// Gets or sets a value indicating whether use deinterlace.\r
+        /// </summary>\r
+        public bool UseDeinterlace { get; set; }\r
+\r
         /// <summary>\r
         /// Gets or sets task.\r
         /// </summary>\r
index a79f4b0e3a2d72ec7201be359facce45527dc925..e670ccb7e17eee88216b2c3b64d8ba7364bc0b71 100644 (file)
@@ -17,10 +17,10 @@ namespace HandBrake.ApplicationServices.Model
     public enum PresetPictureSettingsMode\r
     {\r
         [Display(Name = "None")]\r
-        None,\r
+        None = 0,\r
         [Display(Name = "Custom")]\r
-        Custom,\r
+        Custom = 1,\r
         [Display(Name = "Source Maximum")]\r
-        SourceMaximum,\r
+        SourceMaximum = 2,\r
     }\r
 }
\ No newline at end of file
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/PList.cs b/win/CS/HandBrake.ApplicationServices/Utilities/PList.cs
new file mode 100644 (file)
index 0000000..48212b5
--- /dev/null
@@ -0,0 +1,156 @@
+// --------------------------------------------------------------------------------------------------------------------\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 HandBrake.ApplicationServices.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
+\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 797c456f38b0bb2fbd5b38771089749b5e58dc88..bea765e2759a309be4eb1d28fe08c888c3d1413e 100644 (file)
@@ -9,16 +9,11 @@
 \r
 namespace HandBrake.ApplicationServices.Utilities\r
 {\r
-    using System;\r
-    using System.Collections.ObjectModel;\r
-    using System.IO;\r
     using System.Text;\r
-    using System.Windows.Forms;\r
     using System.Xml;\r
 \r
     using HandBrake.ApplicationServices.Model;\r
     using HandBrake.ApplicationServices.Model.Encoding;\r
-    using HandBrake.ApplicationServices.Services;\r
     using HandBrake.Interop.Model.Encoding;\r
 \r
     /// <summary>\r
@@ -26,451 +21,6 @@ namespace HandBrake.ApplicationServices.Utilities
     /// </summary>\r
     public class PlistUtility\r
     {\r
-        #region Import\r
-\r
-        /// <summary>\r
-        /// Import a Plist Preset\r
-        /// </summary>\r
-        /// <param name="filename">\r
-        /// The filename.\r
-        /// </param>\r
-        /// <returns>\r
-        /// A Preset Object\r
-        /// </returns>\r
-        public static Preset Import(string filename)\r
-        {\r
-            Preset preset = new Preset();\r
-\r
-            XmlNode root = loadFile(filename);\r
-            if (root == null) return null;\r
-\r
-            // We'll query a query parser object and use it's public var structures to store all the data.\r
-            // This will allow the preset loader logic to be used instead of writing custom logic just for this file.\r
-            EncodeTask parsed = new EncodeTask();\r
-            bool useFilters = false;\r
-            PresetPictureSettingsMode pictureSettingsMode = PresetPictureSettingsMode.None;\r
-            string qualityMode = string.Empty;\r
-\r
-            #region Get a List of Audio Track Objects\r
-\r
-            // This is the main <dict> with all the values\r
-            XmlNode mainDict = root.ChildNodes[2].ChildNodes[0].FirstChild;\r
-            XmlNode audioListDict = null;\r
-            ObservableCollection<AudioTrack> audioTracks = new ObservableCollection<AudioTrack>();\r
-\r
-            // Look for the AudioList key\r
-            bool found = false;\r
-            foreach (XmlNode node in mainDict.ChildNodes)\r
-            {\r
-                if (found)\r
-                {\r
-                    audioListDict = node;\r
-                    break;\r
-                }\r
-\r
-                if (node.InnerText == "AudioList")\r
-                {\r
-                    found = true; // We want the next node, as it is the value object.\r
-                }\r
-            }\r
-\r
-            for (int i = 0; i < audioListDict.ChildNodes.Count; i++)\r
-            {\r
-                XmlNode audioChannel = audioListDict.ChildNodes[i];\r
-                AudioTrack track = new AudioTrack();\r
-\r
-                for (int subi = 0; subi < audioChannel.ChildNodes.Count; subi += 2)\r
-                {\r
-                    // Audio Channel Information is here.\r
-                    string key = audioChannel.ChildNodes[subi].InnerText;\r
-                    string value = audioChannel.ChildNodes[subi + 1].InnerText;\r
-                    switch (key)\r
-                    {\r
-                        case "AudioBitrate":\r
-                            track.Bitrate = int.Parse(value);\r
-                            break;\r
-                        case "AudioEncoder":\r
-                            track.Encoder = Converters.GetAudioEncoder(value.Trim());\r
-                            break;\r
-                        case "AudioMixdown":\r
-                            track.MixDown = Converters.GetAudioMixDown(value.Trim());\r
-                            break;\r
-                        case "AudioSamplerate":\r
-                            track.SampleRate = value == "Auto" ? 0 : double.Parse(value);\r
-                            break;\r
-                        case "AudioTrack":\r
-                            //track.SourceTrack = value;\r
-                            break;\r
-                        case "AudioTrackDRCSlider":\r
-                            track.DRC = double.Parse(value);\r
-                            break;\r
-                        case "AudioTrackGainSlider":\r
-                            track.Gain = int.Parse(value.Replace("0.0", "0"));\r
-                            break;\r
-                    }\r
-                }\r
-                audioTracks.Add(track);\r
-                parsed.AudioTracks = audioTracks;\r
-            }\r
-            #endregion\r
-\r
-            #region Parse the reset of the plist keys into local variables\r
-\r
-            XmlNode presetSettings = root.ChildNodes[2].ChildNodes[0].FirstChild;\r
-\r
-            // Start from 2 to avoid the audio settings which we don't need.\r
-            for (int i = 0; i < presetSettings.ChildNodes.Count; i += 2)\r
-            {\r
-                string key = presetSettings.ChildNodes[i].InnerText;\r
-                string value = presetSettings.ChildNodes[i + 1].InnerText;\r
-\r
-                switch (key)\r
-                {\r
-                    // Output Settings\r
-                    case "FileFormat":\r
-                        parsed.OutputFormat = Converters.GetFileFormat(value.Replace("file", string.Empty).Trim());\r
-                        break;\r
-                    case "Mp4HttpOptimize":\r
-                        parsed.OptimizeMP4 = value == "1";\r
-                        break;\r
-                    case "Mp4LargeFile":\r
-                        parsed.LargeFile = value == "1";\r
-                        break;\r
-                    case "Mp4iPodCompatible":\r
-                        parsed.IPod5GSupport = value == "1";\r
-                        break;\r
-\r
-                    // Picture Settings\r
-                    case "PictureAutoCrop":\r
-                        parsed.HasCropping = value != "1";\r
-                        break;\r
-                    case "PictureTopCrop":\r
-                        parsed.Cropping.Top = int.Parse(value);\r
-                        break;\r
-                    case "PictureBottomCrop":\r
-                        parsed.Cropping.Bottom = int.Parse(value);\r
-                        break;\r
-                    case "PictureLeftCrop":\r
-                        parsed.Cropping.Left = int.Parse(value);\r
-                        break;\r
-                    case "PictureRightCrop":\r
-                        parsed.Cropping.Right = int.Parse(value);\r
-                        break;\r
-                    case "PictureHeight":\r
-                        parsed.Height = int.Parse(value);\r
-                        break;\r
-                    case "PictureWidth":\r
-                        parsed.Width = int.Parse(value);\r
-                        break;\r
-                    case "PictureKeepRatio":\r
-                        parsed.KeepDisplayAspect = value == "1";\r
-                        break;\r
-                    case "PicturePAR":\r
-                        switch (value)\r
-                        {\r
-                            case "0":\r
-                                parsed.Anamorphic = Anamorphic.None;\r
-                                break;\r
-                            default:\r
-                                parsed.Anamorphic = Anamorphic.Strict;\r
-                                break;\r
-                            case "2":\r
-                                parsed.Anamorphic = Anamorphic.Loose;\r
-                                break;\r
-                            case "3":\r
-                                parsed.Anamorphic = Anamorphic.Custom;\r
-                                break;\r
-                        }\r
-                        break;\r
-\r
-                    // Filters\r
-                    case "PictureDeblock":\r
-                        parsed.Deblock = int.Parse(value);\r
-                        break;\r
-                    case "PictureDecomb":\r
-                        parsed.Decomb = Decomb.Off;\r
-                        switch (value)\r
-                        {\r
-                            case "1":\r
-                                parsed.Decomb = Decomb.Custom;\r
-                                break;\r
-                            case "2":\r
-                                parsed.Decomb = Decomb.Default;\r
-                                break;\r
-                            case "3":\r
-                                parsed.Decomb = Decomb.Fast;\r
-                                break;\r
-                        }\r
-                        break;\r
-                    case "PictureDecombCustom":\r
-                        if (value != string.Empty)\r
-                        {\r
-                            parsed.CustomDecomb = value;\r
-                        }\r
-                        break;\r
-                    case "PictureDecombDeinterlace":\r
-                        // Not Used\r
-                        break;\r
-                    case "PictureDeinterlace":\r
-                        switch (value)\r
-                        {\r
-                            case "0":\r
-                                parsed.Deinterlace = Deinterlace.Off;\r
-                                break;\r
-                            case "1":\r
-                                parsed.Deinterlace = Deinterlace.Custom;\r
-                                break;\r
-                            case "2":\r
-                                parsed.Deinterlace = Deinterlace.Fast;\r
-                                break;\r
-                            case "3":\r
-                                parsed.Deinterlace = Deinterlace.Slow;\r
-                                break;\r
-                            case "4":\r
-                                parsed.Deinterlace = Deinterlace.Slower;\r
-                                break;\r
-                        }\r
-                        break;\r
-                    case "PictureDeinterlaceCustom":\r
-                        if (value != string.Empty)\r
-                        {\r
-                            parsed.CustomDeinterlace = value;\r
-                        }\r
-                        break;\r
-                    case "PictureDenoise":\r
-                        switch (value)\r
-                        {\r
-                            case "0":\r
-                                parsed.Denoise = Denoise.Off;\r
-                                break;\r
-                            case "1":\r
-                                parsed.Denoise = Denoise.Custom;\r
-                                break;\r
-                            case "2":\r
-                                parsed.Denoise = Denoise.Weak;\r
-                                break;\r
-                            case "3":\r
-                                parsed.Denoise = Denoise.Medium;\r
-                                break;\r
-                            case "4":\r
-                                parsed.Denoise = Denoise.Strong;\r
-                                break;\r
-                        }\r
-\r
-                        break;\r
-                    case "PictureDenoiseCustom":\r
-                        if (value != string.Empty)\r
-                        {\r
-                            parsed.CustomDenoise = value;\r
-                        }\r
-                        break;\r
-                    case "PictureDetelecine":\r
-                        parsed.Detelecine = Detelecine.Off;\r
-                        if (value == "1")\r
-                        {\r
-                            parsed.Detelecine = Detelecine.Custom;\r
-                        }\r
-                        if (value == "2")\r
-                        {\r
-                            parsed.Detelecine = Detelecine.Default;\r
-                        }\r
-                        break;\r
-                    case "PictureDetelecineCustom":\r
-                        if (value != string.Empty)\r
-                        {\r
-                            parsed.CustomDetelecine = value;\r
-                        }\r
-                        break;\r
-\r
-                    // Video Tab\r
-                    case "VideoAvgBitrate":\r
-                        if (!string.IsNullOrEmpty(value))\r
-                        {\r
-                            parsed.VideoBitrate = int.Parse(value);\r
-                        }\r
-                        break;\r
-                    case "VideoEncoder":\r
-                        parsed.VideoEncoder = EnumHelper<VideoEncoder>.GetValue(value);\r
-                        break;\r
-                    case "VideoFramerate":\r
-\r
-                        if (value == "Same as source")\r
-                        {\r
-                            parsed.Framerate = null;\r
-                        }\r
-                        else if (!string.IsNullOrEmpty(value))\r
-                        {\r
-                            parsed.Framerate = double.Parse(value);\r
-                        }\r
-                        break;\r
-                    case "VideoFramerateMode":\r
-                        switch (value)\r
-                        {\r
-                            case "vfr":\r
-                                parsed.FramerateMode = FramerateMode.VFR;\r
-                                break;\r
-                            case "cfr":\r
-                                parsed.FramerateMode = FramerateMode.CFR;\r
-                                break;\r
-                            default:\r
-                                parsed.FramerateMode = FramerateMode.PFR;\r
-                                break;\r
-                        }\r
-                        break;\r
-                    case "VideoGrayScale":\r
-                        parsed.Grayscale = value == "1";\r
-                        break;\r
-                    case "VideoQualitySlider":\r
-                        if (!string.IsNullOrEmpty(value))\r
-                        {\r
-                            parsed.Quality = double.Parse(value);\r
-                        }\r
-                        break;\r
-                    case "VideoQualityType": // The Type of Quality Mode used\r
-                        qualityMode = value;\r
-                        break;\r
-                    case "VideoTurboTwoPass":\r
-                        parsed.TurboFirstPass = value == "1";\r
-                        break;\r
-                    case "VideoTwoPass":\r
-                        parsed.TwoPass = value == "1";\r
-                        break;\r
-\r
-                    // Chapter Markers Tab\r
-                    case "ChapterMarkers":\r
-                        parsed.IncludeChapterMarkers = value == "1";\r
-                        break;\r
-\r
-                    // Advanced x264 tab\r
-                    case "x264Option":\r
-                        parsed.AdvancedEncoderOptions = value;\r
-                        break;\r
-\r
-                    // Preset Information\r
-                    case "PresetBuildNumber":\r
-                        preset.Version = value;\r
-                        break;\r
-                    case "PresetDescription":\r
-                        preset.Description = value;\r
-                        break;\r
-                    case "PresetName":\r
-                        preset.Name = value;\r
-                        break;\r
-                    case "Type":\r
-                        //parsed.Type = value; // TODO find out what this is\r
-                        break;\r
-                    case "UsesMaxPictureSettings":\r
-                        pictureSettingsMode = PresetPictureSettingsMode.SourceMaximum;\r
-                        break;\r
-                    case "UsesPictureFilters":\r
-                        useFilters = value == "1";\r
-                        break;\r
-                    case "UsesPictureSettings":\r
-                        pictureSettingsMode = PresetPictureSettingsMode.Custom;\r
-                        break;\r
-\r
-                    // Allowed Passthru\r
-                    case "AudioAllowAACPass":\r
-                        parsed.AllowedPassthruOptions.AudioAllowAACPass = value == "1";\r
-                        break;\r
-                    case "AudioAllowAC3Pass":\r
-                        parsed.AllowedPassthruOptions.AudioAllowAC3Pass = value == "1";\r
-                        break;\r
-                    case "AudioAllowDTSHDPass":\r
-                        parsed.AllowedPassthruOptions.AudioAllowDTSHDPass = value == "1";\r
-                        break;\r
-                    case "AudioAllowDTSPass":\r
-                        parsed.AllowedPassthruOptions.AudioAllowDTSPass = value == "1";\r
-                        break;\r
-                    case "AudioAllowMP3Pass":\r
-                        parsed.AllowedPassthruOptions.AudioAllowMP3Pass = value == "1";\r
-                        break;\r
-                    case "AudioEncoderFallback":\r
-                        parsed.AllowedPassthruOptions.AudioEncoderFallback = EnumHelper<AudioEncoder>.GetValue(value);\r
-                        break;\r
-                }\r
-            }\r
-\r
-            // Kill any Quality values we don't need.\r
-            switch (qualityMode)\r
-            {\r
-                case "1": // Avg Bitrate\r
-                    parsed.VideoEncodeRateType = VideoEncodeRateType.AverageBitrate;\r
-                    break;\r
-                case "2": // CQ\r
-                    parsed.VideoEncodeRateType = VideoEncodeRateType.ConstantQuality;\r
-                    break;\r
-            }\r
-\r
-            // Default filters if we have to\r
-            if (!useFilters)\r
-            {\r
-                parsed.Detelecine = Detelecine.Off;\r
-                parsed.Denoise = Denoise.Off;\r
-                parsed.Deinterlace = Deinterlace.Off;\r
-                parsed.Decomb = Decomb.Off;\r
-                parsed.Deblock = 0;\r
-                parsed.Grayscale = false;\r
-            }\r
-\r
-            if (pictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)\r
-            {\r
-                parsed.MaxWidth = parsed.Height;\r
-                parsed.MaxHeight = parsed.Width;\r
-            }\r
-            #endregion\r
-\r
-\r
-            preset.Task = parsed;\r
-            preset.PictureSettingsMode = pictureSettingsMode;\r
-            preset.UsePictureFilters = useFilters;\r
-            preset.Category = PresetService.UserPresetCatgoryName;\r
-\r
-            return preset;\r
-        }\r
-\r
-        private static XmlNode loadFile(string filename)\r
-        {\r
-            try\r
-            {\r
-                XmlNode root;\r
-\r
-                if (!File.Exists(filename))\r
-                    return null;\r
-\r
-                string fromfile = string.Empty;\r
-                using (StreamReader sr = File.OpenText(filename))\r
-                {\r
-                    int fileChar;\r
-                    while ((fileChar = sr.Read()) != -1) fromfile += Convert.ToChar(fileChar);\r
-                }\r
-\r
-                XmlDocument doc = new XmlDocument();\r
-                doc.LoadXml(fromfile);\r
-\r
-                root = doc;\r
-                if (!root.HasChildNodes)\r
-                {\r
-                    MessageBox.Show(\r
-                        "The Preset file you selected appears to be invlaid or from an older version of HandBrake",\r
-                        "Error",\r
-                        MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-                    return null;\r
-                }\r
-\r
-                return root;\r
-            }\r
-            catch (Exception)\r
-            {\r
-                MessageBox.Show(\r
-                    "The Preset file you selected appears to be invlaid or from an older version of HandBrake.\n\n Please note, if you are exporting from the MacGui you may need to rebuild your preset so that it uses the current preset plist format.\n The MacGui does not currently update user presets automatically.",\r
-                    "Error",\r
-                    MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-                return null;\r
-            }\r
-        }\r
-        #endregion\r
-\r
         #region Export\r
 \r
         /// <summary>\r
index 2d20c437604b94299ff74aca92da6b99a26b94bb..0c798457bb52d6022fa4bca4f2f4f4647d65cb95 100644 (file)
@@ -16,10 +16,10 @@ namespace HandBrake.Interop.Model.Encoding
                [Display(Name = "None")]\r
                None = 0,\r
                [Display(Name = "Strict")]\r
-               Strict,\r
+               Strict = 1,\r
                [Display(Name = "Loose")]\r
-               Loose,\r
+               Loose = 2,\r
                [Display(Name = "Custom")]\r
-               Custom\r
+               Custom = 3\r
        }\r
 }\r
index 7b03410d002f5f73bf21b87d85a0fb6845bf6e93..a376ef893d0e119b5be9dd177df18ae088747a78 100644 (file)
@@ -12,9 +12,9 @@ namespace HandBrake.Interop.Model.Encoding
        public enum Decomb\r
        {\r
                Off = 0,\r
-               Default,\r
-               Fast,\r
-               Bob,\r
-               Custom\r
+               Default = 2,\r
+               Fast = 3,\r
+               Bob = 4,\r
+               Custom = 1\r
        }\r
 }\r
index 91d8285763349011b0963899a44645bf87bd165d..8e16435acfe53b525d249f69ffa187bf7f017a77 100644 (file)
@@ -9,13 +9,16 @@
 \r
 namespace HandBrake.Interop.Model.Encoding\r
 {\r
-       public enum Deinterlace\r
+    /// <summary>\r
+    /// The deinterlace.\r
+    /// </summary>\r
+    public enum Deinterlace\r
        {\r
                Off = 0,\r
-               Fast,\r
-               Slow,\r
-               Slower,\r
-               Bob,\r
-               Custom\r
+               Fast = 2,\r
+               Slow = 3,\r
+               Slower = 4,\r
+               Bob = 5,\r
+               Custom = 1\r
        }\r
 }\r
index 74c53e039aa963e9052449e01f21f338649a6847..ec64d9e7513df752e867ed952f1304a8c6870950 100644 (file)
@@ -12,9 +12,9 @@ namespace HandBrake.Interop.Model.Encoding
        public enum Denoise\r
        {\r
                Off = 0,\r
-               Weak,\r
-               Medium,\r
-               Strong,\r
-               Custom\r
+               Weak = 2,\r
+               Medium = 3,\r
+               Strong = 4,\r
+               Custom = 1\r
        }\r
 }\r
index 189b7441ff7ceb6a3d54607048789384e5c2f5db..af793097347f607fa226ca7f363fcefce8ad87dd 100644 (file)
@@ -12,7 +12,7 @@ namespace HandBrake.Interop.Model.Encoding
        public enum Detelecine\r
        {\r
                Off = 0,\r
-               Default,\r
-               Custom\r
+               Default = 2,\r
+               Custom = 1\r
        }\r
 }\r
index b3374de36065710db5df7d43ca33b13acd5ac421..7bf052efb6add8d9a6712c53afd9b9f4062bba2d 100644 (file)
@@ -12,7 +12,7 @@ namespace HandBrake.Interop.Model.Encoding
        public enum VideoEncodeRateType\r
        {\r
                TargetSize = 0,\r
-               AverageBitrate,\r
-               ConstantQuality\r
+               AverageBitrate = 1,\r
+               ConstantQuality = 2\r
        }\r
 }\r
index 934a0b18d80de9dae89e41309eecd1da2b80ff5b..b0ae80f934d3ebe8f4f0e0113f91ffec97b240e4 100644 (file)
@@ -22,6 +22,7 @@ namespace HandBrakeWPF.ViewModels
     using Caliburn.Micro;\r
 \r
     using HandBrake.ApplicationServices;\r
+    using HandBrake.ApplicationServices.Factories;\r
     using HandBrake.ApplicationServices.Model;\r
     using HandBrake.ApplicationServices.Model.Encoding;\r
     using HandBrake.ApplicationServices.Parsing;\r
@@ -1353,7 +1354,9 @@ namespace HandBrakeWPF.ViewModels
 \r
             if (!string.IsNullOrEmpty(filename))\r
             {\r
-                Preset preset = PlistUtility.Import(filename);\r
+                PList plist = new PList(filename);\r
+                Preset preset = PlistPresetFactory.CreatePreset(plist);\r
+\r
                 if (this.presetService.CheckIfPresetExists(preset.Name))\r
                 {\r
                     if (!presetService.CanUpdatePreset(preset.Name))\r
index c051786af28cc606d018b764bace7826a2039ef4..77e76845cc34c76222e1b340bb80d0552dec2cb2 100644 (file)
                 <MenuItem Header="Debug" Visibility="{Binding ShowDebugMenu, Converter={StaticResource boolToVisConverter}}" >\r
                     <MenuItem Header="Show CLI Equiv" Micro:Message.Attach="[Event Click] = [Action ShowCliQuery]" />\r
                     <MenuItem Header="Debug Scan Log" Micro:Message.Attach="[Event Click] = [Action DebugScanLog]" />\r
+                    <MenuItem Header="Debug Plist" Micro:Message.Attach="[Event Click] = [Action DebugPlist]" />\r
                 </MenuItem>\r
             </Menu>\r
 \r