OSDN Git Service

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