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 /// Gets or sets a value indicating whether IsScanning.
\r
58 public bool IsScanning { get; set; }
\r
61 /// Scan a Source Path.
\r
62 /// Title 0: scan all
\r
64 /// <param name="sourcePath">Path to the file to scan</param>
\r
65 /// <param name="title">int title number. 0 for scan all</param>
\r
66 public void ScanSource(string sourcePath, int title)
\r
68 Thread t = new Thread(unused => this.RunScan(sourcePath, title));
\r
73 /// Object containing the information parsed in the scan.
\r
75 /// <returns>The DVD object containing the scan information</returns>
\r
76 public DVD SouceData()
\r
78 return this.thisDvd;
\r
82 /// Raw log output from HandBrake CLI
\r
84 /// <returns>The Log Data</returns>
\r
85 public string LogData()
\r
87 return this.readData.Buffer;
\r
91 /// Progress of the scan.
\r
93 /// <returns>The progress of the scan</returns>
\r
94 public string ScanStatus()
\r
96 return this.scanProgress;
\r
100 /// The Scan Process
\r
102 /// <returns>The CLI process</returns>
\r
103 public Process ScanProcess()
\r
105 return this.hbProc;
\r
109 /// Start a scan for a given source path and title
\r
111 /// <param name="sourcePath">Path to the source file</param>
\r
112 /// <param name="title">the title number to look at</param>
\r
113 private void RunScan(object sourcePath, int title)
\r
118 if (this.ScanStared != null)
\r
119 this.ScanStared(this, new EventArgs());
\r
121 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
\r
122 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
\r
123 "\\HandBrake\\logs";
\r
124 string dvdInfoPath = Path.Combine(logDir, "last_scan_log.txt");
\r
126 // Make we don't pick up a stale last_encode_log.txt (and that we have rights to the file)
\r
127 if (File.Exists(dvdInfoPath))
\r
128 File.Delete(dvdInfoPath);
\r
130 string dvdnav = string.Empty;
\r
131 if (Properties.Settings.Default.noDvdNav)
\r
132 dvdnav = " --no-dvdnav";
\r
134 this.hbProc = new Process
\r
138 FileName = handbrakeCLIPath,
\r
140 String.Format(@" -i ""{0}"" -t{1} {2} -v ", sourcePath, title, dvdnav),
\r
141 RedirectStandardOutput = true,
\r
142 RedirectStandardError = true,
\r
143 UseShellExecute = false,
\r
144 CreateNoWindow = true
\r
147 this.hbProc.Start();
\r
149 this.readData = new Parser(this.hbProc.StandardError.BaseStream);
\r
150 this.readData.OnScanProgress += new ScanProgressEventHandler(this.OnScanProgress);
\r
151 this.thisDvd = DVD.Parse(this.readData);
\r
153 // Write the Buffer out to file.
\r
154 StreamWriter scanLog = new StreamWriter(dvdInfoPath);
\r
155 scanLog.Write(this.readData.Buffer);
\r
159 if (this.ScanCompleted != null)
\r
160 this.ScanCompleted(this, new EventArgs());
\r
161 IsScanning = false;
\r
163 catch (Exception exc)
\r
165 Console.WriteLine("frmMain.cs - scanProcess() " + exc);
\r
170 /// Fire an event when the scan process progresses
\r
172 /// <param name="sender">the sender</param>
\r
173 /// <param name="currentTitle">the current title being scanned</param>
\r
174 /// <param name="titleCount">the total number of titles</param>
\r
175 private void OnScanProgress(object sender, int currentTitle, int titleCount)
\r
177 this.scanProgress = string.Format("Processing Title: {0} of {1}", currentTitle, titleCount);
\r
178 if (this.ScanStatusChanged != null)
\r
179 this.ScanStatusChanged(this, new EventArgs());
\r