OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmReadDVD.cs
1 /*  frmReadDVD.cs $\r
2         \r
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
6 \r
7 using System;\r
8 using System.Collections.Generic;\r
9 using System.ComponentModel;\r
10 using System.Data;\r
11 using System.Drawing;\r
12 using System.Text;\r
13 using System.Windows.Forms;\r
14 using System.IO;\r
15 using System.Threading;\r
16 using System.Diagnostics;\r
17 using System.Collections;\r
18 \r
19 \r
20 namespace Handbrake\r
21 {\r
22     public partial class frmReadDVD : Form\r
23     {\r
24         private string inputFile;\r
25         private frmMain mainWindow;\r
26         private Parsing.DVD thisDvd;\r
27         private delegate void UpdateUIHandler();\r
28         Functions.Common hb_common_func = new Functions.Common();\r
29 \r
30         public frmReadDVD(string inputFile, frmMain parent)\r
31         {\r
32             InitializeComponent();\r
33             this.inputFile = inputFile;\r
34             this.mainWindow = parent;\r
35             startScan();\r
36 \r
37         }\r
38 \r
39         private void startScan()\r
40         {\r
41             try\r
42             {\r
43                 lbl_status.Visible = true;\r
44                 ThreadPool.QueueUserWorkItem(startProc);\r
45             }\r
46             catch (Exception exc)\r
47             {\r
48                 MessageBox.Show("frmReadDVD.cs - startScan " + exc.ToString());\r
49             }\r
50         }\r
51 \r
52         private void updateUIElements()\r
53         {\r
54             try\r
55             {\r
56                 if (this.InvokeRequired)\r
57                 {\r
58                     this.BeginInvoke(new UpdateUIHandler(updateUIElements));\r
59                     return;\r
60                 }\r
61                 // Now pass this streamreader to frmMain so that it can be used there.\r
62                 mainWindow.setStreamReader(thisDvd);\r
63 \r
64                 mainWindow.drp_dvdtitle.Items.Clear();\r
65                 mainWindow.drp_dvdtitle.Items.AddRange(thisDvd.Titles.ToArray());\r
66                 mainWindow.drp_dvdtitle.Text = "Automatic";\r
67                 mainWindow.drop_chapterFinish.Text = "Auto";\r
68                 mainWindow.drop_chapterStart.Text = "Auto";\r
69 \r
70                 // Now select the longest title\r
71                 hb_common_func.selectLongestTitle(mainWindow);\r
72 \r
73                 \r
74 \r
75                 this.Close();\r
76             }\r
77             catch (Exception exc)\r
78             {\r
79                 MessageBox.Show("frmReadDVD.cs - updateUIElements " + exc.ToString());\r
80                 this.Close();\r
81             }\r
82         }\r
83 \r
84         Functions.CLI process = new Functions.CLI();\r
85 \r
86         private void startProc(object state)\r
87         {\r
88             try\r
89             {\r
90                 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
91                 string dvdInfoPath = Path.Combine(Path.GetTempPath(), "dvdinfo.dat");\r
92 \r
93                 // Make we don't pick up a stale dvdinfo.dat (and that we have rights to the file)\r
94                 if (File.Exists(dvdInfoPath))\r
95                     File.Delete(dvdInfoPath);\r
96 \r
97                 string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 -v >""{2}"" 2>&1""", handbrakeCLIPath, inputFile, dvdInfoPath);\r
98 \r
99                 ProcessStartInfo hbParseDvd = new ProcessStartInfo("CMD.exe", strCmdLine);\r
100                 hbParseDvd.WindowStyle = ProcessWindowStyle.Hidden;\r
101                 using (Process hbproc = Process.Start(hbParseDvd))\r
102                 {\r
103                     hbproc.WaitForExit();\r
104                     // TODO: Verify exit code if the CLI supports it properly\r
105                 }\r
106 \r
107                 if (!File.Exists(dvdInfoPath))\r
108                 {\r
109                     throw new Exception("Unable to retrieve the DVD Info. dvdinfo.dat is missing.");\r
110                 }\r
111 \r
112                 using (StreamReader sr = new StreamReader(dvdInfoPath))\r
113                 {\r
114                     thisDvd = Parsing.DVD.Parse(sr);\r
115                     sr.Close();\r
116                     sr.Dispose();\r
117                 }\r
118 \r
119                 updateUIElements();\r
120             }\r
121             catch (Exception exc)\r
122             {\r
123                 MessageBox.Show("frmReadDVD.cs - startProc " + exc.ToString());\r
124                 this.Close();\r
125             }\r
126 \r
127         }\r
128     }\r
129 }