OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
index b2dba36..bf00e22 100644 (file)
@@ -1,5 +1,6 @@
 using System;\r
 using System.Collections.Generic;\r
+using System.Collections.Specialized;\r
 using System.ComponentModel;\r
 using System.Data;\r
 using System.Drawing;\r
@@ -9,43 +10,140 @@ using System.Net;
 using System.IO;\r
 using System.Diagnostics;\r
 using System.Threading;\r
+using System.Runtime.InteropServices;\r
+using System.Globalization;\r
+using System.Text.RegularExpressions;\r
+\r
 \r
 namespace Handbrake\r
 {\r
     public partial class frmMain : Form\r
     {\r
+        // -------------------------------------------------------------- \r
+        // Applicaiton Startup Stuff\r
+        // --------------------------------------------------------------\r
+\r
+        #region Application Startup\r
+\r
+        // Some stuff that needs to be Initialized. \r
         private Process hbProc;\r
         private Parsing.DVD thisDVD;\r
-\r
-        // --------------------------------------------------------------\r
-        // Some windows that require only 1 instance.\r
-        // --------------------------------------------------------------\r
-        private frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
         private frmQueue queueWindow = new frmQueue();\r
-        \r
-        // -------------------------------------------------------------- \r
-        // Stuff that needs doing on startup.\r
-        // - Load users default settings. (if required)\r
-        // - Do an update check (if required)\r
-        // --------------------------------------------------------------\r
+\r
+        // The main window beings here...\r
         public frmMain()\r
         {\r
+            // Load the splash screen in this thread\r
+            Form splash = new frmSplashScreen();\r
+            splash.Show();\r
+\r
+            //Create a label that can be updated from the parent thread.\r
+            Label lblStatus = new Label();\r
+\r
+            //Size the label\r
+            lblStatus.Size = new Size(250, 20);\r
+\r
+            //Position the label\r
+            lblStatus.Location = new Point(10, 280);\r
+\r
+            //Put the label on the splash form\r
+            splash.Controls.Add(lblStatus);\r
+\r
+            //Fire a thread to wait for 2 seconds.  The splash screen will exit when the time expires\r
+            Thread timer = new Thread(splashTimer);\r
+            timer.Start();\r
+\r
             InitializeComponent();\r
 \r
+            // show the form, but leave disabled until preloading is complete\r
+            this.Enabled = false;\r
+\r
+            // Show the main form\r
+            this.Show();\r
+\r
+            // Forces frmMain to draw\r
+            Application.DoEvents();\r
+\r
             // Set the Version number lable to the corect version.\r
-            Version.Text = "Version " + Properties.Settings.Default.GuiVersion;\r
+            Version.Text = "Version " + Properties.Settings.Default.CliVersion;\r
 \r
+            // update the status\r
+            lblStatus.Text = "Checking for updates ...";\r
+            // redraw the splash screen\r
+            Application.DoEvents();\r
             // Run the update checker.\r
             updateCheck();\r
-\r
-            // Now load the users default if required.\r
+            Thread.Sleep(200);\r
+\r
+            // Update the presets\r
+            lblStatus.Text = "Updaing Presets ...";\r
+            Application.DoEvents();\r
+            updatePresets();\r
+            Thread.Sleep(200);\r
+\r
+            // Now load the users default if required. (Will overide the above setting)\r
+            lblStatus.Text = "Loading User Default Settings...";\r
+            Application.DoEvents();\r
+            loadNormalPreset();\r
             loadUserDefaults();\r
+            Thread.Sleep(100);\r
+\r
+            // Enable or disable tooltips\r
+            lblStatus.Text = "Loading Tooltips ...";\r
+            Application.DoEvents();\r
+            tooltip();\r
+            Thread.Sleep(100);\r
+\r
+            // Hide the preset bar if required.\r
+            hidePresetBar();\r
+\r
+            //Finished Loading\r
+            lblStatus.Text = "Loading Complete!";\r
+            Application.DoEvents();\r
+            Thread.Sleep(200);\r
+\r
+            // Wait until splash screen is done\r
+            while (timer.IsAlive)\r
+            { Thread.Sleep(100); }\r
+\r
+            //Close the splash screen\r
+            splash.Close();\r
+            splash.Dispose();\r
+\r
+            // Turn the interface back to the user\r
+            this.Enabled = true;\r
+        }\r
+\r
+        private void splashTimer(object sender)\r
+        {\r
+            Thread.Sleep(2000);  //sit for 2 seconds then exit\r
         }\r
 \r
-        public void loadUserDefaults()\r
-        { \r
+        private void showSplash(object sender)\r
+        {\r
+            // Display splash screen for 1.5 Seconds\r
+            Form splash = new frmSplashScreen();\r
+            splash.Show();\r
+            Thread.Sleep(1500);\r
+            splash.Close(); // Then close.\r
+        }\r
+\r
+        private void loadNormalPreset()\r
+        {\r
+            ListViewItem item = listview_presets.FindItemWithText("Normal");\r
+\r
+            if (item != null)\r
+            {\r
+                listview_presets.SelectedItems.Clear();\r
+                item.Selected = true;\r
+            }\r
+        }\r
+\r
+        private void loadUserDefaults()\r
+        {\r
             try\r
             {\r
+                // Load the users default settings or if the user has not got this option enabled, load the normal preset.\r
                 if (Properties.Settings.Default.defaultSettings == "Checked")\r
                 {\r
                     // Source\r
@@ -78,10 +176,21 @@ namespace Handbrake
                     {\r
                         check_2PassEncode.CheckState = CheckState.Checked;\r
                     }\r
-                    if (Properties.Settings.Default.DeInterlace == "Checked")\r
+\r
+                    drp_deInterlace_option.Text = Properties.Settings.Default.DeInterlace;\r
+                    drp_deNoise.Text = Properties.Settings.Default.denoise;\r
+\r
+                    if (Properties.Settings.Default.detelecine == "Checked")\r
                     {\r
-                        check_DeInterlace.CheckState = CheckState.Checked;\r
+                        check_detelecine.CheckState = CheckState.Checked;\r
                     }\r
+\r
+                    if (Properties.Settings.Default.detelecine == "Checked")\r
+                    {\r
+                        check_deblock.CheckState = CheckState.Checked;\r
+                    }\r
+\r
+\r
                     if (Properties.Settings.Default.Grayscale == "Checked")\r
                     {\r
                         check_grayscale.CheckState = CheckState.Checked;\r
@@ -101,6 +210,12 @@ namespace Handbrake
                     {\r
                         check_largeFile.CheckState = CheckState.Checked;\r
                     }\r
+\r
+                    if (Properties.Settings.Default.chapterMarker == "Checked")\r
+                    {\r
+                        Check_ChapterMarkers.CheckState = CheckState.Checked;\r
+                    }\r
+\r
                     // Audio Settings Tab\r
                     drp_audioBitrate.Text = Properties.Settings.Default.AudioBitrate;\r
                     drp_audioSampleRate.Text = Properties.Settings.Default.AudioSampleRate;\r
@@ -112,6 +227,8 @@ namespace Handbrake
                         CheckCRF.CheckState = CheckState.Checked;\r
                     }\r
                     rtf_h264advanced.Text = Properties.Settings.Default.H264;\r
+\r
+                    groupBox_output.Text = "Output Settings (Preset: " + Properties.Settings.Default.selectedPreset + ")";\r
                 }\r
             }\r
             catch (Exception)\r
@@ -120,140 +237,104 @@ namespace Handbrake
             }\r
         }\r
 \r
-        public void updateCheck()\r
+        private Boolean updateCheck()\r
         {\r
-            if (Properties.Settings.Default.updateStatus == "Checked")\r
+            try\r
             {\r
-                try\r
+                if (Properties.Settings.Default.updateStatus == "Checked")\r
                 {\r
                     String updateFile = Properties.Settings.Default.updateFile;\r
                     WebClient client = new WebClient();\r
                     String data = client.DownloadString(updateFile);\r
                     String[] versionData = data.Split('\n');\r
 \r
-                    if ((versionData[0] != Properties.Settings.Default.GuiVersion) || (versionData[1] != Properties.Settings.Default.CliVersion))\r
-                    {\r
-                        lbl_update.Visible = true;\r
-                    }\r
+                    int verdata = int.Parse(versionData[0].Replace(".", ""));\r
+                    int vergui = int.Parse(Properties.Settings.Default.GuiVersion.Replace(".", ""));\r
+                    int verd1 = int.Parse(versionData[1].Replace(".", ""));\r
+                    int cliversion = int.Parse(Properties.Settings.Default.CliVersion.Replace(".", ""));\r
+\r
+                    Boolean update = ((verdata > vergui) || (verd1 > cliversion));\r
+\r
+                    lbl_update.Visible = update;\r
+\r
+                    return update;\r
                 }\r
-                catch (Exception)\r
+                else\r
                 {\r
-                    // Silently ignore the error\r
+                    return false;\r
                 }\r
             }\r
+            catch (Exception)\r
+            {\r
+                // Silently ignore the error\r
+                return false;\r
+            }\r
         }\r
 \r
+        private void tooltip()\r
+        {\r
+            if (Properties.Settings.Default.tooltipEnable == "Checked")\r
+            {\r
+                ToolTip.Active = true;\r
+            }\r
+        }\r
+\r
+        private void hidePresetBar()\r
+        {\r
+            if (Properties.Settings.Default.hidePresets == "Checked")\r
+            {\r
+                btn_presets.Visible = true;\r
+                this.Width = 591;\r
+            }\r
+\r
+        }\r
+\r
+        #endregion\r
+\r
         // -------------------------------------------------------------- \r
         // The main Menu bar.\r
         // -------------------------------------------------------------- \r
 \r
         #region File Menu\r
-\r
         private void mnu_open_Click(object sender, EventArgs e)\r
         {\r
             string filename;\r
             File_Open.ShowDialog();\r
             filename = File_Open.FileName;\r
+\r
             if (filename != "")\r
             {\r
                 try\r
                 {\r
-                    // Create StreamReader & open file\r
-                    StreamReader line = new StreamReader(filename);\r
-                    string temporyLine; // Used for reading the line into a varible before processing on the checkState items below.\r
-                    \r
-                    // Read in the data and set the correct GUI component with the setting.\r
-                    text_source.Text = line.ReadLine();\r
-                    drp_dvdtitle.Text = line.ReadLine();\r
-                    drop_chapterStart.Text = line.ReadLine();\r
-                    drop_chapterFinish.Text = line.ReadLine();\r
-                    text_destination.Text = line.ReadLine();\r
-                    drp_videoEncoder.Text = line.ReadLine();\r
-                    drp_audioCodec.Text = line.ReadLine();\r
-                    text_width.Text = line.ReadLine();\r
-                    text_height.Text = line.ReadLine();\r
-                    text_top.Text = line.ReadLine();\r
-                    text_bottom.Text = line.ReadLine();\r
-                    text_left.Text = line.ReadLine();\r
-                    text_right.Text = line.ReadLine();\r
-                    drp_subtitle.Text = line.ReadLine();\r
-                    text_bitrate.Text = line.ReadLine();\r
-                    text_filesize.Text = line.ReadLine();\r
-                    slider_videoQuality.Value = int.Parse(line.ReadLine());\r
-\r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        check_2PassEncode.CheckState = CheckState.Checked;\r
-                    }\r
-\r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        check_DeInterlace.CheckState = CheckState.Checked;\r
-                    }\r
-\r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        check_grayscale.CheckState = CheckState.Checked;\r
-                    }\r
-\r
-                    drp_videoFramerate.Text = line.ReadLine();\r
+                    // Some things that need to be done to reset some gui components:\r
+                    CheckPixelRatio.CheckState = CheckState.Unchecked;\r
 \r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-                    }\r
+                    //---------------------------\r
+                    // Get the Preset\r
+                    // ---------------------------\r
 \r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        CheckPixelRatio.CheckState = CheckState.Checked;\r
-                    }\r
+                    // Create StreamReader & open file\r
+                    StreamReader line = new StreamReader(filename);\r
 \r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        check_turbo.CheckState = CheckState.Checked;\r
-                    }\r
+                    // Send the query from the file to the Query Parser class\r
+                    Functions.QueryParser presetQuery = Functions.QueryParser.Parse(line.ReadLine());\r
 \r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        check_largeFile.CheckState = CheckState.Checked;\r
-                    }\r
-   \r
-                    drp_audioBitrate.Text = line.ReadLine();\r
-                    drp_audioSampleRate.Text = line.ReadLine();\r
-                    drp_audioChannels.Text = line.ReadLine();\r
-                    drp_audioMixDown.Text = line.ReadLine();\r
-                    \r
-                    // Advanced H264 Options\r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        CheckCRF.CheckState = CheckState.Checked;\r
-                    }\r
-                    rtf_h264advanced.Text = line.ReadLine();\r
+                    // Now load the preset\r
+                    presetLoader(presetQuery, filename);\r
 \r
                     // Close the stream\r
                     line.Close();\r
-\r
-\r
-                    // Fix for SliderValue not appearing when Opening saved file\r
-                    SliderValue.Text = slider_videoQuality.Value + "%";\r
-\r
-                } catch (Exception){\r
+                }\r
+                catch (Exception exc)\r
+                {\r
                     MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
+                    MessageBox.Show(exc.ToString());\r
                 }\r
             }\r
         }\r
 \r
         private void mnu_save_Click(object sender, EventArgs e)\r
         {\r
-\r
             string filename;\r
             File_Save.ShowDialog();\r
             filename = File_Save.FileName;\r
@@ -264,64 +345,25 @@ namespace Handbrake
                     // Create a StreamWriter and open the file\r
                     StreamWriter line = new StreamWriter(filename);\r
 \r
-                    //Source\r
-                    line.WriteLine(text_source.Text);\r
-                    line.WriteLine(drp_dvdtitle.Text);\r
-                    line.WriteLine(drop_chapterStart.Text);\r
-                    line.WriteLine(drop_chapterFinish.Text);\r
-                    //Destination\r
-                    line.WriteLine(text_destination.Text);\r
-                    line.WriteLine(drp_videoEncoder.Text);\r
-                    line.WriteLine(drp_audioCodec.Text);\r
-                    line.WriteLine(text_width.Text);\r
-                    line.WriteLine(text_height.Text);\r
-                    //Picture Settings Tab\r
-                    line.WriteLine(text_top.Text);\r
-                    line.WriteLine(text_bottom.Text);\r
-                    line.WriteLine(text_left.Text);\r
-                    line.WriteLine(text_right.Text);\r
-                    line.WriteLine(drp_subtitle.Text);\r
-                    //Video Settings Tab\r
-                    line.WriteLine(text_bitrate.Text);\r
-                    line.WriteLine(text_filesize.Text);\r
-                    line.WriteLine(slider_videoQuality.Value.ToString());\r
-                    line.WriteLine(check_2PassEncode.CheckState.ToString());\r
-                    line.WriteLine(check_DeInterlace.CheckState.ToString());\r
-                    line.WriteLine(check_grayscale.CheckState.ToString());\r
-                    line.WriteLine(drp_videoFramerate.Text);\r
-                    line.WriteLine(Check_ChapterMarkers.CheckState.ToString());\r
-                    line.WriteLine(CheckPixelRatio.CheckState.ToString());\r
-                    line.WriteLine(check_turbo.CheckState.ToString());\r
-                    line.WriteLine(check_largeFile.CheckState.ToString());\r
-                    //Audio Settings Tab\r
-                    line.WriteLine(drp_audioBitrate.Text);\r
-                    line.WriteLine(drp_audioSampleRate.Text);\r
-                    line.WriteLine(drp_audioChannels.Text);\r
-                    line.WriteLine(drp_audioMixDown.Text);\r
-                    //H264 Tab\r
-                    line.WriteLine(CheckCRF.CheckState.ToString());\r
-                    line.WriteLine(rtf_h264advanced.Text);\r
+                    // Generate and write the query string to the file\r
+                    String query = GenerateTheQuery();\r
+                    line.WriteLine(query);\r
+\r
                     // close the stream\r
                     line.Close();\r
                     MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
                 }\r
-                catch(Exception)\r
+                catch (Exception)\r
                 {\r
                     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
                 }\r
-                \r
-            }\r
-        }\r
 \r
-        private void mnu_update_Click(object sender, EventArgs e)\r
-        {\r
-            Form Update = new frmUpdate();\r
-            Update.ShowDialog();\r
+            }\r
         }\r
 \r
         private void mnu_exit_Click(object sender, EventArgs e)\r
         {\r
-            this.Close();\r
+            Application.Exit();\r
         }\r
 \r
         #endregion\r
@@ -335,6 +377,7 @@ namespace Handbrake
 \r
         private void mnu_viewDVDdata_Click(object sender, EventArgs e)\r
         {\r
+            frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
             dvdInfoWindow.Show();\r
         }\r
 \r
@@ -348,138 +391,45 @@ namespace Handbrake
 \r
         #region Presets Menu\r
 \r
-        private void mnu_preset_ipod133_Click(object sender, EventArgs e)\r
+        private void mnu_presetReset_Click(object sender, EventArgs e)\r
         {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "640";\r
-            text_height.Text = "480";\r
-            drp_videoEncoder.Text = "H.264 (iPod)";\r
-            text_bitrate.Text = "1000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            rtf_h264advanced.Text = "";\r
-            drp_crop.Text = "No Crop";\r
-        }\r
-\r
-        private void mnu_preset_ipod178_Click(object sender, EventArgs e)\r
-        {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "640";\r
-            text_height.Text = "352";\r
-            drp_videoEncoder.Text = "H.264 (iPod)";\r
-            text_bitrate.Text = "1000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            rtf_h264advanced.Text = "";\r
-            drp_crop.Text = "No Crop";\r
-        }\r
-\r
-        private void mnu_preset_ipod235_Click(object sender, EventArgs e)\r
-        {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "640";\r
-            text_height.Text = "272";\r
-            drp_videoEncoder.Text = "H.264 (iPod)";\r
-            text_bitrate.Text = "1000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            rtf_h264advanced.Text = "";\r
-            drp_crop.Text = "No Crop";\r
+            listview_presets.Items.Clear();\r
+            updatePresets();\r
+            MessageBox.Show("Presets have been updated", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
         }\r
 \r
-        private void mnu_appleTv_Click(object sender, EventArgs e)\r
+        private void mnu_SelectDefault_Click(object sender, EventArgs e)\r
         {\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "3000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";\r
-            drp_crop.Text = "No Crop";\r
-            \r
-        }\r
+            ListViewItem item = listview_presets.FindItemWithText("Normal");\r
 \r
-        private void mnu_presetPS3_Click(object sender, EventArgs e)\r
-        {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "3000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "level=41";\r
-            drp_crop.Text = "No Crop";\r
-        }\r
+            if (item != null)\r
+            {\r
+                listview_presets.SelectedItems.Clear();\r
+                item.Selected = true;\r
+            }\r
 \r
-        private void mnu_ProgramDefaultOptions_Click(object sender, EventArgs e)\r
-        {\r
-            //Source\r
-            Properties.Settings.Default.DVDSource = text_source.Text;\r
-            Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;\r
-            Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;\r
-            Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;\r
-            //Destination\r
-            Properties.Settings.Default.VideoDest = text_destination.Text;\r
-            Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;\r
-            Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;\r
-            Properties.Settings.Default.Width = text_width.Text;\r
-            Properties.Settings.Default.Height = text_height.Text;\r
-            //Picture Settings Tab\r
-            Properties.Settings.Default.CroppingOption = drp_crop.Text;\r
-            Properties.Settings.Default.CropTop = text_top.Text;\r
-            Properties.Settings.Default.CropBottom = text_bottom.Text;\r
-            Properties.Settings.Default.CropLeft = text_left.Text;\r
-            Properties.Settings.Default.CropRight = text_right.Text;\r
-            Properties.Settings.Default.Subtitles = drp_subtitle.Text;\r
-            //Video Settings Tab\r
-            Properties.Settings.Default.VideoBitrate = text_bitrate.Text;\r
-            Properties.Settings.Default.VideoFilesize = text_filesize.Text;\r
-            Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;\r
-            Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();\r
-            Properties.Settings.Default.DeInterlace = check_DeInterlace.CheckState.ToString();\r
-            Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();\r
-            Properties.Settings.Default.Framerate = drp_videoFramerate.Text;\r
-            Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();\r
-            Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();\r
-            Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString();\r
-            //Audio Settings Tab\r
-            Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;\r
-            Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;\r
-            Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;\r
-            //H264 Tab\r
-            Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();\r
-            Properties.Settings.Default.H264 = rtf_h264advanced.Text;\r
-            Properties.Settings.Default.Save();\r
+            if (presetStatus == false)\r
+            {\r
+                this.Width = 881;\r
+                presetStatus = true;\r
+                btn_presets.Text = "Hide Presets";\r
+            }\r
         }\r
 \r
         #endregion\r
 \r
         #region Help Menu\r
 \r
-        private void mnu_wiki_Click(object sender, EventArgs e)\r
+\r
+        private void mnu_quickStart_Click(object sender, EventArgs e)\r
         {\r
-           Process.Start("http://handbrake.m0k.org/trac");\r
+            Form QuickStart = new frmQuickStart();\r
+            QuickStart.ShowDialog();\r
         }\r
 \r
-        private void mnu_onlineDocs_Click(object sender, EventArgs e)\r
+        private void mnu_wiki_Click(object sender, EventArgs e)\r
         {\r
-            Process.Start("http://handbrake.m0k.org/?page_id=11");\r
+            Process.Start("http://handbrake.m0k.org/trac");\r
         }\r
 \r
         private void mnu_faq_Click(object sender, EventArgs e)\r
@@ -487,9 +437,14 @@ namespace Handbrake
             Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");\r
         }\r
 \r
+        private void mnu_onlineDocs_Click(object sender, EventArgs e)\r
+        {\r
+            Process.Start("http://handbrake.m0k.org/?page_id=11");\r
+        }\r
+\r
         private void mnu_homepage_Click(object sender, EventArgs e)\r
         {\r
-           Process.Start("http://handbrake.m0k.org");\r
+            Process.Start("http://handbrake.m0k.org");\r
         }\r
 \r
         private void mnu_forum_Click(object sender, EventArgs e)\r
@@ -497,9 +452,22 @@ namespace Handbrake
             Process.Start("http://handbrake.m0k.org/forum");\r
         }\r
 \r
+        private void mnu_UpdateCheck_Click(object sender, EventArgs e)\r
+        {\r
+            Boolean update = updateCheck();\r
+            if (update == true)\r
+            {\r
+                MessageBox.Show("There is a new update available. Please visit http://handbrake.m0k.org for details!", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
+            }\r
+            else\r
+            {\r
+                MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
+            }\r
+        }\r
+\r
         private void mnu_about_Click(object sender, EventArgs e)\r
         {\r
-                       Form About = new frmAbout();\r
+            Form About = new frmAbout();\r
             About.ShowDialog();\r
         }\r
 \r
@@ -508,11 +476,14 @@ namespace Handbrake
         // -------------------------------------------------------------- \r
         // Buttons on the main Window\r
         // --------------------------------------------------------------\r
+\r
+        #region Buttons\r
+\r
         private void btn_Browse_Click(object sender, EventArgs e)\r
         {\r
-            \r
-            String filename ="";\r
+            String filename = "";\r
             text_source.Text = "";\r
+            frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
 \r
             if (RadioDVD.Checked)\r
             {\r
@@ -520,9 +491,9 @@ namespace Handbrake
                 filename = DVD_Open.SelectedPath;\r
                 if (filename != "")\r
                 {\r
+                    Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);\r
                     text_source.Text = filename;\r
-                    Form frmReadDVD = new frmReadDVD(filename, this, dvdInfoWindow);\r
-                    frmReadDVD.ShowDialog();\r
+                    frmRD.ShowDialog();\r
                 }\r
             }\r
             else\r
@@ -531,34 +502,37 @@ namespace Handbrake
                 filename = ISO_Open.FileName;\r
                 if (filename != "")\r
                 {\r
+                    Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);\r
                     text_source.Text = filename;\r
-                    Form frmReadDVD = new frmReadDVD(filename, this, dvdInfoWindow);\r
-                    frmReadDVD.ShowDialog();\r
-                }\r
-            }  \r
-\r
-            // Quick check to make sure some titles were found.\r
-            if (filename != "")\r
-            {\r
-                if (drp_dvdtitle.Items.Count == 0)\r
-                {\r
-                    MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
+                    frmRD.ShowDialog();\r
                 }\r
             }\r
-            else\r
+\r
+            // Check if there was titles in the dvd title dropdown \r
+            if (filename == "")\r
             {\r
                 text_source.Text = "Click 'Browse' to continue";\r
             }\r
 \r
+            // If there are no titles in the dropdown menu then the scan has obviously failed. Display an error message explaining to the user.\r
+            if (drp_dvdtitle.Items.Count == 0)\r
+            {\r
+                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
+            }\r
         }\r
 \r
         private void btn_destBrowse_Click(object sender, EventArgs e)\r
         {\r
-            // TODO: Need to write some code to check if there is a reasonable amount of disk space left.\r
+            // This removes the file extension from the filename box on the save file dialog.\r
+            // It's daft but some users don't realise that typing an extension overrides the dropdown extension selected.\r
+            // Should be a nicer way to do this.\r
+            DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", "").Replace(".m4v", "").Replace(".mkv", "").Replace(".ogm", "").Replace(".avi", "");\r
 \r
+            // Show the dialog and set the main form file path\r
             DVD_Save.ShowDialog();\r
             text_destination.Text = DVD_Save.FileName;\r
 \r
+            // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)\r
             if (Check_ChapterMarkers.Checked)\r
             {\r
                 string destination = text_destination.Text;\r
@@ -585,72 +559,365 @@ namespace Handbrake
 \r
         private void btn_queue_Click(object sender, EventArgs e)\r
         {\r
-            String query = GenerateTheQuery();\r
-            queueWindow.list_queue.Items.Add(query);\r
+\r
+            if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "")\r
+                MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+            else\r
+            {\r
+                string query;\r
+                if (QueryEditorText.Text == "")\r
+                {\r
+                    query = GenerateTheQuery();\r
+                }\r
+                else\r
+                {\r
+                    query = QueryEditorText.Text;\r
+                }\r
+                queueWindow.list_queue.Items.Add(query);\r
+                queueWindow.Show();\r
+            }\r
+        }\r
+\r
+        private void btn_copy_Click(object sender, EventArgs e)\r
+        {\r
+            if (QueryEditorText.Text != "")\r
+                Clipboard.SetText(QueryEditorText.Text, TextDataFormat.Text);\r
+        }\r
+\r
+        private void showQueue()\r
+        {\r
             queueWindow.Show();\r
         }\r
 \r
-        private void showQueue()\r
-        {\r
-            queueWindow.Show();\r
-        }\r
+        #endregion\r
+\r
+        // -------------------------------------------------------------- \r
+        // Main Window Preset System\r
+        // --------------------------------------------------------------\r
+\r
+        #region Preset System\r
+\r
+        // Import Current Presets\r
+        private void updatePresets()\r
+        {\r
+            string[] presets = new string[17];\r
+            presets[0] = "Animation";\r
+            presets[1] = "AppleTV";\r
+            presets[2] = "Bedlam";\r
+            presets[3] = "Blind";\r
+            presets[4] = "Broke";\r
+            presets[5] = "Classic";\r
+            presets[6] = "Constant Quality Rate";\r
+            presets[7] = "Deux Six Quatre";\r
+            presets[8] = "Film";\r
+            presets[9] = "iPhone / iPod Touch";\r
+            presets[10] = "iPod High-Rez";\r
+            presets[11] = "iPod Low-Rez";\r
+            presets[12] = "Normal";\r
+            presets[13] = "PS3";\r
+            presets[14] = "PSP";\r
+            presets[15] = "QuickTime";\r
+            presets[16] = "Television";\r
+\r
+            ListViewItem preset_listview = new ListViewItem();\r
+            string[] presetList = new string[1];\r
+\r
+            foreach (string preset in presets)\r
+            {\r
+                presetList[0] = preset;\r
+                preset_listview = new ListViewItem(presetList);\r
+\r
+                // Now Fill Out List View with Items\r
+                listview_presets.Items.Add(preset_listview);\r
+            }\r
+\r
+            string appPath = Application.StartupPath.ToString() + "\\";\r
+            string strCmdLine = "cmd /c " + '"' + '"' + appPath + "HandBrakeCLI.exe" + '"' + " --preset-list >" + '"' + appPath + "presets.dat" + '"' + " 2>&1" + '"';\r
+            Process hbproc = Process.Start("CMD.exe", strCmdLine);\r
+            hbproc.WaitForExit();\r
+            hbproc.Dispose();\r
+            hbproc.Close();\r
+\r
+        }\r
+\r
+        // Varibles\r
+        private Boolean presetStatus = false;\r
+\r
+        // Buttons\r
+        private void btn_presets_Click(object sender, EventArgs e)\r
+        {\r
+            if (presetStatus == false)\r
+            {\r
+                this.Width = 881;\r
+                presetStatus = true;\r
+                btn_presets.Text = "Hide Presets";\r
+            }\r
+            else\r
+            {\r
+                this.Width = 590;\r
+                presetStatus = false;\r
+                btn_presets.Text = "Show Presets";\r
+            }\r
+\r
+        }\r
+\r
+        private void btn_setDefault_Click(object sender, EventArgs e)\r
+        {\r
+            //Source\r
+            Properties.Settings.Default.DVDSource = text_source.Text;\r
+            Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;\r
+            Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;\r
+            Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;\r
+            //Destination\r
+            Properties.Settings.Default.VideoDest = text_destination.Text;\r
+            Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;\r
+            Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;\r
+            Properties.Settings.Default.Width = text_width.Text;\r
+            Properties.Settings.Default.Height = text_height.Text;\r
+            //Picture Settings Tab\r
+            Properties.Settings.Default.CroppingOption = drp_crop.Text;\r
+            Properties.Settings.Default.CropTop = text_top.Text;\r
+            Properties.Settings.Default.CropBottom = text_bottom.Text;\r
+            Properties.Settings.Default.CropLeft = text_left.Text;\r
+            Properties.Settings.Default.CropRight = text_right.Text;\r
+            Properties.Settings.Default.Subtitles = drp_subtitle.Text;\r
+            //Video Settings Tab\r
+            Properties.Settings.Default.VideoBitrate = text_bitrate.Text;\r
+            Properties.Settings.Default.VideoFilesize = text_filesize.Text;\r
+            Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;\r
+            Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();\r
+            Properties.Settings.Default.DeInterlace = drp_deInterlace_option.Text;\r
+            Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();\r
+            Properties.Settings.Default.Framerate = drp_videoFramerate.Text;\r
+            Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();\r
+            Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();\r
+            Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString();\r
+            Properties.Settings.Default.detelecine = check_detelecine.CheckState.ToString();\r
+            Properties.Settings.Default.denoise = drp_deNoise.Text;\r
+            Properties.Settings.Default.deblock = check_deblock.CheckState.ToString();\r
+            Properties.Settings.Default.chapterMarker = Check_ChapterMarkers.CheckState.ToString();\r
+            //Audio Settings Tab\r
+            Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;\r
+            Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;\r
+            Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;\r
+            //H264 Tab\r
+            Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();\r
+            Properties.Settings.Default.H264 = rtf_h264advanced.Text;\r
+            //Preset\r
+            Properties.Settings.Default.selectedPreset = groupBox_output.Text.Replace("Output Settings (Preset: ", "").Replace("\"", "").Replace(")", "");\r
+            // Save the new default Settings\r
+            Properties.Settings.Default.Save();\r
+            MessageBox.Show("New default settings saved.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
+        }\r
+\r
+        // Preset Selection\r
+        private void listview_presets_SelectedIndexChanged(object sender, EventArgs e)\r
+        {\r
+\r
+            string selectedPreset = null;\r
+            ListView.SelectedListViewItemCollection name = null;\r
+            name = listview_presets.SelectedItems;\r
+\r
+            if (listview_presets.SelectedItems.Count != 0)\r
+                selectedPreset = name[0].SubItems[0].Text;\r
+\r
+            try\r
+            {\r
+                string appPath = Application.StartupPath.ToString() + "\\";\r
+                StreamReader presetInput = new StreamReader(appPath + "presets.dat");\r
+\r
+                while (!presetInput.EndOfStream)\r
+                {\r
+                    if ((char)presetInput.Peek() == '+')\r
+                    {\r
+                        string preset = presetInput.ReadLine().Replace("+ ", "");\r
+                        Regex r = new Regex("(:  )"); // Split on hyphens. \r
+                        string[] presetName = r.Split(preset);\r
+\r
+                        if (selectedPreset == "iPhone / iPod Touch")\r
+                        {\r
+                            selectedPreset = "iPhone";\r
+                        }\r
+\r
+                        if (selectedPreset == presetName[0])\r
+                        {\r
+                            // Need to disable anamorphic now, otherwise it may overide the width / height values later.\r
+                            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
+\r
+                            // Send the query from the file to the Query Parser class\r
+                            Functions.QueryParser presetQuery = Functions.QueryParser.Parse(preset);\r
+\r
+                            // Now load the preset\r
+                            presetLoader(presetQuery, selectedPreset);\r
+                        }\r
+                        \r
+                    }\r
+                    else\r
+                    {\r
+                        presetInput.ReadLine();\r
+                    }\r
+                }\r
+            }\r
+            catch (Exception exc)\r
+            {\r
+                MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+            }\r
+\r
+           \r
+        }\r
+        #endregion\r
+\r
+        //---------------------------------------------------\r
+        // Encode / Cancel Buttons\r
+        // Encode Progress Text Handler\r
+        //---------------------------------------------------\r
+\r
+        #region Encode/CLI\r
+\r
+        Functions.CLI process = new Functions.CLI();\r
+\r
+        private void btn_encode_Click(object sender, EventArgs e)\r
+        {\r
+            if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "")\r
+                MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+            else\r
+            {\r
+                btn_eCancel.Enabled = true;\r
+                String query = "";\r
+                if (QueryEditorText.Text == "")\r
+                {\r
+                    query = GenerateTheQuery();\r
+                }\r
+                else\r
+                {\r
+                    query = QueryEditorText.Text;\r
+                }\r
+\r
+                ThreadPool.QueueUserWorkItem(procMonitor, query);\r
+                lbl_encode.Visible = true;\r
+                lbl_encode.Text = "Encoding in Progress";\r
+            }\r
+        }\r
+\r
+        private void btn_eCancel_Click(object sender, EventArgs e)\r
+        {\r
+            process.killCLI();\r
+            process.setNull();\r
+            lbl_encode.Text = "Encoding Canceled";\r
+        }\r
+\r
+        [DllImport("user32.dll")]\r
+        public static extern void LockWorkStation();\r
+        [DllImport("user32.dll")]\r
+        public static extern int ExitWindowsEx(int uFlags, int dwReason);\r
+\r
+        private void procMonitor(object state)\r
+        {\r
+            // Make sure we are not already encoding and if we are then display an error.\r
+            if (hbProc != null)\r
+            {\r
+                MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+            }\r
+            else\r
+            {\r
+                hbProc = process.runCli(this, (string)state, false, false, false, false);\r
+                hbProc.WaitForExit();\r
+\r
+                try\r
+                {\r
+                    /*\r
+                    //*****************************************************************************************\r
+                    // BUG!\r
+                    // When the below code is used and standard error is set to true, hbcli is outputing a\r
+                    // video stream which has mild corruption issues every few seconds.\r
+                    // Maybe an issue with the Parser cauing the CLI to hickup/pause?\r
+                    //*****************************************************************************************\r
+\r
+                    \r
+                    Parsing.Parser encode = new Parsing.Parser(hbProc.StandardOutput.BaseStream);\r
+                    encode.OnEncodeProgress += encode_OnEncodeProgress;\r
+                    while (!encode.EndOfStream)\r
+                    {\r
+                        encode.ReadLine();\r
+                    }\r
+\r
+                    hbProc.WaitForExit();\r
+                    process.closeCLI();\r
+                     */\r
+\r
+                }\r
+                catch (Exception exc)\r
+                {\r
+                    // Do nothing\r
+                    MessageBox.Show(exc.ToString());\r
+                }\r
+\r
+\r
+                setEncodeLabel();\r
+                hbProc = null;\r
+\r
+                // Do something whent he encode ends.\r
+                switch (Properties.Settings.Default.CompletionOption)\r
+                {\r
+                    case "Shutdown":\r
+                        System.Diagnostics.Process.Start("Shutdown", "-s -t 60");\r
+                        break;\r
+                    case "Log Off":\r
+                        ExitWindowsEx(0, 0);\r
+                        break;\r
+                    case "Suspend":\r
+                        Application.SetSuspendState(PowerState.Suspend, true, true);\r
+                        break;\r
+                    case "Hibernate":\r
+                        Application.SetSuspendState(PowerState.Hibernate, true, true);\r
+                        break;\r
+                    case "Lock System":\r
+                        LockWorkStation();\r
+                        break;\r
+                    case "Quit HandBrake":\r
+                        Application.Exit();\r
+                        break;\r
+                    default:\r
+                        break;\r
+                }\r
+            }\r
+        }\r
+\r
+        private delegate void UpdateUIHandler();\r
 \r
-        private void btn_encode_Click(object sender, EventArgs e)\r
+        private void setEncodeLabel()\r
         {\r
-            String query = "";\r
-            tempEncodeLbl.Visible = true;\r
\r
-            if (QueryEditorText.Text == "")\r
-            {\r
-                query = GenerateTheQuery();\r
-            }\r
-            else\r
+            if (this.InvokeRequired)\r
             {\r
-                query = QueryEditorText.Text;\r
+                this.BeginInvoke(new UpdateUIHandler(setEncodeLabel));\r
+                return;\r
             }\r
-\r
-            ThreadPool.QueueUserWorkItem(procMonitor, query);\r
+            lbl_encode.Text = "Encoding Finished";\r
         }\r
 \r
         private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
         {\r
+\r
             if (this.InvokeRequired)\r
             {\r
                 this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),\r
                     new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
                 return;\r
             }\r
-            tempEncodeLbl.Text = string.Format("Encode Progress: {0}%", PercentComplete);\r
+            lbl_encode.Text = string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
         }\r
 \r
-        private void procMonitor(object state)\r
-        {\r
-            Functions.CLI process = new Functions.CLI();\r
-            hbProc = process.runCli(this, (string)state, true, true, false, true);\r
-\r
-            Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);\r
-            //TODO: prevent this event from being subscribed more than once\r
-            encode.OnEncodeProgress += encode_OnEncodeProgress;\r
-            while (!encode.EndOfStream)\r
-            {\r
-                encode.ReadLine();\r
-            }\r
+        #endregion\r
 \r
-            MessageBox.Show("The ncode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
-            hbProc.WaitForExit();\r
-            hbProc.Close();\r
-            hbProc.Dispose();\r
-            hbProc = null;\r
-            MessageBox.Show("The encode process has now ended.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
-        }\r
-        \r
         //---------------------------------------------------\r
         //  Items that require actions on frmMain\r
         //---------------------------------------------------\r
 \r
+        #region frmMain Actions\r
+\r
         private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
-            lbl_chptWarn.Visible = false;\r
+            drop_chapterStart.BackColor = Color.White;\r
             QueryEditorText.Text = "";\r
             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
             {\r
@@ -661,23 +928,21 @@ namespace Handbrake
 \r
                     if (chapterFinish < chapterStart)\r
                     {\r
-                        lbl_chptWarn.Visible = true;\r
-                        lbl_chptWarn.Text = "Invalid Chapter Range!";\r
+                        drop_chapterStart.BackColor = Color.LightCoral;\r
                     }\r
                 }\r
                 catch (Exception)\r
                 {\r
-                    lbl_chptWarn.Visible = true;\r
-                    lbl_chptWarn.Text = "Invalid Chapter Range!";\r
+                    drop_chapterStart.BackColor = Color.LightCoral;\r
                 }\r
             }\r
 \r
-            \r
+\r
         }\r
 \r
         private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
-            lbl_chptWarn.Visible = false;\r
+            drop_chapterFinish.BackColor = Color.White;\r
             QueryEditorText.Text = "";\r
             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
             {\r
@@ -688,14 +953,12 @@ namespace Handbrake
 \r
                     if (chapterFinish < chapterStart)\r
                     {\r
-                        lbl_chptWarn.Visible = true;\r
-                        lbl_chptWarn.Text = "Invalid Chapter Range!";\r
+                        drop_chapterFinish.BackColor = Color.LightCoral;\r
                     }\r
                 }\r
                 catch (Exception)\r
                 {\r
-                    lbl_chptWarn.Visible = true;\r
-                    lbl_chptWarn.Text = "Invalid Chapter Range!";\r
+                    drop_chapterFinish.BackColor = Color.LightCoral;\r
                 }\r
             }\r
         }\r
@@ -706,6 +969,7 @@ namespace Handbrake
             slider_videoQuality.Value = 0;\r
             SliderValue.Text = "0%";\r
             CheckCRF.CheckState = CheckState.Unchecked;\r
+            CheckCRF.Enabled = false;\r
         }\r
 \r
         private void text_filesize_TextChanged(object sender, EventArgs e)\r
@@ -714,6 +978,7 @@ namespace Handbrake
             slider_videoQuality.Value = 0;\r
             SliderValue.Text = "0%";\r
             CheckCRF.CheckState = CheckState.Unchecked;\r
+            CheckCRF.Enabled = false;\r
         }\r
 \r
         private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
@@ -721,6 +986,7 @@ namespace Handbrake
             SliderValue.Text = slider_videoQuality.Value.ToString() + "%";\r
             text_bitrate.Text = "";\r
             text_filesize.Text = "";\r
+            CheckCRF.Enabled = true;\r
         }\r
 \r
         private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
@@ -730,12 +996,13 @@ namespace Handbrake
 \r
         private void text_width_TextChanged(object sender, EventArgs e)\r
         {\r
-\r
             try\r
             {\r
                 if (CheckPixelRatio.Checked)\r
                 {\r
                     text_width.Text = "";\r
+                    text_width.BackColor = Color.LightCoral;\r
+                    CheckPixelRatio.BackColor = Color.LightCoral;\r
                 }\r
                 else\r
                 {\r
@@ -763,15 +1030,17 @@ namespace Handbrake
                     else\r
                     {\r
                         text_height.Text = height.ToString();\r
+                        text_width.BackColor = Color.LightGreen;\r
                     }\r
                 }\r
             }\r
             catch (Exception)\r
             {\r
                 // No need to throw an error here.\r
+                // Note on non english systems, this will throw an error because of double.Parse(lbl_Aspect.Text); not working.\r
             }\r
-               \r
-          \r
+\r
+\r
         }\r
 \r
         private void text_height_TextChanged(object sender, EventArgs e)\r
@@ -781,6 +1050,8 @@ namespace Handbrake
                 if (CheckPixelRatio.Checked)\r
                 {\r
                     text_height.Text = "";\r
+                    text_height.BackColor = Color.LightCoral;\r
+                    CheckPixelRatio.BackColor = Color.LightCoral;\r
                 }\r
                 else\r
                 {\r
@@ -793,7 +1064,10 @@ namespace Handbrake
                         text_height.BackColor = Color.LightGreen;\r
                     }\r
                 }\r
-            } catch(Exception){\r
+\r
+            }\r
+            catch (Exception)\r
+            {\r
                 // No need to alert the user.\r
             }\r
         }\r
@@ -802,10 +1076,10 @@ namespace Handbrake
         {\r
             if ((string)drp_crop.SelectedItem == "Manual")\r
             {\r
-            text_left.Enabled = true;\r
-            text_right.Enabled = true;\r
-            text_top.Enabled = true;\r
-            text_bottom.Enabled = true;\r
+                text_left.Enabled = true;\r
+                text_right.Enabled = true;\r
+                text_top.Enabled = true;\r
+                text_bottom.Enabled = true;\r
             }\r
 \r
             if ((string)drp_crop.SelectedItem == "Auto Crop")\r
@@ -843,18 +1117,50 @@ namespace Handbrake
 \r
             }\r
         }\r
-        \r
+\r
         private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)\r
         {\r
             text_width.Text = "";\r
             text_height.Text = "";\r
             text_width.BackColor = Color.White;\r
             text_height.BackColor = Color.White;\r
+            CheckPixelRatio.BackColor = TabPage1.BackColor;\r
+        }\r
+\r
+        private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)\r
+        {\r
+            if (check_2PassEncode.CheckState.ToString() == "Checked")\r
+            {\r
+                if (drp_videoEncoder.Text.Contains("H.264"))\r
+                {\r
+                    check_turbo.Enabled = true;\r
+                }\r
+            }\r
+            else\r
+            {\r
+                check_turbo.Enabled = false;\r
+                check_turbo.CheckState = CheckState.Unchecked;\r
+            }\r
+        }\r
+\r
+        private void check_largeFile_CheckedChanged(object sender, EventArgs e)\r
+        {\r
+            if (!text_destination.Text.Contains(".mp4"))\r
+            {\r
+                lbl_largeMp4Warning.Text = "Warning: Only mp4 files are supported";\r
+                lbl_largeMp4Warning.ForeColor = Color.Red;\r
+                check_largeFile.CheckState = CheckState.Unchecked;\r
+            }\r
+            else\r
+            {\r
+                lbl_largeMp4Warning.Text = "Warning: Breaks iPod, @TV, PS3 compatibility.";\r
+                lbl_largeMp4Warning.ForeColor = Color.Black;\r
+            }\r
         }\r
 \r
         private void drp_dvdtitle_Click(object sender, EventArgs e)\r
         {\r
-            if (drp_dvdtitle.Items.Count == 1)\r
+            if (drp_dvdtitle.Items.Count == 0)\r
             {\r
                 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
             }\r
@@ -875,7 +1181,7 @@ namespace Handbrake
                 drp_audioMixDown.Items.Add("Dolby Surround");\r
                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
                 drp_audioMixDown.Items.Add("6 Channel Discrete");\r
-                \r
+\r
                 drp_audioBitrate.Items.Clear();\r
                 drp_audioBitrate.Items.Add("32");\r
                 drp_audioBitrate.Items.Add("40");\r
@@ -911,7 +1217,6 @@ namespace Handbrake
                 drp_audioBitrate.Items.Add("224");\r
                 drp_audioBitrate.Items.Add("256");\r
                 drp_audioBitrate.Items.Add("320");\r
-                drp_audioBitrate.Items.Add("384");\r
             }\r
         }\r
 \r
@@ -950,23 +1255,11 @@ namespace Handbrake
                 destination = destination.Replace(".mp4", ".m4v");\r
                 text_destination.Text = destination;\r
             }\r
-        }\r
-\r
-        private void check_largeFile_CheckedChanged(object sender, EventArgs e)\r
-        {\r
-            if (!text_destination.Text.Contains(".mp4"))\r
-            {\r
-                MessageBox.Show("This option is only compatible with the mp4 file container.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-                check_largeFile.CheckState = CheckState.Unchecked;\r
-            }\r
-        }\r
-\r
-        private void check_turbo_CheckedChanged(object sender, EventArgs e)\r
-        {\r
-            if (!drp_videoEncoder.Text.Contains("H.264"))\r
+            else\r
             {\r
-                MessageBox.Show("This option is only compatible with the H.264 encoder's", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-                check_turbo.CheckState = CheckState.Unchecked;\r
+                string destination = text_destination.Text;\r
+                destination = destination.Replace(".m4v", ".mp4");\r
+                text_destination.Text = destination;\r
             }\r
         }\r
 \r
@@ -977,16 +1270,21 @@ namespace Handbrake
             {\r
                 check_turbo.CheckState = CheckState.Unchecked;\r
                 CheckCRF.CheckState = CheckState.Unchecked;\r
+                CheckCRF.Enabled = false;\r
+                check_turbo.Enabled = false;\r
+                h264Tab.Enabled = false;\r
+                rtf_h264advanced.Text = "";\r
             }\r
-        }\r
-\r
-        private void CheckCRF_CheckedChanged(object sender, EventArgs e)\r
-        {\r
-            if (slider_videoQuality.Value == 0)\r
+            else\r
             {\r
-                MessageBox.Show("This option is can only be used with the 'Video Quality' slider.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-                CheckCRF.CheckState = CheckState.Unchecked;\r
+                CheckCRF.Enabled = true;\r
+                if (check_2PassEncode.CheckState.ToString() == "Checked")\r
+                {\r
+                    check_turbo.Enabled = true;\r
+                }\r
+                h264Tab.Enabled = true;\r
             }\r
+\r
         }\r
 \r
         public void setStreamReader(Parsing.DVD dvd)\r
@@ -1008,12 +1306,14 @@ namespace Handbrake
             if (drp_dvdtitle.Text != "Automatic")\r
             {\r
                 Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;\r
+\r
+                // Set the Aspect Ratio\r
                 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();\r
-                lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);\r
 \r
-                text_width.Text = selectedTitle.Resolution.Width.ToString();\r
-                text_height.Text = selectedTitle.Resolution.Height.ToString();\r
+                // Set the Recommended Cropping values\r
+                lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);\r
 \r
+                // Populate the Start chapter Dropdown\r
                 drop_chapterStart.Items.Clear();\r
                 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());\r
                 if (drop_chapterStart.Items.Count > 0)\r
@@ -1021,6 +1321,7 @@ namespace Handbrake
                     drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();\r
                 }\r
 \r
+                // Populate the Final Chapter Dropdown\r
                 drop_chapterFinish.Items.Clear();\r
                 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());\r
                 if (drop_chapterFinish.Items.Count > 0)\r
@@ -1028,6 +1329,7 @@ namespace Handbrake
                     drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
                 }\r
 \r
+                // Populate the Audio Channels Dropdown\r
                 drp_audioChannels.Items.Clear();\r
                 drp_audioChannels.Items.Add("Automatic");\r
                 drp_audioChannels.Items.AddRange(selectedTitle.AudioTracks.ToArray());\r
@@ -1036,6 +1338,7 @@ namespace Handbrake
                     drp_audioChannels.Text = drp_audioChannels.Items[0].ToString();\r
                 }\r
 \r
+                // Populate the Subtitles dropdown\r
                 drp_subtitle.Items.Clear();\r
                 drp_subtitle.Items.Add("None");\r
                 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());\r
@@ -1046,9 +1349,16 @@ namespace Handbrake
             }\r
         }\r
 \r
+        #endregion\r
+\r
         //---------------------------------------------------\r
-        //  The query Generation function.\r
+        //  Some Functions\r
+        //  - Query Generation\r
         //---------------------------------------------------\r
+\r
+        #region Program Functions\r
+\r
+        // Generate a CLI Query String\r
         public string GenerateTheQuery()\r
         {\r
             string source = text_source.Text;\r
@@ -1058,19 +1368,14 @@ namespace Handbrake
             int totalChapters = drop_chapterFinish.Items.Count - 1;\r
             string dvdChapter = "";\r
 \r
-            if (source ==  "")\r
-                MessageBox.Show("No Source has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-            else\r
-            {\r
-                source = " -i " + '"' + source+ '"'; //'"'+\r
-            }\r
+            source = " -i " + '"' + source + '"';\r
 \r
-            if (dvdTitle ==  "Automatic")\r
+            if (dvdTitle == "Automatic")\r
                 dvdTitle = "";\r
             else\r
             {\r
                 string[] titleInfo = dvdTitle.Split(' ');\r
-                dvdTitle = " -t "+ titleInfo[0];\r
+                dvdTitle = " -t " + titleInfo[0];\r
             }\r
 \r
             if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))\r
@@ -1080,7 +1385,7 @@ namespace Handbrake
             else\r
                 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;\r
 \r
-            string querySource = source+ dvdTitle+ dvdChapter;\r
+            string querySource = source + dvdTitle + dvdChapter;\r
             // ----------------------------------------------------------------------\r
 \r
             // Destination\r
@@ -1091,7 +1396,7 @@ namespace Handbrake
             string width = text_width.Text;\r
             string height = text_height.Text;\r
 \r
-            if (destination ==  "")\r
+            if (destination == "")\r
                 MessageBox.Show("No destination has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             else\r
                 destination = " -o " + '"' + destination + '"'; //'"'+ \r
@@ -1118,7 +1423,7 @@ namespace Handbrake
                     videoEncoder = " -e x264";\r
                     break;\r
             }\r
-           \r
+\r
             switch (audioEncoder)\r
             {\r
                 case "AAC":\r
@@ -1138,15 +1443,21 @@ namespace Handbrake
                     break;\r
             }\r
 \r
-            if (width !=  "")\r
-                width = " -w "+ width;\r
-            \r
+            if (width != "")\r
+                width = " -w " + width;\r
+\r
+\r
+            if (height == "Auto")\r
+            {\r
+                height = "";\r
+            }\r
+            else if (height != "")\r
+            {\r
+                height = " -l " + height;\r
+            }\r
 \r
-            if (height !=  "")\r
-                height = " -l "+ height;\r
-            \r
 \r
-            string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height;\r
+            string queryDestination = destination + videoEncoder + audioEncoder + width + height;\r
             // ----------------------------------------------------------------------\r
 \r
             // Picture Settings Tab\r
@@ -1158,6 +1469,11 @@ namespace Handbrake
             string cropRight = text_right.Text;\r
             string subtitles = drp_subtitle.Text;\r
             string cropOut = "";\r
+            string deInterlace_Option = drp_deInterlace_option.Text;\r
+            string deinterlace = "";\r
+            string grayscale = "";\r
+            string pixelRatio = "";\r
+            string ChapterMarkers = "";\r
             // Returns Crop Query\r
 \r
             if (cropSetting == "Auto Crop")\r
@@ -1165,77 +1481,111 @@ namespace Handbrake
             else if (cropSetting == "No Crop")\r
                 cropOut = " --crop 0:0:0:0 ";\r
             else\r
+            {\r
+                if (text_top.Text == "")\r
+                    cropTop = "0";\r
+                if (text_bottom.Text == "")\r
+                    cropBottom = "0";\r
+                if (text_left.Text == "")\r
+                    cropLeft = "0";\r
+                if (text_right.Text == "")\r
+                    cropRight = "0";\r
+\r
                 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;\r
+            }\r
 \r
-            if (subtitles ==  "None")\r
+            if (subtitles == "None")\r
                 subtitles = "";\r
-            else if (subtitles ==  "")\r
+            else if (subtitles == "")\r
                 subtitles = "";\r
             else\r
             {\r
                 string[] tempSub;\r
                 tempSub = subtitles.Split(' ');\r
-                subtitles = " -s "+ tempSub[0];\r
+                subtitles = " -s " + tempSub[0];\r
+            }\r
+\r
+            switch (deInterlace_Option)\r
+            {\r
+                case "None":\r
+                    deinterlace = "";\r
+                    break;\r
+                case "Original (Fast)":\r
+                    deinterlace = " --deinterlace=fast";\r
+                    break;\r
+                case "yadif (Slow)":\r
+                    deinterlace = " --deinterlace=slow";\r
+                    break;\r
+                case "yadif + mcdeint (Slower)":\r
+                    deinterlace = " --deinterlace=slower";\r
+                    break;\r
+                case "yadif + mcdeint (Slowest)":\r
+                    deinterlace = " --deinterlace=slowest";\r
+                    break;\r
+                default:\r
+                    deinterlace = "";\r
+                    break;\r
             }\r
 \r
-            string queryPictureSettings = cropOut+ subtitles;\r
+            if (check_grayscale.Checked)\r
+                grayscale = " -g ";\r
+\r
+            if (CheckPixelRatio.Checked)\r
+                pixelRatio = " -p ";\r
+\r
+            if (Check_ChapterMarkers.Checked)\r
+                ChapterMarkers = " -m ";\r
+\r
+            string queryPictureSettings = cropOut + subtitles + deinterlace + grayscale + pixelRatio + ChapterMarkers;\r
             // ----------------------------------------------------------------------\r
 \r
             // Video Settings Tab\r
 \r
             string videoBitrate = text_bitrate.Text;\r
             string videoFilesize = text_filesize.Text;\r
-            int videoQuality = slider_videoQuality.Value;\r
+            double videoQuality = slider_videoQuality.Value;\r
             string vidQSetting = "";\r
             string twoPassEncoding = "";\r
-            string deinterlace = "";\r
-            string grayscale = "";\r
             string videoFramerate = drp_videoFramerate.Text;\r
-            string pixelRatio = "";\r
-            string ChapterMarkers = "";\r
             string turboH264 = "";\r
             string largeFile = "";\r
+            string deblock = "";\r
+            string detelecine = "";\r
+            string denoise = "";\r
+            string CRF = CheckCRF.CheckState.ToString();\r
+\r
+            if (CRF == "Checked")\r
+                CRF = " -Q ";\r
+            else\r
+                CRF = "";\r
 \r
-            if (videoBitrate !=  "")\r
-                videoBitrate = " -b "+ videoBitrate;\r
+            if (videoBitrate != "")\r
+                videoBitrate = " -b " + videoBitrate;\r
 \r
-            if (videoFilesize !=  "")\r
-                videoFilesize = " -S "+ videoFilesize;\r
+            if (videoFilesize != "")\r
+                videoFilesize = " -S " + videoFilesize;\r
 \r
             // Video Quality Setting\r
 \r
-            if ((videoQuality ==  0))\r
+            if ((videoQuality == 0))\r
                 vidQSetting = "";\r
             else\r
             {\r
-                videoQuality = videoQuality/ 100;\r
-                if (videoQuality ==  1)\r
+                videoQuality = videoQuality / 100;\r
+                if (videoQuality == 1)\r
                 {\r
                     vidQSetting = "1.0";\r
                 }\r
-\r
-                vidQSetting = " -q " + videoQuality.ToString();\r
+                vidQSetting = " -q " + videoQuality.ToString(new CultureInfo("en-US")); \r
             }\r
 \r
             if (check_2PassEncode.Checked)\r
                 twoPassEncoding = " -2 ";\r
 \r
-            if (check_DeInterlace.Checked)\r
-                deinterlace = " -d ";\r
-\r
-            if (check_grayscale.Checked)\r
-                grayscale = " -g ";\r
-\r
-            if (videoFramerate ==  "Automatic")\r
+            if (videoFramerate == "Automatic")\r
                 videoFramerate = "";\r
             else\r
-                videoFramerate = " -r "+ videoFramerate;\r
-\r
-            if (CheckPixelRatio.Checked)\r
-                pixelRatio = " -p ";\r
-\r
-            if (Check_ChapterMarkers.Checked)\r
-                ChapterMarkers = " -m ";\r
+                videoFramerate = " -r " + videoFramerate;\r
 \r
             if (check_turbo.Checked)\r
                 turboH264 = " -T ";\r
@@ -1243,7 +1593,32 @@ namespace Handbrake
             if (check_largeFile.Checked)\r
                 largeFile = " -4 ";\r
 \r
-            string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + deinterlace + grayscale + videoFramerate + pixelRatio + ChapterMarkers + turboH264 + largeFile;\r
+            if (check_deblock.Checked)\r
+                deblock = " --deblock";\r
+\r
+            if (check_detelecine.Checked)\r
+                detelecine = " --detelecine";\r
+\r
+            switch (drp_deNoise.Text)\r
+            {\r
+                case "None":\r
+                    denoise = "";\r
+                    break;\r
+                case "Weak":\r
+                    denoise = " --denoise=weak";\r
+                    break;\r
+                case "Medium":\r
+                    denoise = " --denoise=medium";\r
+                    break;\r
+                case "Strong":\r
+                    denoise = " --denoise=strong";\r
+                    break;\r
+                default:\r
+                    denoise = "";\r
+                    break;\r
+            }\r
+\r
+            string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + CRF + twoPassEncoding + videoFramerate + turboH264 + largeFile + deblock + detelecine + denoise;\r
             // ----------------------------------------------------------------------\r
 \r
             // Audio Settings Tab\r
@@ -1254,21 +1629,21 @@ namespace Handbrake
             string Mixdown = drp_audioMixDown.Text;\r
             string SixChannelAudio = "";\r
 \r
-            if (audioBitrate !=  "")\r
-                audioBitrate = " -B "+ audioBitrate;\r
+            if (audioBitrate != "")\r
+                audioBitrate = " -B " + audioBitrate;\r
 \r
-            if (audioSampleRate !=  "")\r
-                audioSampleRate = " -R "+ audioSampleRate;\r
+            if (audioSampleRate != "")\r
+                audioSampleRate = " -R " + audioSampleRate;\r
 \r
-            if (audioChannels ==  "Automatic")\r
+            if (audioChannels == "Automatic")\r
                 audioChannels = "";\r
-            else if (audioChannels ==  "")\r
+            else if (audioChannels == "")\r
                 audioChannels = "";\r
             else\r
             {\r
                 string[] tempSub;\r
                 tempSub = audioChannels.Split(' ');\r
-                audioChannels = " -a "+ tempSub[0];\r
+                audioChannels = " -a " + tempSub[0];\r
             }\r
 \r
             switch (Mixdown)\r
@@ -1292,34 +1667,30 @@ namespace Handbrake
                     Mixdown = "6ch";\r
                     break;\r
                 default:\r
-                    Mixdown = "stero";\r
+                    Mixdown = "";\r
                     break;\r
             }\r
 \r
-            if (Mixdown !=  "")\r
-                SixChannelAudio = " -6 "+ Mixdown;\r
+            if (Mixdown != "")\r
+                SixChannelAudio = " -6 " + Mixdown;\r
             else\r
                 SixChannelAudio = "";\r
 \r
-            string queryAudioSettings = audioBitrate+ audioSampleRate+ audioChannels+ SixChannelAudio;\r
+            string queryAudioSettings = audioBitrate + audioSampleRate + audioChannels + SixChannelAudio;\r
             // ----------------------------------------------------------------------\r
 \r
             //  H.264 Tab\r
 \r
-            string CRF = CheckCRF.CheckState.ToString();\r
+\r
             string h264Advanced = rtf_h264advanced.Text;\r
-            if ((CRF ==  "1"))\r
-                CRF = " -Q ";\r
-            else\r
-                CRF = "";\r
 \r
-            if ((h264Advanced ==  ""))\r
+            if ((h264Advanced == ""))\r
                 h264Advanced = "";\r
             else\r
-                h264Advanced = " -x "+ h264Advanced;\r
-    \r
+                h264Advanced = " -x " + h264Advanced;\r
 \r
-            string h264Settings = CRF+ h264Advanced;\r
+\r
+            string h264Settings = h264Advanced;\r
             // ----------------------------------------------------------------------\r
 \r
             // Processors (Program Settings)\r
@@ -1327,10 +1698,10 @@ namespace Handbrake
             string processors = Properties.Settings.Default.Processors;\r
             //  Number of Processors Handler\r
 \r
-            if (processors ==  "Automatic")\r
+            if (processors == "Automatic")\r
                 processors = "";\r
             else\r
-                processors = " -C "+ processors+ " ";\r
+                processors = " -C " + processors + " ";\r
 \r
 \r
             string queryAdvancedSettings = processors;\r
@@ -1339,14 +1710,206 @@ namespace Handbrake
             //  Verbose option (Program Settings)\r
 \r
             string verbose = "";\r
-            if (Properties.Settings.Default.verbose ==  "Checked")\r
+            if (Properties.Settings.Default.verbose == "Checked")\r
                 verbose = " -v ";\r
 \r
             // ----------------------------------------------------------------------\r
 \r
-            return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;\r
+            return querySource + queryDestination + queryPictureSettings + queryVideoSettings + h264Settings + queryAudioSettings + queryAdvancedSettings + verbose;\r
+        }\r
+\r
+        // Load a Preset\r
+        private void presetLoader(Functions.QueryParser presetQuery, string name)\r
+        {\r
+            // ---------------------------\r
+            // Setup the GUI\r
+            // ---------------------------\r
+\r
+            // Source tab\r
+            #region source\r
+            if (presetQuery.Source != "")\r
+                text_source.Text = presetQuery.Source;\r
+\r
+            if (presetQuery.DVDTitle != 0)\r
+                drp_dvdtitle.Text = presetQuery.DVDTitle.ToString();\r
+\r
+            if (presetQuery.DVDChapterStart != 0)\r
+                drop_chapterStart.Text = presetQuery.DVDChapterStart.ToString();\r
+\r
+            if (presetQuery.DVDChapterFinish != 0)\r
+                drop_chapterFinish.Text = presetQuery.DVDChapterFinish.ToString();\r
+\r
+            if (presetQuery.Format != "")\r
+            {\r
+                string destination = text_destination.Text;\r
+                destination = destination.Replace(".mp4", "." + presetQuery.Format);\r
+                destination = destination.Replace(".m4v", "." + presetQuery.Format);\r
+                destination = destination.Replace(".avi", "." + presetQuery.Format);\r
+                destination = destination.Replace(".mkv", "." + presetQuery.Format);\r
+                destination = destination.Replace(".ogm", "." + presetQuery.Format);\r
+                text_destination.Text = destination;\r
+            }\r
+\r
+            #endregion\r
+\r
+            // Destination tab\r
+            #region destination\r
+\r
+            if (presetQuery.Destination != "")\r
+                text_destination.Text = presetQuery.Destination;\r
+\r
+            drp_videoEncoder.Text = presetQuery.VideoEncoder;\r
+            drp_audioCodec.Text = presetQuery.AudioEncoder;\r
+            if (presetQuery.Width != 0)\r
+            {\r
+                text_width.Text = presetQuery.Width.ToString();\r
+           \r
+            }\r
+            else\r
+            {\r
+                text_width.Text = "";\r
+                text_width.BackColor = Color.White;\r
+            }\r
+\r
+            if (presetQuery.Height != 0)\r
+            {\r
+                text_height.Text = presetQuery.Height.ToString();\r
+            }\r
+            else\r
+            {\r
+                text_height.Text = "";\r
+                text_height.BackColor = Color.White;\r
+            }\r
+            #endregion\r
+\r
+            // Picture Settings Tab\r
+            #region Picture\r
+            drp_crop.Text = "Manual";\r
+            text_top.Text = presetQuery.CropTop;\r
+            text_bottom.Text = presetQuery.CropBottom;\r
+            text_left.Text = presetQuery.CropLeft;\r
+            text_right.Text = presetQuery.CropRight;\r
+\r
+            drp_deInterlace_option.Text = presetQuery.DeInterlace;\r
+            drp_deNoise.Text = presetQuery.DeNoise;\r
+\r
+            if (presetQuery.DeTelecine == true)\r
+            {\r
+                check_detelecine.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                check_detelecine.CheckState = CheckState.Unchecked;\r
+            }\r
+\r
+\r
+            if (presetQuery.DeBlock == true)\r
+            {\r
+                check_deblock.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                check_deblock.CheckState = CheckState.Unchecked;\r
+            }\r
+\r
+            if (presetQuery.ChapterMarkers == true)\r
+            {\r
+                Check_ChapterMarkers.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                Check_ChapterMarkers.CheckState = CheckState.Unchecked;\r
+            }\r
+\r
+            if (presetQuery.Anamorphic == true)\r
+            {\r
+                CheckPixelRatio.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                CheckPixelRatio.CheckState = CheckState.Unchecked;\r
+            }\r
+            #endregion\r
+\r
+            // Video Settings Tab\r
+            #region video\r
+            text_bitrate.Text = presetQuery.AverageVideoBitrate;\r
+            text_filesize.Text = presetQuery.VideoTargetSize;\r
+            slider_videoQuality.Value = presetQuery.VideoQuality;\r
+            if (slider_videoQuality.Value != 0)\r
+            {\r
+                CheckCRF.Enabled = true;\r
+                int ql = presetQuery.VideoQuality;\r
+                SliderValue.Text = ql.ToString() + "%";\r
+            }\r
+\r
+            if (presetQuery.TwoPass == true)\r
+            {\r
+                check_2PassEncode.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                check_2PassEncode.CheckState = CheckState.Unchecked;\r
+            }\r
+\r
+            if (presetQuery.Grayscale == true)\r
+            {\r
+                check_grayscale.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                check_grayscale.CheckState = CheckState.Unchecked;\r
+            }\r
+\r
+            drp_videoFramerate.Text = presetQuery.VideoFramerate;\r
+\r
+            if (presetQuery.TurboFirstPass == true)\r
+            {\r
+                check_turbo.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                check_turbo.CheckState = CheckState.Unchecked;\r
+            }\r
+\r
+            if (presetQuery.LargeMP4 == true)\r
+            {\r
+                check_largeFile.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                check_largeFile.CheckState = CheckState.Unchecked;\r
+            }\r
+            if (presetQuery.CRF == true)\r
+            {\r
+                CheckCRF.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                CheckCRF.CheckState = CheckState.Unchecked;\r
+            }\r
+            #endregion\r
+\r
+            // Audio Settings Tab\r
+            #region audio\r
+            drp_audioBitrate.Text = presetQuery.AudioBitrate;\r
+            drp_audioSampleRate.Text = presetQuery.AudioSampleBitrate;\r
+            drp_audioChannels.Text = presetQuery.AudioTrack1;\r
+            drp_audioMixDown.Text = presetQuery.AudioTrackMix;\r
+            drp_subtitle.Text = presetQuery.Subtitles;\r
+            #endregion\r
+\r
+            // H264 Tab & Preset Name\r
+            #region other\r
+            rtf_h264advanced.Text = presetQuery.H264Query;\r
+\r
+            // Set the preset name\r
+            groupBox_output.Text = "Output Settings (Preset: " + name + ")";\r
+            #endregion\r
         }\r
 \r
+        #endregion\r
+\r
         // This is the END of the road ------------------------------------------------------------------------------\r
     }\r
 }
\ No newline at end of file