OSDN Git Service

Change the fifo size from being statically tuned for a Mac Pro with 4 CPUs to dynamic...
[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                 //btn_skip.Visible = true;\r
39                 lbl_progress.Text = "0%";\r
40                 //lbl_progress.Visible = true;\r
41                 lbl_status.Visible = true;\r
42                 // throw cli call and parsing on it's own thread\r
43                 ThreadPool.QueueUserWorkItem(startProc);\r
44             }\r
45             catch (Exception exc)\r
46             {\r
47                 if (Properties.Settings.Default.GuiDebug == "Checked")\r
48                 {\r
49                     MessageBox.Show("frmReadDVD.cs - startScan " + exc.ToString());\r
50                 }\r
51                 else\r
52                 {\r
53                     MessageBox.Show(Properties.Settings.Default.defaultError.ToString());\r
54                 }\r
55             }\r
56         }\r
57    \r
58         private void updateUIElements()\r
59         {\r
60             try\r
61             {\r
62                 if (this.InvokeRequired)\r
63                 {\r
64                     this.BeginInvoke(new UpdateUIHandler(updateUIElements));\r
65                     return;\r
66                 }\r
67                 // Now pass this streamreader to frmMain so that it can be used there.\r
68                 mainWindow.setStreamReader(thisDvd);\r
69 \r
70                 mainWindow.drp_dvdtitle.Items.Clear();\r
71                 mainWindow.drp_dvdtitle.Items.AddRange(thisDvd.Titles.ToArray());\r
72                 mainWindow.drp_dvdtitle.Text = "Automatic";\r
73                 mainWindow.drop_chapterFinish.Text = "Auto";\r
74                 mainWindow.drop_chapterStart.Text = "Auto";\r
75   \r
76                 this.Close();\r
77             }\r
78             catch(Exception exc)\r
79             {\r
80                 if (Properties.Settings.Default.GuiDebug == "Checked")\r
81                 {\r
82                     MessageBox.Show("frmReadDVD.cs - updateUIElements " + exc.ToString());\r
83                 }\r
84                 else\r
85                 {\r
86                     MessageBox.Show(Properties.Settings.Default.defaultError.ToString());\r
87                 }\r
88             }\r
89         }\r
90 \r
91         Functions.CLI process = new Functions.CLI();\r
92 \r
93         private void startProc(object state)\r
94         {\r
95             //string query = "-i " + '"' + inputFile + '"' + " -t0";\r
96             // hbProc = process.runCli(this, query, true, true, false, true);\r
97 \r
98             try\r
99             {\r
100                 string appPath = Application.StartupPath.ToString()+ "\\";\r
101                 string strCmdLine = "cmd /c " + '"' + '"' + appPath + "hbcli.exe" + '"' +  " -i " + '"' + inputFile + '"' + " -t0 >" + '"'+ appPath + "dvdinfo.dat" + '"' + " 2>&1" + '"';\r
102                 Process hbproc = Process.Start("CMD.exe", strCmdLine);\r
103                 hbproc.WaitForExit();\r
104                 hbproc.Dispose();\r
105                 hbproc.Close();\r
106 \r
107           \r
108                 StreamReader sr = new StreamReader(appPath + "dvdinfo.dat");\r
109                 thisDvd = Parsing.DVD.Parse(sr);\r
110                 sr.Close();\r
111 \r
112                 updateUIElements();\r
113             }\r
114             catch (Exception exc)\r
115             {\r
116                 if (Properties.Settings.Default.GuiDebug == "Checked")\r
117                 {\r
118                     MessageBox.Show("frmReadDVD.cs - startProc " + exc.ToString());\r
119                 }\r
120                 else\r
121                 {\r
122                     MessageBox.Show(Properties.Settings.Default.defaultError.ToString());\r
123                 }\r
124             }\r
125 \r
126         }\r
127 \r
128             //*********************************************************************************************************************************************\r
129             /*\r
130              * This has been temporily disabled due to the stderr issue\r
131              * \r
132              * \r
133             Parsing.Parser readData = new Parsing.Parser(hbProc.StandardError.BaseStream);\r
134             readData.OnScanProgress += Parser_OnScanProgress;\r
135             readData.OnReadLine += dvdInfo.HandleParsedData;\r
136             readData.OnReadToEnd += dvdInfo.HandleParsedData;\r
137 \r
138             // Setup the parser\r
139             \r
140 \r
141             if (cancel != 1)\r
142             {\r
143                 updateUIElements();\r
144                 process.killCLI();\r
145                 process.closeCLI();\r
146             }\r
147             */\r
148             //*********************************************************************************************************************************************\r
149 \r
150 \r
151         /*private void Parser_OnScanProgress(object Sender, int CurrentTitle, int TitleCount)\r
152         {\r
153             if (this.InvokeRequired)\r
154             {\r
155                 this.BeginInvoke(new Parsing.ScanProgressEventHandler(Parser_OnScanProgress), new object[] { Sender, CurrentTitle, TitleCount });\r
156                 return;\r
157             }\r
158             int progress = Convert.ToInt32(Convert.ToDouble(CurrentTitle) / Convert.ToDouble(TitleCount) * 100) + 1;\r
159             if (progress > 100)\r
160             {\r
161                 progress = 100;\r
162             }\r
163             this.lbl_progress.Text = progress.ToString() + "%";\r
164         }*/\r
165 \r
166     }\r
167 }