OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmActivityWindow.cs
index ca4edcf..879dd54 100644 (file)
 /*  frmActivityWindow.cs $\r
-       \r
-          This file is part of the HandBrake source code.\r
-          Homepage: <http://handbrake.fr>.\r
-          It may be used under the terms of the GNU General Public License. */\r
-\r
-using System;\r
-using System.ComponentModel;\r
-using System.Text;\r
-using System.Windows.Forms;\r
-using System.IO;\r
-using System.Threading;\r
-using Handbrake.Functions;\r
-using Timer = System.Threading.Timer;\r
+    This file is part of the HandBrake source code.\r
+    Homepage: <http://handbrake.fr>.\r
+    It may be used under the terms of the GNU General Public License. */\r
 \r
 namespace Handbrake\r
 {\r
+    using System;\r
+    using System.ComponentModel;\r
+    using System.Diagnostics;\r
+    using System.IO;\r
+    using System.Text;\r
+    using System.Threading;\r
+    using System.Windows.Forms;\r
+    using Functions;\r
+    using Timer = System.Threading.Timer;\r
+\r
+    /// <summary>\r
+    /// The Activity Log Window\r
+    /// </summary>\r
     public partial class frmActivityWindow : Form\r
     {\r
-        private delegate void SetTextCallback(StringBuilder text);\r
-        private delegate void SetTextClearCallback();\r
-        private int Position;\r
-        private string LastMode;\r
-        private string CurrentMode;\r
-        private Timer WindowTimer;\r
\r
+        /// <summary>\r
+        /// The current position in the log file\r
+        /// </summary>\r
+        private int position;\r
+\r
+        /// <summary>\r
+        /// The previous mode\r
+        /// </summary>\r
+        private string lastMode;\r
+\r
+        /// <summary>\r
+        /// The current mode\r
+        /// </summary>\r
+        private string currentMode;\r
+\r
+        /// <summary>\r
+        /// A Timer for this window\r
+        /// </summary>\r
+        private Timer windowTimer;\r
+\r
+        /// <summary>\r
+        /// Initializes a new instance of the <see cref="frmActivityWindow"/> class.\r
+        /// </summary>\r
+        /// <param name="mode">\r
+        /// The mode.\r
+        /// </param>\r
         public frmActivityWindow(string mode)\r
         {\r
             InitializeComponent();\r
 \r
-            Position = 0;\r
+            position = 0;\r
             if (mode == "scan")\r
                 SetScanMode();\r
             else\r
                 SetEncodeMode();\r
         }\r
 \r
+        /// <summary>\r
+        /// A callback function for updating the ui\r
+        /// </summary>\r
+        /// <param name="text">\r
+        /// The text.\r
+        /// </param>\r
+        private delegate void SetTextCallback(StringBuilder text);\r
+\r
+        /// <summary>\r
+        /// Clear text callback\r
+        /// </summary>\r
+        private delegate void SetTextClearCallback();\r
+\r
+        // Public\r
+\r
+        /// <summary>\r
+        /// Gets or sets SetLogFile.\r
+        /// </summary>\r
+        public string SetLogFile\r
+        {\r
+            get { return string.IsNullOrEmpty(currentMode) ? string.Empty : currentMode; }\r
+            set { currentMode = value; }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Set the window to scan mode\r
+        /// </summary>\r
+        public void SetScanMode()\r
+        {\r
+            Reset();\r
+            SetLogFile = "last_scan_log.txt";\r
+            this.Text = "Activity Window (Scan Log)";\r
+        }\r
+\r
+        /// <summary>\r
+        /// Set the window to encode mode\r
+        /// </summary>\r
+        public void SetEncodeMode()\r
+        {\r
+            Reset();\r
+            SetLogFile = "last_encode_log.txt";\r
+            this.Text = "Activity Window (Enocde Log)";\r
+        }\r
+\r
+        // Logging\r
+\r
+        /// <summary>\r
+        /// On Window load, start a new timer\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void NewActivityWindow_Load(object sender, EventArgs e)\r
         {\r
-            WindowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);\r
+            windowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);\r
         }\r
 \r
+        /// <summary>\r
+        /// Append new text to the window\r
+        /// </summary>\r
+        /// <param name="n">\r
+        /// The n.\r
+        /// </param>\r
         private void LogMonitor(object n)\r
         {\r
-            if (SetLogFile != LastMode) Reset();\r
+            if (SetLogFile != lastMode) Reset();\r
 \r
             // Perform the window update\r
             switch (SetLogFile)\r
             {\r
                 case "last_scan_log.txt":\r
                     AppendWindowText(ReadFile("last_scan_log.txt"));\r
-                    LastMode = "last_scan_log.txt";\r
+                    lastMode = "last_scan_log.txt";\r
                     break;\r
                 case "last_encode_log.txt":\r
                     AppendWindowText(ReadFile("last_encode_log.txt"));\r
-                    LastMode = "last_encode_log.txt";\r
+                    lastMode = "last_encode_log.txt";\r
                     break;\r
             }\r
         }\r
+\r
+        /// <summary>\r
+        /// Read the log file\r
+        /// </summary>\r
+        /// <param name="file">\r
+        /// The file.\r
+        /// </param>\r
+        /// <returns>\r
+        /// A string builder containing the log data\r
+        /// </returns>\r
         private StringBuilder ReadFile(string file)\r
         {\r
             StringBuilder appendText = new StringBuilder();\r
@@ -81,7 +174,7 @@ namespace Handbrake
                     else\r
                     {\r
                         appendText.AppendFormat("Waiting for the log file to be generated ...\n");\r
-                        Position = 0;\r
+                        position = 0;\r
                         ClearWindowText();\r
                         PrintLogHeader();\r
                         return appendText;\r
@@ -94,27 +187,32 @@ namespace Handbrake
                     int i = 1;\r
                     while ((line = sr.ReadLine()) != null)\r
                     {\r
-                        if (i > Position)\r
+                        if (i > position)\r
                         {\r
                             appendText.AppendLine(line);\r
-                            Position++;\r
+                            position++;\r
                         }\r
                         i++;\r
                     }\r
                     sr.Close();\r
                     sr.Dispose();\r
-\r
                 }\r
                 catch (Exception)\r
                 {\r
                     Reset();\r
                     appendText = new StringBuilder();\r
-                    appendText.AppendFormat(\r
-                        "\nThe Log file is currently in use. Waiting for the log file to become accessible ...\n");\r
+                    appendText.AppendLine("\nThe Log file is currently in use. Waiting for the log file to become accessible ...\n");\r
                 }\r
             }\r
             return appendText;\r
         }\r
+\r
+        /// <summary>\r
+        /// Append text to the RTF box\r
+        /// </summary>\r
+        /// <param name="text">\r
+        /// The text.\r
+        /// </param>\r
         private void AppendWindowText(StringBuilder text)\r
         {\r
             try\r
@@ -136,6 +234,10 @@ namespace Handbrake
                 return;\r
             }\r
         }\r
+\r
+        /// <summary>\r
+        /// Clear the contents of the log window\r
+        /// </summary>\r
         private void ClearWindowText()\r
         {\r
             try\r
@@ -148,7 +250,7 @@ namespace Handbrake
                         EndInvoke(invoked);\r
                     }\r
                     else\r
-                        lock(rtf_actLog)\r
+                        lock (rtf_actLog)\r
                             rtf_actLog.Clear();\r
                 }\r
             }\r
@@ -157,6 +259,10 @@ namespace Handbrake
                 return;\r
             }\r
         }\r
+\r
+        /// <summary>\r
+        /// Display the log header\r
+        /// </summary>\r
         private void PrintLogHeader()\r
         {\r
             try\r
@@ -173,19 +279,19 @@ namespace Handbrake
                         lock (rtf_actLog)\r
                         {\r
                             // Print the log header. This function will be re-implimented later. Do not delete.\r
-                            rtf_actLog.AppendText(String.Format("### Windows GUI {1} {0} \n",\r
-                                                                Properties.Settings.Default.hb_build,\r
-                                                                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", SystemInfo.GetCpuCount));\r
-                            rtf_actLog.AppendText(String.Format("### Ram: {0} MB \n", SystemInfo.TotalPhysicalMemory));\r
-                            rtf_actLog.AppendText(String.Format("### Screen: {0}x{1} \n",\r
-                                                                SystemInfo.ScreenBounds.Bounds.Width,\r
-                                                                SystemInfo.ScreenBounds.Bounds.Height));\r
-                            rtf_actLog.AppendText(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));\r
-                            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
+                            StringBuilder header = new StringBuilder();\r
+\r
+                            header.AppendLine(String.Format("### Windows GUI {1} {0} \n", Properties.Settings.Default.hb_build, Properties.Settings.Default.hb_version));\r
+                            header.AppendLine(String.Format("### Running: {0} \n###\n", Environment.OSVersion));\r
+                            header.AppendLine(String.Format("### CPU: {0} \n", SystemInfo.GetCpuCount));\r
+                            header.AppendLine(String.Format("### Ram: {0} MB \n", SystemInfo.TotalPhysicalMemory));\r
+                            header.AppendLine(String.Format("### Screen: {0}x{1} \n", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height));\r
+                            header.AppendLine(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));\r
+                            header.AppendLine(String.Format("### Install Dir: {0} \n", Application.StartupPath));\r
+                            header.AppendLine(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));\r
+                            header.AppendLine("#########################################\n\n");\r
+\r
+                            rtf_actLog.AppendText(header.ToString());\r
                         }\r
                     }\r
                 }\r
@@ -194,76 +300,114 @@ namespace Handbrake
             {\r
                 return;\r
             }\r
-\r
         }\r
+\r
+        /// <summary>\r
+        /// Reset Everything\r
+        /// </summary>\r
         private void Reset()\r
         {\r
-            if (WindowTimer != null)\r
-                WindowTimer.Dispose();\r
-            Position = 0;\r
+            if (windowTimer != null)\r
+                windowTimer.Dispose();\r
+            position = 0;\r
             ClearWindowText();\r
-            PrintLogHeader(); \r
-            WindowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);\r
+            PrintLogHeader();\r
+            windowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);\r
         }\r
 \r
-        #region Public\r
+        // Menus and Buttons\r
 \r
-        public string SetLogFile\r
-        {\r
-            get { return string.IsNullOrEmpty(CurrentMode) ? "" : CurrentMode; }\r
-            set { CurrentMode = value; }\r
-        }\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
+        /// <summary>\r
+        /// Copy log to clipboard\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void MnuCopyLogClick(object sender, EventArgs e)\r
         {\r
-            Reset();\r
-            SetLogFile = "last_encode_log.txt";\r
-            this.Text = "Activity Window (Enocde Log)";\r
+            Clipboard.SetDataObject(rtf_actLog.SelectedText != string.Empty ? rtf_actLog.SelectedText : rtf_actLog.Text, true);\r
         }\r
 \r
-        #endregion\r
-\r
-        #region User Interface\r
-        private void mnu_copy_log_Click(object sender, EventArgs e)\r
-        {\r
-            Clipboard.SetDataObject(rtf_actLog.SelectedText != "" ? rtf_actLog.SelectedText : rtf_actLog.Text, true);\r
-        }\r
-        private void mnu_openLogFolder_Click(object sender, EventArgs e)\r
+        /// <summary>\r
+        /// Open the log folder\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void MnuOpenLogFolderClick(object sender, EventArgs e)\r
         {\r
             string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
             string windir = Environment.GetEnvironmentVariable("WINDIR");\r
-            System.Diagnostics.Process prc = new System.Diagnostics.Process\r
-                                                 {\r
-                                                     StartInfo =\r
-                                                         {\r
-                                                             FileName = windir + @"\explorer.exe",\r
-                                                             Arguments = logDir\r
-                                                         }\r
-                                                 };\r
+            Process prc = new Process\r
+                              {\r
+                                  StartInfo =\r
+                                      {\r
+                                          FileName = windir + @"\explorer.exe",\r
+                                          Arguments = logDir\r
+                                      }\r
+                              };\r
             prc.Start();\r
         }\r
-        private void btn_copy_Click(object sender, EventArgs e)\r
+\r
+        /// <summary>\r
+        /// Copy the log\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void BtnCopyClick(object sender, EventArgs e)\r
         {\r
-            Clipboard.SetDataObject(rtf_actLog.SelectedText != "" ? rtf_actLog.SelectedText : rtf_actLog.Text, true);\r
+            Clipboard.SetDataObject(rtf_actLog.SelectedText != string.Empty ? rtf_actLog.SelectedText : rtf_actLog.Text, true);\r
         }\r
-        private void btn_scan_log_Click(object sender, EventArgs e)\r
+\r
+        /// <summary>\r
+        /// Set scan mode\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void BtnScanLogClick(object sender, EventArgs e)\r
         {\r
             SetScanMode();\r
         }\r
-        private void btn_encode_log_Click(object sender, EventArgs e)\r
+\r
+        /// <summary>\r
+        /// Set the encode mode\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void BtnEncodeLogClick(object sender, EventArgs e)\r
         {\r
             SetEncodeMode();\r
         }\r
-        #endregion\r
 \r
+        // Overrides\r
+\r
+        /// <summary>\r
+        /// override onclosing\r
+        /// </summary>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         protected override void OnClosing(CancelEventArgs e)\r
         {\r
-            WindowTimer.Dispose();\r
+            windowTimer.Dispose();\r
             e.Cancel = true;\r
             this.Dispose();\r
             base.OnClosing(e);\r