OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Parsing / Parser.cs
index 9b0e645..2fc4e63 100644 (file)
@@ -5,6 +5,7 @@
           It may be used under the terms of the GNU General Public License. */\r
 \r
 using System.IO;\r
+using System.Text;\r
 using System.Text.RegularExpressions;\r
 using System;\r
 using System.Globalization;\r
@@ -38,21 +39,21 @@ namespace Handbrake.Parsing
     /// <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
+\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
+        private StringBuilder _buffer = new StringBuilder("");\r
         /// <summary>\r
         /// The output from the CLI process\r
         /// </summary>\r
-        public string Buffer\r
+        public String Buffer\r
         {\r
             get\r
             {\r
-                return m_buffer;\r
+                return _buffer.ToString();\r
             }\r
         }\r
 \r
@@ -82,22 +83,27 @@ namespace Handbrake.Parsing
         /// Default constructor for this object\r
         /// </summary>\r
         /// <param name="baseStream">The stream to parse from</param>\r
-        public Parser(Stream baseStream) : base(baseStream)\r
+        public Parser(Stream baseStream)\r
+            : base(baseStream)\r
         {\r
-            m_buffer = string.Empty;\r
         }\r
 \r
         public override string ReadLine()\r
         {\r
             string tmp = base.ReadLine();\r
 \r
-            m_buffer += tmp;\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
@@ -106,7 +112,8 @@ namespace Handbrake.Parsing
         {\r
             string tmp = base.ReadToEnd();\r
 \r
-            m_buffer += tmp;\r
+            _buffer.Append(tmp + Environment.NewLine);\r
+\r
             if (OnReadToEnd != null)\r
                 OnReadToEnd(this, tmp);\r
 \r