summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Services/Presets
diff options
context:
space:
mode:
authorsr55 <[email protected]>2017-06-07 20:31:46 +0100
committersr55 <[email protected]>2017-06-07 20:31:46 +0100
commite2632a1177355ad0d502c06c288bdad4e01c0b35 (patch)
tree91c2a577f8e7e0e8d87bbd4ebb77f360aa2985bd /win/CS/HandBrakeWPF/Services/Presets
parent8750a04ef458722e8c4c9b3a3af3ddfec9835619 (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/CS/HandBrakeWPF/Services/Presets')
-rw-r--r--win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs5
-rw-r--r--win/CS/HandBrakeWPF/Services/Presets/PresetService.cs99
2 files changed, 68 insertions, 36 deletions
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
}
}