Homepage: <http://handbrake.fr/>.\r
It may be used under the terms of the GNU General Public License. */\r
\r
+using System.Diagnostics.CodeAnalysis;\r
+\r
namespace Handbrake.Services\r
{\r
using System;\r
public IntPtr ProcessHandle { get; set; }\r
\r
/// <summary>\r
- /// Gets or sets a value indicating whether HandBrakeCLI.exe is running\r
+ /// Gets or sets a value indicating whether IsEncoding.\r
/// </summary>\r
- public bool IsEncoding { get; set; }\r
+ public bool IsEncoding\r
+ {\r
+ get;\r
+ set;\r
+ }\r
\r
/// <summary>\r
/// Gets or sets the Process ID\r
/// </param>\r
public void CreatePreviewSample(string query)\r
{\r
- this.Run(new Job {Query = query});\r
+ this.Run(new Job { Query = query });\r
}\r
\r
/// <summary>\r
\r
if (this.EncodeEnded != null)\r
this.EncodeEnded(this, new EventArgs());\r
-\r
- IsEncoding = false;\r
}\r
\r
/// <summary>\r
\r
// HbProcess.StandardInput.AutoFlush = true;\r
// HbProcess.StandardInput.WriteLine("^C");\r
-\r
- IsEncoding = false;\r
}\r
\r
/// <summary>\r
this.job = encJob;\r
try\r
{\r
- IsEncoding = true;\r
-\r
ResetLogReader();\r
\r
+ if (this.EncodeStarted != null)\r
+ this.EncodeStarted(this, new EventArgs());\r
+\r
+ IsEncoding = true;\r
+\r
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
string logPath =\r
Path.Combine(\r
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs",\r
"last_encode_log.txt");\r
- string strCmdLine = String.Format(@" /C """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, encJob.Query, logPath);\r
+ string strCmdLine = String.Format(@" /C """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, encJob.Query,\r
+ logPath);\r
var cliStart = new ProcessStartInfo("CMD.exe", strCmdLine);\r
\r
if (Settings.Default.enocdeStatusInGui)\r
cliStart.WindowStyle = ProcessWindowStyle.Minimized;\r
\r
Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.\r
- this.HbProcess = Process.Start(cliStart);\r
+ Process startProcess = Process.Start(cliStart);\r
+\r
this.ProcessID = Main.GetCliProcess(before);\r
\r
// Fire the Encode Started Event\r
if (this.EncodeStarted != null)\r
this.EncodeStarted(this, new EventArgs());\r
\r
- if (this.HbProcess != null)\r
- this.ProcessHandle = this.HbProcess.MainWindowHandle; // Set the process Handle\r
+ if (startProcess != null)\r
+ this.ProcessHandle = startProcess.MainWindowHandle; // Set the process Handle\r
\r
// Start the Log Monitor\r
windowTimer = new Timer(new TimerCallback(ReadFile), null, 1000, 1000);\r
\r
// Set the process Priority\r
- Process hbCliProcess = null;\r
if (this.ProcessID != -1)\r
- hbCliProcess = Process.GetProcessById(this.ProcessID);\r
+ {\r
+ HbProcess = Process.GetProcessById(this.ProcessID);\r
+ HbProcess.EnableRaisingEvents = true;\r
+ HbProcess.Exited += new EventHandler(HbProcess_Exited);\r
+ }\r
\r
- if (hbCliProcess != null)\r
+ if (HbProcess != null)\r
switch (Settings.Default.processPriority)\r
{\r
case "Realtime":\r
- hbCliProcess.PriorityClass = ProcessPriorityClass.RealTime;\r
+ HbProcess.PriorityClass = ProcessPriorityClass.RealTime;\r
break;\r
case "High":\r
- hbCliProcess.PriorityClass = ProcessPriorityClass.High;\r
+ HbProcess.PriorityClass = ProcessPriorityClass.High;\r
break;\r
case "Above Normal":\r
- hbCliProcess.PriorityClass = ProcessPriorityClass.AboveNormal;\r
+ HbProcess.PriorityClass = ProcessPriorityClass.AboveNormal;\r
break;\r
case "Normal":\r
- hbCliProcess.PriorityClass = ProcessPriorityClass.Normal;\r
+ HbProcess.PriorityClass = ProcessPriorityClass.Normal;\r
break;\r
case "Low":\r
- hbCliProcess.PriorityClass = ProcessPriorityClass.Idle;\r
+ HbProcess.PriorityClass = ProcessPriorityClass.Idle;\r
break;\r
default:\r
- hbCliProcess.PriorityClass = ProcessPriorityClass.BelowNormal;\r
+ HbProcess.PriorityClass = ProcessPriorityClass.BelowNormal;\r
break;\r
}\r
}\r
}\r
\r
/// <summary>\r
+ /// The HandBrakeCLI process has exited.\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The EventArgs.\r
+ /// </param>\r
+ private void HbProcess_Exited(object sender, EventArgs e)\r
+ {\r
+ IsEncoding = false;\r
+ }\r
+\r
+ /// <summary>\r
/// Function to run the CLI directly rather than via CMD\r
/// TODO: Code to handle the Log data has yet to be written.\r
/// TODO: Code to handle the % / ETA info has to be written.\r
this.EncodeStarted(this, new EventArgs());\r
\r
IsEncoding = true;\r
+\r
ResetLogReader();\r
\r
// Setup the job\r
string handbrakeCLIPath = Path.Combine(Environment.CurrentDirectory, "HandBrakeCLI.exe");\r
HbProcess = new Process\r
- {\r
- StartInfo =\r
- {\r
- FileName = handbrakeCLIPath,\r
- Arguments = query,\r
- UseShellExecute = false,\r
- RedirectStandardOutput = true,\r
- RedirectStandardError = true,\r
- RedirectStandardInput = true,\r
- CreateNoWindow = false,\r
- WindowStyle = ProcessWindowStyle.Minimized\r
- }\r
- };\r
+ {\r
+ StartInfo =\r
+ {\r
+ FileName = handbrakeCLIPath,\r
+ Arguments = query,\r
+ UseShellExecute = false,\r
+ RedirectStandardOutput = true,\r
+ RedirectStandardError = true,\r
+ RedirectStandardInput = true,\r
+ CreateNoWindow = false,\r
+ WindowStyle = ProcessWindowStyle.Minimized\r
+ }\r
+ };\r
\r
// Setup event handlers for rediected data\r
HbProcess.ErrorDataReceived += new DataReceivedEventHandler(HbProcErrorDataReceived);\r
if (this.EncodeEnded != null)\r
this.EncodeEnded(this, new EventArgs());\r
\r
- IsEncoding = false;\r
-\r
if (!IsEncoding)\r
{\r
windowTimer.Dispose();\r
{\r
try\r
{\r
- string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +\r
+ "\\HandBrake\\logs";\r
string logPath = Path.Combine(logDir, "last_encode_log.txt");\r
\r
var reader = new StreamReader(File.Open(logPath, FileMode.Open, FileAccess.Read, FileShare.Read));\r
{\r
// last_encode_log.txt is the primary log file. Since .NET can't read this file whilst the CLI is outputing to it (Not even in read only mode),\r
// we'll need to make a copy of it.\r
- string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +\r
+ "\\HandBrake\\logs";\r
string logFile = Path.Combine(logDir, "last_encode_log.txt");\r
string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");\r
\r