diff options
4 files changed, 61 insertions, 1 deletions
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 7f47f4ba4..a03b31450 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -4350,6 +4350,24 @@ namespace HandBrakeWPF.Properties { } /// <summary> + /// Looks up a localized string similar to Duplicate jobs were detected in the queue file that you are trying to import. Do you wish to overwrite the existing records?. + /// </summary> + public static string QueueService_DuplicatesQuestion { + get { + return ResourceManager.GetString("QueueService_DuplicatesQuestion", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Duplicates Detected. + /// </summary> + public static string QueueService_DuplicatesTitle { + get { + return ResourceManager.GetString("QueueService_DuplicatesTitle", resourceCulture); + } + } + + /// <summary> /// Looks up a localized string similar to Actions. /// </summary> public static string QueueView_Actions { diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index a7321af69..29365f2ec 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -2198,4 +2198,10 @@ Where supported, any user presets will have been imported.</value> <data name="SubtitleView_AddRemainingCC" xml:space="preserve">
<value>Add All Remaining Closed Captions</value>
</data>
+ <data name="QueueService_DuplicatesQuestion" xml:space="preserve">
+ <value>Duplicate jobs were detected in the queue file that you are trying to import. Do you wish to overwrite the existing records?</value>
+ </data>
+ <data name="QueueService_DuplicatesTitle" xml:space="preserve">
+ <value>Duplicates Detected</value>
+ </data>
</root>
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs index 52a77f714..3ee126ce9 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs @@ -9,6 +9,7 @@ namespace HandBrakeWPF.Services.Queue.Model
{
+ using System;
using System.Runtime.CompilerServices;
using Caliburn.Micro;
@@ -55,8 +56,12 @@ namespace HandBrakeWPF.Services.Queue.Model this.Id = string.Format("{0}.{1}", GeneralUtilities.ProcessId, id);
this.Statistics = new QueueStats();
+ this.TaskId = Guid.NewGuid().ToString();
}
+ [JsonProperty]
+ public string TaskId { get; set; }
+
[JsonIgnore]
public string Id { get; }
diff --git a/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs b/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs index 9e1c37bc9..25abbd53a 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs @@ -16,6 +16,7 @@ namespace HandBrakeWPF.Services.Queue using System.Diagnostics; using System.IO; using System.Linq; + using System.Windows; using System.Windows.Media.Imaging; using HandBrake.Interop.Interop.Json.Queue; @@ -47,14 +48,17 @@ namespace HandBrakeWPF.Services.Queue private static readonly object QueueLock = new object(); private readonly IUserSettingService userSettingService; private readonly ILog logService; + private readonly IErrorService errorService; + private readonly ObservableCollection<QueueTask> queue = new ObservableCollection<QueueTask>(); private readonly string queueFile; private bool clearCompleted; - public QueueService(IEncode encodeService, IUserSettingService userSettingService, ILog logService) + public QueueService(IEncode encodeService, IUserSettingService userSettingService, ILog logService, IErrorService errorService) { this.userSettingService = userSettingService; this.logService = logService; + this.errorService = errorService; this.EncodeService = encodeService; // If this is the first instance, just use the main queue file, otherwise add the instance id to the filename. @@ -193,8 +197,34 @@ namespace HandBrakeWPF.Services.Queue return; } + List<QueueTask> duplicates = queue.Where(task => reloadedQueue.Any(queueTask => queueTask.TaskId == task.TaskId)).ToList(); + bool replaceDuplicates = false; + if (duplicates.Any()) + { + MessageBoxResult result = this.errorService.ShowMessageBox( + Properties.Resources.QueueService_DuplicatesQuestion, + Properties.Resources.QueueService_DuplicatesTitle, + MessageBoxButton.YesNo, + MessageBoxImage.Question); + + if (result == MessageBoxResult.Yes) + { + foreach (QueueTask task in duplicates) + { + this.queue.Remove(task); + } + + replaceDuplicates = true; + } + } + foreach (QueueTask task in reloadedQueue) { + if (!replaceDuplicates && this.queue.Any(s => s.TaskId == task.TaskId)) + { + continue; + } + this.queue.Add(task); } @@ -205,6 +235,7 @@ namespace HandBrakeWPF.Services.Queue } } + public bool CheckForDestinationPathDuplicates(string destination) { foreach (QueueTask job in this.queue) |