+/* 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 delegate void UpdateUIHandler();\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
- lbl_status.Visible = true;\r
- btn_ok.Enabled = false;\r
- lbl_pressOk.Visible = false;\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
- // Just a quick test to see if data can be pushed to frmDvdInfo.\r
- // What needs to happen here is the plaintext outout needs to be sent to the frmDvdInfo.\r
- dvdInfo.rtf_dvdInfo.Text = thisDvd.ToString();\r
+ string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 -v >""{2}"" 2>&1""", handbrakeCLIPath, inputFile, dvdInfoPath);\r
\r
- this.Close();\r
- }\r
+ ProcessStartInfo hbParseDvd = new ProcessStartInfo("CMD.exe", strCmdLine);\r
+ hbParseDvd.WindowStyle = ProcessWindowStyle.Hidden;\r
\r
- private void startProc(object state)\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
- \r
- Functions.CLI process = new Functions.CLI();\r
- Process hbProc = process.runCli(this, query, true, true, false, true);\r
+ try\r
+ {\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
- Parsing.Parser readData = new Parsing.Parser(hbProc.StandardError.BaseStream);\r
- hbProc.WaitForExit();\r
- hbProc.Close();\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
- // Setup the parser\r
- thisDvd = Parsing.DVD.Parse(readData);\r
+ // Now select the longest title\r
+ if (thisDvd.Titles.Count != 0)\r
+ hb_common_func.selectLongestTitle(mainWindow);\r
\r
- updateUIElements();\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
+ private void closeWindowAfterError()\r
+ {\r
+ try\r
+ {\r
+ if (this.InvokeRequired)\r
+ {\r
+ this.BeginInvoke(new UpdateUIHandler(closeWindowAfterError));\r
+ return;\r
+ }\r
+ this.Close();\r
+ }\r
+ catch (Exception exc)\r
+ {\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
}\r
\r
+ private void btn_cancel_Click(object sender, EventArgs e)\r
+ {\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
}
\ No newline at end of file