OSDN Git Service

WinGui:
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Thu, 26 Nov 2009 15:26:38 +0000 (15:26 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Thu, 26 Nov 2009 15:26:38 +0000 (15:26 +0000)
- Scan.cs was missing from a previous checkin

git-svn-id: svn://localhost/HandBrake/trunk@2986 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/C#/Functions/Scan.cs [new file with mode: 0644]

diff --git a/win/C#/Functions/Scan.cs b/win/C#/Functions/Scan.cs
new file mode 100644 (file)
index 0000000..aca3399
--- /dev/null
@@ -0,0 +1,111 @@
+/*  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