3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Windows.Forms;
\r
10 using System.Diagnostics;
\r
11 using System.Threading;
\r
12 using Handbrake.Parsing;
\r
14 namespace Handbrake.Functions
\r
18 private DVD ThisDvd;
\r
19 private Parser ReadData;
\r
20 private Process HbProc;
\r
21 private string ScanProgress;
\r
24 /// Scan has Started
\r
26 public event EventHandler ScanStared;
\r
29 /// Scan has completed
\r
31 public event EventHandler ScanCompleted;
\r
34 /// Scan process has changed to a new title
\r
36 public event EventHandler ScanStatusChanged;
\r
39 /// Scan a Source Path.
\r
40 /// Title 0: scan all
\r
42 /// <param name="sourcePath">Path to the file to scan</param>
\r
43 /// <param name="title">int title number. 0 for scan all</param>
\r
44 public void ScanSource(string sourcePath, int title)
\r
46 Thread t = new Thread(unused => RunScan(sourcePath, title));
\r
51 /// Object containing the information parsed in the scan.
\r
53 /// <returns></returns>
\r
54 public DVD SouceData()
\r
60 /// Raw log output from HandBrake CLI
\r
62 /// <returns></returns>
\r
63 public String LogData()
\r
65 return ReadData.Buffer;
\r
69 /// Progress of the scan.
\r
71 /// <returns></returns>
\r
72 public String ScanStatus()
\r
74 return ScanProgress;
\r
78 /// The Scan Process
\r
80 /// <returns></returns>
\r
81 public Process ScanProcess()
\r
87 /// Start a scan for a given source path and title
\r
89 /// <param name="sourcePath"></param>
\r
90 /// <param name="title"></param>
\r
91 private void RunScan(object sourcePath, int title)
\r
95 if (ScanStared != null)
\r
96 ScanStared(this, new EventArgs());
\r
98 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
\r
99 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
100 string dvdInfoPath = Path.Combine(logDir, "last_scan_log.txt");
\r
102 // Make we don't pick up a stale last_encode_log.txt (and that we have rights to the file)
\r
103 if (File.Exists(dvdInfoPath))
\r
104 File.Delete(dvdInfoPath);
\r
106 String dvdnav = string.Empty;
\r
107 if (Properties.Settings.Default.noDvdNav)
\r
108 dvdnav = " --no-dvdnav";
\r
110 HbProc = new Process
\r
114 FileName = handbrakeCLIPath,
\r
115 Arguments = String.Format(@" -i ""{0}"" -t{1} {2} -v ", sourcePath, title, dvdnav),
\r
116 RedirectStandardOutput = true,
\r
117 RedirectStandardError = true,
\r
118 UseShellExecute = false,
\r
119 CreateNoWindow = true
\r
124 ReadData = new Parser(HbProc.StandardError.BaseStream);
\r
125 ReadData.OnScanProgress += new ScanProgressEventHandler(OnScanProgress);
\r
126 ThisDvd = DVD.Parse(ReadData);
\r
128 // Write the Buffer out to file.
\r
129 StreamWriter scanLog = new StreamWriter(dvdInfoPath);
\r
130 scanLog.Write(ReadData.Buffer);
\r
134 if (ScanCompleted != null)
\r
135 ScanCompleted(this, new EventArgs());
\r
137 catch (Exception exc)
\r
139 Console.WriteLine("frmMain.cs - scanProcess() " + exc);
\r
144 /// Fire an event when the scan process progresses
\r
146 /// <param name="sender"></param>
\r
147 /// <param name="currentTitle"></param>
\r
148 /// <param name="titleCount"></param>
\r
149 private void OnScanProgress(object sender, int currentTitle, int titleCount)
\r
151 ScanProgress = string.Format("Processing Title: {0} of {1}", currentTitle, titleCount);
\r
152 if (ScanStatusChanged != null)
\r
153 ScanStatusChanged(this, new EventArgs());
\r