2 using System.Collections.Generic;
\r
5 using System.Text.RegularExpressions;
\r
7 namespace Handbrake.Parsing
\r
10 /// A delegate to handle custom events regarding data being parsed from the buffer
\r
12 /// <param name="Sender">The object which raised this delegate</param>
\r
13 /// <param name="Data">The data parsed from the stream</param>
\r
14 public delegate void DataReadEventHandler(object Sender, string Data);
\r
16 public delegate void ScanProgressEventHandler(object Sender, int CurrentTitle, int TitleCount);
\r
19 /// A simple wrapper around a StreamReader to keep track of the entire output from a cli process
\r
21 internal class Parser : StreamReader
\r
23 private string m_buffer;
\r
25 /// The output from the CLI process
\r
27 public string Buffer
\r
31 return this.m_buffer;
\r
36 /// Raised upon a new line being read from stdout/stderr
\r
38 public static event DataReadEventHandler OnReadLine;
\r
41 /// Raised upon the entire stdout/stderr stream being read in a single call
\r
43 public static event DataReadEventHandler OnReadToEnd;
\r
45 public static event ScanProgressEventHandler OnScanProgress;
\r
48 /// Default constructor for this object
\r
50 /// <param name="baseStream">The stream to parse from</param>
\r
51 public Parser(Stream baseStream) : base(baseStream)
\r
53 this.m_buffer = string.Empty;
\r
56 public override string ReadLine()
\r
58 string tmp = base.ReadLine();
\r
59 this.m_buffer += tmp;
\r
60 Match m = Regex.Match(tmp, "^Scanning title ([0-9]*) of ([0-9]*)");
\r
61 if (OnReadLine != null)
\r
63 OnReadLine(this, tmp);
\r
65 if (m.Success && OnScanProgress != null)
\r
67 OnScanProgress(this, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
\r
72 public override string ReadToEnd()
\r
74 string tmp = base.ReadToEnd();
\r
75 this.m_buffer += tmp;
\r
76 if (OnReadToEnd != null)
\r
78 OnReadToEnd(this, tmp);
\r