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