--- /dev/null
+/* Scan.cs $\r
+ \r
+ This file is part of the HandBrake source code.\r
+ Homepage: <http://handbrake.fr>.\r
+ It may be used under the terms of the GNU General Public License. */\r
+\r
+using System;\r
+using System.Windows.Forms;\r
+using System.IO;\r
+using System.Diagnostics;\r
+using System.Threading;\r
+using Handbrake.Parsing;\r
+\r
+namespace Handbrake.Functions\r
+{\r
+ public class Scan\r
+ {\r
+ private DVD _thisDvd;\r
+ private Parser _readData;\r
+ private Process _hbProc;\r
+ private string _scanProgress;\r
+ public event EventHandler ScanStared;\r
+ public event EventHandler ScanCompleted;\r
+ public event EventHandler ScanStatusChanged;\r
+\r
+ public void ScanSource(string sourcePath)\r
+ {\r
+ Thread t = new Thread(new ParameterizedThreadStart(RunScan));\r
+ t.Start(sourcePath);\r
+ }\r
+\r
+ public DVD SouceData()\r
+ {\r
+ return _thisDvd;\r
+ }\r
+\r
+ public String LogData()\r
+ {\r
+ return _readData.Buffer;\r
+ }\r
+\r
+ public String ScanStatus()\r
+ {\r
+ return _scanProgress;\r
+ }\r
+\r
+ public Process ScanProcess()\r
+ {\r
+ return _hbProc;\r
+ }\r
+\r
+ private void RunScan(object sourcePath)\r
+ {\r
+ try\r
+ {\r
+ if (ScanStared != null)\r
+ ScanStared(this, new EventArgs());\r
+\r
+ string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+ string dvdInfoPath = Path.Combine(logDir, "last_scan_log.txt");\r
+\r
+ // Make we don't pick up a stale last_encode_log.txt (and that we have rights to the file)\r
+ if (File.Exists(dvdInfoPath))\r
+ File.Delete(dvdInfoPath);\r
+\r
+ String dvdnav = string.Empty;\r
+ if (Properties.Settings.Default.noDvdNav)\r
+ dvdnav = " --no-dvdnav";\r
+\r
+ _hbProc = new Process\r
+ {\r
+ StartInfo =\r
+ {\r
+ FileName = handbrakeCLIPath,\r
+ Arguments = String.Format(@" -i ""{0}"" -t0 {1} -v ", sourcePath, dvdnav),\r
+ RedirectStandardOutput = true,\r
+ RedirectStandardError = true,\r
+ UseShellExecute = false,\r
+ CreateNoWindow = true\r
+ }\r
+ };\r
+ _hbProc.Start();\r
+\r
+ _readData = new Parser(_hbProc.StandardError.BaseStream);\r
+ _readData.OnScanProgress += new ScanProgressEventHandler(OnScanProgress);\r
+ _thisDvd = DVD.Parse(_readData);\r
+\r
+ // Write the Buffer out to file.\r
+ StreamWriter scanLog = new StreamWriter(dvdInfoPath);\r
+ scanLog.Write(_readData.Buffer);\r
+ scanLog.Flush();\r
+ scanLog.Close();\r
+\r
+ if (ScanCompleted != null)\r
+ ScanCompleted(this, new EventArgs());\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ Console.WriteLine("frmMain.cs - scanProcess() " + exc);\r
+ }\r
+ }\r
+\r
+ private void OnScanProgress(object sender, int currentTitle, int titleCount)\r
+ {\r
+ _scanProgress = string.Format("Processing Title: {0} of {1}", currentTitle, titleCount);\r
+ if (ScanStatusChanged != null)\r
+ ScanStatusChanged(this, new EventArgs());\r
+ }\r
+ }\r
+}
\ No newline at end of file