diff options
author | sr55 <[email protected]> | 2010-07-15 20:15:08 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2010-07-15 20:15:08 +0000 |
commit | 6c9b4d2c4cf5928bb2b472beca76c2edc4c41f03 (patch) | |
tree | 85ba020472dfb475f4db0424ed139da20fa6b64e /win/C#/Functions | |
parent | 5c8cab7ea3c07e36b74bcb8c8198f8ef796e1530 (diff) |
WinGui:
- Multiple instance support.
Each instance has a unique id. id = 0 will use the standard log/queue files.
id = 1,2...n will use standard file names but with the instance id added to the end.
This means that each instance will have it's own queue. Queue is not shared between Instances
If multiple queue files are found when starting up, it will offer to load them all in.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3440 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/Functions')
-rw-r--r-- | win/C#/Functions/Main.cs | 80 |
1 files changed, 26 insertions, 54 deletions
diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index 2bf6e6f5c..15714ee75 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -372,77 +372,51 @@ namespace Handbrake.Functions /// <returns>
/// True if there is a queue to recover.
/// </returns>
- public static bool CheckQueueRecovery()
+ public static List<string> CheckQueueRecovery()
{
try
{
- string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\hb_queue_recovery.xml");
- if (File.Exists(tempPath))
+ string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");
+ List<string> queueFiles = new List<string>();
+
+ DirectoryInfo info = new DirectoryInfo(tempPath);
+ FileInfo[] logFiles = info.GetFiles("*.xml");
+ foreach (FileInfo file in logFiles)
{
- using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read))
+ if (!file.Name.Contains("hb_queue_recovery"))
+ continue;
+
+ using (FileStream strm = new FileStream(Path.Combine(file.DirectoryName, file.Name), FileMode.Open, FileAccess.Read))
{
List<Job> list = Ser.Deserialize(strm) as List<Job>;
if (list != null)
+ {
if (list.Count != 0)
- return true;
+ {
+ queueFiles.Add(file.Name);
+ }
+ }
}
}
- return false;
+
+ return queueFiles;
}
catch (Exception)
{
- return false; // Keep quiet about the error.
+ return new List<string>(); // Keep quiet about the error.
}
}
/// <summary>
- /// Get the Process ID of HandBrakeCLI for the current instance.
+ /// Checks if this HandBrake is running multiple instances
/// </summary>
- /// <param name="before">List of processes before the new process was started</param>
- /// <returns>Int - Process ID</returns>
- public static int GetCliProcess(Process[] before)
+ /// <returns>True if the UI has another instance running</returns>
+ public static bool IsMultiInstance
{
- // This is a bit of a cludge. Maybe someone has a better idea on how to impliment this.
- // Since we used CMD to start HandBrakeCLI, we don't get the process ID from hbProc.
- // Instead we take the processes before and after, and get the ID of HandBrakeCLI.exe
- // avoiding any previous instances of HandBrakeCLI.exe in before.
- // Kill the current process.
-
- DateTime startTime = DateTime.Now;
- TimeSpan duration;
-
- Process[] hbProcesses = Process.GetProcessesByName("HandBrakeCLI");
- while (hbProcesses.Length == 0)
+ get
{
- hbProcesses = Process.GetProcessesByName("HandBrakeCLI");
- duration = DateTime.Now - startTime;
- if (duration.Seconds > 5 && hbProcesses.Length == 0)
- // Make sure we don't wait forever if the process doesn't start
- return -1;
+ return Process.GetProcessesByName("HandBrake").Length > 0 ? true : false;
}
-
- Process hbProcess = null;
- foreach (Process process in hbProcesses)
- {
- bool found = false;
- // Check if the current CLI instance was running before we started the current one
- foreach (Process bprocess in before)
- {
- if (process.Id == bprocess.Id)
- found = true;
- }
-
- // If it wasn't running before, we found the process we want.
- if (!found)
- {
- hbProcess = process;
- break;
- }
- }
- if (hbProcess != null)
- return hbProcess.Id;
-
- return -1;
}
/// <summary>
@@ -457,8 +431,7 @@ namespace Handbrake.Functions FileInfo[] logFiles = info.GetFiles("*.txt");
foreach (FileInfo file in logFiles)
{
- if (!file.Name.Contains("last_scan_log") && !file.Name.Contains("last_encode_log") &&
- !file.Name.Contains("tmp_appReadable_log.txt"))
+ if (!file.Name.Contains("last_scan_log") && !file.Name.Contains("last_encode_log"))
File.Delete(file.FullName);
}
}
@@ -479,8 +452,7 @@ namespace Handbrake.Functions {
if (file.LastWriteTime < DateTime.Now.AddDays(-30))
{
- if (!file.Name.Contains("last_scan_log") && !file.Name.Contains("last_encode_log") &&
- !file.Name.Contains("tmp_appReadable_log.txt"))
+ if (!file.Name.Contains("last_scan_log.txt") && !file.Name.Contains("last_encode_log.txt"))
File.Delete(file.FullName);
}
}
|