+/* frmReadDVD.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.Collections.Generic;\r
using System.ComponentModel;\r
using System.IO;\r
using System.Threading;\r
using System.Diagnostics;\r
+using System.Collections;\r
\r
\r
namespace Handbrake\r
{\r
private string inputFile;\r
private frmMain mainWindow;\r
- private frmDvdInfo dvdInfo;\r
private Parsing.DVD thisDvd;\r
- private Process hbProc;\r
private delegate void UpdateUIHandler();\r
- private int cancel = 0;\r
+ Process hbproc;\r
+ Functions.Common hb_common_func = new Functions.Common();\r
+ Functions.Encode process = new Functions.Encode();\r
\r
- public frmReadDVD(string inputFile, frmMain parent, frmDvdInfo dvdInfoWindow)\r
+ public frmReadDVD(string inputFile, frmMain parent)\r
{\r
InitializeComponent();\r
this.inputFile = inputFile;\r
this.mainWindow = parent;\r
- this.dvdInfo = dvdInfoWindow;\r
+ startScan();\r
}\r
\r
- private void btn_ok_Click(object sender, EventArgs e)\r
+ private void startScan()\r
{\r
- btn_ok.Enabled = false;\r
- //btn_skip.Visible = true;\r
- lbl_pressOk.Visible = false;\r
- lbl_progress.Text = "0%";\r
- //lbl_progress.Visible = true;\r
- lbl_status.Visible = true;\r
- // throw cli call and parsing on it's own thread\r
- ThreadPool.QueueUserWorkItem(startProc);\r
+ try\r
+ {\r
+ lbl_status.Visible = true;\r
+ ThreadPool.QueueUserWorkItem(startProc);\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show("frmReadDVD.cs - startScan " + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ }\r
}\r
- \r
- private void updateUIElements()\r
+ private void startProc(object state)\r
{\r
- if (this.InvokeRequired)\r
+ try\r
{\r
- this.BeginInvoke(new UpdateUIHandler(updateUIElements));\r
- return;\r
- }\r
- // Now pass this streamreader to frmMain so that it can be used there.\r
- mainWindow.setStreamReader(thisDvd);\r
+ string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
+ string dvdInfoPath = Path.Combine(Path.GetTempPath(), "dvdinfo.dat");\r
\r
- mainWindow.drp_dvdtitle.Items.Clear();\r
- mainWindow.drp_dvdtitle.Items.AddRange(thisDvd.Titles.ToArray());\r
+ // Make we don't pick up a stale hb_encode_log.dat (and that we have rights to the file)\r
+ if (File.Exists(dvdInfoPath))\r
+ File.Delete(dvdInfoPath);\r
\r
- this.Close();\r
- }\r
+ string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 -v >""{2}"" 2>&1""", handbrakeCLIPath, inputFile, dvdInfoPath);\r
\r
- Functions.CLI process = new Functions.CLI();\r
- private void startProc(object state)\r
+ ProcessStartInfo hbParseDvd = new ProcessStartInfo("CMD.exe", strCmdLine);\r
+ hbParseDvd.WindowStyle = ProcessWindowStyle.Hidden;\r
+\r
+ using (hbproc = Process.Start(hbParseDvd))\r
+ {\r
+ hbproc.WaitForExit();\r
+ }\r
+\r
+ if (!File.Exists(dvdInfoPath))\r
+ {\r
+ throw new Exception("Unable to retrieve the DVD Info. dvdinfo.dat is missing. \nExpected location of dvdinfo.dat: \n" + dvdInfoPath);\r
+ }\r
+\r
+ using (StreamReader sr = new StreamReader(dvdInfoPath))\r
+ {\r
+ thisDvd = Parsing.DVD.Parse(sr);\r
+ sr.Close();\r
+ sr.Dispose();\r
+ }\r
+\r
+ updateUIElements();\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show("frmReadDVD.cs - startProc() " + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ closeWindowAfterError();\r
+ }\r
+\r
+ }\r
+ private void updateUIElements()\r
{\r
- //string query = "-i " + '"' + inputFile + '"' + " -t0";\r
- // hbProc = process.runCli(this, query, true, true, false, true);\r
-\r
- //*********************************************************************************************************************************************\r
- /*\r
- * Quick and Dirty hack to get around the stderr crashes of hbcli. Lets try feeding brians parser text straight from a text file.\r
- */\r
- string appPath = Application.StartupPath.ToString();\r
- appPath = appPath + "\\";\r
- string strCmdLine = "cmd /c " + '"' + '"' + appPath + "\\hbcli.exe" + '"' + " -i" + '"' + inputFile + '"' + " -t0 >" + '"'+ appPath + "\\dvdinfo.dat" + '"' + " 2>&1" + '"';\r
- Process hbproc = Process.Start("CMD.exe", strCmdLine);\r
- hbproc.WaitForExit();\r
-\r
-\r
- StreamReader sr = new StreamReader(appPath + "dvdinfo.dat");\r
- \r
- thisDvd = Parsing.DVD.Parse(sr);\r
-\r
- sr.Close();\r
- Console.ReadLine();\r
- updateUIElements();\r
- //*********************************************************************************************************************************************\r
-\r
- /*\r
- * This has been temporily disabled due to the stderr issue\r
- * \r
- * \r
- Parsing.Parser readData = new Parsing.Parser(hbProc.StandardError.BaseStream);\r
- readData.OnScanProgress += Parser_OnScanProgress;\r
- readData.OnReadLine += dvdInfo.HandleParsedData;\r
- readData.OnReadToEnd += dvdInfo.HandleParsedData;\r
-\r
- // Setup the parser\r
- \r
-\r
- if (cancel != 1)\r
+ try\r
{\r
- updateUIElements();\r
- process.killCLI();\r
- process.closeCLI();\r
+ if (this.InvokeRequired)\r
+ {\r
+ this.BeginInvoke(new UpdateUIHandler(updateUIElements));\r
+ return;\r
+ }\r
+ // Now pass this streamreader to frmMain so that it can be used there.\r
+ mainWindow.setStreamReader(thisDvd);\r
+\r
+ mainWindow.drp_dvdtitle.Items.Clear();\r
+ if (thisDvd.Titles.Count != 0)\r
+ mainWindow.drp_dvdtitle.Items.AddRange(thisDvd.Titles.ToArray());\r
+ mainWindow.drp_dvdtitle.Text = "Automatic";\r
+ mainWindow.drop_chapterFinish.Text = "Auto";\r
+ mainWindow.drop_chapterStart.Text = "Auto";\r
+\r
+ // Now select the longest title\r
+ if (thisDvd.Titles.Count != 0)\r
+ hb_common_func.selectLongestTitle(mainWindow);\r
+\r
+ this.Close();\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show("frmReadDVD.cs - updateUIElements " + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ this.Close();\r
}\r
- */\r
}\r
-\r
- private void Parser_OnScanProgress(object Sender, int CurrentTitle, int TitleCount)\r
+ private void closeWindowAfterError()\r
{\r
- if (this.InvokeRequired)\r
+ try\r
{\r
- this.BeginInvoke(new Parsing.ScanProgressEventHandler(Parser_OnScanProgress), new object[] { Sender, CurrentTitle, TitleCount });\r
- return;\r
+ if (this.InvokeRequired)\r
+ {\r
+ this.BeginInvoke(new UpdateUIHandler(closeWindowAfterError));\r
+ return;\r
+ }\r
+ this.Close();\r
}\r
- int progress = Convert.ToInt32(Convert.ToDouble(CurrentTitle) / Convert.ToDouble(TitleCount) * 100) + 1;\r
- if (progress > 100)\r
+ catch (Exception exc)\r
{\r
- progress = 100;\r
+ MessageBox.Show("frmReadDVD.cs - closeWindowAfterError - Unable to recover from a serious error. \n\n Error Information: \n " + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
}\r
- this.lbl_progress.Text = progress.ToString() + "%";\r
}\r
\r
- private void btn_skip_Click(object sender, EventArgs e)\r
+ private void btn_cancel_Click(object sender, EventArgs e)\r
{\r
- //process.killCLI();\r
- this.Close();\r
- cancel = 1; \r
+ // This may seem like a long way of killing HandBrakeCLI, but for whatever reason,\r
+ // hbproc.kill/close just won't do the trick.\r
+ try\r
+ {\r
+ string AppName = "HandBrakeCLI";\r
+\r
+ AppName = AppName.ToUpper();\r
+\r
+ System.Diagnostics.Process[] prs = System.Diagnostics.Process.GetProcesses();\r
+ foreach (System.Diagnostics.Process proces in prs)\r
+ {\r
+ if (proces.ProcessName.ToUpper() == AppName)\r
+ {\r
+ proces.Refresh();\r
+ if (!proces.HasExited)\r
+ proces.Kill();\r
+ }\r
+ }\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ MessageBox.Show("Unable to kill HandBrakeCLI.exe \n\nError Information: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ }\r
}\r
-\r
}\r
}
\ No newline at end of file