diff options
author | sr55 <[email protected]> | 2009-11-26 15:26:38 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2009-11-26 15:26:38 +0000 |
commit | 63d5431c5f4c199ceb194160136aed5a6596d18e (patch) | |
tree | 33b7a22953783bdc65a1bca0ba7464b5c43b9264 | |
parent | 8dd32d1a370b061290ff26b4affbe28aa62ba66f (diff) |
WinGui:
- Scan.cs was missing from a previous checkin
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2986 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | win/C#/Functions/Scan.cs | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/win/C#/Functions/Scan.cs b/win/C#/Functions/Scan.cs new file mode 100644 index 000000000..aca3399f3 --- /dev/null +++ b/win/C#/Functions/Scan.cs @@ -0,0 +1,111 @@ +/* Scan.cs $
+
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+using System;
+using System.Windows.Forms;
+using System.IO;
+using System.Diagnostics;
+using System.Threading;
+using Handbrake.Parsing;
+
+namespace Handbrake.Functions
+{
+ public class Scan
+ {
+ private DVD _thisDvd;
+ private Parser _readData;
+ private Process _hbProc;
+ private string _scanProgress;
+ public event EventHandler ScanStared;
+ public event EventHandler ScanCompleted;
+ public event EventHandler ScanStatusChanged;
+
+ public void ScanSource(string sourcePath)
+ {
+ Thread t = new Thread(new ParameterizedThreadStart(RunScan));
+ t.Start(sourcePath);
+ }
+
+ public DVD SouceData()
+ {
+ return _thisDvd;
+ }
+
+ public String LogData()
+ {
+ return _readData.Buffer;
+ }
+
+ public String ScanStatus()
+ {
+ return _scanProgress;
+ }
+
+ public Process ScanProcess()
+ {
+ return _hbProc;
+ }
+
+ private void RunScan(object sourcePath)
+ {
+ try
+ {
+ if (ScanStared != null)
+ ScanStared(this, new EventArgs());
+
+ string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
+ string dvdInfoPath = Path.Combine(logDir, "last_scan_log.txt");
+
+ // Make we don't pick up a stale last_encode_log.txt (and that we have rights to the file)
+ if (File.Exists(dvdInfoPath))
+ File.Delete(dvdInfoPath);
+
+ String dvdnav = string.Empty;
+ if (Properties.Settings.Default.noDvdNav)
+ dvdnav = " --no-dvdnav";
+
+ _hbProc = new Process
+ {
+ StartInfo =
+ {
+ FileName = handbrakeCLIPath,
+ Arguments = String.Format(@" -i ""{0}"" -t0 {1} -v ", sourcePath, dvdnav),
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ UseShellExecute = false,
+ CreateNoWindow = true
+ }
+ };
+ _hbProc.Start();
+
+ _readData = new Parser(_hbProc.StandardError.BaseStream);
+ _readData.OnScanProgress += new ScanProgressEventHandler(OnScanProgress);
+ _thisDvd = DVD.Parse(_readData);
+
+ // Write the Buffer out to file.
+ StreamWriter scanLog = new StreamWriter(dvdInfoPath);
+ scanLog.Write(_readData.Buffer);
+ scanLog.Flush();
+ scanLog.Close();
+
+ if (ScanCompleted != null)
+ ScanCompleted(this, new EventArgs());
+ }
+ catch (Exception exc)
+ {
+ Console.WriteLine("frmMain.cs - scanProcess() " + exc);
+ }
+ }
+
+ private void OnScanProgress(object sender, int currentTitle, int titleCount)
+ {
+ _scanProgress = string.Format("Processing Title: {0} of {1}", currentTitle, titleCount);
+ if (ScanStatusChanged != null)
+ ScanStatusChanged(this, new EventArgs());
+ }
+ }
+}
\ No newline at end of file |