OSDN Git Service

WinGui:
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Mon, 7 Sep 2009 09:01:22 +0000 (09:01 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Mon, 7 Sep 2009 09:01:22 +0000 (09:01 +0000)
- Some fixes to the ActivityWindow. CLI query should always be displayed now.

git-svn-id: svn://localhost/HandBrake/trunk@2807 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/C#/EncodeQueue/EncodeAndQueueHandler.cs
win/C#/frmActivityWindow.cs
win/C#/frmMain.cs

index 6d8a2ce..93cab84 100644 (file)
@@ -336,6 +336,7 @@ namespace Handbrake.EncodeQueue
                     Thread.Sleep(5000);\r
                 }\r
             }\r
+            LastEncode = new Job();\r
 \r
             if (QueueCompleted != null)\r
                 QueueCompleted(this, new EventArgs());\r
@@ -361,6 +362,8 @@ namespace Handbrake.EncodeQueue
         {\r
             try\r
             {\r
+                isEncoding = true;\r
+\r
                 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
                 string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs", "last_encode_log.txt");\r
                 string strCmdLine = String.Format(@" /C """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, query, logPath);\r
@@ -376,8 +379,7 @@ namespace Handbrake.EncodeQueue
 \r
                 Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.\r
                 hbProcess = Process.Start(cliStart);\r
-                processID = Main.getCliProcess(before);\r
-                isEncoding = true;\r
+                processID = Main.getCliProcess(before); \r
                 currentQuery = query;\r
                 if (hbProcess != null)\r
                     processHandle = hbProcess.MainWindowHandle; // Set the process Handle\r
@@ -414,7 +416,6 @@ namespace Handbrake.EncodeQueue
             {\r
                 MessageBox.Show("It would appear that HandBrakeCLI has not started correctly. You should take a look at the Activity log as it may indicate the reason why.\n\n   Detailed Error Information: error occured in runCli()\n\n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
             }\r
-\r
         }\r
 \r
         /// <summary>\r
index c099201..86ed53d 100644 (file)
@@ -18,29 +18,35 @@ namespace Handbrake
 {\r
     public partial class frmActivityWindow : Form\r
     {\r
-        private delegate void SetTextCallback(string text);\r
-        private String read_file;\r
-        private Thread monitor;\r
-        private EncodeAndQueueHandler encodeQueue;\r
-        private int position;  // Position in the arraylist reached by the current log output in the rtf box.\r
-        private string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
-        private frmMain mainWin;\r
-        private Boolean lastUpdate;\r
+        private delegate void setTextCallback(string text);\r
+        private String _readFile;\r
+        private readonly EncodeAndQueueHandler _encodeQueue;\r
+        private int _position;  // Position in the arraylist reached by the current log output in the rtf box.\r
+        private readonly frmMain _mainWin;\r
+        private Boolean _lastUpdate;\r
 \r
         public frmActivityWindow(string file, EncodeAndQueueHandler eh, frmMain mw)\r
         {\r
             InitializeComponent();\r
 \r
-            encodeQueue = eh;\r
-            mainWin = mw;\r
+            _encodeQueue = eh;\r
+            _mainWin = mw;\r
 \r
             if (file == "last_scan_log.txt")\r
-                setLogView(true);\r
+                SetLogView(true);\r
             else\r
-                setLogView(false);\r
+                SetLogView(false);\r
 \r
             // Start a new thread which will montior and keep the log window up to date if required/\r
-            startLogThread(read_file);\r
+            try\r
+            {\r
+                Thread monitor = new Thread(AutoUpdate) { IsBackground = true };\r
+                monitor.Start();\r
+            }\r
+            catch (Exception exc)\r
+            {\r
+                MessageBox.Show("startLogThread(): Exception: \n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+            }\r
         }\r
 \r
         /// <summary>\r
@@ -49,27 +55,13 @@ namespace Handbrake
         /// Encode = false;\r
         /// </summary>\r
         /// <param name="scan">Boolean. Scan = true</param>\r
-        public void setLogView(Boolean scan)\r
+        public void SetLogView(Boolean scan)\r
         {\r
-            position = 0;\r
+            // Reset\r
+            _position = 0;\r
             rtf_actLog.Text = String.Empty;\r
-            displayLogHeader();\r
 \r
-            if (scan)\r
-            {\r
-                txt_log.Text = "Scan Log";\r
-                read_file = "last_scan_log.txt";\r
-            }\r
-            else\r
-            {\r
-                read_file = "last_encode_log.txt";\r
-                txt_log.Text = "Encode Log";\r
-            }\r
-            lastUpdate = false;\r
-        }\r
-        private void displayLogHeader()\r
-        {\r
-            // Add a header to the log file indicating that it's from the Windows GUI and display the windows version\r
+            // Print the log header\r
             rtf_actLog.AppendText(String.Format("### Windows GUI {1} {0} \n", Properties.Settings.Default.hb_build, Properties.Settings.Default.hb_version));\r
             rtf_actLog.AppendText(String.Format("### Running: {0} \n###\n", Environment.OSVersion));\r
             rtf_actLog.AppendText(String.Format("### CPU: {0} \n", getCpuCount()));\r
@@ -79,51 +71,46 @@ namespace Handbrake
             rtf_actLog.AppendText(String.Format("### Install Dir: {0} \n", Application.StartupPath));\r
             rtf_actLog.AppendText(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));\r
             rtf_actLog.AppendText("#########################################\n\n");\r
-            if (encodeQueue.isEncoding && encodeQueue.LastEncode.Query != String.Empty)\r
+            if ((!_encodeQueue.LastEncode.IsEmpty) && _encodeQueue.LastEncode.Query != String.Empty)\r
             {\r
-                rtf_actLog.AppendText("### CLI Query: " + encodeQueue.LastEncode.Query + "\n\n");\r
+                rtf_actLog.AppendText("### CLI Query: " + _encodeQueue.LastEncode.Query + "\n\n");\r
                 rtf_actLog.AppendText("#########################################\n\n");\r
             }\r
-        }\r
-        private void startLogThread(string file)\r
-        {\r
-            try\r
-            {\r
-                string logFile = Path.Combine(logDir, file);\r
-                if (File.Exists(logFile))\r
-                {\r
-                    monitor = new Thread(autoUpdate) { IsBackground = true };\r
-                    monitor.Start();\r
-                }\r
-                else\r
-                    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);\r
 \r
+            // Seutp the log file\r
+            if (scan)\r
+            {\r
+                txt_log.Text = "Scan Log";\r
+                _readFile = "last_scan_log.txt";\r
             }\r
-            catch (Exception exc)\r
+            else\r
             {\r
-                MessageBox.Show("startLogThread(): Exception: \n" + exc);\r
+                _readFile = "last_encode_log.txt";\r
+                txt_log.Text = "Encode Log";\r
             }\r
+            _lastUpdate = false;\r
         }\r
-        private void autoUpdate(object state)\r
+\r
+        private void AutoUpdate(object state)\r
         {\r
             try\r
             {\r
-                lastUpdate = false;\r
-                updateTextFromThread();\r
+                _lastUpdate = false;\r
+                UpdateTextFromThread();\r
                 while (true)\r
                 {\r
                     if (IsHandleCreated)\r
                     {\r
-                        if (encodeQueue.isEncoding || mainWin.isScanning)\r
-                            updateTextFromThread();\r
+                        if (_encodeQueue.isEncoding || _mainWin.isScanning)\r
+                            UpdateTextFromThread();\r
                         else\r
                         {\r
                             // The encode may just have stoped, so, refresh the log one more time before restarting it.\r
-                            if (lastUpdate == false)\r
-                                updateTextFromThread();\r
+                            if (_lastUpdate == false)\r
+                                UpdateTextFromThread();\r
 \r
-                            lastUpdate = true; // Prevents the log window from being updated when there is no encode going.\r
-                            position = 0; // There is no encoding, so reset the log position counter to 0 so it can be reused\r
+                            _lastUpdate = true; // Prevents the log window from being updated when there is no encode going.\r
+                            _position = 0; // There is no encoding, so reset the log position counter to 0 so it can be reused\r
                         }\r
                     }\r
                     Thread.Sleep(1000);\r
@@ -131,14 +118,14 @@ namespace Handbrake
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show("autoUpdate(): Exception: \n" + exc);\r
+                MessageBox.Show("AutoUpdate(): Exception: \n" + exc);\r
             }\r
         }\r
-        private void updateTextFromThread()\r
+        private void UpdateTextFromThread()\r
         {\r
             try\r
             {\r
-                String info = readFile();\r
+                String info = ReadFile();\r
                 if (info.Contains("has exited"))\r
                     info += "\n ############ End of Log ############## \n";\r
 \r
@@ -146,7 +133,7 @@ namespace Handbrake
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show("updateTextFromThread(): Exception: \n" + exc);\r
+                MessageBox.Show("UpdateTextFromThread(): Exception: \n" + exc);\r
             }\r
         }\r
         private void SetText(string text)\r
@@ -157,9 +144,10 @@ namespace Handbrake
                 {\r
                     if (rtf_actLog.InvokeRequired)\r
                     {\r
-                        IAsyncResult invoked = BeginInvoke(new SetTextCallback(SetText), new object[] {text});\r
+                        IAsyncResult invoked = BeginInvoke(new setTextCallback(SetText), new object[] { text });\r
                         EndInvoke(invoked);\r
-                    } else \r
+                    }\r
+                    else\r
                         rtf_actLog.AppendText(text);\r
                 }\r
             }\r
@@ -168,14 +156,15 @@ namespace Handbrake
                 MessageBox.Show("SetText(): Exception: \n" + exc);\r
             }\r
         }\r
-        private String readFile()\r
+        private String ReadFile()\r
         {\r
             String appendText = String.Empty;\r
             try\r
             {\r
                 // last_encode_log.txt is the primary log file. Since .NET can't read this file whilst the CLI is outputing to it (Not even in read only mode),\r
                 // we'll need to make a copy of it.\r
-                string logFile = Path.Combine(logDir, read_file);\r
+                string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+                string logFile = Path.Combine(logDir, _readFile);\r
                 string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");\r
 \r
                 // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.\r
@@ -183,7 +172,10 @@ namespace Handbrake
                     File.Delete(logFile2);\r
 \r
                 // Copy the log file.\r
-                File.Copy(logFile, logFile2);\r
+                if (File.Exists(logFile))\r
+                    File.Copy(logFile, logFile2);\r
+                else\r
+                    return "\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;\r
 \r
                 // Open the copied log file for reading\r
                 StreamReader sr = new StreamReader(logFile2);\r
@@ -191,10 +183,10 @@ namespace Handbrake
                 int i = 1;\r
                 while ((line = sr.ReadLine()) != null)\r
                 {\r
-                    if (i > position)\r
+                    if (i > _position)\r
                     {\r
                         appendText += line + Environment.NewLine;\r
-                        position++;\r
+                        _position++;\r
                     }\r
                     i++;\r
                 }\r
@@ -205,7 +197,7 @@ namespace Handbrake
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show("Error in readFile() \n Unable to read the log file.\n You may have to restart HandBrake.\n  Error Information: \n\n" + exc, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                MessageBox.Show("Error in ReadFile() \n Unable to read the log file.\n You may have to restart HandBrake.\n  Error Information: \n\n" + exc, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             }\r
             return null;\r
         }\r
@@ -243,11 +235,11 @@ namespace Handbrake
         }\r
         private void btn_scan_log_Click(object sender, EventArgs e)\r
         {\r
-            setLogView(true);\r
+            SetLogView(true);\r
         }\r
         private void btn_encode_log_Click(object sender, EventArgs e)\r
         {\r
-            setLogView(false);\r
+            SetLogView(false);\r
         }\r
         #endregion\r
 \r
index 3935b87..a668cc6 100644 (file)
@@ -718,10 +718,12 @@ namespace Handbrake
                             queueWindow.Show(false);\r
 \r
                         setEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
-                        if (ActivityWindow != null)\r
-                            ActivityWindow.setLogView(false);\r
                         encodeQueue.StartEncodeQueue(); // Start The Queue Encoding Process\r
                         lastAction = "encode";   // Set the last action to encode - Used for activity window.\r
+\r
+                        if (ActivityWindow != null)\r
+                            ActivityWindow.SetLogView(false);\r
+                        \r
                     }\r
                     this.Focus();\r
                 }\r
@@ -1412,7 +1414,7 @@ namespace Handbrake
             try\r
             {\r
                 if (ActivityWindow != null)\r
-                    ActivityWindow.setLogView(true);\r
+                    ActivityWindow.SetLogView(true);\r
                 isScanning = true;\r
                 ThreadPool.QueueUserWorkItem(scanProcess);\r
             }\r