diff options
Diffstat (limited to 'win/CS/HandBrakeWPF/Helpers')
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs b/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs index f37fae656..b434fc0b9 100644 --- a/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs @@ -11,8 +11,11 @@ namespace HandBrakeWPF.Helpers {
using System;
using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Globalization;
using System.IO;
using System.Linq;
+ using System.Text.RegularExpressions;
using System.Windows;
using System.Xml.Serialization;
@@ -68,12 +71,19 @@ namespace HandBrakeWPF.Helpers }
// Cleanup old/unused queue files for now.
- if (!GeneralUtilities.IsMultiInstance)
+ foreach (string file in removeFiles)
{
- foreach (string file in removeFiles)
+ Match m = Regex.Match(file, @"([0-9]+).xml");
+ if (m.Success)
{
- File.Delete(file);
+ int processId = int.Parse(m.Groups[1].ToString());
+ if (GeneralUtilities.IsPidACurrentHandBrakeInstance(processId))
+ {
+ continue;
+ }
}
+
+ File.Delete(file);
}
return queueFiles;
@@ -116,16 +126,41 @@ namespace HandBrakeWPF.Helpers foreach (string file in queueFiles)
{
encodeQueue.RestoreQueue(appDataPath + file); // Start Recovery
+ if (!file.Contains(GeneralUtilities.ProcessId.ToString(CultureInfo.InvariantCulture)))
+ {
+ try
+ {
+ // Once we load it in, remove it as we no longer need it.
+ File.Delete(file);
+ }
+ catch (Exception)
+ {
+ // Keep quite, nothing much we can do if there are problems.
+ // We will continue processing files.
+ }
+ }
}
}
else
{
- if (GeneralUtilities.IsMultiInstance) return; // Don't tamper with the files if we are multi instance
-
foreach (string file in queueFiles)
{
if (File.Exists(Path.Combine(appDataPath, file)))
+ {
+ // Check that the file doesn't belong to another running instance.
+ Match m = Regex.Match(file, @"[([0-9]+)].xml");
+ if (m.Success)
+ {
+ int processId = int.Parse(m.Groups[1].ToString());
+ if (GeneralUtilities.IsPidACurrentHandBrakeInstance(processId))
+ {
+ continue;
+ }
+ }
+
+ // Delete it if it doesn't
File.Delete(Path.Combine(appDataPath, file));
+ }
}
}
}
|