diff options
author | sr55 <[email protected]> | 2010-05-18 18:34:59 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2010-05-18 18:34:59 +0000 |
commit | 0a7e0840bc16471dd861cefa97e1902f24e29fd8 (patch) | |
tree | be35f833783ac970848c8efa1b2b2d9960265cbd /win/C#/Services | |
parent | 318116fb6fe20e7f3f4e5f0631c66e9a960aa4ef (diff) |
WinGui:
- Changed the ActivityWindow to be event driven which should make it work a bit better. Please report any bugs / issues you see with this window.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3303 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/Services')
-rw-r--r-- | win/C#/Services/Encode.cs | 69 | ||||
-rw-r--r-- | win/C#/Services/Scan.cs | 131 |
2 files changed, 100 insertions, 100 deletions
diff --git a/win/C#/Services/Encode.cs b/win/C#/Services/Encode.cs index e4b9e6532..677c62c62 100644 --- a/win/C#/Services/Encode.cs +++ b/win/C#/Services/Encode.cs @@ -3,8 +3,6 @@ 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;
@@ -23,6 +21,8 @@ namespace Handbrake.Services /// </summary>
public class Encode
{
+ /* Private Variables */
+
/// <summary>
/// An Encode Job
/// </summary>
@@ -44,6 +44,18 @@ namespace Handbrake.Services private Timer windowTimer;
/// <summary>
+ /// Gets The Process Handle
+ /// </summary>
+ private IntPtr processHandle;
+
+ /// <summary>
+ /// Gets the Process ID
+ /// </summary>
+ private int processID;
+
+ /* Event Handlers */
+
+ /// <summary>
/// Fires when a new CLI Job starts
/// </summary>
public event EventHandler EncodeStarted;
@@ -53,29 +65,19 @@ namespace Handbrake.Services /// </summary>
public event EventHandler EncodeEnded;
+ /* Properties */
+
/// <summary>
/// Gets or sets The HB Process
/// </summary>
public Process HbProcess { get; set; }
/// <summary>
- /// Gets or sets The Process Handle
- /// </summary>
- public IntPtr ProcessHandle { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether IsEncoding.
+ /// Gets a value indicating whether IsEncoding.
/// </summary>
- public bool IsEncoding
- {
- get;
- set;
- }
+ public bool IsEncoding { get; private set; }
- /// <summary>
- /// Gets or sets the Process ID
- /// </summary>
- public int ProcessID { get; set; }
+ /* Public Methods */
/// <summary>
/// Gets ActivityLog.
@@ -84,10 +86,13 @@ namespace Handbrake.Services {
get
{
- if (logBuffer != null)
- return logBuffer.ToString();
+ if (logBuffer == null)
+ {
+ ResetLogReader();
+ ReadFile(null);
+ }
- return string.Empty;
+ return logBuffer != null ? logBuffer.ToString() : string.Empty;
}
}
@@ -125,11 +130,11 @@ namespace Handbrake.Services /// </summary>
public void SafelyClose()
{
- if ((int)this.ProcessHandle == 0)
+ if ((int)this.processHandle == 0)
return;
// Allow the CLI to exit cleanly
- Win32.SetForegroundWindow((int)this.ProcessHandle);
+ Win32.SetForegroundWindow((int)this.processHandle);
SendKeys.Send("^C");
SendKeys.Flush();
@@ -177,22 +182,22 @@ namespace Handbrake.Services Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.
Process startProcess = Process.Start(cliStart);
- this.ProcessID = Main.GetCliProcess(before);
+ this.processID = Main.GetCliProcess(before);
// Fire the Encode Started Event
if (this.EncodeStarted != null)
this.EncodeStarted(this, new EventArgs());
if (startProcess != null)
- this.ProcessHandle = startProcess.MainWindowHandle; // Set the process Handle
+ 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
- if (this.ProcessID != -1)
+ if (this.processID != -1)
{
- HbProcess = Process.GetProcessById(this.ProcessID);
+ HbProcess = Process.GetProcessById(this.processID);
HbProcess.EnableRaisingEvents = true;
HbProcess.Exited += new EventHandler(HbProcess_Exited);
}
@@ -316,8 +321,8 @@ namespace Handbrake.Services }
// Set the class items
- this.ProcessID = HbProcess.Id;
- this.ProcessHandle = HbProcess.Handle;
+ this.processID = HbProcess.Id;
+ this.processHandle = HbProcess.Handle;
}
catch (Exception exc)
{
@@ -330,15 +335,15 @@ namespace Handbrake.Services /// </summary>
protected void Finish()
{
- if (this.EncodeEnded != null)
- this.EncodeEnded(this, new EventArgs());
-
if (!IsEncoding)
{
windowTimer.Dispose();
ReadFile(null);
}
+ if (this.EncodeEnded != null)
+ this.EncodeEnded(this, new EventArgs());
+
// Growl
if (Settings.Default.growlQueue)
GrowlCommunicator.Notify("Queue Completed", "Put down that cocktail...\nyour Handbrake queue is done.");
@@ -481,7 +486,7 @@ namespace Handbrake.Services }
// Put the Query and User Generated Query Flag on the log.
- if (logFilePosition == 0)
+ if (logFilePosition == 0 && job.Query != null)
{
logBuffer.AppendLine("### CLI Query: " + job.Query);
logBuffer.AppendLine("### User Query: " + job.CustomQuery);
diff --git a/win/C#/Services/Scan.cs b/win/C#/Services/Scan.cs index 6fd00a34f..3c62ec96b 100644 --- a/win/C#/Services/Scan.cs +++ b/win/C#/Services/Scan.cs @@ -16,12 +16,14 @@ namespace Handbrake.Services /// <summary>
/// Scan a Source
/// </summary>
- public class Scan
+ public class ScanService
{
+ /* Private Variables */
+
/// <summary>
- /// The information for this source
+ /// A Lock object
/// </summary>
- private DVD thisDvd;
+ private static readonly object locker = new object();
/// <summary>
/// The CLI data parser
@@ -34,11 +36,6 @@ namespace Handbrake.Services private StringBuilder logBuffer;
/// <summary>
- /// A Lock object
- /// </summary>
- private static object locker = new object();
-
- /// <summary>
/// The line number thats been read to in the log file
/// </summary>
private int logFilePosition;
@@ -48,10 +45,7 @@ namespace Handbrake.Services /// </summary>
private Process hbProc;
- /// <summary>
- /// The Progress of the scan
- /// </summary>
- private string scanProgress;
+ /* Event Handlers */
/// <summary>
/// Scan has Started
@@ -68,10 +62,22 @@ namespace Handbrake.Services /// </summary>
public event EventHandler ScanStatusChanged;
+ /* Properties */
+
/// <summary>
- /// Gets or sets a value indicating whether IsScanning.
+ /// Gets a value indicating whether IsScanning.
/// </summary>
- public bool IsScanning { get; set; }
+ public bool IsScanning { get; private set; }
+
+ /// <summary>
+ /// Gets the Scan Status.
+ /// </summary>
+ public string ScanStatus { get; private set; }
+
+ /// <summary>
+ /// Gets the Souce Data.
+ /// </summary>
+ public DVD SouceData { get; private set; }
/// <summary>
/// Gets ActivityLog.
@@ -81,56 +87,36 @@ namespace Handbrake.Services get
{
if (IsScanning)
- return readData.Buffer;
+ return readData.Buffer.ToString();
+
+ if (logBuffer == null)
+ {
+ ResetLogReader();
+ ReadLastScanFile();
+ }
- ReadFile();
- return logBuffer.ToString();
+ return logBuffer != null ? logBuffer.ToString() : string.Empty;
}
}
+ /* Public Methods */
+
/// <summary>
/// Scan a Source Path.
/// Title 0: scan all
/// </summary>
/// <param name="sourcePath">Path to the file to scan</param>
/// <param name="title">int title number. 0 for scan all</param>
- public void ScanSource(string sourcePath, int title)
+ public void Scan(string sourcePath, int title)
{
- Thread t = new Thread(unused => this.RunScan(sourcePath, title));
+ Thread t = new Thread(unused => this.ScanSource(sourcePath, title));
t.Start();
}
/// <summary>
- /// Object containing the information parsed in the scan.
- /// </summary>
- /// <returns>The DVD object containing the scan information</returns>
- public DVD SouceData()
- {
- return this.thisDvd;
- }
-
- /// <summary>
- /// Progress of the scan.
- /// </summary>
- /// <returns>The progress of the scan</returns>
- public string ScanStatus()
- {
- return this.scanProgress;
- }
-
- /// <summary>
- /// The Scan Process
- /// </summary>
- /// <returns>The CLI process</returns>
- public Process ScanProcess()
- {
- return this.hbProc;
- }
-
- /// <summary>
/// Kill the scan
/// </summary>
- public void KillScan()
+ public void Stop()
{
try
{
@@ -145,12 +131,14 @@ namespace Handbrake.Services }
}
+ /* Private Methods */
+
/// <summary>
/// Start a scan for a given source path and title
/// </summary>
/// <param name="sourcePath">Path to the source file</param>
/// <param name="title">the title number to look at</param>
- private void RunScan(object sourcePath, int title)
+ private void ScanSource(object sourcePath, int title)
{
try
{
@@ -177,52 +165,58 @@ namespace Handbrake.Services extraArguments += " --scan ";
this.hbProc = new Process
- {
- StartInfo =
- {
- FileName = handbrakeCLIPath,
- Arguments =
- String.Format(@" -i ""{0}"" -t{1} {2} -v ", sourcePath, title, extraArguments),
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- UseShellExecute = false,
- CreateNoWindow = true
- }
- };
+ {
+ StartInfo =
+ {
+ FileName = handbrakeCLIPath,
+ Arguments =
+ String.Format(@" -i ""{0}"" -t{1} {2} -v ", sourcePath, title,
+ extraArguments),
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ UseShellExecute = false,
+ CreateNoWindow = true
+ }
+ };
// Start the Scan
this.hbProc.Start();
this.readData = new Parser(this.hbProc.StandardError.BaseStream);
this.readData.OnScanProgress += new ScanProgressEventHandler(this.OnScanProgress);
- this.thisDvd = DVD.Parse(this.readData);
+ this.SouceData = DVD.Parse(this.readData);
// Write the Buffer out to file.
StreamWriter scanLog = new StreamWriter(dvdInfoPath);
scanLog.Write(this.readData.Buffer);
scanLog.Flush();
scanLog.Close();
+ logBuffer = readData.Buffer;
+
+ IsScanning = false;
if (this.ScanCompleted != null)
this.ScanCompleted(this, new EventArgs());
- IsScanning = false;
}
catch (Exception exc)
{
- Console.WriteLine("frmMain.cs - scanProcess() " + exc);
+ frmExceptionWindow exceptionWindow = new frmExceptionWindow();
+ exceptionWindow.Setup("frmMain.cs - scanProcess() Error", exc.ToString());
+ exceptionWindow.ShowDialog();
}
- }
+ }
/// <summary>
/// Read the log file
/// </summary>
- private void ReadFile()
+ private void ReadLastScanFile()
{
lock (locker)
{
// 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_scan_log.txt");
string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");
@@ -258,8 +252,9 @@ namespace Handbrake.Services sr.Close();
sr.Dispose();
}
- catch (Exception)
+ catch (Exception exc)
{
+ Console.WriteLine(exc.ToString());
ResetLogReader();
}
}
@@ -282,7 +277,7 @@ namespace Handbrake.Services /// <param name="titleCount">the total number of titles</param>
private void OnScanProgress(object sender, int currentTitle, int titleCount)
{
- this.scanProgress = string.Format("Processing Title: {0} of {1}", currentTitle, titleCount);
+ this.ScanStatus = string.Format("Processing Title: {0} of {1}", currentTitle, titleCount);
if (this.ScanStatusChanged != null)
this.ScanStatusChanged(this, new EventArgs());
}
|