It may be used under the terms of the GNU General Public License. */\r
\r
using System;\r
-using System.Collections.Generic;\r
using System.Windows.Forms;\r
using System.IO;\r
using System.Threading;\r
-using System.Runtime.InteropServices;\r
+using Handbrake.EncodeQueue;\r
+using Handbrake.Functions;\r
using Microsoft.Win32;\r
\r
\r
delegate void SetTextCallback(string text);\r
String read_file;\r
Thread monitor;\r
- Functions.Encode encodeHandler;\r
+ QueueHandler encodeQueue;\r
int position; // Position in the arraylist reached by the current log output in the rtf box.\r
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+ private frmMain mainWin;\r
\r
/// <summary>\r
/// This window should be used to display the RAW output of the handbrake CLI which is produced during an encode.\r
/// </summary>\r
- public frmActivityWindow(string file, Functions.Encode eh)\r
+ public frmActivityWindow(string file, QueueHandler eh, frmMain mw)\r
{\r
InitializeComponent();\r
- this.rtf_actLog.Text = string.Empty;\r
\r
- // When the window closes, we want to abort the monitor thread.\r
- this.Disposed += new EventHandler(forceQuit);\r
-\r
- encodeHandler = eh;\r
+ rtf_actLog.Text = string.Empty;\r
+ encodeQueue = eh;\r
read_file = file;\r
position = 0;\r
+ mainWin = mw;\r
+ \r
+ // When the window closes, we want to abort the monitor thread.\r
+ this.Disposed += new EventHandler(forceQuit);\r
\r
// Print the Log header in the Rich text box.\r
displayLogHeader();\r
\r
- if (file == "dvdinfo.dat")\r
+ if (file == "last_scan_log.txt")\r
txt_log.Text = "Scan Log";\r
- else if (file == "hb_encode_log.dat")\r
+ else if (file == "last_encode_log.txt")\r
txt_log.Text = "Encode Log";\r
\r
// Start a new thread which will montior and keep the log window up to date if required/\r
- startLogThread(read_file); \r
+ startLogThread(read_file);\r
}\r
\r
/// <summary>\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
+ {\r
+ rtf_actLog.AppendText("### CLI Query: " + encodeQueue.LastEncode.Query + "\n\n");\r
+ rtf_actLog.AppendText("#########################################\n\n");\r
+ }\r
}\r
\r
/// <summary>\r
{\r
try\r
{\r
- string logFile = Path.Combine(Path.GetTempPath(), file);\r
+ string logFile = Path.Combine(logDir, file);\r
if (File.Exists(logFile))\r
{\r
// Start a new thread to run the autoUpdate process\r
}\r
\r
/// <summary>\r
- /// Change the log file to be displayed to hb_encode_log.dat\r
- /// </summary>\r
- /// <param name="sender"></param>\r
- /// <param name="e"></param>\r
- private void btn_scan_log_Click(object sender, EventArgs e)\r
- {\r
- if (monitor != null)\r
- monitor.Abort();\r
-\r
- rtf_actLog.Clear();\r
- read_file = "dvdinfo.dat";\r
- displayLogHeader();\r
- startLogThread(read_file);\r
- txt_log.Text = "Scan Log";\r
- }\r
-\r
- /// <summary>\r
- /// Change the log file to be displayed to dvdinfo.dat\r
- /// </summary>\r
- /// <param name="sender"></param>\r
- /// <param name="e"></param>\r
- private void btn_encode_log_Click(object sender, EventArgs e)\r
- {\r
- if (monitor != null)\r
- monitor.Abort();\r
-\r
- rtf_actLog.Clear();\r
- read_file = "hb_encode_log.dat";\r
- position = 0;\r
- displayLogHeader();\r
- startLogThread(read_file);\r
- txt_log.Text = "Encode Log";\r
- }\r
-\r
- /// <summary>\r
- /// Copy to Clipboard\r
- /// </summary>\r
- /// <param name="sender"></param>\r
- /// <param name="e"></param>\r
- private void btn_copy_Click(object sender, EventArgs e)\r
- {\r
- if (rtf_actLog.SelectedText != "")\r
- Clipboard.SetDataObject(rtf_actLog.SelectedText, true);\r
- else\r
- Clipboard.SetDataObject(rtf_actLog.Text, true);\r
- }\r
-\r
- /// <summary>\r
/// Updates the log window with any new data which is in the log file.\r
/// This is done every 5 seconds.\r
/// </summary>\r
updateTextFromThread();\r
while (true)\r
{\r
- if (encodeHandler.isEncoding)\r
+ if (encodeQueue.IsEncoding || mainWin.isScanning)\r
updateTextFromThread();\r
else\r
{\r
{\r
try\r
{\r
- string text;\r
- List<string> data = readFile();\r
- int count = data.Count;\r
+ String info = readFile();\r
+ if (info.Contains("has exited"))\r
+ info += "\n ############ End of Log ############## \n";\r
\r
- while (position < count)\r
- {\r
- text = data[position];\r
- if (data[position].Contains("has exited"))\r
- text = "\n ############ End of Log ############## \n";\r
- position++;\r
-\r
- SetText(text);\r
- }\r
+ SetText(info);\r
}\r
catch (Exception exc)\r
{\r
/// Read the log file, and store the data in a List.\r
/// </summary>\r
/// <returns></returns>\r
- private List<string> readFile()\r
+ private String readFile()\r
{\r
- // Ok, the task here is to, Get an arraylist of log data.\r
- // And update some global varibles which are pointers to the last displayed log line.\r
- List<string> logData = new List<string>();\r
-\r
+ String appendText = String.Empty;\r
try\r
{\r
- // hb_encode_log.dat 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
+ // 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(Path.GetTempPath(), read_file);\r
- string logFile2 = Path.Combine(Path.GetTempPath(), "hb_encode_log_AppReadable.dat");\r
+ string logFile = Path.Combine(logDir, read_file);\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
if (File.Exists(logFile2))\r
\r
// Open the copied log file for reading\r
StreamReader sr = new StreamReader(logFile2);\r
- string line = sr.ReadLine();\r
- while (line != null)\r
+ string line;\r
+ int i = 1;\r
+ while ((line = sr.ReadLine()) != null)\r
{\r
- if (line.Trim() != "")\r
- logData.Add(line + Environment.NewLine);\r
-\r
- line = sr.ReadLine();\r
+ if (i > position)\r
+ {\r
+ appendText += line + Environment.NewLine;\r
+ position++;\r
+ }\r
+ i++;\r
}\r
sr.Close();\r
sr.Dispose();\r
\r
- return logData;\r
+ return appendText;\r
}\r
catch (Exception exc)\r
{\r
this.Close();\r
}\r
\r
- /// <summary>\r
- /// Copy Log Menu Item on the right click menu for the log rtf box\r
- /// </summary>\r
- /// <param name="sender"></param>\r
- /// <param name="e"></param>\r
+ #region User Interface\r
+\r
private void mnu_copy_log_Click(object sender, EventArgs e)\r
{\r
if (rtf_actLog.SelectedText != "")\r
else\r
Clipboard.SetDataObject(rtf_actLog.Text, true);\r
}\r
+ private void mnu_openLogFolder_Click(object sender, EventArgs e)\r
+ {\r
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+ string windir = Environment.GetEnvironmentVariable("WINDIR");\r
+ System.Diagnostics.Process prc = new System.Diagnostics.Process();\r
+ prc.StartInfo.FileName = windir + @"\explorer.exe";\r
+ prc.StartInfo.Arguments = logDir;\r
+ prc.Start();\r
+ }\r
+ private void btn_copy_Click(object sender, EventArgs e)\r
+ {\r
+ if (rtf_actLog.SelectedText != "")\r
+ Clipboard.SetDataObject(rtf_actLog.SelectedText, true);\r
+ else\r
+ Clipboard.SetDataObject(rtf_actLog.Text, true);\r
+ }\r
+ private void btn_scan_log_Click(object sender, EventArgs e)\r
+ {\r
+ // Switch to the scan log.\r
\r
- #region System Information\r
- private struct MEMORYSTATUS // Unused var's are requred here.\r
+ if (monitor != null)\r
+ monitor.Abort();\r
+\r
+ rtf_actLog.Clear();\r
+ read_file = "last_scan_log.txt";\r
+ displayLogHeader();\r
+ startLogThread(read_file);\r
+ txt_log.Text = "Scan Log";\r
+ }\r
+ private void btn_encode_log_Click(object sender, EventArgs e)\r
{\r
- public UInt32 dwLength;\r
- public UInt32 dwMemoryLoad;\r
- public UInt32 dwTotalPhys; // Used\r
- public UInt32 dwAvailPhys;\r
- public UInt32 dwTotalPageFile;\r
- public UInt32 dwAvailPageFile;\r
- public UInt32 dwTotalVirtual;\r
- public UInt32 dwAvailVirtual;\r
+ // Switch to the encode log\r
+\r
+ if (monitor != null)\r
+ monitor.Abort();\r
+\r
+ rtf_actLog.Clear();\r
+ read_file = "last_encode_log.txt";\r
+ position = 0;\r
+ displayLogHeader();\r
+ startLogThread(read_file);\r
+ txt_log.Text = "Encode Log";\r
}\r
\r
- [DllImport("kernel32.dll")]\r
- private static extern void GlobalMemoryStatus\r
- (\r
- ref MEMORYSTATUS lpBuffer\r
- );\r
+ #endregion\r
+\r
+ #region System Information\r
+ \r
\r
/// <summary>\r
/// Returns the total physical ram in a system\r
/// <returns></returns>\r
public uint TotalPhysicalMemory()\r
{\r
- MEMORYSTATUS memStatus = new MEMORYSTATUS();\r
- GlobalMemoryStatus(ref memStatus);\r
+ Win32.MEMORYSTATUS memStatus = new Win32.MEMORYSTATUS();\r
+ Win32.GlobalMemoryStatus(ref memStatus);\r
\r
uint MemoryInfo = memStatus.dwTotalPhys;\r
MemoryInfo = MemoryInfo / 1024 / 1024;\r