2 This file is part of the HandBrake source code.
\r
3 Homepage: <http://handbrake.fr>.
\r
4 It may be used under the terms of the GNU General Public License. */
\r
6 namespace Handbrake.Functions
\r
9 using System.Diagnostics;
\r
11 using System.Threading;
\r
12 using System.Windows.Forms;
\r
21 /// The information for this source
\r
23 private DVD thisDvd;
\r
26 /// The CLI data parser
\r
28 private Parser readData;
\r
31 /// The Process belonging to the CLI
\r
33 private Process hbProc;
\r
36 /// The Progress of the scan
\r
38 private string scanProgress;
\r
41 /// Scan has Started
\r
43 public event EventHandler ScanStared;
\r
46 /// Scan has completed
\r
48 public event EventHandler ScanCompleted;
\r
51 /// Scan process has changed to a new title
\r
53 public event EventHandler ScanStatusChanged;
\r
56 /// Scan a Source Path.
\r
57 /// Title 0: scan all
\r
59 /// <param name="sourcePath">Path to the file to scan</param>
\r
60 /// <param name="title">int title number. 0 for scan all</param>
\r
61 public void ScanSource(string sourcePath, int title)
\r
63 Thread t = new Thread(unused => this.RunScan(sourcePath, title));
\r
68 /// Object containing the information parsed in the scan.
\r
70 /// <returns>The DVD object containing the scan information</returns>
\r
71 public DVD SouceData()
\r
73 return this.thisDvd;
\r
77 /// Raw log output from HandBrake CLI
\r
79 /// <returns>The Log Data</returns>
\r
80 public string LogData()
\r
82 return this.readData.Buffer;
\r
86 /// Progress of the scan.
\r
88 /// <returns>The progress of the scan</returns>
\r
89 public string ScanStatus()
\r
91 return this.scanProgress;
\r
95 /// The Scan Process
\r
97 /// <returns>The CLI process</returns>
\r
98 public Process ScanProcess()
\r
100 return this.hbProc;
\r
104 /// Start a scan for a given source path and title
\r
106 /// <param name="sourcePath">Path to the source file</param>
\r
107 /// <param name="title">the title number to look at</param>
\r
108 private void RunScan(object sourcePath, int title)
\r
112 if (this.ScanStared != null)
\r
113 this.ScanStared(this, new EventArgs());
\r
115 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
\r
116 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
\r
117 "\\HandBrake\\logs";
\r
118 string dvdInfoPath = Path.Combine(logDir, "last_scan_log.txt");
\r
120 // Make we don't pick up a stale last_encode_log.txt (and that we have rights to the file)
\r
121 if (File.Exists(dvdInfoPath))
\r
122 File.Delete(dvdInfoPath);
\r
124 string dvdnav = string.Empty;
\r
125 if (Properties.Settings.Default.noDvdNav)
\r
126 dvdnav = " --no-dvdnav";
\r
128 this.hbProc = new Process
\r
132 FileName = handbrakeCLIPath,
\r
134 String.Format(@" -i ""{0}"" -t{1} {2} -v ", sourcePath, title, dvdnav),
\r
135 RedirectStandardOutput = true,
\r
136 RedirectStandardError = true,
\r
137 UseShellExecute = false,
\r
138 CreateNoWindow = true
\r
141 this.hbProc.Start();
\r
143 this.readData = new Parser(this.hbProc.StandardError.BaseStream);
\r
144 this.readData.OnScanProgress += new ScanProgressEventHandler(this.OnScanProgress);
\r
145 this.thisDvd = DVD.Parse(this.readData);
\r
147 // Write the Buffer out to file.
\r
148 StreamWriter scanLog = new StreamWriter(dvdInfoPath);
\r
149 scanLog.Write(this.readData.Buffer);
\r
153 if (this.ScanCompleted != null)
\r
154 this.ScanCompleted(this, new EventArgs());
\r
156 catch (Exception exc)
\r
158 Console.WriteLine("frmMain.cs - scanProcess() " + exc);
\r
163 /// Fire an event when the scan process progresses
\r
165 /// <param name="sender">the sender</param>
\r
166 /// <param name="currentTitle">the current title being scanned</param>
\r
167 /// <param name="titleCount">the total number of titles</param>
\r
168 private void OnScanProgress(object sender, int currentTitle, int titleCount)
\r
170 this.scanProgress = string.Format("Processing Title: {0} of {1}", currentTitle, titleCount);
\r
171 if (this.ScanStatusChanged != null)
\r
172 this.ScanStatusChanged(this, new EventArgs());
\r