3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Collections.Generic;
\r
9 using System.ComponentModel;
\r
11 using System.Drawing;
\r
13 using System.Windows.Forms;
\r
15 using System.Threading;
\r
16 using System.Diagnostics;
\r
17 using System.Collections;
\r
22 public partial class frmReadDVD : Form
\r
24 private string inputFile;
\r
25 private frmMain mainWindow;
\r
26 private frmDvdInfo dvdInfo;
\r
27 private Parsing.DVD thisDvd;
\r
28 private delegate void UpdateUIHandler();
\r
30 public frmReadDVD(string inputFile, frmMain parent, frmDvdInfo dvdInfoWindow)
\r
32 InitializeComponent();
\r
33 this.inputFile = inputFile;
\r
34 this.mainWindow = parent;
\r
35 this.dvdInfo = dvdInfoWindow;
\r
40 private void startScan()
\r
44 lbl_status.Visible = true;
\r
45 ThreadPool.QueueUserWorkItem(startProc);
\r
47 catch (Exception exc)
\r
49 MessageBox.Show("frmReadDVD.cs - startScan " + exc.ToString());
\r
53 private void updateUIElements()
\r
57 if (this.InvokeRequired)
\r
59 this.BeginInvoke(new UpdateUIHandler(updateUIElements));
\r
62 // Now pass this streamreader to frmMain so that it can be used there.
\r
63 mainWindow.setStreamReader(thisDvd);
\r
65 mainWindow.drp_dvdtitle.Items.Clear();
\r
66 mainWindow.drp_dvdtitle.Items.AddRange(thisDvd.Titles.ToArray());
\r
67 mainWindow.drp_dvdtitle.Text = "Automatic";
\r
68 mainWindow.drop_chapterFinish.Text = "Auto";
\r
69 mainWindow.drop_chapterStart.Text = "Auto";
\r
71 // Now select the longest title
\r
72 int current_largest = 0;
\r
73 Handbrake.Parsing.Title title2Select = thisDvd.Titles[0];
\r
75 foreach (Handbrake.Parsing.Title x in thisDvd.Titles)
\r
77 string title = x.ToString();
\r
78 if (title != "Automatic")
\r
80 string[] y = title.Split(' ');
\r
81 string time = y[1].Replace("(", "").Replace(")", "");
\r
82 string[] z = time.Split(':');
\r
84 int hours = int.Parse(z[0]) * 60 * 60;
\r
85 int minutes = int.Parse(z[1]) * 60;
\r
86 int seconds = int.Parse(z[2]);
\r
87 int total_sec = hours + minutes + seconds;
\r
89 if (current_largest == 0)
\r
91 current_largest = hours + minutes + seconds;
\r
96 if (total_sec > current_largest)
\r
98 current_largest = total_sec;
\r
107 mainWindow.drp_dvdtitle.SelectedItem = title2Select;
\r
111 catch (Exception exc)
\r
113 MessageBox.Show("frmReadDVD.cs - updateUIElements " + exc.ToString());
\r
117 Functions.CLI process = new Functions.CLI();
\r
119 private void startProc(object state)
\r
123 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
\r
124 string dvdInfoPath = Path.Combine(Path.GetTempPath(), "dvdinfo.dat");
\r
126 // Make we don't pick up a stale dvdinfo.dat (and that we have rights to the file)
\r
127 if (File.Exists(dvdInfoPath))
\r
128 File.Delete(dvdInfoPath);
\r
130 string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 -v >""{2}"" 2>&1""", handbrakeCLIPath, inputFile, dvdInfoPath);
\r
132 ProcessStartInfo hbParseDvd = new ProcessStartInfo("CMD.exe", strCmdLine);
\r
133 hbParseDvd.WindowStyle = ProcessWindowStyle.Hidden;
\r
134 using (Process hbproc = Process.Start(hbParseDvd))
\r
136 hbproc.WaitForExit();
\r
137 // TODO: Verify exit code if the CLI supports it properly
\r
140 if (!File.Exists(dvdInfoPath))
\r
142 throw new Exception("Unable to retrieve the DVD Info. dvdinfo.dat is missing.");
\r
145 using (StreamReader sr = new StreamReader(dvdInfoPath))
\r
147 thisDvd = Parsing.DVD.Parse(sr);
\r
150 updateUIElements();
\r
152 catch (Exception exc)
\r
154 MessageBox.Show("frmReadDVD.cs - startProc " + exc.ToString());
\r