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.Collections.Generic;
\r
9 using System.ComponentModel;
\r
11 using System.Drawing;
\r
13 using System.Windows.Forms;
\r
15 using System.Threading;
\r
16 using System.Diagnostics;
\r
17 using System.Runtime.InteropServices;
\r
23 public partial class frmActivityWindow : Form
\r
26 /// This window should be used to display the RAW output of the handbrake CLI which is produced during an encode.
\r
31 public frmActivityWindow(string file)
\r
33 InitializeComponent();
\r
34 this.rtf_actLog.Text = string.Empty;
\r
38 string logFile = Path.Combine(Path.GetTempPath(), read_file);
\r
39 if (File.Exists(logFile))
\r
41 if (read_file == "dvdinfo.dat") // No need to refresh the window if we are viwing dvdinfo.dat
\r
42 updateTextFromThread();
\r
43 else // however, we should refresh when reading the encode log file.
\r
45 monitorFile = new Thread(autoUpdate);
\r
46 monitorFile.Start();
\r
50 MessageBox.Show("The log file could not be found. Maybe you cleared your system's tempory folder or maybe you just havn't run an encode yet.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
53 // Update the Activity window every 5 seconds with the latest log data.
\r
54 private void autoUpdate(object state)
\r
58 updateTextFromThread();
\r
63 private delegate void UpdateUIHandler();
\r
64 private void updateTextFromThread()
\r
68 if (this.InvokeRequired)
\r
70 this.BeginInvoke(new UpdateUIHandler(updateTextFromThread));
\r
73 rtf_actLog.Text = readFile();
\r
74 this.rtf_actLog.SelectionStart = this.rtf_actLog.Text.Length - 1;
\r
75 this.rtf_actLog.ScrollToCaret();
\r
77 catch (Exception exc)
\r
79 MessageBox.Show(exc.ToString());
\r
83 private string readFile()
\r
88 // hb_encode_log.dat is the primary log file. Since .NET can't read this file whilst the CLI is outputing to it,
\r
89 // we'll need to make a copy of it.
\r
90 string logFile = Path.Combine(Path.GetTempPath(), read_file);
\r
91 string logFile2 = Path.Combine(Path.GetTempPath(), "hb_encode_log_AppReadable.dat");
\r
94 // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.
\r
95 if (File.Exists(logFile2))
\r
96 File.Delete(logFile2);
\r
98 // Copy the log file.
\r
99 File.Copy(logFile, logFile2);
\r
101 // Begin processing the log file.
\r
102 StreamReader sr = new StreamReader(logFile2);
\r
103 string line = sr.ReadLine();
\r
104 while (line != null)
\r
106 log = log + (line + System.Environment.NewLine);
\r
107 line = sr.ReadLine();
\r
112 catch (Exception exc)
\r
114 MessageBox.Show("An Error has occured! \n\n" + exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
120 protected override void OnClosing(CancelEventArgs e)
\r
122 if (monitorFile != null)
\r
123 monitorFile.Abort();
\r