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
27 public frmActivityWindow()
\r
29 InitializeComponent();
\r
30 this.rtf_actLog.Text = string.Empty;
\r
31 monitorFile = new Thread(autoUpdate);
\r
35 private void btn_close_Click(object sender, EventArgs e)
\r
37 monitorFile.Abort();
\r
41 private void frmActivityWindow_Load(object sender, EventArgs e)
\r
43 this.rtf_actLog.Text = string.Empty;
\r
44 rtf_actLog.Text = readFile();
\r
46 monitorFile.Start();
\r
49 private void autoUpdate(object state)
\r
53 updateTextFromThread();
\r
58 private delegate void UpdateUIHandler();
\r
59 private void updateTextFromThread()
\r
61 if (this.InvokeRequired)
\r
63 this.BeginInvoke(new UpdateUIHandler(updateTextFromThread));
\r
66 rtf_actLog.Text = readFile();
\r
67 this.rtf_actLog.SelectionStart = this.rtf_actLog.Text.Length -1;
\r
68 this.rtf_actLog.ScrollToCaret();
\r
70 if (rtf_actLog.Text.Contains("HandBrake has exited."))
\r
71 monitorFile.Abort();
\r
74 private string readFile()
\r
79 // hb_encode_log.dat is the primary log file. Since .NET can't read this file whilst the CLI is outputing to it,
\r
80 // we'll need to make a copy of it.
\r
81 string logFile = Path.Combine(Path.GetTempPath(), "hb_encode_log.dat");
\r
82 string logFile2 = Path.Combine(Path.GetTempPath(), "hb_encode_log_AppReadable.dat");
\r
84 // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.
\r
85 if (File.Exists(logFile2))
\r
86 File.Delete(logFile2);
\r
88 // Copy the log file.
\r
89 File.Copy(logFile, logFile2);
\r
91 // Begin processing the log file.
\r
92 StreamReader sr = new StreamReader(logFile2);
\r
93 string line = sr.ReadLine();
\r
94 while (line != null)
\r
96 log = log + (line + System.Environment.NewLine);
\r
97 line = sr.ReadLine();
\r
101 catch (Exception exc)
\r
103 MessageBox.Show("An Error has occured! \n\n" + exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
109 private void btn_copy_Click(object sender, EventArgs e)
\r
111 if (rtf_actLog.Text != "")
\r
112 Clipboard.SetText(rtf_actLog.Text, TextDataFormat.Rtf);
\r
115 private void btn_refresh_Click(object sender, EventArgs e)
\r
117 rtf_actLog.Clear();
\r
118 rtf_actLog.Text = readFile();
\r