{\r
public partial class frmActivityWindow : Form\r
{\r
- private delegate void SetTextCallback(string text);\r
- private String read_file;\r
- private Thread monitor;\r
- private EncodeAndQueueHandler encodeQueue;\r
- private int position; // Position in the arraylist reached by the current log output in the rtf box.\r
- private string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
- private frmMain mainWin;\r
- private Boolean lastUpdate;\r
+ private delegate void setTextCallback(string text);\r
+ private String _readFile;\r
+ private readonly EncodeAndQueueHandler _encodeQueue;\r
+ private int _position; // Position in the arraylist reached by the current log output in the rtf box.\r
+ private readonly frmMain _mainWin;\r
+ private Boolean _lastUpdate;\r
\r
public frmActivityWindow(string file, EncodeAndQueueHandler eh, frmMain mw)\r
{\r
InitializeComponent();\r
\r
- encodeQueue = eh;\r
- mainWin = mw;\r
+ _encodeQueue = eh;\r
+ _mainWin = mw;\r
\r
if (file == "last_scan_log.txt")\r
- setLogView(true);\r
+ SetLogView(true);\r
else\r
- setLogView(false);\r
+ SetLogView(false);\r
\r
// Start a new thread which will montior and keep the log window up to date if required/\r
- startLogThread(read_file);\r
+ try\r
+ {\r
+ Thread monitor = new Thread(AutoUpdate) { IsBackground = true };\r
+ monitor.Start();\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show("startLogThread(): Exception: \n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ }\r
}\r
\r
/// <summary>\r
/// Encode = false;\r
/// </summary>\r
/// <param name="scan">Boolean. Scan = true</param>\r
- public void setLogView(Boolean scan)\r
+ public void SetLogView(Boolean scan)\r
{\r
- position = 0;\r
+ // Reset\r
+ _position = 0;\r
rtf_actLog.Text = String.Empty;\r
- displayLogHeader();\r
\r
- if (scan)\r
- {\r
- txt_log.Text = "Scan Log";\r
- read_file = "last_scan_log.txt";\r
- }\r
- else\r
- {\r
- read_file = "last_encode_log.txt";\r
- txt_log.Text = "Encode Log";\r
- }\r
- lastUpdate = false;\r
- }\r
- private void displayLogHeader()\r
- {\r
- // Add a header to the log file indicating that it's from the Windows GUI and display the windows version\r
+ // Print the log header\r
rtf_actLog.AppendText(String.Format("### Windows GUI {1} {0} \n", Properties.Settings.Default.hb_build, Properties.Settings.Default.hb_version));\r
rtf_actLog.AppendText(String.Format("### Running: {0} \n###\n", Environment.OSVersion));\r
rtf_actLog.AppendText(String.Format("### CPU: {0} \n", getCpuCount()));\r
rtf_actLog.AppendText(String.Format("### Install Dir: {0} \n", Application.StartupPath));\r
rtf_actLog.AppendText(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));\r
rtf_actLog.AppendText("#########################################\n\n");\r
- if (encodeQueue.isEncoding && encodeQueue.LastEncode.Query != String.Empty)\r
+ if ((!_encodeQueue.LastEncode.IsEmpty) && _encodeQueue.LastEncode.Query != String.Empty)\r
{\r
- rtf_actLog.AppendText("### CLI Query: " + encodeQueue.LastEncode.Query + "\n\n");\r
+ rtf_actLog.AppendText("### CLI Query: " + _encodeQueue.LastEncode.Query + "\n\n");\r
rtf_actLog.AppendText("#########################################\n\n");\r
}\r
- }\r
- private void startLogThread(string file)\r
- {\r
- try\r
- {\r
- string logFile = Path.Combine(logDir, file);\r
- if (File.Exists(logFile))\r
- {\r
- monitor = new Thread(autoUpdate) { IsBackground = true };\r
- monitor.Start();\r
- }\r
- else\r
- 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);\r
\r
+ // Seutp the log file\r
+ if (scan)\r
+ {\r
+ txt_log.Text = "Scan Log";\r
+ _readFile = "last_scan_log.txt";\r
}\r
- catch (Exception exc)\r
+ else\r
{\r
- MessageBox.Show("startLogThread(): Exception: \n" + exc);\r
+ _readFile = "last_encode_log.txt";\r
+ txt_log.Text = "Encode Log";\r
}\r
+ _lastUpdate = false;\r
}\r
- private void autoUpdate(object state)\r
+\r
+ private void AutoUpdate(object state)\r
{\r
try\r
{\r
- lastUpdate = false;\r
- updateTextFromThread();\r
+ _lastUpdate = false;\r
+ UpdateTextFromThread();\r
while (true)\r
{\r
if (IsHandleCreated)\r
{\r
- if (encodeQueue.isEncoding || mainWin.isScanning)\r
- updateTextFromThread();\r
+ if (_encodeQueue.isEncoding || _mainWin.isScanning)\r
+ UpdateTextFromThread();\r
else\r
{\r
// The encode may just have stoped, so, refresh the log one more time before restarting it.\r
- if (lastUpdate == false)\r
- updateTextFromThread();\r
+ if (_lastUpdate == false)\r
+ UpdateTextFromThread();\r
\r
- lastUpdate = true; // Prevents the log window from being updated when there is no encode going.\r
- position = 0; // There is no encoding, so reset the log position counter to 0 so it can be reused\r
+ _lastUpdate = true; // Prevents the log window from being updated when there is no encode going.\r
+ _position = 0; // There is no encoding, so reset the log position counter to 0 so it can be reused\r
}\r
}\r
Thread.Sleep(1000);\r
}\r
catch (Exception exc)\r
{\r
- MessageBox.Show("autoUpdate(): Exception: \n" + exc);\r
+ MessageBox.Show("AutoUpdate(): Exception: \n" + exc);\r
}\r
}\r
- private void updateTextFromThread()\r
+ private void UpdateTextFromThread()\r
{\r
try\r
{\r
- String info = readFile();\r
+ String info = ReadFile();\r
if (info.Contains("has exited"))\r
info += "\n ############ End of Log ############## \n";\r
\r
}\r
catch (Exception exc)\r
{\r
- MessageBox.Show("updateTextFromThread(): Exception: \n" + exc);\r
+ MessageBox.Show("UpdateTextFromThread(): Exception: \n" + exc);\r
}\r
}\r
private void SetText(string text)\r
{\r
if (rtf_actLog.InvokeRequired)\r
{\r
- IAsyncResult invoked = BeginInvoke(new SetTextCallback(SetText), new object[] {text});\r
+ IAsyncResult invoked = BeginInvoke(new setTextCallback(SetText), new object[] { text });\r
EndInvoke(invoked);\r
- } else \r
+ }\r
+ else\r
rtf_actLog.AppendText(text);\r
}\r
}\r
MessageBox.Show("SetText(): Exception: \n" + exc);\r
}\r
}\r
- private String readFile()\r
+ private String ReadFile()\r
{\r
String appendText = String.Empty;\r
try\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 logFile = Path.Combine(logDir, read_file);\r
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+ string logFile = Path.Combine(logDir, _readFile);\r
string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");\r
\r
// Make sure the application readable log file does not already exist. FileCopy fill fail if it does.\r
File.Delete(logFile2);\r
\r
// Copy the log file.\r
- File.Copy(logFile, logFile2);\r
+ if (File.Exists(logFile))\r
+ File.Copy(logFile, logFile2);\r
+ else\r
+ 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;\r
\r
// Open the copied log file for reading\r
StreamReader sr = new StreamReader(logFile2);\r
int i = 1;\r
while ((line = sr.ReadLine()) != null)\r
{\r
- if (i > position)\r
+ if (i > _position)\r
{\r
appendText += line + Environment.NewLine;\r
- position++;\r
+ _position++;\r
}\r
i++;\r
}\r
}\r
catch (Exception exc)\r
{\r
- 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);\r
+ 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);\r
}\r
return null;\r
}\r
}\r
private void btn_scan_log_Click(object sender, EventArgs e)\r
{\r
- setLogView(true);\r
+ SetLogView(true);\r
}\r
private void btn_encode_log_Click(object sender, EventArgs e)\r
{\r
- setLogView(false);\r
+ SetLogView(false);\r
}\r
#endregion\r
\r