From 4b8c299e283bcce467eebf59248524ed94befa5d Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 11 May 2019 17:24:54 +0100 Subject: WinGui: More Robust Queue Backup and Recovery. --- win/CS/HandBrakeWPF/Services/Queue/QueueService.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'win/CS/HandBrakeWPF/Services') diff --git a/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs b/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs index 0a9c6e8e9..48c29f4f4 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs @@ -42,9 +42,6 @@ namespace HandBrakeWPF.Services.Queue using QueueCompletedEventArgs = HandBrakeWPF.EventArgs.QueueCompletedEventArgs; using QueueProgressEventArgs = HandBrakeWPF.EventArgs.QueueProgressEventArgs; - /// - /// The HandBrake Queue - /// public class QueueService : Interfaces.IQueueService { #region Constants and Fields @@ -218,6 +215,12 @@ namespace HandBrakeWPF.Services.Queue ? exportPath : Path.Combine(appDataPath, string.Format(this.queueFile, string.Empty)); + // Make a copy of the file before we replace it. This way, if we crash we can recover. + if (File.Exists(tempPath)) + { + File.Copy(tempPath, tempPath + ".last"); + } + using (StreamWriter writer = new StreamWriter(tempPath)) { List tasks = this.queue.Where(item => item.Status != QueueItemStatus.Completed).ToList(); @@ -225,6 +228,11 @@ namespace HandBrakeWPF.Services.Queue writer.Write(queueJson); } + if (File.Exists(tempPath + ".last")) + { + File.Delete(tempPath + ".last"); + } + watch.Stop(); Debug.WriteLine("Queue Save (ms): " + watch.ElapsedMilliseconds); } @@ -679,6 +687,7 @@ namespace HandBrakeWPF.Services.Queue this.BackupQueue(string.Empty); return; } + this.EncodeService.Start(job.Task, job.Configuration); this.BackupQueue(string.Empty); } -- cgit v1.2.3