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.Functions;
\r
14 using Timer = System.Threading.Timer;
\r
18 public partial class frmActivityWindow : Form
\r
20 private delegate void SetTextCallback(StringBuilder text);
\r
21 private delegate void SetTextClearCallback();
\r
22 private int Position;
\r
23 private string LastMode;
\r
24 private string CurrentMode;
\r
25 private Timer WindowTimer;
\r
27 public frmActivityWindow(string mode)
\r
29 InitializeComponent();
\r
38 private void NewActivityWindow_Load(object sender, EventArgs e)
\r
40 WindowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);
\r
43 private void LogMonitor(object n)
\r
45 if (SetLogFile != LastMode) Reset();
\r
47 // Perform the window update
\r
50 case "last_scan_log.txt":
\r
51 AppendWindowText(ReadFile("last_scan_log.txt"));
\r
52 LastMode = "last_scan_log.txt";
\r
54 case "last_encode_log.txt":
\r
55 AppendWindowText(ReadFile("last_encode_log.txt"));
\r
56 LastMode = "last_encode_log.txt";
\r
60 private StringBuilder ReadFile(string file)
\r
62 StringBuilder appendText = new StringBuilder();
\r
65 // 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
66 // we'll need to make a copy of it.
\r
67 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
\r
68 "\\HandBrake\\logs";
\r
69 string logFile = Path.Combine(logDir, file);
\r
70 string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");
\r
74 // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.
\r
75 if (File.Exists(logFile2))
\r
76 File.Delete(logFile2);
\r
78 // Copy the log file.
\r
79 if (File.Exists(logFile))
\r
80 File.Copy(logFile, logFile2, true);
\r
83 appendText.AppendFormat("Waiting for the log file to be generated ...\n");
\r
91 // Only use text which continues on from the last read line
\r
92 StreamReader sr = new StreamReader(logFile2);
\r
95 while ((line = sr.ReadLine()) != null)
\r
99 appendText.AppendLine(line);
\r
108 catch (Exception exc)
\r
111 appendText = new StringBuilder();
\r
112 appendText.AppendFormat(
\r
113 "\nThe Log file is currently in use. Waiting for the log file to become accessible ...\n");
\r
118 private void AppendWindowText(StringBuilder text)
\r
122 if (IsHandleCreated)
\r
124 if (rtf_actLog.InvokeRequired)
\r
126 IAsyncResult invoked = BeginInvoke(new SetTextCallback(AppendWindowText), new object[] { text });
\r
127 EndInvoke(invoked);
\r
131 rtf_actLog.AppendText(text.ToString());
\r
139 private void ClearWindowText()
\r
143 if (IsHandleCreated)
\r
145 if (rtf_actLog.InvokeRequired)
\r
147 IAsyncResult invoked = BeginInvoke(new SetTextClearCallback(ClearWindowText));
\r
148 EndInvoke(invoked);
\r
152 rtf_actLog.Clear();
\r
160 private void PrintLogHeader()
\r
164 if (IsHandleCreated)
\r
166 if (rtf_actLog.InvokeRequired)
\r
168 IAsyncResult invoked = BeginInvoke(new SetTextClearCallback(PrintLogHeader));
\r
169 EndInvoke(invoked);
\r
175 // Print the log header. This function will be re-implimented later. Do not delete.
\r
176 rtf_actLog.AppendText(String.Format("### Windows GUI {1} {0} \n",
\r
177 Properties.Settings.Default.hb_build,
\r
178 Properties.Settings.Default.hb_version));
\r
179 rtf_actLog.AppendText(String.Format("### Running: {0} \n###\n", Environment.OSVersion));
\r
180 rtf_actLog.AppendText(String.Format("### CPU: {0} \n", SystemInfo.GetCpuCount));
\r
181 rtf_actLog.AppendText(String.Format("### Ram: {0} MB \n", SystemInfo.TotalPhysicalMemory));
\r
182 rtf_actLog.AppendText(String.Format("### Screen: {0}x{1} \n",
\r
183 SystemInfo.ScreenBounds.Bounds.Width,
\r
184 SystemInfo.ScreenBounds.Bounds.Height));
\r
185 rtf_actLog.AppendText(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));
\r
186 rtf_actLog.AppendText(String.Format("### Install Dir: {0} \n", Application.StartupPath));
\r
187 rtf_actLog.AppendText(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));
\r
188 rtf_actLog.AppendText("#########################################\n\n");
\r
199 private void Reset()
\r
201 if (WindowTimer != null)
\r
202 WindowTimer.Dispose();
\r
206 WindowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);
\r
211 public string SetLogFile
\r
213 get { return string.IsNullOrEmpty(CurrentMode) ? "" : CurrentMode; }
\r
214 set { CurrentMode = value; }
\r
216 public void SetScanMode()
\r
219 SetLogFile = "last_scan_log.txt";
\r
220 this.Text = "Activity Window (Scan Log)";
\r
222 public void SetEncodeMode()
\r
225 SetLogFile = "last_encode_log.txt";
\r
226 this.Text = "Activity Window (Enocde Log)";
\r
231 #region User Interface
\r
232 private void mnu_copy_log_Click(object sender, EventArgs e)
\r
234 Clipboard.SetDataObject(rtf_actLog.SelectedText != "" ? rtf_actLog.SelectedText : rtf_actLog.Text, true);
\r
236 private void mnu_openLogFolder_Click(object sender, EventArgs e)
\r
238 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
239 string windir = Environment.GetEnvironmentVariable("WINDIR");
\r
240 System.Diagnostics.Process prc = new System.Diagnostics.Process
\r
244 FileName = windir + @"\explorer.exe",
\r
250 private void btn_copy_Click(object sender, EventArgs e)
\r
252 Clipboard.SetDataObject(rtf_actLog.SelectedText != "" ? rtf_actLog.SelectedText : 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 protected override void OnClosing(CancelEventArgs e)
\r
266 WindowTimer.Dispose();
\r