1 /* frmActivityWindow.cs $
\r
2 This file is part of the HandBrake source code.
\r
3 Homepage: <http://handbrake.fr>.
\r
4 It may be used under the terms of the GNU General Public License. */
\r
9 using System.ComponentModel;
\r
10 using System.Diagnostics;
\r
13 using System.Threading;
\r
14 using System.Windows.Forms;
\r
18 using Timer = System.Threading.Timer;
\r
21 /// The Activity Log Window
\r
23 public partial class frmActivityWindow : Form
\r
26 /// The current position in the log file
\r
28 private int position;
\r
31 /// A Timer for this window
\r
33 private Timer windowTimer;
\r
36 /// The Encode Object
\r
38 private Encode encode;
\r
46 /// The Type of log that the window is currently dealing with
\r
48 private ActivityLogMode mode;
\r
51 /// Initializes a new instance of the <see cref="frmActivityWindow"/> class.
\r
53 /// <param name="mode">
\r
56 /// <param name="encode">
\r
59 /// <param name="scan">
\r
62 public frmActivityWindow(ActivityLogMode mode, Encode encode, Scan scan)
\r
64 InitializeComponent();
\r
66 this.encode = encode;
\r
73 /// A callback function for updating the ui
\r
75 /// <param name="text">
\r
78 private delegate void SetTextCallback(StringBuilder text);
\r
81 /// Clear text callback
\r
83 private delegate void SetTextClearCallback();
\r
88 /// Set the window to scan mode
\r
90 /// <param name="setMode">
\r
93 public void SetMode(ActivityLogMode setMode)
\r
96 this.mode = setMode;
\r
97 this.Text = mode == ActivityLogMode.Scan ? "Activity Window (Scan Log)" : "Activity Window (Enocde Log)";
\r
103 /// On Window load, start a new timer
\r
105 /// <param name="sender">
\r
108 /// <param name="e">
\r
111 private void NewActivityWindow_Load(object sender, EventArgs e)
\r
113 windowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);
\r
117 /// Append new text to the window
\r
119 /// <param name="n">
\r
122 private void LogMonitor(object n)
\r
124 AppendWindowText(GetLog());
\r
128 /// New Code for getting the Activity log from the Services rather than reading a file.
\r
131 /// The StringBuilder containing a log
\r
133 private StringBuilder GetLog()
\r
135 StringBuilder appendText = new StringBuilder();
\r
137 if (this.mode == ActivityLogMode.Scan)
\r
139 if (scan == null || scan.ActivityLog == string.Empty)
\r
141 appendText.AppendFormat("Waiting for the log to be generated ...\n");
\r
148 using (StringReader reader = new StringReader(scan.ActivityLog))
\r
150 LogReader(reader, appendText);
\r
155 if (encode == null || encode.ActivityLog == string.Empty)
\r
157 appendText.AppendFormat("Waiting for the log to be generated ...\n");
\r
164 using (StringReader reader = new StringReader(encode.ActivityLog))
\r
166 LogReader(reader, appendText);
\r
173 /// Reads the log data from a Scan or Encode object
\r
175 /// <param name="reader">
\r
178 /// <param name="appendText">
\r
179 /// The append text.
\r
181 private void LogReader(StringReader reader, StringBuilder appendText)
\r
185 while ((line = reader.ReadLine()) != null)
\r
189 appendText.AppendLine(line);
\r
197 /// Append text to the RTF box
\r
199 /// <param name="text">
\r
202 private void AppendWindowText(StringBuilder text)
\r
206 if (IsHandleCreated)
\r
208 if (rtf_actLog.InvokeRequired)
\r
210 IAsyncResult invoked = BeginInvoke(new SetTextCallback(AppendWindowText), new object[] { text });
\r
211 EndInvoke(invoked);
\r
215 rtf_actLog.AppendText(text.ToString());
\r
225 /// Clear the contents of the log window
\r
227 private void ClearWindowText()
\r
231 if (IsHandleCreated)
\r
233 if (rtf_actLog.InvokeRequired)
\r
235 IAsyncResult invoked = BeginInvoke(new SetTextClearCallback(ClearWindowText));
\r
236 EndInvoke(invoked);
\r
240 rtf_actLog.Clear();
\r
250 /// Display the log header
\r
252 private void PrintLogHeader()
\r
256 if (IsHandleCreated)
\r
258 if (rtf_actLog.InvokeRequired)
\r
260 IAsyncResult invoked = BeginInvoke(new SetTextClearCallback(PrintLogHeader));
\r
261 EndInvoke(invoked);
\r
267 // Print the log header. This function will be re-implimented later. Do not delete.
\r
268 StringBuilder header = new StringBuilder();
\r
270 header.Append(String.Format("### Windows GUI {1} {0} \n", Properties.Settings.Default.hb_build, Properties.Settings.Default.hb_version));
\r
271 header.Append(String.Format("### Running: {0} \n###\n", Environment.OSVersion));
\r
272 header.Append(String.Format("### CPU: {0} \n", SystemInfo.GetCpuCount));
\r
273 header.Append(String.Format("### Ram: {0} MB \n", SystemInfo.TotalPhysicalMemory));
\r
274 header.Append(String.Format("### Screen: {0}x{1} \n", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height));
\r
275 header.Append(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));
\r
276 header.Append(String.Format("### Install Dir: {0} \n", Application.StartupPath));
\r
277 header.Append(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));
\r
278 header.Append("#########################################\n\n");
\r
280 rtf_actLog.AppendText(header.ToString());
\r
292 /// Reset Everything
\r
294 private void Reset()
\r
296 if (windowTimer != null)
\r
297 windowTimer.Dispose();
\r
301 windowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);
\r
304 // Menus and Buttons
\r
307 /// Copy log to clipboard
\r
309 /// <param name="sender">
\r
312 /// <param name="e">
\r
315 private void MnuCopyLogClick(object sender, EventArgs e)
\r
317 Clipboard.SetDataObject(rtf_actLog.SelectedText != string.Empty ? rtf_actLog.SelectedText : rtf_actLog.Text, true);
\r
321 /// Open the log folder
\r
323 /// <param name="sender">
\r
326 /// <param name="e">
\r
329 private void MnuOpenLogFolderClick(object sender, EventArgs e)
\r
331 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
332 string windir = Environment.GetEnvironmentVariable("WINDIR");
\r
333 Process prc = new Process
\r
337 FileName = windir + @"\explorer.exe",
\r
347 /// <param name="sender">
\r
350 /// <param name="e">
\r
353 private void BtnCopyClick(object sender, EventArgs e)
\r
355 Clipboard.SetDataObject(rtf_actLog.SelectedText != string.Empty ? rtf_actLog.SelectedText : rtf_actLog.Text, true);
\r
361 /// <param name="sender">
\r
364 /// <param name="e">
\r
367 private void BtnScanLogClick(object sender, EventArgs e)
\r
369 SetMode(ActivityLogMode.Scan);
\r
373 /// Set the encode mode
\r
375 /// <param name="sender">
\r
378 /// <param name="e">
\r
381 private void BtnEncodeLogClick(object sender, EventArgs e)
\r
383 SetMode(ActivityLogMode.Encode);
\r
389 /// override onclosing
\r
391 /// <param name="e">
\r
394 protected override void OnClosing(CancelEventArgs e)
\r
396 windowTimer.Dispose();
\r