1 /* frmActivityWindow.cs $
\r
3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.ComponentModel;
\r
10 using System.Windows.Forms;
\r
12 using System.Threading;
\r
13 using Handbrake.EncodeQueue;
\r
14 using Handbrake.Functions;
\r
15 using Microsoft.Win32;
\r
20 public partial class frmActivityWindow : Form
\r
22 private delegate void setTextCallback(StringBuilder text);
\r
23 private delegate void setTextClearCallback();
\r
24 private static int _position;
\r
25 private static string _lastMode;
\r
26 private static string _currentMode;
\r
27 private Thread monitor;
\r
28 private Boolean kilLThread;
\r
30 public frmActivityWindow()
\r
32 InitializeComponent();
\r
34 private void NewActivityWindow_Load(object sender, EventArgs e)
\r
37 monitor = new Thread(LogMonitor);
\r
45 catch (Exception exc)
\r
47 MessageBox.Show(exc.ToString());
\r
51 private void LogMonitor()
\r
55 if (!IsHandleCreated || kilLThread) // break out the thread if the window has been disposed.
\r
58 // Perform a reset if require.
\r
59 // If we have switched to a different log file, we want to start from the beginning.
\r
60 if (SetLogFile != _lastMode)
\r
67 // Perform the window update
\r
70 case "last_scan_log.txt":
\r
71 AppendWindowText(ReadFile("last_scan_log.txt"));
\r
72 _lastMode = "last_scan_log.txt";
\r
74 case "last_encode_log.txt":
\r
75 AppendWindowText(ReadFile("last_encode_log.txt"));
\r
76 _lastMode = "last_encode_log.txt";
\r
83 private StringBuilder ReadFile(string file)
\r
85 StringBuilder appendText = new StringBuilder();
\r
87 // 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
88 // we'll need to make a copy of it.
\r
89 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
90 string logFile = Path.Combine(logDir, file);
\r
91 string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");
\r
95 // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.
\r
96 if (File.Exists(logFile2))
\r
97 File.Delete(logFile2);
\r
99 // Copy the log file.
\r
100 if (File.Exists(logFile))
\r
101 File.Copy(logFile, logFile2, true);
\r
104 appendText.AppendFormat("Waiting for the log file to be generated ...\n");
\r
111 // Start the Reader
\r
112 // Only use text which continues on from the last read line
\r
113 StreamReader sr = new StreamReader(logFile2);
\r
116 while ((line = sr.ReadLine()) != null)
\r
120 appendText.AppendLine(line);
\r
129 catch (Exception exc)
\r
131 appendText.AppendFormat("\nERROR: The Log file could not be read. You may need to restart HandBrake! " + exc);
\r
137 private void AppendWindowText(StringBuilder text)
\r
141 if (IsHandleCreated)
\r
143 if (rtf_actLog.InvokeRequired)
\r
145 IAsyncResult invoked = BeginInvoke(new setTextCallback(AppendWindowText), new object[] { text });
\r
146 EndInvoke(invoked);
\r
149 rtf_actLog.AppendText(text.ToString());
\r
152 catch (Exception exc)
\r
154 MessageBox.Show("SetWindowText(): Exception: \n" + exc);
\r
157 private void ClearWindowText()
\r
161 if (IsHandleCreated)
\r
163 if (rtf_actLog.InvokeRequired)
\r
165 IAsyncResult invoked = BeginInvoke(new setTextClearCallback(ClearWindowText));
\r
166 EndInvoke(invoked);
\r
169 rtf_actLog.Clear();
\r
172 catch (Exception exc)
\r
174 MessageBox.Show("ClearWindowText(): Exception: \n" + exc);
\r
177 public void PrintLogHeader()
\r
181 if (IsHandleCreated)
\r
183 if (rtf_actLog.InvokeRequired)
\r
185 IAsyncResult invoked = BeginInvoke(new setTextClearCallback(PrintLogHeader));
\r
186 EndInvoke(invoked);
\r
190 // Print the log header. This function will be re-implimented later. Do not delete.
\r
191 rtf_actLog.AppendText(String.Format("### Windows GUI {1} {0} \n", Properties.Settings.Default.hb_build, Properties.Settings.Default.hb_version));
\r
192 rtf_actLog.AppendText(String.Format("### Running: {0} \n###\n", Environment.OSVersion));
\r
193 rtf_actLog.AppendText(String.Format("### CPU: {0} \n", getCpuCount()));
\r
194 rtf_actLog.AppendText(String.Format("### Ram: {0} MB \n", TotalPhysicalMemory()));
\r
195 rtf_actLog.AppendText(String.Format("### Screen: {0}x{1} \n", screenBounds().Bounds.Width, screenBounds().Bounds.Height));
\r
196 rtf_actLog.AppendText(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));
\r
197 rtf_actLog.AppendText(String.Format("### Install Dir: {0} \n", Application.StartupPath));
\r
198 rtf_actLog.AppendText(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));
\r
199 rtf_actLog.AppendText("#########################################\n\n");
\r
203 catch (Exception exc)
\r
205 MessageBox.Show("PrintLogHeader(): Exception: \n" + exc);
\r
212 public string SetLogFile
\r
214 get { return string.IsNullOrEmpty(_currentMode) ? "" : _currentMode; }
\r
215 set { _currentMode = value; }
\r
217 public void SetScanMode()
\r
219 SetLogFile = "last_scan_log.txt";
\r
220 this.Text = "Activity Window (Scan Log)";
\r
222 public void SetEncodeMode()
\r
224 SetLogFile = "last_encode_log.txt";
\r
225 this.Text = "Activity Window (Enocde Log)";
\r
230 #region User Interface
\r
231 private void mnu_copy_log_Click(object sender, EventArgs e)
\r
233 if (rtf_actLog.SelectedText != "")
\r
234 Clipboard.SetDataObject(rtf_actLog.SelectedText, true);
\r
236 Clipboard.SetDataObject(rtf_actLog.Text, true);
\r
238 private void mnu_openLogFolder_Click(object sender, EventArgs e)
\r
240 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
241 string windir = Environment.GetEnvironmentVariable("WINDIR");
\r
242 System.Diagnostics.Process prc = new System.Diagnostics.Process();
\r
243 prc.StartInfo.FileName = windir + @"\explorer.exe";
\r
244 prc.StartInfo.Arguments = logDir;
\r
247 private void btn_copy_Click(object sender, EventArgs e)
\r
249 if (rtf_actLog.SelectedText != "")
\r
250 Clipboard.SetDataObject(rtf_actLog.SelectedText, true);
\r
252 Clipboard.SetDataObject(rtf_actLog.Text, true);
\r
254 private void btn_scan_log_Click(object sender, EventArgs e)
\r
258 private void btn_encode_log_Click(object sender, EventArgs e)
\r
264 #region System Information
\r
266 /// Returns the total physical ram in a system
\r
268 /// <returns></returns>
\r
269 public uint TotalPhysicalMemory()
\r
271 Win32.MEMORYSTATUS memStatus = new Win32.MEMORYSTATUS();
\r
272 Win32.GlobalMemoryStatus(ref memStatus);
\r
274 uint MemoryInfo = memStatus.dwTotalPhys;
\r
275 MemoryInfo = MemoryInfo / 1024 / 1024;
\r
281 /// Get the number of CPU Cores
\r
283 /// <returns>Object</returns>
\r
284 public Object getCpuCount()
\r
286 RegistryKey RegKey = Registry.LocalMachine;
\r
287 RegKey = RegKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
\r
288 return RegKey.GetValue("ProcessorNameString");
\r
292 /// Get the System screen size information.
\r
294 /// <returns>System.Windows.Forms.Scree</returns>
\r
295 public Screen screenBounds()
\r
297 return Screen.PrimaryScreen;
\r
301 protected override void OnClosing(CancelEventArgs e)
\r