diff options
author | sr55 <[email protected]> | 2017-06-07 20:31:46 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2017-06-07 20:31:46 +0100 |
commit | e2632a1177355ad0d502c06c288bdad4e01c0b35 (patch) | |
tree | 91c2a577f8e7e0e8d87bbd4ebb77f360aa2985bd /win | |
parent | 8750a04ef458722e8c4c9b3a3af3ddfec9835619 (diff) |
WinGui: Support importing preset categories that can be exported from the MacGUI. Also fix a few minor bugs in the preset factory.
Diffstat (limited to 'win')
5 files changed, 75 insertions, 38 deletions
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 @@ -32,6 +32,11 @@ namespace HandBrake.ApplicationServices.Interop.Json.Presets public string PresetName { get; set; }
/// <summary>
+ /// Description for the preset group.
+ /// </summary>
+ public string PresetDescription { get; set; }
+
+ /// <summary>
/// Gets or sets the type.
/// </summary>
public int Type { get; set; }
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 { }
/// <summary>
- /// 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?.
/// </summary>
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: <value>You can not import a preset with the same name as a built-in preset.</value>
</data>
<data name="Main_PresetOverwriteWarning" xml:space="preserve">
- <value>This preset appears to already exist. Would you like to overwrite it?</value>
+ <value>The preset "{0}" already exists. Would you like to overwrite it?</value>
</data>
<data name="Main_Presets" xml:space="preserve">
<value>Presets</value>
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<AudioEncoder>.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 /// </summary>
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<HBPreset>(objectPreset.ToString());
-
- Preset preset = null;
- try
+ PresetCategory category = JsonConvert.DeserializeObject<PresetCategory>(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<HBPreset>(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
}
}
|