diff options
author | sr55 <[email protected]> | 2009-09-07 09:01:22 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2009-09-07 09:01:22 +0000 |
commit | ca462aa5deeba2b4ffd1b114074d61620cd07e98 (patch) | |
tree | 121b884632790adde9fd35531ae7cb9271076a28 /win/C#/frmActivityWindow.cs | |
parent | 74302fd6044b633bcd683bb8e6a0faa39d113732 (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/C#/frmActivityWindow.cs')
-rw-r--r-- | win/C#/frmActivityWindow.cs | 134 |
1 files changed, 63 insertions, 71 deletions
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
|