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 | |
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')
-rw-r--r-- | win/C#/Functions/Encode.cs | 36 | ||||
-rw-r--r-- | win/C#/Functions/Main.cs | 48 |
2 files changed, 78 insertions, 6 deletions
diff --git a/win/C#/Functions/Encode.cs b/win/C#/Functions/Encode.cs index 044fad359..a6bfd263a 100644 --- a/win/C#/Functions/Encode.cs +++ b/win/C#/Functions/Encode.cs @@ -19,29 +19,33 @@ namespace Handbrake.Functions private static extern void LockWorkStation();
[DllImport("user32.dll")]
private static extern int ExitWindowsEx(int uFlags, int dwReason);
-
- // Declarations
- Process hbProc = new Process();
-
+
/// <summary>
/// Execute a HandBrakeCLI process.
/// </summary>
/// <param name="query">The CLI Query</param>
public Process runCli(string query)
{
+ Process hbProc = new Process();
try
{
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
string logPath = Path.Combine(logDir, "last_encode_log.txt");
-
string strCmdLine = String.Format(@" CMD /c """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, query, logPath);
ProcessStartInfo cliStart = new ProcessStartInfo("CMD.exe", strCmdLine);
+ if (Properties.Settings.Default.enocdeStatusInGui == "Checked")
+ {
+ cliStart.RedirectStandardOutput = true;
+ cliStart.UseShellExecute = false;
+ }
if (Properties.Settings.Default.cli_minimized == "Checked")
cliStart.WindowStyle = ProcessWindowStyle.Minimized;
+
+ Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.
hbProc = Process.Start(cliStart);
- processID = hbProc.Id;
+ processID = Main.getCliProcess(before);
isEncoding = true;
currentQuery = query;
@@ -73,10 +77,30 @@ namespace Handbrake.Functions {
MessageBox.Show("An error occured in runCli()\n Error Information: \n\n" + exc);
}
+
return hbProc;
}
/// <summary>
+ /// Kill the CLI process
+ /// </summary>
+ public void closeCLI()
+ {
+ Process[] prs = Process.GetProcesses();
+ foreach (Process process in prs)
+ {
+ if (process.Id == processID)
+ {
+ process.Refresh();
+ if (!process.HasExited)
+ process.Kill();
+
+ process.WaitForExit();
+ }
+ }
+ }
+
+ /// <summary>
/// Perform an action after an encode. e.g a shutdown, standby, restart etc.
/// </summary>
public void afterEncodeAction()
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;
+ }
+
}
}
|