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.Main hb_common_func = new Functions.Main();
\r
30 Functions.Encode process = new Functions.Encode();
\r
32 public frmReadDVD(string inputFile, frmMain parent)
\r
34 InitializeComponent();
\r
35 this.inputFile = inputFile;
\r
36 this.mainWindow = parent;
\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(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
53 private void startProc(object state)
\r
57 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
\r
58 string dvdInfoPath = Path.Combine(Path.GetTempPath(), "dvdinfo.dat");
\r
60 // Make we don't pick up a stale hb_encode_log.dat (and that we have rights to the file)
\r
61 if (File.Exists(dvdInfoPath))
\r
62 File.Delete(dvdInfoPath);
\r
64 string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 -v >""{2}"" 2>&1""", handbrakeCLIPath, inputFile, dvdInfoPath);
\r
66 ProcessStartInfo hbParseDvd = new ProcessStartInfo("CMD.exe", strCmdLine);
\r
67 hbParseDvd.WindowStyle = ProcessWindowStyle.Hidden;
\r
69 using (hbproc = Process.Start(hbParseDvd))
\r
71 hbproc.WaitForExit();
\r
74 if (!File.Exists(dvdInfoPath))
\r
76 throw new Exception("Unable to retrieve the DVD Info. dvdinfo.dat is missing. \nExpected location of dvdinfo.dat: \n" + dvdInfoPath);
\r
79 using (StreamReader sr = new StreamReader(dvdInfoPath))
\r
81 thisDvd = Parsing.DVD.Parse(sr);
\r
88 catch (Exception exc)
\r
90 MessageBox.Show("frmReadDVD.cs - startProc() " + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
91 closeWindowAfterError();
\r
95 private void updateUIElements()
\r
99 if (this.InvokeRequired)
\r
101 this.BeginInvoke(new UpdateUIHandler(updateUIElements));
\r
104 // Now pass this streamreader to frmMain so that it can be used there.
\r
105 mainWindow.setStreamReader(thisDvd);
\r
107 mainWindow.drp_dvdtitle.Items.Clear();
\r
108 if (thisDvd.Titles.Count != 0)
\r
109 mainWindow.drp_dvdtitle.Items.AddRange(thisDvd.Titles.ToArray());
\r
110 mainWindow.drp_dvdtitle.Text = "Automatic";
\r
111 mainWindow.drop_chapterFinish.Text = "Auto";
\r
112 mainWindow.drop_chapterStart.Text = "Auto";
\r
114 // Now select the longest title
\r
115 if (thisDvd.Titles.Count != 0)
\r
116 mainWindow.drp_dvdtitle.SelectedItem = hb_common_func.selectLongestTitle(mainWindow.drp_dvdtitle);
\r
120 catch (Exception exc)
\r
122 MessageBox.Show("frmReadDVD.cs - updateUIElements " + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
127 private void closeWindowAfterError()
\r
131 if (this.InvokeRequired)
\r
133 this.BeginInvoke(new UpdateUIHandler(closeWindowAfterError));
\r
138 catch (Exception exc)
\r
140 MessageBox.Show("frmReadDVD.cs - closeWindowAfterError - Unable to recover from a serious error. \nYou may need to restart HandBrake. \n\n Error Information: \n " + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
144 private void btn_cancel_Click(object sender, EventArgs e)
\r
146 // This may seem like a long way of killing HandBrakeCLI, but for whatever reason,
\r
147 // hbproc.kill/close just won't do the trick.
\r
150 string AppName = "HandBrakeCLI";
\r
152 AppName = AppName.ToUpper();
\r
154 System.Diagnostics.Process[] prs = System.Diagnostics.Process.GetProcesses();
\r
155 foreach (System.Diagnostics.Process proces in prs)
\r
157 if (proces.ProcessName.ToUpper() == AppName)
\r
160 if (!proces.HasExited)
\r
165 catch (Exception ex)
\r
167 MessageBox.Show("Unable to kill HandBrakeCLI.exe \nYou may need to manually kill HandBrakeCLI.exe using the Windows Task Manager if it does not close automatically within the next few minutes. \n\nError Information: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r