diff options
author | sr55 <[email protected]> | 2008-08-16 19:42:44 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2008-08-16 19:42:44 +0000 |
commit | fa9459cd2bd333541564d08a3bfc7d0edf44443b (patch) | |
tree | dabba69dfbc834befb4ce662e40a9805ec5a51d3 /win/C#/frmActivityWindow.cs | |
parent | 0d63c1bef741e359f8d10664266ad4c6b411cd6c (diff) |
WinGui:
- One elusive cross-thread bug in the Activity window fix (hopefully) + some tweaks to the log display
- Nicer Exception Handling Message box errors for frmReadDVD.
- frmMain Minimize to taskbar no tooltip text exception fixed.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1634 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/frmActivityWindow.cs')
-rw-r--r-- | win/C#/frmActivityWindow.cs | 130 |
1 files changed, 51 insertions, 79 deletions
diff --git a/win/C#/frmActivityWindow.cs b/win/C#/frmActivityWindow.cs index 63157909c..fad0efcad 100644 --- a/win/C#/frmActivityWindow.cs +++ b/win/C#/frmActivityWindow.cs @@ -15,19 +15,17 @@ using System.IO; using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
-using Microsoft.Win32;
+
namespace Handbrake
{
public partial class frmActivityWindow : Form
{
-
- Thread monitorFile;
String read_file;
+ Thread monitor;
frmMain mainWindow;
frmQueue queueWindow;
int position = 0; // Position in the arraylist reached by the current log output in the rtf box.
-
/// <summary>
/// This window should be used to display the RAW output of the handbrake CLI which is produced during an encode.
@@ -36,61 +34,46 @@ namespace Handbrake public frmActivityWindow(string file, frmMain fm, frmQueue fq)
{
InitializeComponent();
+ this.rtf_actLog.Text = string.Empty;
mainWindow = fm;
queueWindow = fq;
read_file = file;
-
- // Reset some varibles
- this.rtf_actLog.Text = string.Empty;
position = 0;
+ // System Information
+ Functions.SystemInfo info = new Functions.SystemInfo();
+
+ // Add a header to the log file indicating that it's from the Windows GUI and display the windows version
+ rtf_actLog.AppendText("### Windows GUI \n");
+ rtf_actLog.AppendText(String.Format("### Running: {0} \n###\n", Environment.OSVersion.ToString()));
+ rtf_actLog.AppendText(String.Format("### CPU: {0} \n", info.getCpuCount()));
+ rtf_actLog.AppendText(String.Format("### Ram: {0} MB \n", info.TotalPhysicalMemory()));
+ rtf_actLog.AppendText(String.Format("### Screen: {0}x{1} \n", info.screenBounds().Bounds.Width, info.screenBounds().Bounds.Height));
+ rtf_actLog.AppendText(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));
+ rtf_actLog.AppendText(String.Format("### Install Dir: {0} \n", Application.StartupPath));
+ rtf_actLog.AppendText(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));
+ rtf_actLog.AppendText("#########################################\n\n");
+
string logFile = Path.Combine(Path.GetTempPath(), read_file);
if (File.Exists(logFile))
{
-
- // Get the CPU Processor Name
- RegistryKey RegKey = Registry.LocalMachine;
- RegKey = RegKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
- Object cpuType = RegKey.GetValue("ProcessorNameString");
-
- // Get the screen resolution
- System.Windows.Forms.Screen scr = System.Windows.Forms.Screen.PrimaryScreen;
-
- // Physical Ram
- Functions.SystemInfo info = new Functions.SystemInfo();
- uint memory = info.TotalPhysicalMemory();
-
- // Add a header to the log file indicating that it's from the Windows GUI and display the windows version
- rtf_actLog.AppendText("### Windows GUI \n");
- rtf_actLog.AppendText(String.Format("### Running: {0} \n###\n", Environment.OSVersion.ToString()));
- rtf_actLog.AppendText(String.Format("### CPU: {0} \n", cpuType));
- rtf_actLog.AppendText(String.Format("### Ram: {0} MB \n", memory));
- rtf_actLog.AppendText(String.Format("### Screen: {0}x{1} \n", scr.Bounds.Width, scr.Bounds.Height));
- rtf_actLog.AppendText(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));
- rtf_actLog.AppendText(String.Format("### Install Dir: {0} \n", Application.StartupPath));
- rtf_actLog.AppendText(String.Format("### Data Dir: {0} \n###\n", Application.UserAppDataPath));
-
// Start a new thread to run the autoUpdate process
- monitorFile = new Thread(autoUpdate);
- monitorFile.Start();
+ monitor = new Thread(autoUpdate);
+ monitor.IsBackground = true;
+ monitor.Start();
}
else
- 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);
-
- // Handle the event of the window being disposed. This is needed to make sure HandBrake exit's cleanly.
+ rtf_actLog.AppendText("\n\n\nERROR: The log file could not be found. \nMaybe you cleared your system's tempory folder or maybe you just havn't run an encode yet. \nTried to find the log file in: " + logFile);
+
+ // When the window closes, we want to abort the monitor thread.
this.Disposed += new EventHandler(forceQuit);
}
- // Ok, so, this function is called when someone closes frmMain but didn't close frmActivitWindow first.
- // When you close frmMain, the activity window gets closed (disposed of) but, this doens't kill the threads that it started.
- // When that thread tries to access the disposed rich text box, it causes an exception.
- // Basically, this function is called when the window is disposed of, to kill the thread and close the window properly.
- // This allows HandBrake to close cleanly.
private void forceQuit(object sender, EventArgs e)
{
- if (monitorFile != null)
- monitorFile.Abort();
+ if (monitor != null)
+ monitor.Abort();
this.Close();
}
@@ -101,7 +84,7 @@ namespace Handbrake Boolean lastUpdate = false;
updateTextFromThread();
while (true)
- {
+ {
if ((mainWindow.isEncoding() == true) || (queueWindow.isEncoding() == true))
updateTextFromThread();
else
@@ -110,42 +93,42 @@ namespace Handbrake if (lastUpdate == false)
updateTextFromThread();
- lastUpdate = true;
- position = 0;
+ lastUpdate = true; // Prevents the log window from being updated when there is no encode going.
+ position = 0; // There is no encoding, so reset the log position counter to 0 so it can be reused
}
Thread.Sleep(5000);
}
}
- private delegate void UpdateUIHandler();
private void updateTextFromThread()
{
- try
- {
- if (this.InvokeRequired)
- {
- this.BeginInvoke(new UpdateUIHandler(updateTextFromThread));
- return;
- }
- // Initialize a pointer and get the log data arraylist
- ArrayList data = readFile();
+ string text = "";
+ ArrayList data = readFile();
- while (position < data.Count)
- {
- rtf_actLog.AppendText(data[position].ToString());
- if (data[position].ToString().Contains("has exited"))
- {
- rtf_actLog.AppendText("\n ############ End of Encode ############## \n");
- }
- position++;
- }
+ while (position < data.Count)
+ {
+ text = data[position].ToString();
+ if (data[position].ToString().Contains("has exited"))
+ text = "\n ############ End of Encode ############## \n";
+ position++;
- // this.rtf_actLog.SelectionStart = this.rtf_actLog.Text.Length - 1;
- // this.rtf_actLog.ScrollToCaret();
+ SetText(text);
}
- catch (Exception exc)
+ }
+ delegate void SetTextCallback(string text);
+ private void SetText(string text)
+ {
+ // InvokeRequired required compares the thread ID of the
+ // calling thread to the thread ID of the creating thread.
+ // If these threads are different, it returns true.
+ if (this.rtf_actLog.InvokeRequired)
+ {
+ SetTextCallback d = new SetTextCallback(SetText);
+ this.Invoke(d, new object[] { text });
+ }
+ else
{
- MessageBox.Show("An error has occured in: updateTextFromThread(). \n You may have to restart HandBrake. \n Error Information: \n\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ this.rtf_actLog.AppendText(text);
}
}
@@ -191,16 +174,5 @@ namespace Handbrake return null;
}
-
- // Ok, We need to make sure the monitor thread is dead when we close the window.
- protected override void OnClosing(CancelEventArgs e)
- {
- if (monitorFile != null)
- monitorFile.Abort();
- e.Cancel = true;
- this.Hide();
- base.OnClosing(e);
- }
-
}
}
\ No newline at end of file |