From: sr55 Date: Wed, 7 Jun 2017 19:31:46 +0000 (+0100) Subject: WinGui: Support importing preset categories that can be exported from the MacGUI... X-Git-Tag: 1.1.0~541 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e2632a1177355ad0d502c06c288bdad4e01c0b35;p=handbrake WinGui: Support importing preset categories that can be exported from the MacGUI. Also fix a few minor bugs in the preset factory. --- diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/PresetCategory.cs b/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/PresetCategory.cs index 799ea0876..182772106 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/PresetCategory.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/PresetCategory.cs @@ -31,6 +31,11 @@ namespace HandBrake.ApplicationServices.Interop.Json.Presets /// public string PresetName { get; set; } + /// + /// Description for the preset group. + /// + public string PresetDescription { get; set; } + /// /// Gets or sets the type. /// diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 13bc0a312..a2b1d136a 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -832,7 +832,7 @@ namespace HandBrakeWPF.Properties { } /// - /// Looks up a localized string similar to This preset appears to already exist. Would you like to overwrite it?. + /// Looks up a localized string similar to The preset "{0}" already exists. Would you like to overwrite it?. /// public static string Main_PresetOverwriteWarning { get { diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index dbd14c314..2e318f3cd 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -378,7 +378,7 @@ In order to use the QuickSync encoder, you must: You can not import a preset with the same name as a built-in preset. - This preset appears to already exist. Would you like to overwrite it? + The preset "{0}" already exists. Would you like to overwrite it? Presets diff --git a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs index 55eb3f1b9..9b252e030 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs @@ -429,6 +429,11 @@ namespace HandBrakeWPF.Services.Presets.Factories // track.CompressionLevel = audioTrack.AudioCompressionLevel; // track.AudioDitherMethod = audioTrack.AudioDitherMethod; + if (audioTrack.AudioEncoder == "ca_aac") + { + audioTrack.AudioEncoder = "av_aac"; // No Core Audio support on windows. + } + track.Encoder = EnumHelper.GetValue(audioTrack.AudioEncoder); track.MixDown = HandBrakeEncoderHelpers.GetMixdown(audioTrack.AudioMixdown); diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs index 61e051fcd..b581becb2 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs @@ -43,6 +43,8 @@ namespace HandBrakeWPF.Services.Presets /// public class PresetService : IPresetService { + // TODO Strip out the error handling from this service and let upstream UI layer handle it. + #region Private Variables public const int ForcePresetReset = 3; @@ -195,50 +197,30 @@ namespace HandBrakeWPF.Services.Presets { foreach (var objectPreset in container.PresetList) { - HBPreset hbPreset = JsonConvert.DeserializeObject(objectPreset.ToString()); - - Preset preset = null; - try + PresetCategory category = JsonConvert.DeserializeObject(objectPreset.ToString()); + if (category != null && category.ChildrenArray.Count > 0) { - preset = JsonPresetFactory.ImportPreset(hbPreset); - preset.Category = UserPresetCatgoryName; // TODO can we get this from the preset? - - // IF we are using Source Max, Set the Max Width / Height values. - if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum) + foreach (HBPreset hbPreset in category.ChildrenArray) { - preset.Task.MaxWidth = preset.Task.Height; - preset.Task.MaxHeight = preset.Task.Width; + Preset preset = this.ConvertHbPreset(hbPreset); + if (preset != null) + { + this.AddOrUpdateImportedPreset(preset); + } } } - 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; - } - - if (this.CheckIfPresetExists(preset.Name)) + else { - if (!this.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) + HBPreset hbPreset = JsonConvert.DeserializeObject(objectPreset.ToString()); + if (hbPreset != null) { - this.Update(preset); + Preset preset = this.ConvertHbPreset(hbPreset); + if (preset != null) + { + this.AddOrUpdateImportedPreset(preset); + } } } - else - { - this.Add(preset, false); - } } } } @@ -871,6 +853,51 @@ namespace HandBrakeWPF.Services.Presets } } + private Preset ConvertHbPreset(HBPreset hbPreset) + { + Preset preset = null; + + preset = JsonPresetFactory.ImportPreset(hbPreset); + preset.Category = UserPresetCatgoryName; // TODO can we get this from the preset? + + // 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; + } + + private void AddOrUpdateImportedPreset(Preset preset) + { + if (preset == null) + { + this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, string.Empty); + return; + } + + if (this.CheckIfPresetExists(preset.Name)) + { + if (!this.CanUpdatePreset(preset.Name)) + { + MessageBox.Show(Resources.Main_PresetErrorBuiltInName, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + + MessageBoxResult result = MessageBox.Show(string.Format(Resources.Main_PresetOverwriteWarning, preset.Name), Resources.Overwrite, MessageBoxButton.YesNo, MessageBoxImage.Warning); + if (result == MessageBoxResult.Yes) + { + this.Update(preset); + } + } + else + { + this.Add(preset, false); + } + } + #endregion } }