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
22 public event EventHandler ScanStared;
\r
23 public event EventHandler ScanCompleted;
\r
24 public event EventHandler ScanStatusChanged;
\r
26 public void ScanSource(string sourcePath, int title)
\r
28 Thread t = new Thread(unused => RunScan(sourcePath, title));
\r
32 public DVD SouceData()
\r
37 public String LogData()
\r
39 return _readData.Buffer;
\r
42 public String ScanStatus()
\r
44 return _scanProgress;
\r
47 public Process ScanProcess()
\r
52 private void RunScan(object sourcePath, int title)
\r
56 if (ScanStared != null)
\r
57 ScanStared(this, new EventArgs());
\r
59 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
\r
60 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
61 string dvdInfoPath = Path.Combine(logDir, "last_scan_log.txt");
\r
63 // Make we don't pick up a stale last_encode_log.txt (and that we have rights to the file)
\r
64 if (File.Exists(dvdInfoPath))
\r
65 File.Delete(dvdInfoPath);
\r
67 String dvdnav = string.Empty;
\r
68 if (Properties.Settings.Default.noDvdNav)
\r
69 dvdnav = " --no-dvdnav";
\r
71 _hbProc = new Process
\r
75 FileName = handbrakeCLIPath,
\r
76 Arguments = String.Format(@" -i ""{0}"" -t{1} {2} -v ", sourcePath, title, dvdnav),
\r
77 RedirectStandardOutput = true,
\r
78 RedirectStandardError = true,
\r
79 UseShellExecute = false,
\r
80 CreateNoWindow = true
\r
85 _readData = new Parser(_hbProc.StandardError.BaseStream);
\r
86 _readData.OnScanProgress += new ScanProgressEventHandler(OnScanProgress);
\r
87 _thisDvd = DVD.Parse(_readData);
\r
89 // Write the Buffer out to file.
\r
90 StreamWriter scanLog = new StreamWriter(dvdInfoPath);
\r
91 scanLog.Write(_readData.Buffer);
\r
95 if (ScanCompleted != null)
\r
96 ScanCompleted(this, new EventArgs());
\r
98 catch (Exception exc)
\r
100 Console.WriteLine("frmMain.cs - scanProcess() " + exc);
\r
104 private void OnScanProgress(object sender, int currentTitle, int titleCount)
\r
106 _scanProgress = string.Format("Processing Title: {0} of {1}", currentTitle, titleCount);
\r
107 if (ScanStatusChanged != null)
\r
108 ScanStatusChanged(this, new EventArgs());
\r