diff options
author | sr55 <[email protected]> | 2009-05-13 19:50:47 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2009-05-13 19:50:47 +0000 |
commit | 43b29fa60d2d30aa1802a7b913436f86cfe3d73f (patch) | |
tree | 80770c72e687ccebbf3cbe23679ab715c814cbce /win/C#/Functions/Main.cs | |
parent | 78db7280456c556a3015f93ec54d579e2935085a (diff) |
WinGui:
- The CLI status information can now optionally be displayed in the encode status bar in the GUI.
- Fixed Scan and Encode cancel functions with a hack. It was killing CMD.exe, not HandBrakeCLI.exe
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2416 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/Functions/Main.cs')
-rw-r--r-- | win/C#/Functions/Main.cs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index d7161205f..a95f5e144 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -11,6 +11,7 @@ using System.Diagnostics; using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Xml.Serialization;
+using System.Threading;
namespace Handbrake.Functions
{
@@ -371,5 +372,52 @@ namespace Handbrake.Functions }
}
+ /// <summary>
+ /// Get the Process ID of HandBrakeCLI for the current instance.
+ /// </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)
+ {
+ // 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.
+
+ Process[] hbProcesses = Process.GetProcessesByName("HandBrakeCLI");
+
+ // Another hack. We maybe need to wait a few seconds for HandBrakeCLI to launch
+ if (hbProcesses.Length == 0)
+ {
+ Thread.Sleep(2000);
+ hbProcesses = Process.GetProcessesByName("HandBrakeCLI");
+ }
+
+ Process hbProcess = null;
+ if (hbProcesses.Length > 0)
+ foreach (Process process in hbProcesses)
+ {
+ Boolean 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;
+ }
+
}
}
|