\r
namespace HandBrake.ApplicationServices.Functions\r
{\r
- using System;\r
- using System.Collections.Generic;\r
using System.Diagnostics;\r
\r
/// <summary>\r
/// <summary>\r
/// Get the Process ID of HandBrakeCLI for the current instance.\r
/// </summary>\r
- /// <param name="before">List of processes before the new process was started</param>\r
- /// <returns>Int - Process ID</returns>\r
- public static int GetCliProcess(Process[] before)\r
+ /// <returns>A list of processes</returns>\r
+ public static Process[] GetCliProcess()\r
{\r
- // This is a bit of a cludge. Maybe someone has a better idea on how to impliment this.\r
- // Since we used CMD to start HandBrakeCLI, we don't get the process ID from hbProc.\r
- // Instead we take the processes before and after, and get the ID of HandBrakeCLI.exe\r
- // avoiding any previous instances of HandBrakeCLI.exe in before.\r
- // Kill the current process.\r
-\r
- DateTime startTime = DateTime.Now;\r
- TimeSpan duration;\r
-\r
- Process[] hbProcesses = Process.GetProcessesByName("HandBrakeCLI");\r
- while (hbProcesses.Length == 0)\r
- {\r
- hbProcesses = Process.GetProcessesByName("HandBrakeCLI");\r
- duration = DateTime.Now - startTime;\r
- if (duration.Seconds > 5 && hbProcesses.Length == 0)\r
- // Make sure we don't wait forever if the process doesn't start\r
- return -1;\r
- }\r
-\r
- Process hbProcess = null;\r
- foreach (Process process in hbProcesses)\r
- {\r
- bool found = false;\r
- // Check if the current CLI instance was running before we started the current one\r
- foreach (Process bprocess in before)\r
- {\r
- if (process.Id == bprocess.Id)\r
- found = true;\r
- }\r
-\r
- // If it wasn't running before, we found the process we want.\r
- if (!found)\r
- {\r
- hbProcess = process;\r
- break;\r
- }\r
- }\r
- if (hbProcess != null)\r
- return hbProcess.Id;\r
-\r
- return -1;\r
+ return Process.GetProcessesByName("HandBrakeCLI");\r
}\r
\r
/// <summary>\r
using HandBrake.ApplicationServices.Properties;\r
using HandBrake.ApplicationServices.Services.Interfaces;\r
\r
- using Timer = System.Threading.Timer;\r
-\r
/// <summary>\r
/// Class which handles the CLI\r
/// </summary>\r
{\r
#region Private Variables\r
\r
- /// <summary>\r
- /// An Encode Job\r
- /// </summary>\r
- private Job job;\r
-\r
/// <summary>\r
/// The Log Buffer\r
/// </summary>\r
/// </param>\r
protected void Run(Job encJob, bool enableLogging)\r
{\r
- this.job = encJob;\r
try\r
{\r
IsEncoding = true;\r