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
10 using System.ComponentModel;
\r
11 using System.Diagnostics;
\r
14 using System.Threading;
\r
15 using System.Windows.Forms;
\r
17 using Timer = System.Threading.Timer;
\r
19 public partial class frmActivityWindow : Form
\r
21 private delegate void SetTextCallback(StringBuilder text);
\r
23 private delegate void SetTextClearCallback();
\r
25 private int Position;
\r
26 private string LastMode;
\r
27 private string CurrentMode;
\r
28 private Timer WindowTimer;
\r
30 public frmActivityWindow(string mode)
\r
32 InitializeComponent();
\r
41 private void NewActivityWindow_Load(object sender, EventArgs e)
\r
43 WindowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);
\r
46 private void LogMonitor(object n)
\r
48 if (SetLogFile != LastMode) Reset();
\r
50 // Perform the window update
\r
53 case "last_scan_log.txt":
\r
54 AppendWindowText(ReadFile("last_scan_log.txt"));
\r
55 LastMode = "last_scan_log.txt";
\r
57 case "last_encode_log.txt":
\r
58 AppendWindowText(ReadFile("last_encode_log.txt"));
\r
59 LastMode = "last_encode_log.txt";
\r
64 private StringBuilder ReadFile(string file)
\r
66 StringBuilder appendText = new StringBuilder();
\r
69 // 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
70 // we'll need to make a copy of it.
\r
71 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
\r
72 "\\HandBrake\\logs";
\r
73 string logFile = Path.Combine(logDir, file);
\r
74 string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");
\r
78 // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.
\r
79 if (File.Exists(logFile2))
\r
80 File.Delete(logFile2);
\r
82 // Copy the log file.
\r
83 if (File.Exists(logFile))
\r
84 File.Copy(logFile, logFile2, true);
\r
87 appendText.AppendFormat("Waiting for the log file to be generated ...\n");
\r
95 // Only use text which continues on from the last read line
\r
96 StreamReader sr = new StreamReader(logFile2);
\r
99 while ((line = sr.ReadLine()) != null)
\r
103 appendText.AppendLine(line);
\r
114 appendText = new StringBuilder();
\r
115 appendText.AppendFormat(
\r
116 "\nThe Log file is currently in use. Waiting for the log file to become accessible ...\n");
\r
122 private void AppendWindowText(StringBuilder text)
\r
126 if (IsHandleCreated)
\r
128 if (rtf_actLog.InvokeRequired)
\r
130 IAsyncResult invoked = BeginInvoke(new SetTextCallback(AppendWindowText), new object[] {text});
\r
131 EndInvoke(invoked);
\r
135 rtf_actLog.AppendText(text.ToString());
\r
144 private void ClearWindowText()
\r
148 if (IsHandleCreated)
\r
150 if (rtf_actLog.InvokeRequired)
\r
152 IAsyncResult invoked = BeginInvoke(new SetTextClearCallback(ClearWindowText));
\r
153 EndInvoke(invoked);
\r
157 rtf_actLog.Clear();
\r
166 private void PrintLogHeader()
\r
170 if (IsHandleCreated)
\r
172 if (rtf_actLog.InvokeRequired)
\r
174 IAsyncResult invoked = BeginInvoke(new SetTextClearCallback(PrintLogHeader));
\r
175 EndInvoke(invoked);
\r
181 // Print the log header. This function will be re-implimented later. Do not delete.
\r
182 rtf_actLog.AppendText(String.Format("### Windows GUI {1} {0} \n",
\r
183 Properties.Settings.Default.hb_build,
\r
184 Properties.Settings.Default.hb_version));
\r
185 rtf_actLog.AppendText(String.Format("### Running: {0} \n###\n", Environment.OSVersion));
\r
186 rtf_actLog.AppendText(String.Format("### CPU: {0} \n", SystemInfo.GetCpuCount));
\r
187 rtf_actLog.AppendText(String.Format("### Ram: {0} MB \n", SystemInfo.TotalPhysicalMemory));
\r
188 rtf_actLog.AppendText(String.Format("### Screen: {0}x{1} \n",
\r
189 SystemInfo.ScreenBounds.Bounds.Width,
\r
190 SystemInfo.ScreenBounds.Bounds.Height));
\r
191 rtf_actLog.AppendText(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));
\r
192 rtf_actLog.AppendText(String.Format("### Install Dir: {0} \n", Application.StartupPath));
\r
193 rtf_actLog.AppendText(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));
\r
194 rtf_actLog.AppendText("#########################################\n\n");
\r
205 private void Reset()
\r
207 if (WindowTimer != null)
\r
208 WindowTimer.Dispose();
\r
212 WindowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);
\r
217 public string SetLogFile
\r
219 get { return string.IsNullOrEmpty(CurrentMode) ? string.Empty : CurrentMode; }
\r
220 set { CurrentMode = value; }
\r
223 public void SetScanMode()
\r
226 SetLogFile = "last_scan_log.txt";
\r
227 this.Text = "Activity Window (Scan Log)";
\r
230 public void SetEncodeMode()
\r
233 SetLogFile = "last_encode_log.txt";
\r
234 this.Text = "Activity Window (Enocde Log)";
\r
239 #region User Interface
\r
241 private void mnu_copy_log_Click(object sender, EventArgs e)
\r
243 Clipboard.SetDataObject(rtf_actLog.SelectedText != string.Empty ? rtf_actLog.SelectedText : rtf_actLog.Text, true);
\r
246 private void mnu_openLogFolder_Click(object sender, EventArgs e)
\r
248 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
249 string windir = Environment.GetEnvironmentVariable("WINDIR");
\r
250 Process prc = new Process
\r
254 FileName = windir + @"\explorer.exe",
\r
261 private void btn_copy_Click(object sender, EventArgs e)
\r
263 Clipboard.SetDataObject(rtf_actLog.SelectedText != string.Empty ? rtf_actLog.SelectedText : rtf_actLog.Text, true);
\r
266 private void btn_scan_log_Click(object sender, EventArgs e)
\r
271 private void btn_encode_log_Click(object sender, EventArgs e)
\r
278 protected override void OnClosing(CancelEventArgs e)
\r
280 WindowTimer.Dispose();
\r