summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorsr55 <[email protected]>2010-04-30 20:24:05 +0000
committersr55 <[email protected]>2010-04-30 20:24:05 +0000
commit792bbf1668069fc8ccc8d8f9cc5a8bceee14640c (patch)
tree102d022088775a8fa5dd37109cb6945b86ea4607 /win
parentc1d2b77d9e0c0bdb37da785be22059832fc507a5 (diff)
WinGui:
- Some minor re factoring to the encode service. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3280 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win')
-rw-r--r--win/C#/Services/Encode.cs103
-rw-r--r--win/C#/Services/Queue.cs2
2 files changed, 64 insertions, 41 deletions
diff --git a/win/C#/Services/Encode.cs b/win/C#/Services/Encode.cs
index ba19f187a..e4b9e6532 100644
--- a/win/C#/Services/Encode.cs
+++ b/win/C#/Services/Encode.cs
@@ -3,6 +3,8 @@
Homepage: <http://handbrake.fr/>.
It may be used under the terms of the GNU General Public License. */
+using System.Diagnostics.CodeAnalysis;
+
namespace Handbrake.Services
{
using System;
@@ -62,9 +64,13 @@ namespace Handbrake.Services
public IntPtr ProcessHandle { get; set; }
/// <summary>
- /// Gets or sets a value indicating whether HandBrakeCLI.exe is running
+ /// Gets or sets a value indicating whether IsEncoding.
/// </summary>
- public bool IsEncoding { get; set; }
+ public bool IsEncoding
+ {
+ get;
+ set;
+ }
/// <summary>
/// Gets or sets the Process ID
@@ -93,7 +99,7 @@ namespace Handbrake.Services
/// </param>
public void CreatePreviewSample(string query)
{
- this.Run(new Job {Query = query});
+ this.Run(new Job { Query = query });
}
/// <summary>
@@ -110,8 +116,6 @@ namespace Handbrake.Services
if (this.EncodeEnded != null)
this.EncodeEnded(this, new EventArgs());
-
- IsEncoding = false;
}
/// <summary>
@@ -131,8 +135,6 @@ namespace Handbrake.Services
// HbProcess.StandardInput.AutoFlush = true;
// HbProcess.StandardInput.WriteLine("^C");
-
- IsEncoding = false;
}
/// <summary>
@@ -146,16 +148,20 @@ namespace Handbrake.Services
this.job = encJob;
try
{
- IsEncoding = true;
-
ResetLogReader();
+ if (this.EncodeStarted != null)
+ this.EncodeStarted(this, new EventArgs());
+
+ IsEncoding = true;
+
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
string logPath =
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs",
"last_encode_log.txt");
- string strCmdLine = String.Format(@" /C """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, encJob.Query, logPath);
+ string strCmdLine = String.Format(@" /C """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, encJob.Query,
+ logPath);
var cliStart = new ProcessStartInfo("CMD.exe", strCmdLine);
if (Settings.Default.enocdeStatusInGui)
@@ -169,44 +175,48 @@ namespace Handbrake.Services
cliStart.WindowStyle = ProcessWindowStyle.Minimized;
Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.
- this.HbProcess = Process.Start(cliStart);
+ Process startProcess = Process.Start(cliStart);
+
this.ProcessID = Main.GetCliProcess(before);
// Fire the Encode Started Event
if (this.EncodeStarted != null)
this.EncodeStarted(this, new EventArgs());
- if (this.HbProcess != null)
- this.ProcessHandle = this.HbProcess.MainWindowHandle; // Set the process Handle
+ if (startProcess != null)
+ this.ProcessHandle = startProcess.MainWindowHandle; // Set the process Handle
// Start the Log Monitor
windowTimer = new Timer(new TimerCallback(ReadFile), null, 1000, 1000);
// Set the process Priority
- Process hbCliProcess = null;
if (this.ProcessID != -1)
- hbCliProcess = Process.GetProcessById(this.ProcessID);
+ {
+ HbProcess = Process.GetProcessById(this.ProcessID);
+ HbProcess.EnableRaisingEvents = true;
+ HbProcess.Exited += new EventHandler(HbProcess_Exited);
+ }
- if (hbCliProcess != null)
+ if (HbProcess != null)
switch (Settings.Default.processPriority)
{
case "Realtime":
- hbCliProcess.PriorityClass = ProcessPriorityClass.RealTime;
+ HbProcess.PriorityClass = ProcessPriorityClass.RealTime;
break;
case "High":
- hbCliProcess.PriorityClass = ProcessPriorityClass.High;
+ HbProcess.PriorityClass = ProcessPriorityClass.High;
break;
case "Above Normal":
- hbCliProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
+ HbProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
break;
case "Normal":
- hbCliProcess.PriorityClass = ProcessPriorityClass.Normal;
+ HbProcess.PriorityClass = ProcessPriorityClass.Normal;
break;
case "Low":
- hbCliProcess.PriorityClass = ProcessPriorityClass.Idle;
+ HbProcess.PriorityClass = ProcessPriorityClass.Idle;
break;
default:
- hbCliProcess.PriorityClass = ProcessPriorityClass.BelowNormal;
+ HbProcess.PriorityClass = ProcessPriorityClass.BelowNormal;
break;
}
}
@@ -222,6 +232,20 @@ namespace Handbrake.Services
}
/// <summary>
+ /// The HandBrakeCLI process has exited.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The EventArgs.
+ /// </param>
+ private void HbProcess_Exited(object sender, EventArgs e)
+ {
+ IsEncoding = false;
+ }
+
+ /// <summary>
/// Function to run the CLI directly rather than via CMD
/// TODO: Code to handle the Log data has yet to be written.
/// TODO: Code to handle the % / ETA info has to be written.
@@ -237,24 +261,25 @@ namespace Handbrake.Services
this.EncodeStarted(this, new EventArgs());
IsEncoding = true;
+
ResetLogReader();
// Setup the job
string handbrakeCLIPath = Path.Combine(Environment.CurrentDirectory, "HandBrakeCLI.exe");
HbProcess = new Process
- {
- StartInfo =
- {
- FileName = handbrakeCLIPath,
- Arguments = query,
- UseShellExecute = false,
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- RedirectStandardInput = true,
- CreateNoWindow = false,
- WindowStyle = ProcessWindowStyle.Minimized
- }
- };
+ {
+ StartInfo =
+ {
+ FileName = handbrakeCLIPath,
+ Arguments = query,
+ UseShellExecute = false,
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ RedirectStandardInput = true,
+ CreateNoWindow = false,
+ WindowStyle = ProcessWindowStyle.Minimized
+ }
+ };
// Setup event handlers for rediected data
HbProcess.ErrorDataReceived += new DataReceivedEventHandler(HbProcErrorDataReceived);
@@ -308,8 +333,6 @@ namespace Handbrake.Services
if (this.EncodeEnded != null)
this.EncodeEnded(this, new EventArgs());
- IsEncoding = false;
-
if (!IsEncoding)
{
windowTimer.Dispose();
@@ -356,7 +379,8 @@ namespace Handbrake.Services
{
try
{
- string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
+ "\\HandBrake\\logs";
string logPath = Path.Combine(logDir, "last_encode_log.txt");
var reader = new StreamReader(File.Open(logPath, FileMode.Open, FileAccess.Read, FileShare.Read));
@@ -436,7 +460,8 @@ namespace Handbrake.Services
{
// 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),
// we'll need to make a copy of it.
- string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
+ "\\HandBrake\\logs";
string logFile = Path.Combine(logDir, "last_encode_log.txt");
string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");
diff --git a/win/C#/Services/Queue.cs b/win/C#/Services/Queue.cs
index 4aba9774c..39437fcbc 100644
--- a/win/C#/Services/Queue.cs
+++ b/win/C#/Services/Queue.cs
@@ -364,8 +364,6 @@ namespace Handbrake.Services
HbProcess.Close();
HbProcess.Dispose();
- IsEncoding = false;
-
// Growl
if (Properties.Settings.Default.growlEncode)
GrowlCommunicator.Notify("Encode Completed",