diff options
author | sr55 <[email protected]> | 2019-05-11 17:24:54 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2019-05-11 17:24:54 +0100 |
commit | 4b8c299e283bcce467eebf59248524ed94befa5d (patch) | |
tree | dcd5aeca06a1a65c10d76d0fe8ae58298302b26c /win/CS/HandBrakeWPF | |
parent | d66c23d4a81c6165965114e855a4f361c9481649 (diff) |
WinGui: More Robust Queue Backup and Recovery.
Diffstat (limited to 'win/CS/HandBrakeWPF')
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs | 22 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Services/Queue/QueueService.cs | 15 |
2 files changed, 34 insertions, 3 deletions
diff --git a/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs b/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs index 072baafc7..6120c6b78 100644 --- a/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs @@ -46,6 +46,10 @@ namespace HandBrakeWPF.Helpers {
try
{
+ // Check for any Corrupted Backup Files and try recover them
+ RecoverFromBackupFailure();
+
+ // Now check for all available recovery files. (There may be more than 1 for multi-instance support)
string tempPath = DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly());
DirectoryInfo info = new DirectoryInfo(tempPath);
IEnumerable<FileInfo> foundFiles = info.GetFiles("*.json").Where(f => f.Name.StartsWith(QueueFileName));
@@ -181,6 +185,24 @@ namespace HandBrakeWPF.Helpers return foundFiles.Any();
}
+ private static void RecoverFromBackupFailure()
+ {
+ string appDataPath = DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly());
+ DirectoryInfo info = new DirectoryInfo(appDataPath);
+ IEnumerable<FileInfo> foundFiles = info.GetFiles("*.last");
+
+ foreach (FileInfo file in foundFiles)
+ {
+ string corruptedFile = file.FullName.Replace(".last", string.Empty);
+ if (File.Exists(corruptedFile))
+ {
+ File.Delete(corruptedFile);
+ }
+
+ File.Move(file.FullName, corruptedFile);
+ }
+ }
+
private static List<string> GetFilesExcludingActiveProcesses(IEnumerable<FileInfo> foundFiles, List<string> filterQueueFiles)
{
List<string> queueFiles = new List<string>();
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; - /// <summary> - /// The HandBrake Queue - /// </summary> 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<QueueTask> 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); } |