OSDN Git Service

WinGUI:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmReadDVD.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.ComponentModel;\r
4 using System.Data;\r
5 using System.Drawing;\r
6 using System.Text;\r
7 using System.Windows.Forms;\r
8 using System.IO;\r
9 using System.Threading;\r
10 using System.Diagnostics;\r
11 \r
12 \r
13 namespace Handbrake\r
14 {\r
15     public partial class frmReadDVD : Form\r
16     {\r
17         private string inputFile;\r
18         private frmMain mainWindow;\r
19         private frmDvdInfo dvdInfo;\r
20         private Parsing.DVD thisDvd;\r
21         private Process hbProc;\r
22         private delegate void UpdateUIHandler();\r
23 \r
24         public frmReadDVD(string inputFile, frmMain parent, frmDvdInfo dvdInfoWindow)\r
25         {\r
26             InitializeComponent();\r
27             this.inputFile = inputFile;\r
28             this.mainWindow = parent;\r
29             this.dvdInfo = dvdInfoWindow;\r
30             startScan();\r
31             \r
32         }\r
33 \r
34         private void startScan()\r
35         {\r
36             try\r
37             {\r
38                 lbl_status.Visible = true;\r
39                 ThreadPool.QueueUserWorkItem(startProc);\r
40             }\r
41             catch (Exception exc)\r
42             {\r
43                 if (Properties.Settings.Default.GuiDebug == "Checked")\r
44                 {\r
45                     MessageBox.Show("frmReadDVD.cs - startScan " + exc.ToString());\r
46                 }\r
47                 else\r
48                 {\r
49                     MessageBox.Show(Properties.Settings.Default.defaultError.ToString());\r
50                 }\r
51             }\r
52         }\r
53    \r
54         private void updateUIElements()\r
55         {\r
56             try\r
57             {\r
58                 if (this.InvokeRequired)\r
59                 {\r
60                     this.BeginInvoke(new UpdateUIHandler(updateUIElements));\r
61                     return;\r
62                 }\r
63                 // Now pass this streamreader to frmMain so that it can be used there.\r
64                 mainWindow.setStreamReader(thisDvd);\r
65 \r
66                 mainWindow.drp_dvdtitle.Items.Clear();\r
67                 mainWindow.drp_dvdtitle.Items.AddRange(thisDvd.Titles.ToArray());\r
68                 mainWindow.drp_dvdtitle.Text = "Automatic";\r
69                 mainWindow.drop_chapterFinish.Text = "Auto";\r
70                 mainWindow.drop_chapterStart.Text = "Auto";\r
71   \r
72                 this.Close();\r
73             }\r
74             catch(Exception exc)\r
75             {\r
76                 if (Properties.Settings.Default.GuiDebug == "Checked")\r
77                 {\r
78                     MessageBox.Show("frmReadDVD.cs - updateUIElements " + exc.ToString());\r
79                 }\r
80                 else\r
81                 {\r
82                     MessageBox.Show(Properties.Settings.Default.defaultError.ToString());\r
83                 }\r
84             }\r
85         }\r
86 \r
87         Functions.CLI process = new Functions.CLI();\r
88 \r
89         private void startProc(object state)\r
90         {\r
91             try\r
92             {\r
93                 string appPath = Application.StartupPath.ToString()+ "\\";\r
94                 string strCmdLine = "cmd /c " + '"' + '"' + appPath + "HandBrakeCLI.exe" + '"' + " -i " + '"' + inputFile + '"' + " -t0 >" + '"' + appPath + "dvdinfo.dat" + '"' + " 2>&1" + '"';\r
95                 Process hbproc = Process.Start("CMD.exe", strCmdLine);\r
96                 hbproc.WaitForExit();\r
97                 hbproc.Dispose();\r
98                 hbproc.Close();\r
99 \r
100           \r
101                 StreamReader sr = new StreamReader(appPath + "dvdinfo.dat");\r
102                 thisDvd = Parsing.DVD.Parse(sr);\r
103                 sr.Close();\r
104 \r
105                 updateUIElements();\r
106             }\r
107             catch (Exception exc)\r
108             {\r
109                 if (Properties.Settings.Default.GuiDebug == "Checked")\r
110                 {\r
111                     MessageBox.Show("frmReadDVD.cs - startProc " + exc.ToString());\r
112                 }\r
113                 else\r
114                 {\r
115                     MessageBox.Show(Properties.Settings.Default.defaultError.ToString());\r
116                 }\r
117             }\r
118 \r
119         }\r
120     }\r
121 }