OSDN Git Service

6a61ae735a2bd1d52402d799525d3a373b91f93b
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / Common.cs
1 /*  Common.cs $\r
2         \r
3            This file is part of the HandBrake source code.\r
4            Homepage: <http://handbrake.fr>.\r
5            It may be used under the terms of the GNU General Public License. */\r
6 \r
7 using System;\r
8 using System.Collections;\r
9 using System.Text;\r
10 using System.Windows.Forms;\r
11 using System.Globalization;\r
12 using System.IO;\r
13 using System.Drawing;\r
14 using System.Diagnostics;\r
15 using System.Text.RegularExpressions;\r
16 \r
17 namespace Handbrake.Functions\r
18 {\r
19     class Common\r
20     {\r
21         #region Presets\r
22 \r
23         /// <summary>\r
24         /// Update the presets.dat file with the latest version of HandBrak's presets from the CLI\r
25         /// </summary>\r
26         public void grabCLIPresets()\r
27         {\r
28             string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
29             string presetsPath = Path.Combine(Application.StartupPath, "presets.dat");\r
30 \r
31             string strCmdLine = String.Format(@"cmd /c """"{0}"" --preset-list >""{1}"" 2>&1""", handbrakeCLIPath, presetsPath);\r
32 \r
33             ProcessStartInfo hbGetPresets = new ProcessStartInfo("CMD.exe", strCmdLine);\r
34             hbGetPresets.WindowStyle = ProcessWindowStyle.Hidden;\r
35 \r
36             Process hbproc = Process.Start(hbGetPresets);\r
37             hbproc.WaitForExit();\r
38             hbproc.Dispose();\r
39             hbproc.Close();\r
40         }\r
41         /// <summary>\r
42         /// This function takes in a Query which has been parsed by QueryParser and\r
43         /// set's all the GUI widgets correctly.\r
44         /// </summary>\r
45         /// <param name="mainWindow"></param>\r
46         /// <param name="presetQuery">The Parsed CLI Query</param>\r
47         /// <param name="name">Name of the preset</param>\r
48         public void presetLoader(frmMain mainWindow, Functions.QueryParser presetQuery, string name)\r
49         {\r
50             // ---------------------------\r
51             // Setup the GUI\r
52             // ---------------------------\r
53 \r
54             // Source tab\r
55             #region source\r
56             // Reset some vaules to stock first to prevent errors.\r
57             mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;\r
58 \r
59             // Now load all the new settings onto the main window\r
60             mainWindow.drp_dvdtitle.Text = "Automatic";\r
61             mainWindow.drop_chapterStart.Text = "Auto";\r
62             mainWindow.drop_chapterFinish.Text = "Auto";\r
63 \r
64             if (presetQuery.Format != null)\r
65             {\r
66                 string destination = mainWindow.text_destination.Text;\r
67                 destination = destination.Replace(".mp4", "." + presetQuery.Format);\r
68                 destination = destination.Replace(".m4v", "." + presetQuery.Format);\r
69                 destination = destination.Replace(".avi", "." + presetQuery.Format);\r
70                 destination = destination.Replace(".mkv", "." + presetQuery.Format);\r
71                 destination = destination.Replace(".ogm", "." + presetQuery.Format);\r
72                 mainWindow.text_destination.Text = destination;\r
73             }\r
74 \r
75             #endregion\r
76 \r
77             // Destination tab\r
78             #region destination\r
79 \r
80             mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;\r
81 \r
82             if (presetQuery.Format != null)\r
83             {\r
84                 if (presetQuery.Format == "mp4")\r
85                     mainWindow.drop_format.SelectedIndex = 0;\r
86                 else if (presetQuery.Format == "m4v")\r
87                     mainWindow.drop_format.SelectedIndex = 1;\r
88                 else if (presetQuery.Format == "mkv")\r
89                     mainWindow.drop_format.SelectedIndex = 2;\r
90                 else if (presetQuery.Format == "avi")\r
91                     mainWindow.drop_format.SelectedIndex = 3;\r
92                 else if (presetQuery.Format == "ogm")\r
93                     mainWindow.drop_format.SelectedIndex = 4;\r
94             }\r
95 \r
96             if (presetQuery.IpodAtom == true)\r
97                 mainWindow.check_iPodAtom.CheckState = CheckState.Checked;\r
98             else\r
99                 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;\r
100 \r
101             if (presetQuery.OptimizeMP4 == true)\r
102                 mainWindow.check_optimiseMP4.CheckState = CheckState.Checked;\r
103             else\r
104                 mainWindow.check_optimiseMP4.CheckState = CheckState.Unchecked;\r
105 \r
106             #endregion\r
107 \r
108             // Picture Settings Tab\r
109             #region Picture\r
110 \r
111             if (presetQuery.CropTop == "0" && presetQuery.CropBottom == "0" && presetQuery.CropLeft == "0" && presetQuery.CropRight == "0")\r
112             {\r
113                 mainWindow.drp_crop.SelectedIndex = 2;\r
114             }\r
115             else if (presetQuery.CropTop != null && presetQuery.CropBottom != null && presetQuery.CropLeft != null && presetQuery.CropRight != null)\r
116             {\r
117                 mainWindow.drp_crop.SelectedIndex = 1;\r
118                 mainWindow.text_top.Text = presetQuery.CropTop;\r
119                 mainWindow.text_bottom.Text = presetQuery.CropBottom;\r
120                 mainWindow.text_left.Text = presetQuery.CropLeft;\r
121                 mainWindow.text_right.Text = presetQuery.CropRight;\r
122             }\r
123             else\r
124             {\r
125                 mainWindow.drp_crop.SelectedIndex = 0;\r
126             }\r
127 \r
128             mainWindow.drp_deInterlace_option.Text = presetQuery.DeInterlace;\r
129             mainWindow.drp_deNoise.Text = presetQuery.DeNoise;\r
130 \r
131             if (presetQuery.Decomb == true)\r
132                 mainWindow.check_decomb.CheckState = CheckState.Checked;\r
133             else\r
134                 mainWindow.check_decomb.CheckState = CheckState.Unchecked;\r
135 \r
136             if (presetQuery.DeTelecine == true)\r
137                 mainWindow.check_detelecine.CheckState = CheckState.Checked;\r
138             else\r
139                 mainWindow.check_detelecine.CheckState = CheckState.Unchecked;\r
140 \r
141 \r
142             if (presetQuery.DeBlock == true)\r
143                 mainWindow.check_deblock.CheckState = CheckState.Checked;\r
144             else\r
145                 mainWindow.check_deblock.CheckState = CheckState.Unchecked;\r
146 \r
147 \r
148             if (presetQuery.Anamorphic == true)\r
149                 mainWindow.drp_anamorphic.SelectedIndex = 1;\r
150             else\r
151                 mainWindow.drp_anamorphic.SelectedIndex = 0;\r
152 \r
153             if (presetQuery.LooseAnamorphic == true)\r
154                 mainWindow.drp_anamorphic.SelectedIndex = 2;\r
155             else\r
156             {\r
157                 if (presetQuery.Anamorphic != true)\r
158                     mainWindow.drp_anamorphic.SelectedIndex = 0;\r
159             }\r
160 \r
161             if (presetQuery.Width != 0)\r
162                 mainWindow.text_width.Text = presetQuery.Width.ToString();\r
163             else\r
164             {\r
165                 mainWindow.text_width.Text = "";\r
166             }\r
167 \r
168             if (presetQuery.Height != 0)\r
169                 mainWindow.text_height.Text = presetQuery.Height.ToString();\r
170             else\r
171             {\r
172                 mainWindow.text_height.Text = "";\r
173             }\r
174 \r
175             if (presetQuery.VFR == true)\r
176                 mainWindow.check_vfr.CheckState = CheckState.Checked;\r
177             else\r
178                 mainWindow.check_vfr.CheckState = CheckState.Unchecked;\r
179             #endregion\r
180 \r
181             // Video Settings Tab\r
182             #region video\r
183             mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;\r
184             mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;\r
185             mainWindow.slider_videoQuality.Value = presetQuery.VideoQuality;\r
186             if (mainWindow.slider_videoQuality.Value != 0)\r
187             {\r
188                 int ql = presetQuery.VideoQuality;\r
189                 mainWindow.SliderValue.Text = ql.ToString() + "%";\r
190             }\r
191 \r
192             if (presetQuery.TwoPass == true)\r
193                 mainWindow.check_2PassEncode.CheckState = CheckState.Checked;\r
194             else\r
195                 mainWindow.check_2PassEncode.CheckState = CheckState.Unchecked;\r
196 \r
197             if (presetQuery.Grayscale == true)\r
198                 mainWindow.check_grayscale.CheckState = CheckState.Checked;\r
199             else\r
200                 mainWindow.check_grayscale.CheckState = CheckState.Unchecked;\r
201 \r
202             mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;\r
203 \r
204             if (presetQuery.TurboFirstPass == true)\r
205                 mainWindow.check_turbo.CheckState = CheckState.Checked;\r
206             else\r
207                 mainWindow.check_turbo.CheckState = CheckState.Unchecked;\r
208 \r
209             if (presetQuery.LargeMP4 == true)\r
210                 mainWindow.check_largeFile.CheckState = CheckState.Checked;\r
211             else\r
212             {\r
213                 mainWindow.check_largeFile.CheckState = CheckState.Unchecked;\r
214                 mainWindow.check_largeFile.BackColor = Color.Transparent;\r
215             }\r
216 \r
217 \r
218 \r
219             #endregion\r
220 \r
221             // Chapter Markers Tab\r
222             #region Chapter Markers\r
223 \r
224             if (presetQuery.ChapterMarkers == true)\r
225             {\r
226                 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;\r
227                 mainWindow.text_destination.Text = mainWindow.text_destination.Text.Replace(".mp4", ".m4v");\r
228             }\r
229             else\r
230                 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;\r
231 \r
232             #endregion\r
233 \r
234             // Audio Settings Tab\r
235             #region Audio\r
236 \r
237             // Handle Track 1\r
238             if (presetQuery.AudioTrack1 == string.Empty)\r
239                 mainWindow.drp_track1Audio.Text = "Automatic";\r
240             else\r
241                 mainWindow.drp_track1Audio.Text = presetQuery.AudioTrack1;\r
242 \r
243             // Handle Track 2\r
244             if (presetQuery.AudioEncoder2 != null)  // Fix for loading in built in presets. Where 2 encoders but no tracks in the preset.\r
245             {\r
246                 mainWindow.drp_track2Audio.Enabled = true;\r
247                 mainWindow.drp_audsr_2.Enabled = true;\r
248                 mainWindow.drp_audmix_2.Enabled = true;\r
249                 mainWindow.drp_audenc_2.Enabled = true;\r
250                 mainWindow.drp_audbit_2.Enabled = true;\r
251                 mainWindow.drp_audsr_2.Text = "48";\r
252                 if ((presetQuery.AudioTrack2 != null) && (presetQuery.AudioTrack2 != "None"))\r
253                     mainWindow.drp_track2Audio.Text = presetQuery.AudioTrack2;\r
254                 else\r
255                     mainWindow.drp_track2Audio.Text = "Automatic";\r
256             }\r
257             else if (presetQuery.AudioTrack2 == "None")\r
258             {\r
259                 mainWindow.drp_track2Audio.Text = "None";\r
260                 mainWindow.drp_track2Audio.SelectedIndex = 0;\r
261                 mainWindow.drp_audsr_2.Enabled = false;\r
262                 mainWindow.drp_audmix_2.Enabled = false;\r
263                 mainWindow.drp_audenc_2.Enabled = false;\r
264                 mainWindow.drp_audbit_2.Enabled = false;\r
265             }\r
266             else\r
267             {\r
268                 mainWindow.drp_track2Audio.Text = presetQuery.AudioTrack2;\r
269                 mainWindow.drp_audsr_2.Enabled = true;\r
270                 mainWindow.drp_audmix_2.Enabled = true;\r
271                 mainWindow.drp_audenc_2.Enabled = true;\r
272                 mainWindow.drp_audbit_2.Enabled = true;\r
273             }\r
274 \r
275             // Handle Track 3\r
276             if (presetQuery.AudioTrack3 == "None")\r
277             {\r
278                 mainWindow.drp_track3Audio.SelectedIndex = 0;\r
279                 mainWindow.drp_audsr_3.Enabled = false;\r
280                 mainWindow.drp_audmix_3.Enabled = false;\r
281                 mainWindow.drp_audenc_3.Enabled = false;\r
282                 mainWindow.drp_audbit_3.Enabled = false;\r
283                 mainWindow.trackBar3.Enabled = false;\r
284 \r
285                 mainWindow.drp_track3Audio.Text = "None";\r
286                 mainWindow.drp_audsr_3.Text = "";\r
287                 mainWindow.drp_audmix_3.Text = "Automatic";\r
288                 mainWindow.drp_audenc_3.Text = "";\r
289                 mainWindow.drp_audbit_3.Text = "";\r
290                 mainWindow.trackBar3.Value = 0;\r
291 \r
292             }\r
293             else\r
294             {\r
295                 mainWindow.drp_track3Audio.Text = presetQuery.AudioTrack3;\r
296                 mainWindow.drp_audsr_3.Enabled = true;\r
297                 mainWindow.drp_audmix_3.Enabled = true;\r
298                 mainWindow.drp_audenc_3.Enabled = true;\r
299                 mainWindow.drp_audbit_3.Enabled = true;\r
300                 mainWindow.trackBar3.Enabled = true;\r
301             }\r
302 \r
303             // Handle Track 4\r
304             if (presetQuery.AudioTrack4 == "None")\r
305             {\r
306                 mainWindow.drp_track4Audio.SelectedIndex = 0;\r
307                 mainWindow.drp_audsr_4.Enabled = false;\r
308                 mainWindow.drp_audmix_4.Enabled = false;\r
309                 mainWindow.drp_audenc_4.Enabled = false;\r
310                 mainWindow.drp_audbit_4.Enabled = false;\r
311                 mainWindow.trackBar4.Enabled = false;\r
312 \r
313                 mainWindow.drp_track4Audio.Text = "None";\r
314                 mainWindow.drp_audsr_4.Text = "";\r
315                 mainWindow.drp_audmix_4.Text = "Automatic";\r
316                 mainWindow.drp_audenc_4.Text = "";\r
317                 mainWindow.drp_audbit_4.Text = "";\r
318                 mainWindow.trackBar4.Value = 0;\r
319             }\r
320             else\r
321             {\r
322                 mainWindow.drp_track4Audio.Text = presetQuery.AudioTrack4;\r
323                 mainWindow.drp_audsr_4.Enabled = true;\r
324                 mainWindow.drp_audmix_4.Enabled = true;\r
325                 mainWindow.drp_audenc_4.Enabled = true;\r
326                 mainWindow.drp_audbit_4.Enabled = true;\r
327                 mainWindow.trackBar4.Enabled = true;\r
328             }\r
329 \r
330             // Now lets start setting stuff\r
331             if (presetQuery.AudioEncoder1 != null)\r
332                 mainWindow.drp_audenc_1.Text = presetQuery.AudioEncoder1;\r
333             mainWindow.drp_audenc_2.Text = presetQuery.AudioEncoder2;\r
334             mainWindow.drp_audenc_3.Text = presetQuery.AudioEncoder3;\r
335             mainWindow.drp_audenc_4.Text = presetQuery.AudioEncoder4;\r
336 \r
337             if (presetQuery.AudioBitrate1 != null)\r
338                 mainWindow.drp_audbit_1.Text = presetQuery.AudioBitrate1;\r
339             mainWindow.drp_audbit_2.Text = presetQuery.AudioBitrate2;\r
340             mainWindow.drp_audbit_3.Text = presetQuery.AudioBitrate4;\r
341             mainWindow.drp_audbit_3.Text = presetQuery.AudioBitrate4;\r
342 \r
343             if (presetQuery.AudioSamplerate1 != null)\r
344                 mainWindow.drp_audsr_1.Text = presetQuery.AudioSamplerate1;\r
345             mainWindow.drp_audsr_2.Text = presetQuery.AudioSamplerate2;\r
346             mainWindow.drp_audsr_3.Text = presetQuery.AudioSamplerate3;\r
347             mainWindow.drp_audsr_4.Text = presetQuery.AudioSamplerate4;\r
348 \r
349             mainWindow.drp_audmix_1.Text = presetQuery.AudioTrackMix1;\r
350             mainWindow.drp_audmix_2.Text = presetQuery.AudioTrackMix2;\r
351             mainWindow.drp_audmix_3.Text = presetQuery.AudioTrackMix3;\r
352             mainWindow.drp_audmix_4.Text = presetQuery.AudioTrackMix4;\r
353 \r
354 \r
355             // Dynamic Range Compression (Should be a float but we use double for ease)\r
356             double value = 0;\r
357             double actualValue = 0;\r
358 \r
359             value = presetQuery.DRC1;\r
360             if (value > 0)\r
361                 value = value - 10;\r
362             mainWindow.trackBar1.Value = int.Parse(value.ToString());\r
363             actualValue = presetQuery.DRC1 / 10;\r
364             mainWindow.lbl_drc1.Text = actualValue.ToString();\r
365 \r
366             value = presetQuery.DRC2;\r
367             if (value > 0)\r
368                 value = value - 10;\r
369             mainWindow.trackBar2.Value = int.Parse(value.ToString());\r
370             actualValue = presetQuery.DRC2 / 10;\r
371             mainWindow.lbl_drc2.Text = actualValue.ToString();\r
372 \r
373             value = presetQuery.DRC3;\r
374             if (value > 0)\r
375                 value = value - 10;\r
376             mainWindow.trackBar3.Value = int.Parse(value.ToString());\r
377             actualValue = presetQuery.DRC3 / 10;\r
378             mainWindow.lbl_drc3.Text = actualValue.ToString();\r
379 \r
380             value = presetQuery.DRC4;\r
381             if (value > 0)\r
382                 value = value - 10;\r
383             mainWindow.trackBar4.Value = int.Parse(value.ToString());\r
384             actualValue = presetQuery.DRC4 / 10;\r
385             mainWindow.lbl_drc4.Text = actualValue.ToString();\r
386 \r
387 \r
388             // Subtitle Stuff\r
389             mainWindow.drp_subtitle.Text = presetQuery.Subtitles;\r
390 \r
391             if (presetQuery.ForcedSubtitles == true)\r
392             {\r
393                 mainWindow.check_forced.CheckState = CheckState.Checked;\r
394                 mainWindow.check_forced.Enabled = true;\r
395             }\r
396             else\r
397                 mainWindow.check_forced.CheckState = CheckState.Unchecked;\r
398 \r
399 \r
400             #endregion\r
401 \r
402             // H264 Tab & Preset Name\r
403             #region other\r
404             mainWindow.rtf_x264Query.Text = presetQuery.H264Query;\r
405 \r
406             // Set the preset name\r
407             mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";\r
408             #endregion\r
409         }\r
410 \r
411         #endregion\r
412 \r
413         #region Query Generator & Chapter CSV Creation\r
414 \r
415         /// <summary>\r
416         /// Generates a CLI query based on the GUI widgets.\r
417         /// </summary>\r
418         /// <param name="mainWindow"></param>\r
419         /// <returns>The CLI String</returns>\r
420         public string GenerateTheQuery(frmMain mainWindow)\r
421         {\r
422             // Source tab\r
423             #region source\r
424             string query = "";\r
425 \r
426             if ((mainWindow.text_source.Text != "") && (mainWindow.text_source.Text.Trim() != "Click 'Source' to continue"))\r
427                 query = " -i " + '"' + mainWindow.text_source.Text + '"';\r
428 \r
429             if (mainWindow.drp_dvdtitle.Text != "Automatic")\r
430             {\r
431                 string[] titleInfo = mainWindow.drp_dvdtitle.Text.Split(' ');\r
432                 query += " -t " + titleInfo[0];\r
433             }\r
434 \r
435             if (mainWindow.drop_chapterFinish.Text == mainWindow.drop_chapterStart.Text && mainWindow.drop_chapterStart.Text != "Auto")\r
436                 query += " -c " + mainWindow.drop_chapterStart.Text;\r
437             else if (mainWindow.drop_chapterStart.Text == "Auto" && mainWindow.drop_chapterFinish.Text != "Auto")\r
438                 query += " -c " + "0-" + mainWindow.drop_chapterFinish.Text;\r
439             else if (mainWindow.drop_chapterStart.Text != "Auto" && mainWindow.drop_chapterFinish.Text != "Auto")\r
440                 query += " -c " + mainWindow.drop_chapterStart.Text + "-" + mainWindow.drop_chapterFinish.Text;\r
441 \r
442             #endregion\r
443 \r
444             // Destination tab\r
445             #region Destination\r
446             if (mainWindow.text_destination.Text != "")\r
447                 query += " -o " + '"' + mainWindow.text_destination.Text + '"';\r
448             #endregion\r
449 \r
450             query += generateTabbedComponentsQuery(mainWindow, mainWindow.text_source.Text);\r
451             return query;\r
452         }\r
453         /// <summary>\r
454         /// Generates a CLI query for the preview function.\r
455         /// This basically forces a shortened version of the encdode.\r
456         /// </summary>\r
457         /// <param name="mainWindow"></param>\r
458         /// <returns>Returns a CLI query String.</returns>\r
459         public string GeneratePreviewQuery(frmMain mainWindow)\r
460         {\r
461             // Source tab\r
462             #region source\r
463             string query = "";\r
464 \r
465             if ((mainWindow.text_source.Text != "") && (mainWindow.text_source.Text.Trim() != "Click 'Source' to continue"))\r
466                 query = " -i " + '"' + mainWindow.text_source.Text + '"';\r
467 \r
468             if (mainWindow.drp_dvdtitle.Text != "Automatic")\r
469             {\r
470                 string[] titleInfo = mainWindow.drp_dvdtitle.Text.Split(' ');\r
471                 query += " -t " + titleInfo[0];\r
472             }\r
473 \r
474             query += " -c 2";\r
475             #endregion\r
476 \r
477             // Destination tab\r
478             #region Destination\r
479             if (mainWindow.text_destination.Text != "")\r
480                 query += " -o " + '"' + mainWindow.text_destination.Text.Replace(".m", "_sample.m").Replace(".avi", "_sample.avi").Replace(".ogm", "_sample.ogm") + '"';\r
481 \r
482             #endregion\r
483 \r
484             query += generateTabbedComponentsQuery(mainWindow, mainWindow.text_source.Text);\r
485             return query;\r
486         }\r
487 \r
488         // Generates part of the CLI query, for the tabbed components only.\r
489         private string generateTabbedComponentsQuery(frmMain mainWindow, string source)\r
490         {\r
491             string query = "";\r
492 \r
493             // Picture Settings Tab\r
494             #region Picture Settings Tab\r
495 \r
496             switch (mainWindow.drp_videoEncoder.Text)\r
497             {\r
498                 case "MPEG-4 (FFmpeg)":\r
499                     query += " -e ffmpeg";\r
500                     break;\r
501                 case "MPEG-4 (XviD)":\r
502                     query += " -e xvid";\r
503                     break;\r
504                 case "H.264 (x264)":\r
505                     query += " -e x264";\r
506                     break;\r
507                 case "VP3 (Theora)":\r
508                     query += " -e theora";\r
509                     break;\r
510                 default:\r
511                     query += " -e x264";\r
512                     break;\r
513             }\r
514 \r
515             if (mainWindow.text_width.Text != "")\r
516                 query += " -w " + mainWindow.text_width.Text;\r
517 \r
518             if (mainWindow.text_height.Text != "")\r
519                 query += " -l " + mainWindow.text_height.Text;\r
520 \r
521             string cropTop = mainWindow.text_top.Text;\r
522             string cropBottom = mainWindow.text_bottom.Text;\r
523             string cropLeft = mainWindow.text_left.Text;\r
524             string cropRight = mainWindow.text_right.Text;\r
525 \r
526             if (mainWindow.drp_crop.Text == "No Crop")\r
527                 query += " --crop 0:0:0:0 ";\r
528             else if (mainWindow.drp_crop.Text == "Custom")\r
529             {\r
530                 if (mainWindow.text_top.Text == string.Empty)\r
531                     cropTop = "0";\r
532                 if (mainWindow.text_bottom.Text == string.Empty)\r
533                     cropBottom = "0";\r
534                 if (mainWindow.text_left.Text == string.Empty)\r
535                     cropLeft = "0";\r
536                 if (mainWindow.text_right.Text == string.Empty)\r
537                     cropRight = "0";\r
538 \r
539                 query += " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;\r
540             }\r
541 \r
542             switch (mainWindow.drp_deInterlace_option.Text)\r
543             {\r
544                 case "None":\r
545                     query += "";\r
546                     break;\r
547                 case "Fast":\r
548                     query += " --deinterlace=\"fast\"";\r
549                     break;\r
550                 case "Slow":\r
551                     query += " --deinterlace=\"slow\"";\r
552                     break;\r
553                 case "Slower":\r
554                     query += " --deinterlace=\"slower\"";\r
555                     break;\r
556                 case "Slowest":\r
557                     query += " --deinterlace=\"slowest\"";\r
558                     break;\r
559                 default:\r
560                     query += "";\r
561                     break;\r
562             }\r
563 \r
564             if (mainWindow.check_decomb.Checked)\r
565             {\r
566                 string decombValue = Properties.Settings.Default.decomb;\r
567                 if (decombValue != "" && decombValue != Properties.Settings.Default.default_decomb)\r
568                     query += " --decomb=\"" + decombValue + "\"";\r
569                 else\r
570                     query += " --decomb ";\r
571             }\r
572 \r
573             if (mainWindow.check_grayscale.Checked)\r
574                 query += " -g ";\r
575 \r
576             if (mainWindow.drp_anamorphic.SelectedIndex == 1)\r
577                 query += " -p ";\r
578             else if (mainWindow.drp_anamorphic.SelectedIndex == 2)\r
579                 query += " -P ";\r
580 \r
581             if (mainWindow.check_deblock.Checked)\r
582                 query += " --deblock";\r
583 \r
584             if (mainWindow.check_detelecine.Checked)\r
585                 query += " --detelecine";\r
586 \r
587             if (mainWindow.check_vfr.Checked)\r
588                 query += " -V ";\r
589             #endregion\r
590 \r
591             // Video Settings Tab\r
592             #region Video Settings Tab\r
593             // These are output settings features\r
594             if (mainWindow.check_largeFile.Checked)\r
595                 query += " -4 ";\r
596 \r
597             if (mainWindow.check_iPodAtom.Checked)\r
598                 query += " -I ";\r
599 \r
600             if (mainWindow.check_optimiseMP4.Checked)\r
601                 query += " -O ";\r
602 \r
603             // Video Settings\r
604             if (mainWindow.text_bitrate.Text != "")\r
605                 query += " -b " + mainWindow.text_bitrate.Text;\r
606 \r
607             if (mainWindow.text_filesize.Text != "")\r
608                 query += " -S " + mainWindow.text_filesize.Text;\r
609 \r
610             // Video Quality Setting\r
611             double videoQuality = mainWindow.slider_videoQuality.Value;\r
612             if (videoQuality != 0)\r
613             {\r
614                 videoQuality = videoQuality / 100;\r
615                 query += " -q " + videoQuality.ToString(new CultureInfo("en-US"));\r
616             }\r
617 \r
618             if (mainWindow.check_2PassEncode.Checked)\r
619                 query += " -2 ";\r
620 \r
621             if (mainWindow.drp_videoFramerate.Text != "Same as source")\r
622             {\r
623                 if (!mainWindow.check_vfr.Checked)\r
624                     query += " -r " + mainWindow.drp_videoFramerate.Text;\r
625             }\r
626 \r
627             if (mainWindow.check_turbo.Checked)\r
628                 query += " -T ";\r
629 \r
630 \r
631 \r
632             switch (mainWindow.drp_deNoise.Text)\r
633             {\r
634                 case "None":\r
635                     query += "";\r
636                     break;\r
637                 case "Weak":\r
638                     query += " --denoise=\"weak\"";\r
639                     break;\r
640                 case "Medium":\r
641                     query += " --denoise=\"medium\"";\r
642                     break;\r
643                 case "Strong":\r
644                     query += " --denoise=\"strong\"";\r
645                     break;\r
646                 default:\r
647                     query += "";\r
648                     break;\r
649             }\r
650             #endregion\r
651 \r
652             // Audio Settings Tab\r
653             #region Audio Settings Tab\r
654             // Track 1\r
655             string track1 = mainWindow.drp_track1Audio.Text;\r
656             string aencoder1 = mainWindow.drp_audenc_1.Text;\r
657             string audioBitrate1 = mainWindow.drp_audbit_1.Text;\r
658             string audioSampleRate1 = mainWindow.drp_audsr_1.Text;\r
659             string Mixdown1 = mainWindow.drp_audmix_1.Text;\r
660             string drc1 = mainWindow.trackBar1.Value.ToString();\r
661 \r
662             // Track 2\r
663             string track2 = mainWindow.drp_track2Audio.Text;\r
664             string aencoder2 = mainWindow.drp_audenc_2.Text;\r
665             string audioBitrate2 = mainWindow.drp_audbit_2.Text;\r
666             string audioSampleRate2 = mainWindow.drp_audsr_2.Text;\r
667             string Mixdown2 = mainWindow.drp_audmix_2.Text;\r
668             string drc2 = mainWindow.trackBar2.Value.ToString();\r
669 \r
670             // Track 3\r
671             string track3 = mainWindow.drp_track3Audio.Text;\r
672             string aencoder3 = mainWindow.drp_audenc_3.Text;\r
673             string audioBitrate3 = mainWindow.drp_audbit_3.Text;\r
674             string audioSampleRate3 = mainWindow.drp_audsr_3.Text;\r
675             string Mixdown3 = mainWindow.drp_audmix_3.Text;\r
676             string drc3 = mainWindow.trackBar3.Value.ToString();\r
677 \r
678             // Track 4\r
679             string track4 = mainWindow.drp_track4Audio.Text;\r
680             string aencoder4 = mainWindow.drp_audenc_4.Text;\r
681             string audioBitrate4 = mainWindow.drp_audbit_4.Text;\r
682             string audioSampleRate4 = mainWindow.drp_audsr_4.Text;\r
683             string Mixdown4 = mainWindow.drp_audmix_4.Text;\r
684             string drc4 = mainWindow.trackBar4.Value.ToString();\r
685 \r
686 \r
687             //\r
688             // Audio Track Selections\r
689             //\r
690             if (track1 == "Automatic")\r
691                 query += " -a 1";\r
692             else if (track1 != "None")\r
693             {\r
694                 string[] tempSub = track1.Split(' ');\r
695                 query += " -a " + tempSub[0];\r
696             }\r
697 \r
698             if (track2 != "None")\r
699             {\r
700                 string[] tempSub;\r
701                 tempSub = track2.Split(' ');\r
702 \r
703                 if (track1 == "None")\r
704                     query += " -a none," + tempSub[0];\r
705                 else\r
706                     query += "," + tempSub[0];\r
707             }\r
708 \r
709             if (track3 != "None")\r
710             {\r
711                 string[] tempSub;\r
712                 tempSub = track3.Split(' ');\r
713                 query += "," + tempSub[0];\r
714             }\r
715 \r
716             if (track4 != "None")\r
717             {\r
718                 string[] tempSub;\r
719                 tempSub = track4.Split(' ');\r
720                 query += "," + tempSub[0];\r
721             }\r
722 \r
723             //\r
724             // Audio Encoder\r
725             //\r
726             if (aencoder1 != "")\r
727                 query += " -E " + getAudioEncoder(aencoder1);\r
728 \r
729             if (aencoder2 != "")\r
730             {\r
731                 if (aencoder1 == string.Empty)\r
732                     query += " -E faac," + getAudioEncoder(aencoder2);\r
733                 else\r
734                     query += "," + getAudioEncoder(aencoder2);\r
735             }\r
736 \r
737             if (aencoder3 != "")\r
738                 query += "," + getAudioEncoder(aencoder3);\r
739 \r
740             if (aencoder4 != "")\r
741                 query += "," + getAudioEncoder(aencoder4);\r
742 \r
743             //\r
744             // Audio Bitrate Selections\r
745             //\r
746             if (audioBitrate1 != "")\r
747                 query += " -B " + audioBitrate1;\r
748 \r
749             if (audioBitrate2 != "")\r
750             {\r
751                 if (audioBitrate1 == string.Empty)\r
752                     query += " -B 160," + audioBitrate2;\r
753                 else\r
754                     query += "," + audioBitrate2;\r
755             }\r
756 \r
757             if (audioBitrate3 != "")\r
758                 query += "," + audioBitrate3;\r
759 \r
760             if (audioBitrate4 != "")\r
761                 query += "," + audioBitrate4;\r
762 \r
763 \r
764             //Audio Sample Rate   - audioSampleRate\r
765             if (audioSampleRate1 != "")\r
766                 query += " -R " + audioSampleRate1.Replace("Auto", "0");\r
767 \r
768             if (audioSampleRate2 != "")\r
769             {\r
770                 if (audioSampleRate1 == string.Empty)\r
771                     query += " -R 0," + audioSampleRate2.Replace("Auto", "0");\r
772                 else\r
773                     query += "," + audioSampleRate2.Replace("Auto", "0");\r
774             }\r
775             else\r
776             {\r
777                 // All this is a hack, because when AppleTV is selected, there is no sample rate selected. so just add a 48\r
778                 // It should probably be setup later so the GUI widget has the value 48 in it.\r
779 \r
780                 if ((track2 != "") && (track2 != "None"))\r
781                 {\r
782                     if (audioSampleRate1 == string.Empty)\r
783                         query += " -R 0,0";\r
784                     else\r
785                         query += ",0";\r
786                 }\r
787             }\r
788 \r
789             if (audioSampleRate3 != "")\r
790                 query += "," + audioSampleRate3.Replace("Auto", "0");\r
791 \r
792             if (audioSampleRate4 != "")\r
793                 query += "," + audioSampleRate4.Replace("Auto", "0");\r
794 \r
795             //\r
796             // Audio Mixdown Selections\r
797             //\r
798 \r
799             if (Mixdown1 != "")\r
800                 query += " -6 " + getMixDown(Mixdown1);\r
801             else\r
802                 query += " -6 dpl2";\r
803 \r
804             if (Mixdown2 != "" && track2 != "None")\r
805                 query += "," + getMixDown(Mixdown2);\r
806 \r
807             if (Mixdown3 != "" && track3 != "None" && track2 != "None")\r
808                 query += "," + getMixDown(Mixdown3);\r
809 \r
810             if (Mixdown4 != "" && track4 != "None" && track3 != "None")\r
811                 query += "," + getMixDown(Mixdown4);\r
812 \r
813 \r
814             //\r
815             // DRC\r
816             //\r
817             double value = 0;\r
818 \r
819             value = mainWindow.trackBar1.Value / 10.0;\r
820             value++;\r
821 \r
822             if (value > 1.0)\r
823                 query += " -D " + value;\r
824             else\r
825                 query += " -D 1";\r
826 \r
827             value = mainWindow.trackBar2.Value / 10.0;\r
828             value++;\r
829             if (track2 != "None" && drc2 != "0")\r
830                 query += "," + value;\r
831             else if (track2 != "None" && drc2 == "0")\r
832                 query += ",1";\r
833 \r
834             value = mainWindow.trackBar3.Value / 10.0;\r
835             value++;\r
836             if (track3 != "None" && drc3 != "0")\r
837                 query += "," + value;\r
838             else if (track3 != "None" && drc3 == "0")\r
839                 query += ",1";\r
840 \r
841             value = mainWindow.trackBar4.Value / 10.0;\r
842             value++;\r
843             if (track4 != "None" && drc4 != "0")\r
844                 query += "," + value;\r
845             else if (track4 != "None" && drc4 == "0")\r
846                 query += ",1";\r
847 \r
848             // Subtitles\r
849             string subtitles = mainWindow.drp_subtitle.Text;\r
850             if (subtitles == "Autoselect")\r
851                 query += " -U ";\r
852             else if (subtitles != "" && subtitles != "None")\r
853             {\r
854                 string[] tempSub;\r
855                 tempSub = subtitles.Split(' ');\r
856                 query += " -s " + tempSub[0];\r
857             }\r
858 \r
859             if (mainWindow.check_forced.Checked)\r
860                 query += " -F ";\r
861 \r
862             #endregion\r
863 \r
864             // Chapter Markers Tab\r
865             #region Chapter Markers\r
866 \r
867             // Attach Source name and dvd title to the start of the chapters.csv filename.\r
868             // This is for the queue. It allows different chapter name files for each title.\r
869             string source_name = mainWindow.text_source.Text;\r
870             string[] sourceName = source.Split('\\');\r
871             source_name = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");\r
872             source_name = source_name.Replace("\"", "");\r
873 \r
874             string source_title = mainWindow.drp_dvdtitle.Text;\r
875             string[] titlesplit = source_title.Split(' ');\r
876             source_title = titlesplit[0];\r
877 \r
878             if (mainWindow.Check_ChapterMarkers.Checked)\r
879             {\r
880                 if ((source_name.Trim().Replace("-i ", "") != "Click 'Browse' to continue") && (source_name.Trim().Replace("-i ", "") != ""))\r
881                 {\r
882                     if (source_title != "Automatic")\r
883                     {\r
884                         string filename = source_name + "-" + source_title + "-chapters.csv";\r
885                         string path = Path.Combine(Path.GetTempPath(), filename);\r
886 \r
887                         Boolean saveCSV = chapterCSVSave(mainWindow, path);\r
888                         if (saveCSV == false)\r
889                             query += " -m ";\r
890                         else\r
891                             query += " --markers=" + "\"" + path + "\"";\r
892                     }\r
893                     else\r
894                     {\r
895                         string filename = source_name + "-chapters.csv";\r
896                         string path = Path.Combine(Path.GetTempPath(), filename);\r
897 \r
898                         Boolean saveCSV = chapterCSVSave(mainWindow, path);\r
899                         if (saveCSV == false)\r
900                             query += " -m ";\r
901                         else\r
902                             query += " --markers=" + "\"" + path + "\"";\r
903                     }\r
904                 }\r
905                 else\r
906                 {\r
907                     string path = Path.Combine(Path.GetTempPath(), "chapters.csv");\r
908                     query += " --markers=" + "\"" + path + "\"";\r
909                 }\r
910             }\r
911             #endregion\r
912 \r
913             // H264 Tab\r
914             #region  H264 Tab\r
915             if (mainWindow.rtf_x264Query.Text != "")\r
916                 query += " -x " + mainWindow.rtf_x264Query.Text;\r
917             #endregion\r
918 \r
919             // Other\r
920             #region Processors / Other\r
921             string processors = Properties.Settings.Default.Processors;\r
922             if (processors != "Automatic")\r
923                 query += " -C " + processors + " ";\r
924 \r
925             query += " -v ";\r
926             #endregion\r
927 \r
928             return query;\r
929         }\r
930         // Get the CLI equive of the audio mixdown from the widget name.\r
931         private string getMixDown(string selectedAudio)\r
932         {\r
933             switch (selectedAudio)\r
934             {\r
935                 case "Automatic":\r
936                     return "dpl2";\r
937                 case "Mono":\r
938                     return "mono";\r
939                 case "Stereo":\r
940                     return "stereo";\r
941                 case "Dolby Surround":\r
942                     return "dpl1";\r
943                 case "Dolby Pro Logic II":\r
944                     return "dpl2";\r
945                 case "6 Channel Discrete":\r
946                     return "6ch";\r
947                 default:\r
948                     return "dpl2";\r
949             }\r
950         }\r
951         // Get the CLI equiv of the audio encoder from the widget name.\r
952         private string getAudioEncoder(string selectedEncoder)\r
953         {\r
954             switch (selectedEncoder)\r
955             {\r
956                 case "AAC":\r
957                     return "faac";\r
958                 case "MP3":\r
959                     return "lame";\r
960                 case "Vorbis":\r
961                     return "vorbis";\r
962                 case "AC3":\r
963                     return "ac3";\r
964                 default:\r
965                     return "";\r
966             }\r
967         }\r
968         // This function saves the data in the chapters tab, dataGridView into a CSV file called chapters.csv\r
969         // in a directory specified by file_path_name\r
970         private Boolean chapterCSVSave(frmMain mainWindow, string file_path_name)\r
971         {\r
972             try\r
973             {\r
974                 StringBuilder csv = new StringBuilder();\r
975 \r
976                 foreach (DataGridViewRow row in mainWindow.data_chpt.Rows)\r
977                 {\r
978                     csv.Append(row.Cells[0].Value.ToString());\r
979                     csv.Append(",");\r
980                     csv.Append(row.Cells[1].Value.ToString());\r
981                     csv.Append(Environment.NewLine);\r
982                 }\r
983                 StreamWriter file = new StreamWriter(file_path_name);\r
984                 file.Write(csv.ToString());\r
985                 file.Close();\r
986                 file.Dispose();\r
987                 return true;\r
988 \r
989             }\r
990             catch (Exception exc)\r
991             {\r
992                 MessageBox.Show("Unable to save Chapter Makrers file! \nChapter marker names will NOT be saved in your encode \n\n" + exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
993                 return false;\r
994             }\r
995         }\r
996 \r
997         #endregion\r
998 \r
999         #region frmMain Actions\r
1000 \r
1001         /// <summary>\r
1002         /// Select the longest title in the DVD title dropdown menu on frmMain\r
1003         /// </summary>\r
1004         public void selectLongestTitle(frmMain mainWindow)\r
1005         {\r
1006             int current_largest = 0;\r
1007             Handbrake.Parsing.Title title2Select;\r
1008 \r
1009             // Check if there are titles in the DVD title dropdown menu and make sure, it's not just "Automatic"\r
1010             if (mainWindow.drp_dvdtitle.Items[0].ToString() != "Automatic")\r
1011                 title2Select = (Handbrake.Parsing.Title)mainWindow.drp_dvdtitle.Items[0];\r
1012             else\r
1013                 title2Select = null;\r
1014 \r
1015             // So, If there are titles in the DVD Title dropdown menu, lets select the longest.\r
1016             if (title2Select != null)\r
1017             {\r
1018                 foreach (Handbrake.Parsing.Title x in mainWindow.drp_dvdtitle.Items)\r
1019                 {\r
1020                     string title = x.ToString();\r
1021                     if (title != "Automatic")\r
1022                     {\r
1023                         string[] y = title.Split(' ');\r
1024                         string time = y[1].Replace("(", "").Replace(")", "");\r
1025                         string[] z = time.Split(':');\r
1026 \r
1027                         int hours = int.Parse(z[0]) * 60 * 60;\r
1028                         int minutes = int.Parse(z[1]) * 60;\r
1029                         int seconds = int.Parse(z[2]);\r
1030                         int total_sec = hours + minutes + seconds;\r
1031 \r
1032                         if (current_largest == 0)\r
1033                         {\r
1034                             current_largest = hours + minutes + seconds;\r
1035                             title2Select = x;\r
1036                         }\r
1037                         else\r
1038                         {\r
1039                             if (total_sec > current_largest)\r
1040                             {\r
1041                                 current_largest = total_sec;\r
1042                                 title2Select = x;\r
1043                             }\r
1044                         }\r
1045                     }\r
1046                 }\r
1047 \r
1048                 // Now set the longest title in the gui.\r
1049                 mainWindow.drp_dvdtitle.SelectedItem = title2Select;\r
1050             }\r
1051         }\r
1052 \r
1053         /// <summary>\r
1054         /// Set's up the DataGridView on the Chapters tab (frmMain)\r
1055         /// </summary>\r
1056         /// <param name="mainWindow"></param>\r
1057         public void chapterNaming(frmMain mainWindow)\r
1058         {\r
1059             try\r
1060             {\r
1061                 mainWindow.data_chpt.Rows.Clear();\r
1062                 int i = 0;\r
1063                 int rowCount = 0;\r
1064                 int start = 0;\r
1065                 int finish = 0;\r
1066                 if (mainWindow.drop_chapterFinish.Text != "Auto")\r
1067                     finish = int.Parse(mainWindow.drop_chapterFinish.Text);\r
1068 \r
1069                 if (mainWindow.drop_chapterStart.Text != "Auto")\r
1070                     start = int.Parse(mainWindow.drop_chapterStart.Text);\r
1071 \r
1072                 rowCount = finish - (start - 1);\r
1073 \r
1074                 while (i < rowCount)\r
1075                 {\r
1076                     DataGridViewRow row = new DataGridViewRow();\r
1077 \r
1078                     mainWindow.data_chpt.Rows.Insert(i, row);\r
1079                     mainWindow.data_chpt.Rows[i].Cells[0].Value = (i + 1);\r
1080                     mainWindow.data_chpt.Rows[i].Cells[1].Value = "Chapter " + (i + 1);\r
1081                     i++;\r
1082                 }\r
1083             }\r
1084             catch (Exception exc)\r
1085             {\r
1086                 MessageBox.Show("chapterNaming() Error has occured: \n" + exc.ToString());\r
1087             }\r
1088         }\r
1089 \r
1090         /// <summary>\r
1091         /// Function which generates the filename and path automatically based on \r
1092         /// the Source Name, DVD title and DVD Chapters\r
1093         /// </summary>\r
1094         /// <param name="mainWindow"></param>\r
1095         public void autoName(frmMain mainWindow)\r
1096         {\r
1097             if (Properties.Settings.Default.autoNaming == "Checked")\r
1098             {\r
1099                 if (mainWindow.drp_dvdtitle.Text != "Automatic")\r
1100                 {\r
1101                     string source = mainWindow.text_source.Text;\r
1102                     string[] sourceName = source.Split('\\');\r
1103                     source = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");\r
1104 \r
1105                     string title = mainWindow.drp_dvdtitle.Text;\r
1106                     string[] titlesplit = title.Split(' ');\r
1107                     title = titlesplit[0];\r
1108 \r
1109                     string cs = mainWindow.drop_chapterStart.Text;\r
1110                     string cf = mainWindow.drop_chapterFinish.Text;\r
1111 \r
1112                     if (title == "Automatic")\r
1113                         title = "";\r
1114                     if (cs == "Auto")\r
1115                         cs = "";\r
1116                     if (cf == "Auto")\r
1117                         cf = "";\r
1118 \r
1119                     string dash = "";\r
1120                     if (cf != "Auto")\r
1121                         dash = "-";\r
1122 \r
1123                     if (!mainWindow.text_destination.Text.Contains("\\"))\r
1124                     {\r
1125                         string filePath = "";\r
1126                         if (Properties.Settings.Default.autoNamePath.Trim() != "")\r
1127                         {\r
1128                             if (Properties.Settings.Default.autoNamePath.Trim() != "Click 'Browse' to set the default location")\r
1129                                 filePath = Properties.Settings.Default.autoNamePath + "\\";\r
1130                         }\r
1131                         mainWindow.text_destination.Text = filePath + source + "_T" + title + "_C" + cs + dash + cf + ".mp4";\r
1132                     }\r
1133                     else\r
1134                     {\r
1135                         string dest = mainWindow.text_destination.Text;\r
1136 \r
1137                         string[] destName = dest.Split('\\');\r
1138 \r
1139 \r
1140                         string[] extension = dest.Split('.');\r
1141                         string ext = extension[extension.Length - 1];\r
1142 \r
1143                         destName[destName.Length - 1] = source + "_T" + title + "_C" + cs + dash + cf + "." + ext;\r
1144 \r
1145                         string fullDest = "";\r
1146                         foreach (string part in destName)\r
1147                         {\r
1148                             if (fullDest != "")\r
1149                                 fullDest = fullDest + "\\" + part;\r
1150                             else\r
1151                                 fullDest = fullDest + part;\r
1152                         }\r
1153 \r
1154                         mainWindow.text_destination.Text = fullDest;\r
1155                     }\r
1156                 }\r
1157             }\r
1158         }\r
1159 \r
1160         #endregion\r
1161 \r
1162         #region Version and Update Checking\r
1163 \r
1164         /// <summary>\r
1165         /// Checks for updates and returns true if an update is available.\r
1166         /// </summary>\r
1167         /// <param name="debug">Turns on debug mode. Don't use on program startup</param>\r
1168         /// <returns>Boolean True = Update available</returns>\r
1169         public Boolean updateCheck(Boolean debug)\r
1170         {\r
1171             try\r
1172             {\r
1173                 Functions.AppcastReader rssRead = new Functions.AppcastReader();\r
1174                 string build = rssRead.build();\r
1175 \r
1176                 int latest = int.Parse(build);\r
1177                 int current = Properties.Settings.Default.hb_build;\r
1178                 int skip = Properties.Settings.Default.skipversion;\r
1179 \r
1180                 if (latest == skip)\r
1181                     return false;\r
1182                 else\r
1183                 {\r
1184                     Boolean update = (latest > current);\r
1185                     return update;\r
1186                 }\r
1187             }\r
1188             catch (Exception exc)\r
1189             {\r
1190                 if (debug == true)\r
1191                     MessageBox.Show("Unable to check for updates, Please try again later. \n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
1192                 return false;\r
1193             }\r
1194         }\r
1195         /// <summary>\r
1196         /// Get's HandBrakes version data from the CLI.\r
1197         /// </summary>\r
1198         /// <returns>Arraylist of Version Data. 0 = hb_version 1 = hb_build</returns>\r
1199         public ArrayList getCliVersionData()\r
1200         {\r
1201             ArrayList cliVersionData = new ArrayList();\r
1202             // 0 = SVN Build / Version\r
1203             // 1 = Build Date\r
1204 \r
1205             Process cliProcess = new Process();\r
1206             ProcessStartInfo handBrakeCLI = new ProcessStartInfo("HandBrakeCLI.exe", " -u");\r
1207             handBrakeCLI.UseShellExecute = false;\r
1208             handBrakeCLI.RedirectStandardError = true;\r
1209             handBrakeCLI.RedirectStandardOutput = true;\r
1210             handBrakeCLI.CreateNoWindow = true;\r
1211             cliProcess.StartInfo = handBrakeCLI;\r
1212             cliProcess.Start();\r
1213 \r
1214             // Retrieve standard output and report back to parent thread until the process is complete\r
1215             String line;\r
1216             TextReader stdOutput = cliProcess.StandardError;\r
1217 \r
1218             while (!cliProcess.HasExited)\r
1219             {\r
1220                 line = stdOutput.ReadLine();\r
1221                 Match m = Regex.Match(line, @"HandBrake [0-9\.]*svn[0-9]*[M]* \([0-9]*\)");\r
1222                 if (m.Success != false)\r
1223                 {\r
1224                     string data = line.Replace("(", "").Replace(")", "").Replace("HandBrake ", "");\r
1225                     string[] arr = data.Split(' ');\r
1226                     cliVersionData.Add(arr[0]);\r
1227                     cliVersionData.Add(arr[1]);\r
1228                     return cliVersionData;\r
1229                 }\r
1230             }\r
1231             return null;\r
1232         }\r
1233 \r
1234         #endregion\r
1235 \r
1236         #region Queue\r
1237         /// <summary>\r
1238         /// Check if the queue recovery file contains records.\r
1239         /// If it does, it means the last queue did not complete before HandBrake closed.\r
1240         /// So, return a boolean if true. \r
1241         /// </summary>\r
1242         public Boolean check_queue_recovery()\r
1243         {\r
1244             try\r
1245             {\r
1246                 string tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");\r
1247                 using (StreamReader reader = new StreamReader(tempPath))\r
1248                 {\r
1249                     string queue_item = reader.ReadLine();\r
1250                     if (queue_item == null)\r
1251                     {\r
1252                         reader.Close();\r
1253                         reader.Dispose();\r
1254                         return false;\r
1255                     }\r
1256                     else // There exists an item in the recovery queue file, so try and recovr it.\r
1257                     {\r
1258                         reader.Close();\r
1259                         reader.Dispose();\r
1260                         return true;\r
1261                     }\r
1262                 }\r
1263             }\r
1264             catch (Exception)\r
1265             {\r
1266                 // Keep quiet about the error.\r
1267                 return false;\r
1268             }\r
1269         }\r
1270         #endregion\r
1271 \r
1272     }\r
1273 }