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 Parsing.DVD thisDvd;
\r
27 private delegate void UpdateUIHandler();
\r
29 Functions.Common hb_common_func = new Functions.Common();
\r
31 public frmReadDVD(string inputFile, frmMain parent)
\r
33 InitializeComponent();
\r
34 this.inputFile = inputFile;
\r
35 this.mainWindow = parent;
\r
39 private void startScan()
\r
43 lbl_status.Visible = true;
\r
44 ThreadPool.QueueUserWorkItem(startProc);
\r
46 catch (Exception exc)
\r
48 MessageBox.Show("frmReadDVD.cs - startScan " + exc.ToString());
\r
52 private void updateUIElements()
\r
56 if (this.InvokeRequired)
\r
58 this.BeginInvoke(new UpdateUIHandler(updateUIElements));
\r
61 // Now pass this streamreader to frmMain so that it can be used there.
\r
62 mainWindow.setStreamReader(thisDvd);
\r
64 mainWindow.drp_dvdtitle.Items.Clear();
\r
65 if (thisDvd.Titles.Count != 0)
\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 if (thisDvd.Titles.Count != 0)
\r
73 hb_common_func.selectLongestTitle(mainWindow);
\r
77 catch (Exception exc)
\r
79 MessageBox.Show("frmReadDVD.cs - updateUIElements " + exc.ToString());
\r
84 Functions.Encode process = new Functions.Encode();
\r
86 private void startProc(object state)
\r
90 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
\r
91 string dvdInfoPath = Path.Combine(Path.GetTempPath(), "dvdinfo.dat");
\r
93 // Make we don't pick up a stale hb_encode_log.dat (and that we have rights to the file)
\r
94 if (File.Exists(dvdInfoPath))
\r
95 File.Delete(dvdInfoPath);
\r
97 string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 -v >""{2}"" 2>&1""", handbrakeCLIPath, inputFile, dvdInfoPath);
\r
99 ProcessStartInfo hbParseDvd = new ProcessStartInfo("CMD.exe", strCmdLine);
\r
100 hbParseDvd.WindowStyle = ProcessWindowStyle.Hidden;
\r
102 using (hbproc = Process.Start(hbParseDvd))
\r
104 hbproc.WaitForExit();
\r
107 if (!File.Exists(dvdInfoPath))
\r
109 throw new Exception("Unable to retrieve the DVD Info. dvdinfo.dat is missing.");
\r
112 using (StreamReader sr = new StreamReader(dvdInfoPath))
\r
114 thisDvd = Parsing.DVD.Parse(sr);
\r
119 updateUIElements();
\r
121 catch (Exception exc)
\r
123 MessageBox.Show("frmReadDVD.cs - startProc " + exc.ToString());
\r
129 private void btn_cancel_Click(object sender, EventArgs e)
\r
131 // This may seem like a long way of killing HandBrakeCLI, but for whatever reason,
\r
132 // hbproc.kill/close just won't do the trick.
\r
135 string AppName = "HandBrakeCLI";
\r
137 AppName = AppName.ToUpper();
\r
139 System.Diagnostics.Process[] prs = System.Diagnostics.Process.GetProcesses();
\r
140 foreach (System.Diagnostics.Process proces in prs)
\r
142 if (proces.ProcessName.ToUpper() == AppName)
\r
145 if (!proces.HasExited)
\r
150 catch (Exception ex)
\r
152 MessageBox.Show(ex.Message);
\r