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
29 frmQueue queueWindow;
\r
32 /// This window should be used to display the RAW output of the handbrake CLI which is produced during an encode.
\r
35 public frmActivityWindow(string file, frmMain fm, frmQueue fq)
\r
37 InitializeComponent();
\r
42 this.rtf_actLog.Text = string.Empty;
\r
46 string logFile = Path.Combine(Path.GetTempPath(), read_file);
\r
47 if (File.Exists(logFile))
\r
49 if (read_file == "dvdinfo.dat") // No need to refresh the window if we are viwing dvdinfo.dat
\r
50 updateTextFromThread();
\r
51 else // however, we should refresh when reading the encode log file.
\r
53 monitorFile = new Thread(autoUpdate);
\r
54 monitorFile.Start();
\r
58 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
61 // Update the Activity window every 5 seconds with the latest log data.
\r
62 private void autoUpdate(object state)
\r
64 updateTextFromThread();
\r
67 if ((mainWindow.isEncoding() == true) || (queueWindow.isEncoding() == true))
\r
68 updateTextFromThread();
\r
73 private delegate void UpdateUIHandler();
\r
74 private void updateTextFromThread()
\r
78 if (this.InvokeRequired)
\r
80 this.BeginInvoke(new UpdateUIHandler(updateTextFromThread));
\r
83 rtf_actLog.Text = readFile();
\r
84 this.rtf_actLog.SelectionStart = this.rtf_actLog.Text.Length - 1;
\r
85 this.rtf_actLog.ScrollToCaret();
\r
87 catch (Exception exc)
\r
89 MessageBox.Show(exc.ToString());
\r
93 private string readFile()
\r
98 // hb_encode_log.dat is the primary log file. Since .NET can't read this file whilst the CLI is outputing to it,
\r
99 // we'll need to make a copy of it.
\r
100 string logFile = Path.Combine(Path.GetTempPath(), read_file);
\r
101 string logFile2 = Path.Combine(Path.GetTempPath(), "hb_encode_log_AppReadable.dat");
\r
104 // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.
\r
105 if (File.Exists(logFile2))
\r
106 File.Delete(logFile2);
\r
108 // Copy the log file.
\r
109 File.Copy(logFile, logFile2);
\r
111 // Begin processing the log file.
\r
112 StreamReader sr = new StreamReader(logFile2);
\r
113 string line = sr.ReadLine();
\r
114 while (line != null)
\r
116 log = log + (line + System.Environment.NewLine);
\r
117 line = sr.ReadLine();
\r
122 catch (Exception exc)
\r
124 MessageBox.Show("An Error has occured! \n\n" + exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
130 protected override void OnClosing(CancelEventArgs e)
\r
132 if (monitorFile != null)
\r
133 monitorFile.Abort();
\r