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
17 /// A delegate to handle events regarding progress during DVD scanning
\r
19 /// <param name="Sender">The object who's raising the event</param>
\r
20 /// <param name="CurrentTitle">The title number currently being processed</param>
\r
21 /// <param name="TitleCount">The total number of titiles to be processed</param>
\r
22 public delegate void ScanProgressEventHandler(object Sender, int CurrentTitle, int TitleCount);
\r
25 /// A simple wrapper around a StreamReader to keep track of the entire output from a cli process
\r
27 internal class Parser : StreamReader
\r
29 private string m_buffer;
\r
31 /// The output from the CLI process
\r
33 public string Buffer
\r
37 return this.m_buffer;
\r
42 /// Raised upon a new line being read from stdout/stderr
\r
44 public static event DataReadEventHandler OnReadLine;
\r
47 /// Raised upon the entire stdout/stderr stream being read in a single call
\r
49 public static event DataReadEventHandler OnReadToEnd;
\r
52 /// Raised upon the catching of a "Scanning title # of #..." in the stream
\r
54 public static event ScanProgressEventHandler OnScanProgress;
\r
57 /// Default constructor for this object
\r
59 /// <param name="baseStream">The stream to parse from</param>
\r
60 public Parser(Stream baseStream) : base(baseStream)
\r
62 this.m_buffer = string.Empty;
\r
65 public override string ReadLine()
\r
67 string tmp = base.ReadLine();
\r
68 this.m_buffer += tmp;
\r
69 Match m = Regex.Match(tmp, "^Scanning title ([0-9]*) of ([0-9]*)");
\r
70 if (OnReadLine != null)
\r
72 OnReadLine(this, tmp);
\r
74 if (m.Success && OnScanProgress != null)
\r
76 OnScanProgress(this, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
\r
81 public override string ReadToEnd()
\r
83 string tmp = base.ReadToEnd();
\r
84 this.m_buffer += tmp;
\r
85 if (OnReadToEnd != null)
\r
87 OnReadToEnd(this, tmp);
\r