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
20 public partial class frmActivityWindow : Form
\r
23 /// This window should be used to display the RAW output of the handbrake CLI which is produced during an encode.
\r
28 public frmActivityWindow(string file)
\r
30 InitializeComponent();
\r
31 this.rtf_actLog.Text = string.Empty;
\r
32 monitorFile = new Thread(autoUpdate);
\r
37 private void frmActivityWindow_Load(object sender, EventArgs e)
\r
39 this.rtf_actLog.Text = string.Empty;
\r
40 rtf_actLog.Text = readFile();
\r
42 monitorFile.Start();
\r
45 private void autoUpdate(object state)
\r
49 updateTextFromThread();
\r
54 private delegate void UpdateUIHandler();
\r
55 private void updateTextFromThread()
\r
57 if (this.InvokeRequired)
\r
59 this.BeginInvoke(new UpdateUIHandler(updateTextFromThread));
\r
62 rtf_actLog.Text = readFile();
\r
63 this.rtf_actLog.SelectionStart = this.rtf_actLog.Text.Length -1;
\r
64 this.rtf_actLog.ScrollToCaret();
\r
66 if (rtf_actLog.Text.Contains("HandBrake has exited."))
\r
67 monitorFile.Abort();
\r
70 private string readFile()
\r
75 // hb_encode_log.dat is the primary log file. Since .NET can't read this file whilst the CLI is outputing to it,
\r
76 // we'll need to make a copy of it.
\r
77 string logFile = Path.Combine(Path.GetTempPath(), read_file);
\r
78 string logFile2 = Path.Combine(Path.GetTempPath(), "hb_encode_log_AppReadable.dat");
\r
80 // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.
\r
81 if (File.Exists(logFile2))
\r
82 File.Delete(logFile2);
\r
84 // Copy the log file.
\r
85 File.Copy(logFile, logFile2);
\r
87 // Begin processing the log file.
\r
88 StreamReader sr = new StreamReader(logFile2);
\r
89 string line = sr.ReadLine();
\r
90 while (line != null)
\r
92 log = log + (line + System.Environment.NewLine);
\r
93 line = sr.ReadLine();
\r
97 catch (Exception exc)
\r
99 MessageBox.Show("An Error has occured! \n\n" + exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r