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