OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Parsing / Parser.cs
index b3bca01..3dd2fde 100644 (file)
@@ -1,59 +1,63 @@
 /*  Parser.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.IO;\r
-using System.Text.RegularExpressions;\r
-using System;\r
-using System.Globalization;\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.Parsing\r
 {\r
+    using System;\r
+    using System.Globalization;\r
+    using System.IO;\r
+    using System.Text;\r
+    using System.Text.RegularExpressions;\r
+\r
     /// <summary>\r
     /// A delegate to handle custom events regarding data being parsed from the buffer\r
     /// </summary>\r
-    /// <param name="Sender">The object which raised this delegate</param>\r
-    /// <param name="Data">The data parsed from the stream</param>\r
-    public delegate void DataReadEventHandler(object Sender, string Data);\r
+    /// <param name="sender">The object which raised this delegate</param>\r
+    /// <param name="data">The data parsed from the stream</param>\r
+    public delegate void DataReadEventHandler(object sender, string data);\r
 \r
     /// <summary>\r
     /// A delegate to handle events regarding progress during DVD scanning\r
     /// </summary>\r
-    /// <param name="Sender">The object who's raising the event</param>\r
-    /// <param name="CurrentTitle">The title number currently being processed</param>\r
-    /// <param name="TitleCount">The total number of titiles to be processed</param>\r
-    public delegate void ScanProgressEventHandler(object Sender, int CurrentTitle, int TitleCount);\r
+    /// <param name="sender">The object who's raising the event</param>\r
+    /// <param name="currentTitle">The title number currently being processed</param>\r
+    /// <param name="titleCount">The total number of titiles to be processed</param>\r
+    public delegate void ScanProgressEventHandler(object sender, int currentTitle, int titleCount);\r
 \r
     /// <summary>\r
     /// A delegate to handle encode progress updates // EXPERIMENTAL\r
     /// </summary>\r
-    /// <param name="Sender">The object which raised the event</param>\r
-    /// <param name="CurrentTask">The current task being processed from the queue</param>\r
-    /// <param name="TaskCount">The total number of tasks in queue</param>\r
-    /// <param name="PercentComplete">The percentage this task is complete</param>\r
-    /// <param name="CurrentFps">The current encoding fps</param>\r
-    /// <param name="AverageFps">The average encoding fps for this task</param>\r
-    /// <param name="TimeRemaining">The estimated time remaining for this task to complete</param>\r
-    public delegate void EncodeProgressEventHandler(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining);\r
-\r
-       \r
+    /// <param name="sender">The object which raised the event</param>\r
+    /// <param name="currentTask">The current task being processed from the queue</param>\r
+    /// <param name="taskCount">The total number of tasks in queue</param>\r
+    /// <param name="percentComplete">The percentage this task is complete</param>\r
+    /// <param name="currentFps">The current encoding fps</param>\r
+    /// <param name="averageFps">The average encoding fps for this task</param>\r
+    /// <param name="timeRemaining">The estimated time remaining for this task to complete</param>\r
+    public delegate void EncodeProgressEventHandler(object sender, int currentTask, int taskCount, float percentComplete, float currentFps, float averageFps, TimeSpan timeRemaining);\r
+\r
+\r
     /// <summary>\r
     /// A simple wrapper around a StreamReader to keep track of the entire output from a cli process\r
     /// </summary>\r
     internal class Parser : StreamReader\r
     {\r
-        private string m_buffer;\r
         /// <summary>\r
-        /// The output from the CLI process\r
+        /// The Buffer StringBuilder\r
         /// </summary>\r
-        public string Buffer\r
+        private StringBuilder buffer = new StringBuilder(string.Empty);\r
+\r
+        /// <summary>\r
+        /// Initializes a new instance of the <see cref="Parser"/> class. \r
+        /// Default constructor for this object\r
+        /// </summary>\r
+        /// <param name="baseStream">\r
+        /// The stream to parse from\r
+        /// </param>\r
+        public Parser(Stream baseStream) : base(baseStream)\r
         {\r
-            get\r
-            {\r
-                return m_buffer;\r
-            }\r
         }\r
 \r
         /// <summary>\r
@@ -71,42 +75,57 @@ namespace Handbrake.Parsing
         /// </summary>\r
         public event ScanProgressEventHandler OnScanProgress;\r
 \r
-        #region Experimetnal Code\r
         /// <summary>\r
         /// Raised upon the catching of a "Scanning title # of #..." in the stream\r
         /// </summary>\r
         public event EncodeProgressEventHandler OnEncodeProgress;\r
-        #endregion\r
 \r
         /// <summary>\r
-        /// Default constructor for this object\r
+        /// Gets the buffer of data that came from the CLI standard input/error\r
         /// </summary>\r
-        /// <param name="baseStream">The stream to parse from</param>\r
-        public Parser(Stream baseStream) : base(baseStream)\r
+        public string Buffer\r
         {\r
-            m_buffer = string.Empty;\r
+            get { return buffer.ToString(); }\r
         }\r
 \r
+        /// <summary>\r
+        /// Read a line from standard in/err\r
+        /// </summary>\r
+        /// <returns>\r
+        /// The read line\r
+        /// </returns>\r
         public override string ReadLine()\r
         {\r
             string tmp = base.ReadLine();\r
 \r
-            m_buffer += tmp + Environment.NewLine;\r
-            Match m = Regex.Match(tmp, "^Scanning title ([0-9]*) of ([0-9]*)");\r
+            buffer.Append(tmp + Environment.NewLine);\r
+\r
+            Match m = null;\r
+            if (tmp.Contains("Scanning title"))\r
+                m = Regex.Match(tmp, "^Scanning title ([0-9]*) of ([0-9]*)");\r
+\r
             if (OnReadLine != null)\r
                 OnReadLine(this, tmp);\r
 \r
-            if (m.Success && OnScanProgress != null)\r
-                OnScanProgress(this, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));\r
+            if (m != null)\r
+                if (m.Success && OnScanProgress != null)\r
+                    OnScanProgress(this, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));\r
 \r
             return tmp;\r
         }\r
 \r
+        /// <summary>\r
+        /// Read to the end of the input stream\r
+        /// </summary>\r
+        /// <returns>\r
+        /// A string of the input data\r
+        /// </returns>\r
         public override string ReadToEnd()\r
         {\r
             string tmp = base.ReadToEnd();\r
 \r
-            m_buffer += tmp + Environment.NewLine;\r
+            buffer.Append(tmp + Environment.NewLine);\r
+\r
             if (OnReadToEnd != null)\r
                 OnReadToEnd(this, tmp);\r
 \r
@@ -116,7 +135,7 @@ namespace Handbrake.Parsing
         /// <summary>\r
         /// Pase the CLI status output (from standard output)\r
         /// </summary>\r
-        public void readEncodeStatus()\r
+        public void ReadEncodeStatus()\r
         {\r
             CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");\r
             string tmp = base.ReadLine();\r
@@ -138,4 +157,4 @@ namespace Handbrake.Parsing
             }\r
         }\r
     }\r
-}\r
+}
\ No newline at end of file