diff options
author | sr55 <[email protected]> | 2015-01-20 11:36:33 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2015-01-20 11:36:33 +0000 |
commit | 26e7efb9e7ab8a319a4912ae2287b69f02251006 (patch) | |
tree | f0663c1352e51282cd470d8f785895ac1f52f089 | |
parent | 7fda02b9bba6ca1f6858780e584d89ba72afe73f (diff) |
WinGui: Improve the preset load failure error message. Remove some duplicate keys in the encode task model. Change some of the preview properties to nullable.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6781 b64f7644-9d1e-0410-96f1-a4d463321fa5
5 files changed, 71 insertions, 57 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeService.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeService.cs index 2253d96e8..1aaa0d301 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeService.cs @@ -116,8 +116,8 @@ namespace HandBrake.ApplicationServices.Services.Encode ? QueryGeneratorUtility.GeneratePreviewQuery(
new EncodeTask(this.currentTask.Task),
encodeQueueTask.Configuration,
- this.currentTask.Task.PreviewEncodeDuration,
- this.currentTask.Task.PreviewEncodeStartAt)
+ this.currentTask.Task.PreviewEncodeDuration.HasValue ? this.currentTask.Task.PreviewEncodeDuration.Value : 0,
+ this.currentTask.Task.PreviewEncodeStartAt.HasValue ? this.currentTask.Task.PreviewEncodeStartAt.Value : 0)
: QueryGeneratorUtility.GenerateQuery(new EncodeTask(this.currentTask.Task), encodeQueueTask.Configuration);
ProcessStartInfo cliStart = new ProcessStartInfo(handbrakeCLIPath, query)
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/EncodeTask.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/EncodeTask.cs index 86b0d06ec..86735482a 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/EncodeTask.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/EncodeTask.cs @@ -146,9 +146,6 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model this.FastDecode = task.FastDecode;
this.ExtraAdvancedArguments = task.ExtraAdvancedArguments;
- this.PreviewStartAt = task.PreviewStartAt;
- this.PreviewDuration = task.PreviewDuration;
-
this.ShowAdvancedTab = task.ShowAdvancedTab;
this.X265Preset = task.X265Preset;
@@ -505,14 +502,19 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model #region Preview
/// <summary>
- /// Gets or sets StartAt.
+ /// Gets or sets a value indicating whether IsPreviewEncode.
/// </summary>
- public int? PreviewStartAt { get; set; }
+ public bool IsPreviewEncode { get; set; }
/// <summary>
- /// Gets or sets Duration.
+ /// Gets or sets PreviewEncodeDuration.
/// </summary>
- public int? PreviewDuration { get; set; }
+ public int? PreviewEncodeDuration { get; set; }
+
+ /// <summary>
+ /// Gets or sets PreviewEncodeStartAt.
+ /// </summary>
+ public int? PreviewEncodeStartAt { get; set; }
#endregion
@@ -543,21 +545,6 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model }
/// <summary>
- /// Gets or sets a value indicating whether IsPreviewEncode.
- /// </summary>
- public bool IsPreviewEncode { get; set; }
-
- /// <summary>
- /// Gets or sets PreviewEncodeDuration.
- /// </summary>
- public int PreviewEncodeDuration { get; set; }
-
- /// <summary>
- /// Gets or sets PreviewEncodeStartAt.
- /// </summary>
- public int PreviewEncodeStartAt { get; set; }
-
- /// <summary>
/// Gets or sets a value indicating whether advanced panel enabled.
/// </summary>
public bool ShowAdvancedTab
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs b/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs index 50388fc0d..37d9499cd 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs @@ -127,8 +127,8 @@ namespace HandBrake.ApplicationServices.Utilities if (work.PointToPointMode == PointToPointMode.Preview)
{
- job.StartAtPreview = work.PreviewStartAt.HasValue ? work.PreviewStartAt.Value : 1;
- job.SecondsEnd = work.PreviewDuration.HasValue ? work.PreviewEncodeDuration : 30;
+ job.StartAtPreview = work.PreviewEncodeStartAt.HasValue ? work.PreviewEncodeStartAt.Value : 1;
+ job.SecondsEnd = work.PreviewEncodeDuration.HasValue ? work.PreviewEncodeDuration.Value : 30;
job.SeekPoints = configuration.PreviewScanCount;
}
diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs index 2528679b6..be8357f68 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs @@ -17,6 +17,7 @@ namespace HandBrakeWPF.Services.Presets using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
+ using System.Windows;
using System.Windows.Forms;
using System.Xml.Serialization;
@@ -24,6 +25,7 @@ namespace HandBrakeWPF.Services.Presets using HandBrake.ApplicationServices.Services.Encode.Model.Models;
using HandBrake.ApplicationServices.Utilities;
+ using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Presets.Interfaces;
using HandBrakeWPF.Services.Presets.Model;
@@ -34,9 +36,6 @@ namespace HandBrakeWPF.Services.Presets /// </summary>
public class PresetService : IPresetService
{
-
- // TODO refactor filename
-
#region Private Variables
private static readonly int CurrentPresetVersion = 1;
@@ -61,7 +60,6 @@ namespace HandBrakeWPF.Services.Presets /// </summary>
private readonly string legacyUserPresetFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\user_presets.xml";
-
/// <summary>
/// The Built In Presets File
/// </summary>
@@ -72,9 +70,25 @@ namespace HandBrakeWPF.Services.Presets /// </summary>
private readonly ObservableCollection<Preset> presets = new ObservableCollection<Preset>();
+ /// <summary>
+ /// The Error Service.
+ /// </summary>
+ private readonly IErrorService errorService;
+
#endregion
/// <summary>
+ /// Initializes a new instance of the <see cref="PresetService"/> class.
+ /// </summary>
+ /// <param name="errorService">
+ /// The error service.
+ /// </param>
+ public PresetService(IErrorService errorService)
+ {
+ this.errorService = errorService;
+ }
+
+ /// <summary>
/// Gets a Collection of presets.
/// </summary>
public ObservableCollection<Preset> Presets
@@ -392,25 +406,32 @@ namespace HandBrakeWPF.Services.Presets /// <param name="file">
/// The broken presets file.
/// </param>
- private static void RecoverFromCorruptedPresetFile(string file)
+ /// <returns>
+ /// The <see cref="string"/>.
+ /// </returns>
+ private static string RecoverFromCorruptedPresetFile(string file)
{
try
{
// Recover from Error.
+ string disabledFile = string.Format("{0}.{1}", file, GeneralUtilities.ProcessId);
if (File.Exists(file))
{
- string disabledFile = string.Format("{0}.{1}", file, GeneralUtilities.ProcessId);
- File.Move(file, disabledFile);
+ File.Move(file, disabledFile);
if (File.Exists(file))
{
File.Delete(file);
}
}
+
+ return disabledFile;
}
catch (IOException)
{
// Give up
}
+
+ return "Sorry, the archiving failed.";
}
/// <summary>
@@ -477,40 +498,46 @@ namespace HandBrakeWPF.Services.Presets if (File.Exists(this.userPresetFile))
{
// New Preset Format.
+ bool createBackup = false;
+ PresetContainer presetContainer = null;
using (StreamReader reader = new StreamReader(this.userPresetFile))
{
- PresetContainer presetContainer = null;
-
- bool createBackup = false;
try
{
- presetContainer = JsonConvert.DeserializeObject<PresetContainer>(reader.ReadToEnd());
- }
+ presetContainer = JsonConvert.DeserializeObject<PresetContainer>(reader.ReadToEnd());
+ }
catch (Exception exc)
{
createBackup = true;
}
+ }
- // If we have old presets, or the container wasn't parseable, or we have a version mismatch, backup the user preset file
- // incase something goes wrong.
- if (createBackup || (presetContainer != null && presetContainer.Version < CurrentPresetVersion))
- {
- string backupFile = this.userPresetFile + "." + GeneralUtilities.ProcessId;
- File.Copy(this.userPresetFile, backupFile);
- }
+ // If we have old presets, or the container wasn't parseable, or we have a version mismatch, backup the user preset file
+ // incase something goes wrong.
+ if (createBackup || (presetContainer != null && presetContainer.Version < CurrentPresetVersion))
+ {
+ string fileName = RecoverFromCorruptedPresetFile(this.userPresetFile);
+ this.errorService.ShowMessageBox(
+ "HandBrake is unable to load your user presets because they are from an older version of HandBrake. Your old presets file has been renamed so that it doesn't get loaded on next launch."
+ + Environment.NewLine + Environment.NewLine + "Archived File: " + fileName,
+ "Unable to load user presets.",
+ MessageBoxButton.OK,
+ MessageBoxImage.Exclamation);
+ return;
+ }
- // Load the current presets.
- if (presetContainer != null && !string.IsNullOrEmpty(presetContainer.Presets))
+ // Load the current presets.
+ if (presetContainer != null && !string.IsNullOrEmpty(presetContainer.Presets))
+ {
+ JsonSerializerSettings settings = new JsonSerializerSettings();
+ settings.MissingMemberHandling = MissingMemberHandling.Ignore;
+
+ List<Preset> list = JsonConvert.DeserializeObject<List<Preset>>(presetContainer.Presets);
+ foreach (Preset preset in list)
{
- JsonSerializerSettings settings = new JsonSerializerSettings();
- settings.MissingMemberHandling = MissingMemberHandling.Ignore;
- List<Preset> list = JsonConvert.DeserializeObject<List<Preset>>(presetContainer.Presets);
- foreach (Preset preset in list)
- {
- this.presets.Add(preset);
- }
+ this.presets.Add(preset);
}
- }
+ }
}
// We did a preset convertion, so save the updates.
diff --git a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs index a05ea2194..452db5cc8 100644 --- a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs @@ -526,8 +526,8 @@ namespace HandBrakeWPF.ViewModels EncodeTask encodeTask = new EncodeTask(this.Task)
{
- PreviewDuration = this.Duration,
- PreviewStartAt = this.SelectedPreviewImage,
+ PreviewEncodeDuration = this.Duration,
+ PreviewEncodeStartAt = this.SelectedPreviewImage,
PointToPointMode = PointToPointMode.Preview
};
|