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
\r
private void startScan()\r
}\r
catch (Exception exc)\r
{\r
- MessageBox.Show("frmReadDVD.cs - startScan " + exc.ToString());\r
+ MessageBox.Show("frmReadDVD.cs - startScan " + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
}\r
}\r
+ private void startProc(object state)\r
+ {\r
+ try\r
+ {\r
+ string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
+ string dvdInfoPath = Path.Combine(Path.GetTempPath(), "dvdinfo.dat");\r
+\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
+ string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 -v >""{2}"" 2>&1""", handbrakeCLIPath, inputFile, dvdInfoPath);\r
+\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
try\r
mainWindow.setStreamReader(thisDvd);\r
\r
mainWindow.drp_dvdtitle.Items.Clear();\r
- mainWindow.drp_dvdtitle.Items.AddRange(thisDvd.Titles.ToArray());\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());\r
+ MessageBox.Show("frmReadDVD.cs - updateUIElements " + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ this.Close();\r
}\r
}\r
-\r
- Functions.CLI process = new Functions.CLI();\r
-\r
- private void startProc(object state)\r
+ private void closeWindowAfterError()\r
{\r
try\r
{\r
- string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
- string dvdInfoPath = Path.Combine(Path.GetTempPath(), "dvdinfo.dat");\r
-\r
- // Make we don't pick up a stale dvdinfo.dat (and that we have rights to the file)\r
- if (File.Exists(dvdInfoPath))\r
- File.Delete(dvdInfoPath);\r
-\r
- string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 -v >""{2}"" 2>&1""", handbrakeCLIPath, inputFile, dvdInfoPath);\r
-\r
- ProcessStartInfo hbParseDvd = new ProcessStartInfo("CMD.exe", strCmdLine);\r
- hbParseDvd.WindowStyle = ProcessWindowStyle.Hidden;\r
- using (Process hbproc = Process.Start(hbParseDvd))\r
- {\r
- hbproc.WaitForExit();\r
- // TODO: Verify exit code if the CLI supports it properly\r
- } \r
-\r
- if (!File.Exists(dvdInfoPath))\r
+ if (this.InvokeRequired)\r
{\r
- throw new Exception("Unable to retrieve the DVD Info. dvdinfo.dat missing.");\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
- using (StreamReader sr = new StreamReader(dvdInfoPath))\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
- thisDvd = Parsing.DVD.Parse(sr);\r
+ if (proces.ProcessName.ToUpper() == AppName)\r
+ {\r
+ proces.Refresh();\r
+ if (!proces.HasExited)\r
+ proces.Kill();\r
+ }\r
}\r
-\r
- updateUIElements();\r
}\r
- catch (Exception exc)\r
+ catch (Exception ex)\r
{\r
- MessageBox.Show("frmReadDVD.cs - startProc " + exc.ToString());\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