summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Helpers
diff options
context:
space:
mode:
authorsr55 <[email protected]>2012-10-13 19:48:12 +0000
committersr55 <[email protected]>2012-10-13 19:48:12 +0000
commit029c9b1db2fbf86fc8ded15580cd8023e4b180fc (patch)
tree227743486b489e989f0b1c67234ebefa4316b10c /win/CS/HandBrakeWPF/Helpers
parent2a18d05b52ea084b4bb968f3622872a8a08d83fa (diff)
WinGui: Refactor multi-instance support to use Process ID. Fix old log file cleanup function.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5016 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/Helpers')
-rw-r--r--win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs45
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));
+ }
}
}
}