summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorsr55 <[email protected]>2009-09-07 09:01:22 +0000
committersr55 <[email protected]>2009-09-07 09:01:22 +0000
commitca462aa5deeba2b4ffd1b114074d61620cd07e98 (patch)
tree121b884632790adde9fd35531ae7cb9271076a28 /win
parent74302fd6044b633bcd683bb8e6a0faa39d113732 (diff)
WinGui:
- Some fixes to the ActivityWindow. CLI query should always be displayed now. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2807 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win')
-rw-r--r--win/C#/EncodeQueue/EncodeAndQueueHandler.cs7
-rw-r--r--win/C#/frmActivityWindow.cs134
-rw-r--r--win/C#/frmMain.cs8
3 files changed, 72 insertions, 77 deletions
diff --git a/win/C#/EncodeQueue/EncodeAndQueueHandler.cs b/win/C#/EncodeQueue/EncodeAndQueueHandler.cs
index 6d8a2ce2f..93cab845a 100644
--- a/win/C#/EncodeQueue/EncodeAndQueueHandler.cs
+++ b/win/C#/EncodeQueue/EncodeAndQueueHandler.cs
@@ -336,6 +336,7 @@ namespace Handbrake.EncodeQueue
Thread.Sleep(5000);
}
}
+ LastEncode = new Job();
if (QueueCompleted != null)
QueueCompleted(this, new EventArgs());
@@ -361,6 +362,8 @@ namespace Handbrake.EncodeQueue
{
try
{
+ 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, query, logPath);
@@ -376,8 +379,7 @@ namespace Handbrake.EncodeQueue
Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.
hbProcess = Process.Start(cliStart);
- processID = Main.getCliProcess(before);
- isEncoding = true;
+ processID = Main.getCliProcess(before);
currentQuery = query;
if (hbProcess != null)
processHandle = hbProcess.MainWindowHandle; // Set the process Handle
@@ -414,7 +416,6 @@ namespace Handbrake.EncodeQueue
{
MessageBox.Show("It would appear that HandBrakeCLI has not started correctly. You should take a look at the Activity log as it may indicate the reason why.\n\n Detailed Error Information: error occured in runCli()\n\n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
-
}
/// <summary>
diff --git a/win/C#/frmActivityWindow.cs b/win/C#/frmActivityWindow.cs
index c09920126..86ed53d06 100644
--- a/win/C#/frmActivityWindow.cs
+++ b/win/C#/frmActivityWindow.cs
@@ -18,29 +18,35 @@ namespace Handbrake
{
public partial class frmActivityWindow : Form
{
- private delegate void SetTextCallback(string text);
- private String read_file;
- private Thread monitor;
- private EncodeAndQueueHandler encodeQueue;
- private int position; // Position in the arraylist reached by the current log output in the rtf box.
- private string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
- private frmMain mainWin;
- private Boolean lastUpdate;
+ private delegate void setTextCallback(string text);
+ private String _readFile;
+ private readonly EncodeAndQueueHandler _encodeQueue;
+ private int _position; // Position in the arraylist reached by the current log output in the rtf box.
+ private readonly frmMain _mainWin;
+ private Boolean _lastUpdate;
public frmActivityWindow(string file, EncodeAndQueueHandler eh, frmMain mw)
{
InitializeComponent();
- encodeQueue = eh;
- mainWin = mw;
+ _encodeQueue = eh;
+ _mainWin = mw;
if (file == "last_scan_log.txt")
- setLogView(true);
+ SetLogView(true);
else
- setLogView(false);
+ SetLogView(false);
// Start a new thread which will montior and keep the log window up to date if required/
- startLogThread(read_file);
+ try
+ {
+ Thread monitor = new Thread(AutoUpdate) { IsBackground = true };
+ monitor.Start();
+ }
+ catch (Exception exc)
+ {
+ MessageBox.Show("startLogThread(): Exception: \n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
}
/// <summary>
@@ -49,27 +55,13 @@ namespace Handbrake
/// Encode = false;
/// </summary>
/// <param name="scan">Boolean. Scan = true</param>
- public void setLogView(Boolean scan)
+ public void SetLogView(Boolean scan)
{
- position = 0;
+ // Reset
+ _position = 0;
rtf_actLog.Text = String.Empty;
- displayLogHeader();
- if (scan)
- {
- txt_log.Text = "Scan Log";
- read_file = "last_scan_log.txt";
- }
- else
- {
- read_file = "last_encode_log.txt";
- txt_log.Text = "Encode Log";
- }
- lastUpdate = false;
- }
- private void displayLogHeader()
- {
- // Add a header to the log file indicating that it's from the Windows GUI and display the windows version
+ // Print the log header
rtf_actLog.AppendText(String.Format("### Windows GUI {1} {0} \n", Properties.Settings.Default.hb_build, Properties.Settings.Default.hb_version));
rtf_actLog.AppendText(String.Format("### Running: {0} \n###\n", Environment.OSVersion));
rtf_actLog.AppendText(String.Format("### CPU: {0} \n", getCpuCount()));
@@ -79,51 +71,46 @@ namespace Handbrake
rtf_actLog.AppendText(String.Format("### Install Dir: {0} \n", Application.StartupPath));
rtf_actLog.AppendText(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));
rtf_actLog.AppendText("#########################################\n\n");
- if (encodeQueue.isEncoding && encodeQueue.LastEncode.Query != String.Empty)
+ if ((!_encodeQueue.LastEncode.IsEmpty) && _encodeQueue.LastEncode.Query != String.Empty)
{
- rtf_actLog.AppendText("### CLI Query: " + encodeQueue.LastEncode.Query + "\n\n");
+ rtf_actLog.AppendText("### CLI Query: " + _encodeQueue.LastEncode.Query + "\n\n");
rtf_actLog.AppendText("#########################################\n\n");
}
- }
- private void startLogThread(string file)
- {
- try
- {
- string logFile = Path.Combine(logDir, file);
- if (File.Exists(logFile))
- {
- monitor = new Thread(autoUpdate) { IsBackground = true };
- monitor.Start();
- }
- else
- rtf_actLog.AppendText("\n\n\nERROR: The log file could not be found. \nMaybe you cleared your system's tempory folder or maybe you just havn't run an encode yet. \nTried to find the log file in: " + logFile);
+ // Seutp the log file
+ if (scan)
+ {
+ txt_log.Text = "Scan Log";
+ _readFile = "last_scan_log.txt";
}
- catch (Exception exc)
+ else
{
- MessageBox.Show("startLogThread(): Exception: \n" + exc);
+ _readFile = "last_encode_log.txt";
+ txt_log.Text = "Encode Log";
}
+ _lastUpdate = false;
}
- private void autoUpdate(object state)
+
+ private void AutoUpdate(object state)
{
try
{
- lastUpdate = false;
- updateTextFromThread();
+ _lastUpdate = false;
+ UpdateTextFromThread();
while (true)
{
if (IsHandleCreated)
{
- if (encodeQueue.isEncoding || mainWin.isScanning)
- updateTextFromThread();
+ if (_encodeQueue.isEncoding || _mainWin.isScanning)
+ UpdateTextFromThread();
else
{
// The encode may just have stoped, so, refresh the log one more time before restarting it.
- if (lastUpdate == false)
- updateTextFromThread();
+ if (_lastUpdate == false)
+ UpdateTextFromThread();
- lastUpdate = true; // Prevents the log window from being updated when there is no encode going.
- position = 0; // There is no encoding, so reset the log position counter to 0 so it can be reused
+ _lastUpdate = true; // Prevents the log window from being updated when there is no encode going.
+ _position = 0; // There is no encoding, so reset the log position counter to 0 so it can be reused
}
}
Thread.Sleep(1000);
@@ -131,14 +118,14 @@ namespace Handbrake
}
catch (Exception exc)
{
- MessageBox.Show("autoUpdate(): Exception: \n" + exc);
+ MessageBox.Show("AutoUpdate(): Exception: \n" + exc);
}
}
- private void updateTextFromThread()
+ private void UpdateTextFromThread()
{
try
{
- String info = readFile();
+ String info = ReadFile();
if (info.Contains("has exited"))
info += "\n ############ End of Log ############## \n";
@@ -146,7 +133,7 @@ namespace Handbrake
}
catch (Exception exc)
{
- MessageBox.Show("updateTextFromThread(): Exception: \n" + exc);
+ MessageBox.Show("UpdateTextFromThread(): Exception: \n" + exc);
}
}
private void SetText(string text)
@@ -157,9 +144,10 @@ namespace Handbrake
{
if (rtf_actLog.InvokeRequired)
{
- IAsyncResult invoked = BeginInvoke(new SetTextCallback(SetText), new object[] {text});
+ IAsyncResult invoked = BeginInvoke(new setTextCallback(SetText), new object[] { text });
EndInvoke(invoked);
- } else
+ }
+ else
rtf_actLog.AppendText(text);
}
}
@@ -168,14 +156,15 @@ namespace Handbrake
MessageBox.Show("SetText(): Exception: \n" + exc);
}
}
- private String readFile()
+ private String ReadFile()
{
String appendText = String.Empty;
try
{
// 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 logFile = Path.Combine(logDir, read_file);
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
+ string logFile = Path.Combine(logDir, _readFile);
string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");
// Make sure the application readable log file does not already exist. FileCopy fill fail if it does.
@@ -183,7 +172,10 @@ namespace Handbrake
File.Delete(logFile2);
// Copy the log file.
- File.Copy(logFile, logFile2);
+ if (File.Exists(logFile))
+ File.Copy(logFile, logFile2);
+ else
+ return "\n\n\nERROR: The log file could not be found. \nMaybe you cleared your system's tempory folder or maybe you just havn't run an encode yet. \nTried to find the log file in: " + logFile;
// Open the copied log file for reading
StreamReader sr = new StreamReader(logFile2);
@@ -191,10 +183,10 @@ namespace Handbrake
int i = 1;
while ((line = sr.ReadLine()) != null)
{
- if (i > position)
+ if (i > _position)
{
appendText += line + Environment.NewLine;
- position++;
+ _position++;
}
i++;
}
@@ -205,7 +197,7 @@ namespace Handbrake
}
catch (Exception exc)
{
- MessageBox.Show("Error in readFile() \n Unable to read the log file.\n You may have to restart HandBrake.\n Error Information: \n\n" + exc, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ MessageBox.Show("Error in ReadFile() \n Unable to read the log file.\n You may have to restart HandBrake.\n Error Information: \n\n" + exc, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
return null;
}
@@ -243,11 +235,11 @@ namespace Handbrake
}
private void btn_scan_log_Click(object sender, EventArgs e)
{
- setLogView(true);
+ SetLogView(true);
}
private void btn_encode_log_Click(object sender, EventArgs e)
{
- setLogView(false);
+ SetLogView(false);
}
#endregion
diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs
index 3935b873f..a668cc69e 100644
--- a/win/C#/frmMain.cs
+++ b/win/C#/frmMain.cs
@@ -718,10 +718,12 @@ namespace Handbrake
queueWindow.Show(false);
setEncodeStarted(); // Encode is running, so setup the GUI appropriately
- if (ActivityWindow != null)
- ActivityWindow.setLogView(false);
encodeQueue.StartEncodeQueue(); // Start The Queue Encoding Process
lastAction = "encode"; // Set the last action to encode - Used for activity window.
+
+ if (ActivityWindow != null)
+ ActivityWindow.SetLogView(false);
+
}
this.Focus();
}
@@ -1412,7 +1414,7 @@ namespace Handbrake
try
{
if (ActivityWindow != null)
- ActivityWindow.setLogView(true);
+ ActivityWindow.SetLogView(true);
isScanning = true;
ThreadPool.QueueUserWorkItem(scanProcess);
}