+/* 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
\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
\r
private void startScan()\r
{\r
try\r
{\r
- //btn_skip.Visible = true;\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
}\r
catch (Exception exc)\r
{\r
- if (Properties.Settings.Default.GuiDebug == "Checked")\r
- {\r
- MessageBox.Show("frmReadDVD.cs - startScan " + exc.ToString());\r
- }\r
- else\r
- {\r
- MessageBox.Show(Properties.Settings.Default.defaultError.ToString());\r
- }\r
+ MessageBox.Show("frmReadDVD.cs - startScan " + exc.ToString());\r
}\r
}\r
- \r
+\r
private void updateUIElements()\r
{\r
try\r
mainWindow.drp_dvdtitle.Text = "Automatic";\r
mainWindow.drop_chapterFinish.Text = "Auto";\r
mainWindow.drop_chapterStart.Text = "Auto";\r
- \r
+\r
+ // Now select the longest title\r
+ int current_largest = 0;\r
+ Handbrake.Parsing.Title title2Select = thisDvd.Titles[0];\r
+\r
+ foreach (Handbrake.Parsing.Title x in thisDvd.Titles)\r
+ {\r
+ string title = x.ToString();\r
+ if (title != "Automatic")\r
+ {\r
+ string[] y = title.Split(' ');\r
+ string time = y[1].Replace("(", "").Replace(")", "");\r
+ string[] z = time.Split(':');\r
+\r
+ int hours = int.Parse(z[0]) * 60 * 60;\r
+ int minutes = int.Parse(z[1]) * 60;\r
+ int seconds = int.Parse(z[2]);\r
+ int total_sec = hours + minutes + seconds;\r
+\r
+ if (current_largest == 0)\r
+ {\r
+ current_largest = hours + minutes + seconds;\r
+ title2Select = x;\r
+ }\r
+ else\r
+ {\r
+ if (total_sec > current_largest)\r
+ {\r
+ current_largest = total_sec;\r
+ title2Select = x;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ mainWindow.drp_dvdtitle.SelectedItem = title2Select;\r
+\r
this.Close();\r
}\r
- catch(Exception exc)\r
+ catch (Exception exc)\r
{\r
- if (Properties.Settings.Default.GuiDebug == "Checked")\r
- {\r
- MessageBox.Show("frmReadDVD.cs - updateUIElements " + exc.ToString());\r
- }\r
- else\r
- {\r
- MessageBox.Show(Properties.Settings.Default.defaultError.ToString());\r
- }\r
+ MessageBox.Show("frmReadDVD.cs - updateUIElements " + exc.ToString());\r
+ this.Close();\r
}\r
}\r
\r
\r
private void startProc(object state)\r
{\r
- //string query = "-i " + '"' + inputFile + '"' + " -t0";\r
- // hbProc = process.runCli(this, query, true, true, false, true);\r
-\r
try\r
{\r
- string appPath = Application.StartupPath.ToString()+ "\\";\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
- hbproc.Dispose();\r
- hbproc.Close();\r
-\r
- \r
- StreamReader sr = new StreamReader(appPath + "dvdinfo.dat");\r
- thisDvd = Parsing.DVD.Parse(sr);\r
- sr.Close();\r
+ string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
+ string dvdInfoPath = Path.Combine(Path.GetTempPath(), "dvdinfo.dat");\r
\r
- updateUIElements();\r
- }\r
- catch (Exception exc)\r
- {\r
- if (Properties.Settings.Default.GuiDebug == "Checked")\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
- MessageBox.Show("frmReadDVD.cs - startProc " + exc.ToString());\r
+ hbproc.WaitForExit();\r
+ // TODO: Verify exit code if the CLI supports it properly\r
}\r
- else\r
+\r
+ if (!File.Exists(dvdInfoPath))\r
{\r
- MessageBox.Show(Properties.Settings.Default.defaultError.ToString());\r
+ throw new Exception("Unable to retrieve the DVD Info. dvdinfo.dat is missing.");\r
}\r
- }\r
-\r
- }\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
+ using (StreamReader sr = new StreamReader(dvdInfoPath))\r
+ {\r
+ thisDvd = Parsing.DVD.Parse(sr);\r
+ sr.Close();\r
+ sr.Dispose();\r
+ }\r
\r
- if (cancel != 1)\r
- {\r
updateUIElements();\r
- process.killCLI();\r
- process.closeCLI();\r
- }\r
- */\r
- //*********************************************************************************************************************************************\r
-\r
-\r
- /*private void Parser_OnScanProgress(object Sender, int CurrentTitle, int TitleCount)\r
- {\r
- if (this.InvokeRequired)\r
- {\r
- this.BeginInvoke(new Parsing.ScanProgressEventHandler(Parser_OnScanProgress), new object[] { Sender, CurrentTitle, TitleCount });\r
- return;\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 - startProc " + exc.ToString());\r
+ this.Close();\r
}\r
- this.lbl_progress.Text = progress.ToString() + "%";\r
- }*/\r
\r
+ }\r
}\r
}
\ No newline at end of file