OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmActivityWindow.cs
index f909abc..5f41c79 100644 (file)
@@ -10,7 +10,6 @@ using System.Text;
 using System.Windows.Forms;\r
 using System.IO;\r
 using System.Threading;\r
-using Handbrake.EncodeQueue;\r
 using Handbrake.Functions;\r
 using Microsoft.Win32;\r
 \r
@@ -24,23 +23,31 @@ namespace Handbrake
         private static int _position;\r
         private static string _lastMode;\r
         private static string _currentMode;\r
+        private Thread _monitor;\r
+        private Boolean _kilLThread;\r
 \r
-        public frmActivityWindow()\r
+        public frmActivityWindow(string mode)\r
         {\r
+            _kilLThread = false;\r
+            _position = 0;\r
+            if (mode == "scan")\r
+                SetScanMode();\r
+            else\r
+                SetEncodeMode();\r
+\r
             InitializeComponent();\r
         }\r
         private void NewActivityWindow_Load(object sender, EventArgs e)\r
         {\r
-            SetScanMode();\r
-            Thread monitor = new Thread(LogMonitor);\r
-\r
+            _monitor = new Thread(LogMonitor);\r
+            \r
             try\r
             {\r
-                monitor.Start();\r
+                _monitor.Start();\r
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show(exc.ToString());\r
+                MessageBox.Show("Unable to monitor HandBrakes log files. Please report this error. If the problem presists, try rebooting your computer.\n\n Debug Informaton:\n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
             }\r
         }\r
 \r
@@ -48,14 +55,13 @@ namespace Handbrake
         {\r
             while (true)\r
             {\r
+                if (!IsHandleCreated || _kilLThread) // break out the thread if the window has been disposed.\r
+                    break;\r
+\r
                 // Perform a reset if require.\r
                 // If we have switched to a different log file, we want to start from the beginning.\r
                 if (SetLogFile != _lastMode)\r
-                {\r
-                    _position = 0;\r
-                    ClearWindowText();\r
-                    PrintLogHeader();\r
-                }\r
+                    Reset();\r
 \r
                 // Perform the window update\r
                 switch (SetLogFile)\r
@@ -70,7 +76,15 @@ namespace Handbrake
                         break;\r
                 }\r
 \r
-                Thread.Sleep(1000);\r
+                try\r
+                {\r
+                    Thread.Sleep(1000);\r
+                }\r
+                catch (ThreadInterruptedException)\r
+                {\r
+                    // Do Nothnig.\r
+                }\r
+\r
             }\r
         }\r
         private StringBuilder ReadFile(string file)\r
@@ -121,7 +135,7 @@ namespace Handbrake
             }\r
             catch (Exception exc)\r
             {\r
-                appendText.AppendFormat("\nERROR: The Log file could not be read. You may need to restart HandBrake! " + exc);\r
+                appendText.AppendFormat("\n The Log file could not be read. You may need to restart HandBrake! " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
                 _position = 0;\r
                 ClearWindowText();\r
             }\r
@@ -141,10 +155,13 @@ namespace Handbrake
                     else\r
                         rtf_actLog.AppendText(text.ToString());\r
                 }\r
+            } catch(ThreadInterruptedException)\r
+            {\r
+                // Do Nothing\r
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show("SetWindowText(): Exception: \n" + exc);\r
+                MessageBox.Show("Unless you are having problems, you can probably ignore this error. It would not hurt to report this error!\n\nSetWindowText(): Exception: \n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
             }\r
         }\r
         private void ClearWindowText()\r
@@ -164,10 +181,10 @@ namespace Handbrake
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show("ClearWindowText(): Exception: \n" + exc);\r
+                MessageBox.Show("Unless you are having problems, you can probably ignore this error. It would not hurt to report this error!\n\nClearWindowText(): Exception: \n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
             }\r
         }\r
-        public void PrintLogHeader()\r
+        private void PrintLogHeader()\r
         {\r
             try\r
             {\r
@@ -195,9 +212,15 @@ namespace Handbrake
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show("PrintLogHeader(): Exception: \n" + exc);\r
+                MessageBox.Show("Unless you are having problems, you can probably ignore this error. It would not hurt to report this error!\n\nPrintLogHeader(): Exception: \n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
             }\r
-            \r
+\r
+        }\r
+        private void Reset()\r
+        {\r
+            _position = 0;\r
+            ClearWindowText();\r
+            PrintLogHeader();\r
         }\r
 \r
         #region Public\r
@@ -209,11 +232,13 @@ namespace Handbrake
         }\r
         public void SetScanMode()\r
         {\r
+            Reset();\r
             SetLogFile = "last_scan_log.txt";\r
             this.Text = "Activity Window (Scan Log)";\r
         }\r
         public void SetEncodeMode()\r
         {\r
+            Reset();\r
             SetLogFile = "last_encode_log.txt";\r
             this.Text = "Activity Window (Enocde Log)";\r
         }\r
@@ -293,8 +318,11 @@ namespace Handbrake
 \r
         protected override void OnClosing(CancelEventArgs e)\r
         {\r
+            _kilLThread = true;\r
+            _monitor.Interrupt();\r
+            _monitor.Join();\r
             e.Cancel = true;\r
-            this.Hide();\r
+            this.Dispose();\r
             base.OnClosing(e);\r
         }\r
     }\r