OSDN Git Service

59e31c53186421a5947285cf680f5513537ae3a6
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.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.Net;\r
9 using System.IO;\r
10 using System.Diagnostics;\r
11 using System.Threading;\r
12 \r
13 namespace Handbrake\r
14 {\r
15     public partial class frmMain : Form\r
16     {\r
17         private Process hbProc;\r
18         private Parsing.DVD thisDVD;\r
19 \r
20         // --------------------------------------------------------------\r
21         // Some windows that require only 1 instance.\r
22         // --------------------------------------------------------------\r
23         private frmQueue queueWindow = new frmQueue();  \r
24         \r
25         // -------------------------------------------------------------- \r
26         // Stuff that needs doing on startup.\r
27         // - Load users default settings. (if required)\r
28         // - Do an update check (if required)\r
29         // --------------------------------------------------------------\r
30         private frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
31         \r
32         public frmMain()\r
33         {\r
34             \r
35             ThreadPool.QueueUserWorkItem(showSplash);\r
36             Thread.Sleep(3000);\r
37 \r
38             InitializeComponent();\r
39 \r
40             // This is a quick Hack fix for the cross-thread problem with frmDvdIndo ************************\r
41             dvdInfoWindow.Show();\r
42             dvdInfoWindow.Hide();\r
43             // **********************************************************************************************\r
44 \r
45             // Set the Version number lable to the corect version.\r
46             Version.Text = "Version " + Properties.Settings.Default.GuiVersion;\r
47 \r
48             // Run the update checker.\r
49             updateCheck();\r
50 \r
51             // Now load the users default if required.\r
52             loadUserDefaults();\r
53         }\r
54 \r
55         public void showSplash(object sender)\r
56         {\r
57             Form splash = new frmSplashScreen();\r
58             splash.Show();\r
59             Thread.Sleep(3000);\r
60             splash.Close();\r
61         }\r
62         public void loadUserDefaults()\r
63         { \r
64             try\r
65             {\r
66                 if (Properties.Settings.Default.defaultSettings == "Checked")\r
67                 {\r
68                     // Source\r
69                     text_source.Text = Properties.Settings.Default.DVDSource;\r
70                     drp_dvdtitle.Text = Properties.Settings.Default.DVDTitle;\r
71                     drop_chapterStart.Text = Properties.Settings.Default.ChapterStart;\r
72                     drop_chapterFinish.Text = Properties.Settings.Default.ChapterFinish;\r
73 \r
74                     // Destination\r
75                     text_destination.Text = Properties.Settings.Default.VideoDest;\r
76                     drp_videoEncoder.Text = Properties.Settings.Default.VideoEncoder;\r
77                     drp_audioCodec.Text = Properties.Settings.Default.AudioEncoder;\r
78                     text_width.Text = Properties.Settings.Default.Width;\r
79                     text_height.Text = Properties.Settings.Default.Height;\r
80 \r
81                     // Picture Settings Tab\r
82                     drp_crop.Text = Properties.Settings.Default.CroppingOption;\r
83                     text_top.Text = Properties.Settings.Default.CropTop;\r
84                     text_bottom.Text = Properties.Settings.Default.CropBottom;\r
85                     text_left.Text = Properties.Settings.Default.CropLeft;\r
86                     text_right.Text = Properties.Settings.Default.CropRight;\r
87                     drp_subtitle.Text = Properties.Settings.Default.Subtitles;\r
88 \r
89                     // Video Settings Tab\r
90                     text_bitrate.Text = Properties.Settings.Default.VideoBitrate;\r
91                     text_filesize.Text = Properties.Settings.Default.VideoFilesize;\r
92                     slider_videoQuality.Value = Properties.Settings.Default.VideoQuality;\r
93 \r
94                     if (Properties.Settings.Default.TwoPass == "Checked")\r
95                     {\r
96                         check_2PassEncode.CheckState = CheckState.Checked;\r
97                     }\r
98                     if (Properties.Settings.Default.DeInterlace == "Checked")\r
99                     {\r
100                         check_DeInterlace.CheckState = CheckState.Checked;\r
101                     }\r
102                     if (Properties.Settings.Default.Grayscale == "Checked")\r
103                     {\r
104                         check_grayscale.CheckState = CheckState.Checked;\r
105                     }\r
106 \r
107                     drp_videoFramerate.Text = Properties.Settings.Default.Framerate;\r
108 \r
109                     if (Properties.Settings.Default.PixelRatio == "Checked")\r
110                     {\r
111                         CheckPixelRatio.CheckState = CheckState.Checked;\r
112                     }\r
113                     if (Properties.Settings.Default.turboFirstPass == "Checked")\r
114                     {\r
115                         check_turbo.CheckState = CheckState.Checked;\r
116                     }\r
117                     if (Properties.Settings.Default.largeFile == "Checked")\r
118                     {\r
119                         check_largeFile.CheckState = CheckState.Checked;\r
120                     }\r
121                     // Audio Settings Tab\r
122                     drp_audioBitrate.Text = Properties.Settings.Default.AudioBitrate;\r
123                     drp_audioSampleRate.Text = Properties.Settings.Default.AudioSampleRate;\r
124                     drp_audioChannels.Text = Properties.Settings.Default.AudioChannels;\r
125 \r
126                     // H264 Tab\r
127                     if (Properties.Settings.Default.CRF == "Checked")\r
128                     {\r
129                         CheckCRF.CheckState = CheckState.Checked;\r
130                     }\r
131                     rtf_h264advanced.Text = Properties.Settings.Default.H264;\r
132                 }\r
133             }\r
134             catch (Exception)\r
135             {\r
136                 // No real need to alert the user. Try/Catch only in just incase there is a problem reading the settings xml file.\r
137             }\r
138         }\r
139 \r
140         public void updateCheck()\r
141         {\r
142             if (Properties.Settings.Default.updateStatus == "Checked")\r
143             {\r
144                 try\r
145                 {\r
146                     String updateFile = Properties.Settings.Default.updateFile;\r
147                     WebClient client = new WebClient();\r
148                     String data = client.DownloadString(updateFile);\r
149                     String[] versionData = data.Split('\n');\r
150 \r
151                     if ((versionData[0] != Properties.Settings.Default.GuiVersion) || (versionData[1] != Properties.Settings.Default.CliVersion))\r
152                     {\r
153                         lbl_update.Visible = true;\r
154                     }\r
155                 }\r
156                 catch (Exception)\r
157                 {\r
158                     // Silently ignore the error\r
159                 }\r
160             }\r
161         }\r
162 \r
163         // -------------------------------------------------------------- \r
164         // The main Menu bar.\r
165         // -------------------------------------------------------------- \r
166 \r
167         #region File Menu\r
168 \r
169         private void mnu_open_Click(object sender, EventArgs e)\r
170         {\r
171             string filename;\r
172             File_Open.ShowDialog();\r
173             filename = File_Open.FileName;\r
174             if (filename != "")\r
175             {\r
176                 try\r
177                 {\r
178                     // Create StreamReader & open file\r
179                     StreamReader line = new StreamReader(filename);\r
180                     string temporyLine; // Used for reading the line into a varible before processing on the checkState items below.\r
181                     \r
182                     // Read in the data and set the correct GUI component with the setting.\r
183                     text_source.Text = line.ReadLine();\r
184                     drp_dvdtitle.Text = line.ReadLine();\r
185                     drop_chapterStart.Text = line.ReadLine();\r
186                     drop_chapterFinish.Text = line.ReadLine();\r
187                     text_destination.Text = line.ReadLine();\r
188                     drp_videoEncoder.Text = line.ReadLine();\r
189                     drp_audioCodec.Text = line.ReadLine();\r
190                     text_width.Text = line.ReadLine();\r
191                     text_height.Text = line.ReadLine();\r
192                     text_top.Text = line.ReadLine();\r
193                     text_bottom.Text = line.ReadLine();\r
194                     text_left.Text = line.ReadLine();\r
195                     text_right.Text = line.ReadLine();\r
196                     drp_subtitle.Text = line.ReadLine();\r
197                     text_bitrate.Text = line.ReadLine();\r
198                     text_filesize.Text = line.ReadLine();\r
199                     slider_videoQuality.Value = int.Parse(line.ReadLine());\r
200 \r
201                     temporyLine = line.ReadLine();\r
202                     if (temporyLine == "Checked")\r
203                     {\r
204                         check_2PassEncode.CheckState = CheckState.Checked;\r
205                     }\r
206 \r
207                     temporyLine = line.ReadLine();\r
208                     if (temporyLine == "Checked")\r
209                     {\r
210                         check_DeInterlace.CheckState = CheckState.Checked;\r
211                     }\r
212 \r
213                     temporyLine = line.ReadLine();\r
214                     if (temporyLine == "Checked")\r
215                     {\r
216                         check_grayscale.CheckState = CheckState.Checked;\r
217                     }\r
218 \r
219                     drp_videoFramerate.Text = line.ReadLine();\r
220 \r
221                     temporyLine = line.ReadLine();\r
222                     if (temporyLine == "Checked")\r
223                     {\r
224                         Check_ChapterMarkers.CheckState = CheckState.Checked;\r
225                     }\r
226 \r
227                     temporyLine = line.ReadLine();\r
228                     if (temporyLine == "Checked")\r
229                     {\r
230                         CheckPixelRatio.CheckState = CheckState.Checked;\r
231                     }\r
232 \r
233                     temporyLine = line.ReadLine();\r
234                     if (temporyLine == "Checked")\r
235                     {\r
236                         check_turbo.CheckState = CheckState.Checked;\r
237                     }\r
238 \r
239                     temporyLine = line.ReadLine();\r
240                     if (temporyLine == "Checked")\r
241                     {\r
242                         check_largeFile.CheckState = CheckState.Checked;\r
243                     }\r
244    \r
245                     drp_audioBitrate.Text = line.ReadLine();\r
246                     drp_audioSampleRate.Text = line.ReadLine();\r
247                     drp_audioChannels.Text = line.ReadLine();\r
248                     drp_audioMixDown.Text = line.ReadLine();\r
249                     \r
250                     // Advanced H264 Options\r
251                     temporyLine = line.ReadLine();\r
252                     if (temporyLine == "Checked")\r
253                     {\r
254                         CheckCRF.CheckState = CheckState.Checked;\r
255                     }\r
256                     rtf_h264advanced.Text = line.ReadLine();\r
257 \r
258                     // Close the stream\r
259                     line.Close();\r
260 \r
261 \r
262                     // Fix for SliderValue not appearing when Opening saved file\r
263                     SliderValue.Text = slider_videoQuality.Value + "%";\r
264 \r
265                 } catch (Exception){\r
266                     MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
267                 }\r
268             }\r
269         }\r
270 \r
271         private void mnu_save_Click(object sender, EventArgs e)\r
272         {\r
273 \r
274             string filename;\r
275             File_Save.ShowDialog();\r
276             filename = File_Save.FileName;\r
277             if (filename != "")\r
278             {\r
279                 try\r
280                 {\r
281                     // Create a StreamWriter and open the file\r
282                     StreamWriter line = new StreamWriter(filename);\r
283 \r
284                     //Source\r
285                     line.WriteLine(text_source.Text);\r
286                     line.WriteLine(drp_dvdtitle.Text);\r
287                     line.WriteLine(drop_chapterStart.Text);\r
288                     line.WriteLine(drop_chapterFinish.Text);\r
289                     //Destination\r
290                     line.WriteLine(text_destination.Text);\r
291                     line.WriteLine(drp_videoEncoder.Text);\r
292                     line.WriteLine(drp_audioCodec.Text);\r
293                     line.WriteLine(text_width.Text);\r
294                     line.WriteLine(text_height.Text);\r
295                     //Picture Settings Tab\r
296                     line.WriteLine(text_top.Text);\r
297                     line.WriteLine(text_bottom.Text);\r
298                     line.WriteLine(text_left.Text);\r
299                     line.WriteLine(text_right.Text);\r
300                     line.WriteLine(drp_subtitle.Text);\r
301                     //Video Settings Tab\r
302                     line.WriteLine(text_bitrate.Text);\r
303                     line.WriteLine(text_filesize.Text);\r
304                     line.WriteLine(slider_videoQuality.Value.ToString());\r
305                     line.WriteLine(check_2PassEncode.CheckState.ToString());\r
306                     line.WriteLine(check_DeInterlace.CheckState.ToString());\r
307                     line.WriteLine(check_grayscale.CheckState.ToString());\r
308                     line.WriteLine(drp_videoFramerate.Text);\r
309                     line.WriteLine(Check_ChapterMarkers.CheckState.ToString());\r
310                     line.WriteLine(CheckPixelRatio.CheckState.ToString());\r
311                     line.WriteLine(check_turbo.CheckState.ToString());\r
312                     line.WriteLine(check_largeFile.CheckState.ToString());\r
313                     //Audio Settings Tab\r
314                     line.WriteLine(drp_audioBitrate.Text);\r
315                     line.WriteLine(drp_audioSampleRate.Text);\r
316                     line.WriteLine(drp_audioChannels.Text);\r
317                     line.WriteLine(drp_audioMixDown.Text);\r
318                     //H264 Tab\r
319                     line.WriteLine(CheckCRF.CheckState.ToString());\r
320                     line.WriteLine(rtf_h264advanced.Text);\r
321                     // close the stream\r
322                     line.Close();\r
323                     MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
324                 }\r
325                 catch(Exception)\r
326                 {\r
327                     MessageBox.Show("Unable to write to the file. Please make sure the location has the correct permissions for file writing.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
328                 }\r
329                 \r
330             }\r
331         }\r
332 \r
333         private void mnu_update_Click(object sender, EventArgs e)\r
334         {\r
335             Form Update = new frmUpdate();\r
336             Update.ShowDialog();\r
337         }\r
338 \r
339         private void mnu_exit_Click(object sender, EventArgs e)\r
340         {\r
341             this.Close();\r
342         }\r
343 \r
344         #endregion\r
345 \r
346         #region Tools Menu\r
347 \r
348         private void mnu_encode_Click(object sender, EventArgs e)\r
349         {\r
350             showQueue();\r
351         }\r
352 \r
353        \r
354         private void mnu_viewDVDdata_Click(object sender, EventArgs e)\r
355         {\r
356             try\r
357             {\r
358                 dvdInfoWindow.Show();\r
359                 \r
360             }\r
361             catch (Exception)\r
362             {\r
363             }\r
364 \r
365             // BUG *******************************************************\r
366             // Cross-thread operation not valid: Control 'rtf_dvdInfo' accessed from a thread other than the thread it was created on.\r
367             // This happens when the DVD is scanned and this item is then selected.\r
368             // If this item is selected so a blank copy of the window appears, then a DVD is scanned, there is no cross-thread issue.\r
369             // NOTE: Try/catch added to prevent final build crashing.\r
370             // NOTE2: Included a quick fix in frmMain(). Simply show and hide the window when starting the app.\r
371             // Note3: Suspect the problem lies with line 30.\r
372             // ***********************************************************\r
373 \r
374         }\r
375 \r
376         private void mnu_options_Click(object sender, EventArgs e)\r
377         {\r
378             Form Options = new frmOptions();\r
379             Options.ShowDialog();\r
380         }\r
381 \r
382         #endregion\r
383 \r
384         #region Presets Menu\r
385 \r
386         private void mnu_preset_ipod133_Click(object sender, EventArgs e)\r
387         {\r
388             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
389             text_width.Text = "640";\r
390             text_height.Text = "480";\r
391             drp_videoEncoder.Text = "H.264 (iPod)";\r
392             text_bitrate.Text = "1000";\r
393             text_filesize.Text = "";\r
394             slider_videoQuality.Value = 0;\r
395             SliderValue.Text = "0%";\r
396             drp_audioBitrate.Text = "160";\r
397             rtf_h264advanced.Text = "";\r
398             drp_crop.Text = "No Crop";\r
399         }\r
400 \r
401         private void mnu_preset_ipod178_Click(object sender, EventArgs e)\r
402         {\r
403             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
404             text_width.Text = "640";\r
405             text_height.Text = "352";\r
406             drp_videoEncoder.Text = "H.264 (iPod)";\r
407             text_bitrate.Text = "1000";\r
408             text_filesize.Text = "";\r
409             slider_videoQuality.Value = 0;\r
410             SliderValue.Text = "0%";\r
411             drp_audioBitrate.Text = "160";\r
412             rtf_h264advanced.Text = "";\r
413             drp_crop.Text = "No Crop";\r
414         }\r
415 \r
416         private void mnu_preset_ipod235_Click(object sender, EventArgs e)\r
417         {\r
418             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
419             text_width.Text = "640";\r
420             text_height.Text = "272";\r
421             drp_videoEncoder.Text = "H.264 (iPod)";\r
422             text_bitrate.Text = "1000";\r
423             text_filesize.Text = "";\r
424             slider_videoQuality.Value = 0;\r
425             SliderValue.Text = "0%";\r
426             drp_audioBitrate.Text = "160";\r
427             rtf_h264advanced.Text = "";\r
428             drp_crop.Text = "No Crop";\r
429         }\r
430 \r
431         private void mnu_appleTv_Click(object sender, EventArgs e)\r
432         {\r
433             text_width.Text = "";\r
434             text_height.Text = "";\r
435             drp_videoEncoder.Text = "H.264";\r
436             text_bitrate.Text = "3000";\r
437             text_filesize.Text = "";\r
438             slider_videoQuality.Value = 0;\r
439             SliderValue.Text = "0%";\r
440             drp_audioBitrate.Text = "160";\r
441             CheckPixelRatio.CheckState = CheckState.Checked;\r
442             drp_audioSampleRate.Text = "48";\r
443             rtf_h264advanced.Text = "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";\r
444             drp_crop.Text = "No Crop";\r
445             \r
446         }\r
447 \r
448         private void mnu_presetPS3_Click(object sender, EventArgs e)\r
449         {\r
450             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
451             text_width.Text = "";\r
452             text_height.Text = "";\r
453             drp_videoEncoder.Text = "H.264";\r
454             text_bitrate.Text = "3000";\r
455             text_filesize.Text = "";\r
456             slider_videoQuality.Value = 0;\r
457             SliderValue.Text = "0%";\r
458             drp_audioBitrate.Text = "160";\r
459             CheckPixelRatio.CheckState = CheckState.Checked;\r
460             drp_audioSampleRate.Text = "48";\r
461             rtf_h264advanced.Text = "level=41";\r
462             drp_crop.Text = "No Crop";\r
463         }\r
464 \r
465         private void mnu_ProgramDefaultOptions_Click(object sender, EventArgs e)\r
466         {\r
467             //Source\r
468             Properties.Settings.Default.DVDSource = text_source.Text;\r
469             Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;\r
470             Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;\r
471             Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;\r
472             //Destination\r
473             Properties.Settings.Default.VideoDest = text_destination.Text;\r
474             Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;\r
475             Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;\r
476             Properties.Settings.Default.Width = text_width.Text;\r
477             Properties.Settings.Default.Height = text_height.Text;\r
478             //Picture Settings Tab\r
479             Properties.Settings.Default.CroppingOption = drp_crop.Text;\r
480             Properties.Settings.Default.CropTop = text_top.Text;\r
481             Properties.Settings.Default.CropBottom = text_bottom.Text;\r
482             Properties.Settings.Default.CropLeft = text_left.Text;\r
483             Properties.Settings.Default.CropRight = text_right.Text;\r
484             Properties.Settings.Default.Subtitles = drp_subtitle.Text;\r
485             //Video Settings Tab\r
486             Properties.Settings.Default.VideoBitrate = text_bitrate.Text;\r
487             Properties.Settings.Default.VideoFilesize = text_filesize.Text;\r
488             Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;\r
489             Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();\r
490             Properties.Settings.Default.DeInterlace = check_DeInterlace.CheckState.ToString();\r
491             Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();\r
492             Properties.Settings.Default.Framerate = drp_videoFramerate.Text;\r
493             Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();\r
494             Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();\r
495             Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString();\r
496             //Audio Settings Tab\r
497             Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;\r
498             Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;\r
499             Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;\r
500             //H264 Tab\r
501             Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();\r
502             Properties.Settings.Default.H264 = rtf_h264advanced.Text;\r
503             Properties.Settings.Default.Save();\r
504         }\r
505 \r
506         #endregion\r
507 \r
508         #region Help Menu\r
509 \r
510         private void mnu_wiki_Click(object sender, EventArgs e)\r
511         {\r
512            Process.Start("http://handbrake.m0k.org/trac");\r
513         }\r
514 \r
515         private void mnu_onlineDocs_Click(object sender, EventArgs e)\r
516         {\r
517             Process.Start("http://handbrake.m0k.org/?page_id=11");\r
518         }\r
519 \r
520         private void mnu_faq_Click(object sender, EventArgs e)\r
521         {\r
522             Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");\r
523         }\r
524 \r
525         private void mnu_homepage_Click(object sender, EventArgs e)\r
526         {\r
527            Process.Start("http://handbrake.m0k.org");\r
528         }\r
529 \r
530         private void mnu_forum_Click(object sender, EventArgs e)\r
531         {\r
532             Process.Start("http://handbrake.m0k.org/forum");\r
533         }\r
534 \r
535         private void mnu_about_Click(object sender, EventArgs e)\r
536         {\r
537                         Form About = new frmAbout();\r
538             About.ShowDialog();\r
539         }\r
540 \r
541         #endregion\r
542 \r
543         // -------------------------------------------------------------- \r
544         // Buttons on the main Window\r
545         // --------------------------------------------------------------\r
546         private void btn_Browse_Click(object sender, EventArgs e)\r
547         {\r
548             \r
549             String filename ="";\r
550             text_source.Text = "";\r
551             \r
552             //int scanTwice = 0;\r
553 \r
554             if (RadioDVD.Checked)\r
555             {\r
556                 DVD_Open.ShowDialog();\r
557                 filename = DVD_Open.SelectedPath;\r
558                 if (filename != "")\r
559                 {\r
560                     Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);\r
561                     text_source.Text = filename;\r
562                     frmRD.ShowDialog();\r
563                 }\r
564             }\r
565             else\r
566             {\r
567                 ISO_Open.ShowDialog();\r
568                 filename = ISO_Open.FileName;\r
569                 if (filename != "")\r
570                 {\r
571                     Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);\r
572                     text_source.Text = filename;\r
573                     frmRD.ShowDialog();\r
574                 }\r
575             }  \r
576 \r
577             // Check if there was titles in the dvd title dropdown\r
578             // If there isn't any, rescan the DVD. hbcli occasionally fails (see bug in encode) with standard error.\r
579             if (filename != "")\r
580             {\r
581                // Disbaled the 2nd pass for the time being.\r
582                /* if (drp_dvdtitle.Items.Count == 0) \r
583                 {\r
584                     if (scanTwice == 0)\r
585                     {\r
586                         MessageBox.Show("Scan Failed. Waiting 5 Seconds before attempting to re-scan the source a 2nd time.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
587                         Thread.Sleep(3000);\r
588                         Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);\r
589                         frmRD.ShowDialog();\r
590                         scanTwice = 1;\r
591                     }\r
592                 }*/\r
593             }\r
594             else\r
595             {\r
596                 text_source.Text = "Click 'Browse' to continue";\r
597             }\r
598 \r
599             if (drp_dvdtitle.Items.Count == 0)\r
600             {\r
601                 MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source. Please refer to the FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
602            }\r
603 \r
604         }\r
605 \r
606         private void btn_destBrowse_Click(object sender, EventArgs e)\r
607         {\r
608             // TODO: Need to write some code to check if there is a reasonable amount of disk space left.\r
609 \r
610             DVD_Save.ShowDialog();\r
611             text_destination.Text = DVD_Save.FileName;\r
612 \r
613             if (Check_ChapterMarkers.Checked)\r
614             {\r
615                 string destination = text_destination.Text;\r
616                 destination = destination.Replace(".mp4", ".m4v");\r
617                 text_destination.Text = destination;\r
618             }\r
619         }\r
620 \r
621         private void btn_h264Clear_Click(object sender, EventArgs e)\r
622         {\r
623             rtf_h264advanced.Text = "";\r
624         }\r
625 \r
626         private void GenerateQuery_Click(object sender, EventArgs e)\r
627         {\r
628             String query = GenerateTheQuery();\r
629             QueryEditorText.Text = query;\r
630         }\r
631 \r
632         private void btn_ClearQuery_Click(object sender, EventArgs e)\r
633         {\r
634             QueryEditorText.Text = "";\r
635         }\r
636 \r
637         private void btn_queue_Click(object sender, EventArgs e)\r
638         {\r
639             if (text_destination.Text != "" && text_source.Text != "")\r
640             {\r
641                 string query;\r
642                 if (QueryEditorText.Text == "")\r
643                 {\r
644                     query = GenerateTheQuery();\r
645                 }\r
646                 else\r
647                 {\r
648                     query = QueryEditorText.Text;\r
649                 }\r
650                 queueWindow.list_queue.Items.Add(query);\r
651                 queueWindow.Show();\r
652             } \r
653             else \r
654             {\r
655                 MessageBox.Show("No Source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
656             }\r
657         }\r
658 \r
659         private void showQueue()\r
660         {\r
661             queueWindow.Show();\r
662         }\r
663 \r
664 \r
665 \r
666 \r
667 \r
668         //---------------------------------------------------\r
669         // Encode / Cancel Buttons\r
670         // Encode Progress Text Handler\r
671         //---------------------------------------------------\r
672 \r
673         Functions.CLI process = new Functions.CLI();\r
674 \r
675         private void btn_encode_Click(object sender, EventArgs e)\r
676         {\r
677             btn_eCancel.Enabled = true;\r
678             String query = "";\r
679             lbl_encode.Visible = false;\r
680  \r
681             if (QueryEditorText.Text == "")\r
682             {\r
683                 query = GenerateTheQuery();\r
684             }\r
685             else\r
686             {\r
687                 query = QueryEditorText.Text;\r
688             }\r
689 \r
690             ThreadPool.QueueUserWorkItem(procMonitor, query);\r
691             lbl_encode.Text = "Encoding Started";\r
692         }\r
693 \r
694         private void btn_eCancel_Click(object sender, EventArgs e)\r
695         {\r
696             process.killCLI();\r
697             process.setNull();\r
698             lbl_encode.Text = "Encoding Canceled";\r
699         }\r
700    \r
701         private void procMonitor(object state)\r
702         {\r
703             // Make sure we are not already encoding and if we are then display an error.\r
704             if (hbProc != null)\r
705             {\r
706                 MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
707             }\r
708             else\r
709             {\r
710                 hbProc = process.runCli(this, (string)state, false, false, false, false);\r
711                 MessageBox.Show("The encode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
712                 hbProc.WaitForExit();\r
713 \r
714                 try\r
715                 {\r
716 \r
717                     //*****************************************************************************************\r
718                     // BUG!\r
719                     // When the below code is used and standard error is set to true, hbcli is outputing a\r
720                     // video stream which has mild corruption issues every few seconds.\r
721                     // Maybe an issue with the Parser cauing the CLI to hickup/pause?\r
722                     //*****************************************************************************************\r
723 \r
724                     \r
725                     /*Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);\r
726                     encode.OnEncodeProgress += encode_OnEncodeProgress;\r
727                     while (!encode.EndOfStream)\r
728                     {\r
729                         encode.ReadLine();\r
730                     }\r
731 \r
732                     hbProc.WaitForExit();\r
733                     process.closeCLI();\r
734                     */\r
735                 }\r
736                 catch (Exception)\r
737                 {\r
738                     // Do nothing\r
739                 }\r
740 \r
741                 MessageBox.Show("The encode process has now ended.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
742                 hbProc = null;\r
743             }\r
744         }\r
745 \r
746         private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
747         {\r
748             if (this.InvokeRequired)\r
749             {\r
750                 this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),\r
751                     new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
752                 return;\r
753             }\r
754             lbl_encode.Text = string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
755         }\r
756         \r
757         //---------------------------------------------------\r
758         //  Items that require actions on frmMain\r
759         //---------------------------------------------------\r
760 \r
761         private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)\r
762         {\r
763             lbl_chptWarn.Visible = false;\r
764             QueryEditorText.Text = "";\r
765             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
766             {\r
767                 try\r
768                 {\r
769                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
770                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
771 \r
772                     if (chapterFinish < chapterStart)\r
773                     {\r
774                         lbl_chptWarn.Visible = true;\r
775                         lbl_chptWarn.Text = "Invalid Chapter Range!";\r
776                     }\r
777                 }\r
778                 catch (Exception)\r
779                 {\r
780                     lbl_chptWarn.Visible = true;\r
781                     lbl_chptWarn.Text = "Invalid Chapter Range!";\r
782                 }\r
783             }\r
784 \r
785             \r
786         }\r
787 \r
788         private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)\r
789         {\r
790             lbl_chptWarn.Visible = false;\r
791             QueryEditorText.Text = "";\r
792             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
793             {\r
794                 try\r
795                 {\r
796                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
797                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
798 \r
799                     if (chapterFinish < chapterStart)\r
800                     {\r
801                         lbl_chptWarn.Visible = true;\r
802                         lbl_chptWarn.Text = "Invalid Chapter Range!";\r
803                     }\r
804                 }\r
805                 catch (Exception)\r
806                 {\r
807                     lbl_chptWarn.Visible = true;\r
808                     lbl_chptWarn.Text = "Invalid Chapter Range!";\r
809                 }\r
810             }\r
811         }\r
812 \r
813         private void text_bitrate_TextChanged(object sender, EventArgs e)\r
814         {\r
815             text_filesize.Text = "";\r
816             slider_videoQuality.Value = 0;\r
817             SliderValue.Text = "0%";\r
818             CheckCRF.CheckState = CheckState.Unchecked;\r
819             CheckCRF.Enabled = false;\r
820         }\r
821 \r
822         private void text_filesize_TextChanged(object sender, EventArgs e)\r
823         {\r
824             text_bitrate.Text = "";\r
825             slider_videoQuality.Value = 0;\r
826             SliderValue.Text = "0%";\r
827             CheckCRF.CheckState = CheckState.Unchecked;\r
828             CheckCRF.Enabled = false;\r
829         }\r
830 \r
831         private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
832         {\r
833             SliderValue.Text = slider_videoQuality.Value.ToString() + "%";\r
834             text_bitrate.Text = "";\r
835             text_filesize.Text = "";\r
836             CheckCRF.Enabled = true;\r
837         }\r
838 \r
839         private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
840         {\r
841             Process.Start("http://handbrake.m0k.org/trac/wiki/x264Options");\r
842         }\r
843 \r
844         private void text_width_TextChanged(object sender, EventArgs e)\r
845         {\r
846 \r
847             try\r
848             {\r
849                 if (CheckPixelRatio.Checked)\r
850                 {\r
851                     text_width.Text = "";\r
852                     text_width.BackColor = Color.White;\r
853                 }\r
854                 else\r
855                 {\r
856                     if ((int.Parse(text_width.Text) % 16) != 0)\r
857                     {\r
858                         text_width.BackColor = Color.LightCoral;\r
859                     }\r
860                     else\r
861                     {\r
862                         text_width.BackColor = Color.LightGreen;\r
863                     }\r
864                 }\r
865 \r
866                 if (lbl_Aspect.Text != "Select a Title")\r
867                 {\r
868                     double height = int.Parse(text_width.Text) / double.Parse(lbl_Aspect.Text);\r
869                     double mod16 = height % 16;\r
870                     height = height - mod16;\r
871 \r
872                     if (text_width.Text == "")\r
873                     {\r
874                         text_height.Text = "";\r
875                         text_width.BackColor = Color.White;\r
876                     }\r
877                     else\r
878                     {\r
879                         text_height.Text = height.ToString();\r
880                     }\r
881                 }\r
882             }\r
883             catch (Exception)\r
884             {\r
885                 // No need to throw an error here.\r
886             }\r
887                \r
888           \r
889         }\r
890 \r
891         private void text_height_TextChanged(object sender, EventArgs e)\r
892         {\r
893             try\r
894             {\r
895                 if (CheckPixelRatio.Checked)\r
896                 {\r
897                     text_height.Text = "";\r
898                     text_width.BackColor = Color.White;\r
899                 }\r
900                 else\r
901                 {\r
902                     if ((int.Parse(text_height.Text) % 16) != 0)\r
903                     {\r
904                         text_height.BackColor = Color.LightCoral;\r
905                     }\r
906                     else\r
907                     {\r
908                         text_height.BackColor = Color.LightGreen;\r
909                     }\r
910                 }\r
911             } catch(Exception){\r
912                 // No need to alert the user.\r
913             }\r
914         }\r
915 \r
916         private void drp_crop_SelectedIndexChanged(object sender, EventArgs e)\r
917         {\r
918             if ((string)drp_crop.SelectedItem == "Manual")\r
919             {\r
920             text_left.Enabled = true;\r
921             text_right.Enabled = true;\r
922             text_top.Enabled = true;\r
923             text_bottom.Enabled = true;\r
924             }\r
925 \r
926             if ((string)drp_crop.SelectedItem == "Auto Crop")\r
927             {\r
928                 text_left.Enabled = false;\r
929                 text_right.Enabled = false;\r
930                 text_top.Enabled = false;\r
931                 text_bottom.Enabled = false;\r
932                 text_left.Text = "";\r
933                 text_right.Text = "";\r
934                 text_top.Text = "";\r
935                 text_bottom.Text = "";\r
936 \r
937                 if (lbl_RecomendedCrop.Text != "Select a Title")\r
938                 {\r
939                     string[] temp = new string[4];\r
940                     temp = lbl_RecomendedCrop.Text.Split('/');\r
941                     text_left.Text = temp[2];\r
942                     text_right.Text = temp[3];\r
943                     text_top.Text = temp[0];\r
944                     text_bottom.Text = temp[1];\r
945                 }\r
946             }\r
947 \r
948             if ((string)drp_crop.SelectedItem == "No Crop")\r
949             {\r
950                 text_left.Enabled = false;\r
951                 text_right.Enabled = false;\r
952                 text_top.Enabled = false;\r
953                 text_bottom.Enabled = false;\r
954                 text_left.Text = "0";\r
955                 text_right.Text = "0";\r
956                 text_top.Text = "0";\r
957                 text_bottom.Text = "0";\r
958 \r
959             }\r
960         }\r
961         \r
962         private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)\r
963         {\r
964             text_width.Text = "";\r
965             text_height.Text = "";\r
966             text_width.BackColor = Color.White;\r
967             text_height.BackColor = Color.White;\r
968         }\r
969 \r
970         private void drp_dvdtitle_Click(object sender, EventArgs e)\r
971         {\r
972             if (drp_dvdtitle.Items.Count == 1)\r
973             {\r
974                 MessageBox.Show("There are no titles to select. Please scan the DVD by clicking the 'browse' button above before trying to select a title.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
975             }\r
976         }\r
977 \r
978         private void drp_audioCodec_SelectedIndexChanged(object sender, EventArgs e)\r
979         {\r
980 \r
981             //CLI Audio mixdown Names: mono stereo dpl1 dpl2 6ch\r
982 \r
983             drp_audioMixDown.Items.Clear();\r
984 \r
985             if (drp_audioCodec.Text == "AAC")\r
986             {\r
987                 drp_audioMixDown.Items.Clear();\r
988                 drp_audioMixDown.Items.Add("Mono");\r
989                 drp_audioMixDown.Items.Add("Stereo");\r
990                 drp_audioMixDown.Items.Add("Dolby Surround");\r
991                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
992                 drp_audioMixDown.Items.Add("6 Channel Discrete");\r
993                 \r
994                 drp_audioBitrate.Items.Clear();\r
995                 drp_audioBitrate.Items.Add("32");\r
996                 drp_audioBitrate.Items.Add("40");\r
997                 drp_audioBitrate.Items.Add("48");\r
998                 drp_audioBitrate.Items.Add("56");\r
999                 drp_audioBitrate.Items.Add("64");\r
1000                 drp_audioBitrate.Items.Add("80");\r
1001                 drp_audioBitrate.Items.Add("86");\r
1002                 drp_audioBitrate.Items.Add("112");\r
1003                 drp_audioBitrate.Items.Add("128");\r
1004                 drp_audioBitrate.Items.Add("160");\r
1005 \r
1006             }\r
1007             else\r
1008             {\r
1009                 drp_audioMixDown.Items.Clear();\r
1010                 drp_audioMixDown.Items.Add("Stereo");\r
1011                 drp_audioMixDown.Items.Add("Dolby Surround");\r
1012                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
1013 \r
1014                 drp_audioBitrate.Items.Clear();\r
1015                 drp_audioBitrate.Items.Add("32");\r
1016                 drp_audioBitrate.Items.Add("40");\r
1017                 drp_audioBitrate.Items.Add("48");\r
1018                 drp_audioBitrate.Items.Add("56");\r
1019                 drp_audioBitrate.Items.Add("64");\r
1020                 drp_audioBitrate.Items.Add("80");\r
1021                 drp_audioBitrate.Items.Add("86");\r
1022                 drp_audioBitrate.Items.Add("112");\r
1023                 drp_audioBitrate.Items.Add("128");\r
1024                 drp_audioBitrate.Items.Add("160");\r
1025                 drp_audioBitrate.Items.Add("192");\r
1026                 drp_audioBitrate.Items.Add("224");\r
1027                 drp_audioBitrate.Items.Add("256");\r
1028                 drp_audioBitrate.Items.Add("320");\r
1029                 drp_audioBitrate.Items.Add("384");\r
1030             }\r
1031         }\r
1032 \r
1033         private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e)\r
1034         {\r
1035             if (drp_audioCodec.Text == "AAC")\r
1036             {\r
1037                 if (drp_audioMixDown.Text == "6 Channel Discrete")\r
1038                 {\r
1039 \r
1040                     drp_audioBitrate.Items.Clear();\r
1041                     drp_audioBitrate.Items.Add("32");\r
1042                     drp_audioBitrate.Items.Add("40");\r
1043                     drp_audioBitrate.Items.Add("48");\r
1044                     drp_audioBitrate.Items.Add("56");\r
1045                     drp_audioBitrate.Items.Add("64");\r
1046                     drp_audioBitrate.Items.Add("80");\r
1047                     drp_audioBitrate.Items.Add("86");\r
1048                     drp_audioBitrate.Items.Add("112");\r
1049                     drp_audioBitrate.Items.Add("128");\r
1050                     drp_audioBitrate.Items.Add("160");\r
1051                     drp_audioBitrate.Items.Add("192");\r
1052                     drp_audioBitrate.Items.Add("224");\r
1053                     drp_audioBitrate.Items.Add("256");\r
1054                     drp_audioBitrate.Items.Add("320");\r
1055                     drp_audioBitrate.Items.Add("384");\r
1056                 }\r
1057             }\r
1058         }\r
1059 \r
1060         private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)\r
1061         {\r
1062             if (Check_ChapterMarkers.Checked)\r
1063             {\r
1064                 string destination = text_destination.Text;\r
1065                 destination = destination.Replace(".mp4", ".m4v");\r
1066                 text_destination.Text = destination;\r
1067             }\r
1068         }\r
1069 \r
1070         private void check_largeFile_CheckedChanged(object sender, EventArgs e)\r
1071         {\r
1072             if (!text_destination.Text.Contains(".mp4"))\r
1073             {\r
1074                 MessageBox.Show("This option is only compatible with the mp4 file container.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1075                 check_largeFile.CheckState = CheckState.Unchecked;\r
1076             }\r
1077         }\r
1078 \r
1079         private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)\r
1080         {\r
1081             //Turn off some options which are H.264 only when the user selects a non h.264 encoder\r
1082             if (!drp_videoEncoder.Text.Contains("H.264"))\r
1083             {\r
1084                 check_turbo.CheckState = CheckState.Unchecked;\r
1085                 CheckCRF.CheckState = CheckState.Unchecked;\r
1086                 CheckCRF.Enabled = false;\r
1087                 check_turbo.Enabled = false;\r
1088                 h264Tab.Enabled = false;\r
1089             }\r
1090             else\r
1091             {\r
1092                 CheckCRF.Enabled = true;\r
1093                 check_turbo.Enabled = true;\r
1094                 h264Tab.Enabled = true;\r
1095             }\r
1096 \r
1097         }\r
1098 \r
1099         public void setStreamReader(Parsing.DVD dvd)\r
1100         {\r
1101             this.thisDVD = dvd;\r
1102         }\r
1103 \r
1104         private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)\r
1105         {\r
1106             // Reset some values on the form\r
1107             lbl_Aspect.Text = "Select a Title";\r
1108             lbl_RecomendedCrop.Text = "Select a Title";\r
1109             drop_chapterStart.Items.Clear();\r
1110             drop_chapterFinish.Items.Clear();\r
1111             QueryEditorText.Text = "";\r
1112 \r
1113             // If the dropdown is set to automatic nothing else needs to be done.\r
1114             // Otheriwse if its not, title data has to be loased from parsing.\r
1115             if (drp_dvdtitle.Text != "Automatic")\r
1116             {\r
1117                 Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;\r
1118 \r
1119                 // Set the Aspect Ratio\r
1120                 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();\r
1121 \r
1122                 // Set the Recommended Cropping values\r
1123                 lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);\r
1124                 \r
1125                 // Populate the Start chapter Dropdown\r
1126                 drop_chapterStart.Items.Clear();\r
1127                 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());\r
1128                 if (drop_chapterStart.Items.Count > 0)\r
1129                 {\r
1130                     drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();\r
1131                 }\r
1132 \r
1133                 // Populate the Final Chapter Dropdown\r
1134                 drop_chapterFinish.Items.Clear();\r
1135                 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());\r
1136                 if (drop_chapterFinish.Items.Count > 0)\r
1137                 {\r
1138                     drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
1139                 }\r
1140 \r
1141                 // Populate the Audio Channels Dropdown\r
1142                 drp_audioChannels.Items.Clear();\r
1143                 drp_audioChannels.Items.Add("Automatic");\r
1144                 drp_audioChannels.Items.AddRange(selectedTitle.AudioTracks.ToArray());\r
1145                 if (drp_audioChannels.Items.Count > 0)\r
1146                 {\r
1147                     drp_audioChannels.Text = drp_audioChannels.Items[0].ToString();\r
1148                 }\r
1149 \r
1150                 // Populate the Subtitles dropdown\r
1151                 drp_subtitle.Items.Clear();\r
1152                 drp_subtitle.Items.Add("None");\r
1153                 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());\r
1154                 if (drp_subtitle.Items.Count > 0)\r
1155                 {\r
1156                     drp_subtitle.Text = drp_subtitle.Items[0].ToString();\r
1157                 }\r
1158             }\r
1159         }\r
1160 \r
1161         //---------------------------------------------------\r
1162         //  The query Generation function.\r
1163         //---------------------------------------------------\r
1164         public string GenerateTheQuery()\r
1165         {\r
1166             string source = text_source.Text;\r
1167             string dvdTitle = drp_dvdtitle.Text;\r
1168             string chapterStart = drop_chapterStart.Text;\r
1169             string chapterFinish = drop_chapterFinish.Text;\r
1170             int totalChapters = drop_chapterFinish.Items.Count - 1;\r
1171             string dvdChapter = "";\r
1172 \r
1173             if (source ==  "")\r
1174                 MessageBox.Show("No Source has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1175             else\r
1176             {\r
1177                 source = " -i " + '"' + source+ '"'; //'"'+\r
1178             }\r
1179 \r
1180             if (dvdTitle ==  "Automatic")\r
1181                 dvdTitle = "";\r
1182             else\r
1183             {\r
1184                 string[] titleInfo = dvdTitle.Split(' ');\r
1185                 dvdTitle = " -t "+ titleInfo[0];\r
1186             }\r
1187 \r
1188             if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))\r
1189                 dvdChapter = "";\r
1190             else if (chapterFinish == chapterStart)\r
1191                 dvdChapter = " -c " + chapterStart;\r
1192             else\r
1193                 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;\r
1194 \r
1195             string querySource = source+ dvdTitle+ dvdChapter;\r
1196             // ----------------------------------------------------------------------\r
1197 \r
1198             // Destination\r
1199 \r
1200             string destination = text_destination.Text;\r
1201             string videoEncoder = drp_videoEncoder.Text;\r
1202             string audioEncoder = drp_audioCodec.Text;\r
1203             string width = text_width.Text;\r
1204             string height = text_height.Text;\r
1205 \r
1206             if (destination ==  "")\r
1207                 MessageBox.Show("No destination has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1208             else\r
1209                 destination = " -o " + '"' + destination + '"'; //'"'+ \r
1210 \r
1211 \r
1212             switch (videoEncoder)\r
1213             {\r
1214                 case "Mpeg 4":\r
1215                     videoEncoder = " -e ffmpeg";\r
1216                     break;\r
1217                 case "Xvid":\r
1218                     videoEncoder = " -e xvid";\r
1219                     break;\r
1220                 case "H.264":\r
1221                     videoEncoder = " -e x264";\r
1222                     break;\r
1223                 case "H.264 Baseline 1.3":\r
1224                     videoEncoder = " -e x264b13";\r
1225                     break;\r
1226                 case "H.264 (iPod)":\r
1227                     videoEncoder = " -e x264b30";\r
1228                     break;\r
1229                 default:\r
1230                     videoEncoder = " -e x264";\r
1231                     break;\r
1232             }\r
1233            \r
1234             switch (audioEncoder)\r
1235             {\r
1236                 case "AAC":\r
1237                     audioEncoder = " -E faac";\r
1238                     break;\r
1239                 case "MP3":\r
1240                     audioEncoder = " -E lame";\r
1241                     break;\r
1242                 case "Vorbis":\r
1243                     audioEncoder = " -E vorbis";\r
1244                     break;\r
1245                 case "AC3":\r
1246                     audioEncoder = " -E ac3";\r
1247                     break;\r
1248                 default:\r
1249                     audioEncoder = " -E faac";\r
1250                     break;\r
1251             }\r
1252 \r
1253             if (width !=  "")\r
1254                 width = " -w "+ width;\r
1255             \r
1256 \r
1257             if (height !=  "")\r
1258                 height = " -l "+ height;\r
1259             \r
1260 \r
1261             string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height;\r
1262             // ----------------------------------------------------------------------\r
1263 \r
1264             // Picture Settings Tab\r
1265 \r
1266             string cropSetting = drp_crop.Text;\r
1267             string cropTop = text_top.Text;\r
1268             string cropBottom = text_bottom.Text;\r
1269             string cropLeft = text_left.Text;\r
1270             string cropRight = text_right.Text;\r
1271             string subtitles = drp_subtitle.Text;\r
1272             string cropOut = "";\r
1273             // Returns Crop Query\r
1274 \r
1275             if (cropSetting == "Auto Crop")\r
1276                 cropOut = "";\r
1277             else if (cropSetting == "No Crop")\r
1278                 cropOut = " --crop 0:0:0:0 ";\r
1279             else\r
1280                 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;\r
1281 \r
1282             if (subtitles ==  "None")\r
1283                 subtitles = "";\r
1284             else if (subtitles ==  "")\r
1285                 subtitles = "";\r
1286             else\r
1287             {\r
1288                 string[] tempSub;\r
1289                 tempSub = subtitles.Split(' ');\r
1290                 subtitles = " -s "+ tempSub[0];\r
1291             }\r
1292 \r
1293             string queryPictureSettings = cropOut+ subtitles;\r
1294             // ----------------------------------------------------------------------\r
1295 \r
1296             // Video Settings Tab\r
1297 \r
1298             string videoBitrate = text_bitrate.Text;\r
1299             string videoFilesize = text_filesize.Text;\r
1300             int videoQuality = slider_videoQuality.Value;\r
1301             string vidQSetting = "";\r
1302             string twoPassEncoding = "";\r
1303             string deinterlace = "";\r
1304             string grayscale = "";\r
1305             string videoFramerate = drp_videoFramerate.Text;\r
1306             string pixelRatio = "";\r
1307             string ChapterMarkers = "";\r
1308             string turboH264 = "";\r
1309             string largeFile = "";\r
1310 \r
1311             if (videoBitrate !=  "")\r
1312                 videoBitrate = " -b "+ videoBitrate;\r
1313 \r
1314             if (videoFilesize !=  "")\r
1315                 videoFilesize = " -S "+ videoFilesize;\r
1316 \r
1317             // Video Quality Setting\r
1318 \r
1319             if ((videoQuality ==  0))\r
1320                 vidQSetting = "";\r
1321             else\r
1322             {\r
1323                 videoQuality = videoQuality/ 100;\r
1324                 if (videoQuality ==  1)\r
1325                 {\r
1326                     vidQSetting = "1.0";\r
1327                 }\r
1328 \r
1329                 vidQSetting = " -q " + videoQuality.ToString();\r
1330             }\r
1331 \r
1332             if (check_2PassEncode.Checked)\r
1333                 twoPassEncoding = " -2 ";\r
1334 \r
1335             if (check_DeInterlace.Checked)\r
1336                 deinterlace = " -d ";\r
1337 \r
1338             if (check_grayscale.Checked)\r
1339                 grayscale = " -g ";\r
1340 \r
1341             if (videoFramerate ==  "Automatic")\r
1342                 videoFramerate = "";\r
1343             else\r
1344                 videoFramerate = " -r "+ videoFramerate;\r
1345 \r
1346             if (CheckPixelRatio.Checked)\r
1347                 pixelRatio = " -p ";\r
1348 \r
1349             if (Check_ChapterMarkers.Checked)\r
1350                 ChapterMarkers = " -m ";\r
1351 \r
1352             if (check_turbo.Checked)\r
1353                 turboH264 = " -T ";\r
1354 \r
1355             if (check_largeFile.Checked)\r
1356                 largeFile = " -4 ";\r
1357 \r
1358             string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + deinterlace + grayscale + videoFramerate + pixelRatio + ChapterMarkers + turboH264 + largeFile;\r
1359             // ----------------------------------------------------------------------\r
1360 \r
1361             // Audio Settings Tab\r
1362 \r
1363             string audioBitrate = drp_audioBitrate.Text;\r
1364             string audioSampleRate = drp_audioSampleRate.Text;\r
1365             string audioChannels = drp_audioChannels.Text;\r
1366             string Mixdown = drp_audioMixDown.Text;\r
1367             string SixChannelAudio = "";\r
1368 \r
1369             if (audioBitrate !=  "")\r
1370                 audioBitrate = " -B "+ audioBitrate;\r
1371 \r
1372             if (audioSampleRate !=  "")\r
1373                 audioSampleRate = " -R "+ audioSampleRate;\r
1374 \r
1375             if (audioChannels ==  "Automatic")\r
1376                 audioChannels = "";\r
1377             else if (audioChannels ==  "")\r
1378                 audioChannels = "";\r
1379             else\r
1380             {\r
1381                 string[] tempSub;\r
1382                 tempSub = audioChannels.Split(' ');\r
1383                 audioChannels = " -a "+ tempSub[0];\r
1384             }\r
1385 \r
1386             switch (Mixdown)\r
1387             {\r
1388                 case "Automatic":\r
1389                     Mixdown = "";\r
1390                     break;\r
1391                 case "Mono":\r
1392                     Mixdown = "mono";\r
1393                     break;\r
1394                 case "Stereo":\r
1395                     Mixdown = "stereo";\r
1396                     break;\r
1397                 case "Dolby Surround":\r
1398                     Mixdown = "dpl1";\r
1399                     break;\r
1400                 case "Dolby Pro Logic II":\r
1401                     Mixdown = "dpl2";\r
1402                     break;\r
1403                 case "6 Channel Discrete":\r
1404                     Mixdown = "6ch";\r
1405                     break;\r
1406                 default:\r
1407                     Mixdown = "stero";\r
1408                     break;\r
1409             }\r
1410 \r
1411             if (Mixdown !=  "")\r
1412                 SixChannelAudio = " -6 "+ Mixdown;\r
1413             else\r
1414                 SixChannelAudio = "";\r
1415 \r
1416             string queryAudioSettings = audioBitrate+ audioSampleRate+ audioChannels+ SixChannelAudio;\r
1417             // ----------------------------------------------------------------------\r
1418 \r
1419             //  H.264 Tab\r
1420 \r
1421             string CRF = CheckCRF.CheckState.ToString();\r
1422             string h264Advanced = rtf_h264advanced.Text;\r
1423             if ((CRF ==  "1"))\r
1424                 CRF = " -Q ";\r
1425             else\r
1426                 CRF = "";\r
1427 \r
1428             if ((h264Advanced ==  ""))\r
1429                 h264Advanced = "";\r
1430             else\r
1431                 h264Advanced = " -x "+ h264Advanced;\r
1432     \r
1433 \r
1434             string h264Settings = CRF+ h264Advanced;\r
1435             // ----------------------------------------------------------------------\r
1436 \r
1437             // Processors (Program Settings)\r
1438 \r
1439             string processors = Properties.Settings.Default.Processors;\r
1440             //  Number of Processors Handler\r
1441 \r
1442             if (processors ==  "Automatic")\r
1443                 processors = "";\r
1444             else\r
1445                 processors = " -C "+ processors+ " ";\r
1446 \r
1447 \r
1448             string queryAdvancedSettings = processors;\r
1449             // ----------------------------------------------------------------------\r
1450 \r
1451             //  Verbose option (Program Settings)\r
1452 \r
1453             string verbose = "";\r
1454             if (Properties.Settings.Default.verbose ==  "Checked")\r
1455                 verbose = " -v ";\r
1456 \r
1457             // ----------------------------------------------------------------------\r
1458 \r
1459             return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;\r
1460         }\r
1461 \r
1462         \r
1463 \r
1464         // This is the END of the road ------------------------------------------------------------------------------\r
1465     }\r
1466 }