OSDN Git Service

LinGui: make Help->Guide work on windows/mingw
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
index ca36cb9..1a1cfae 100644 (file)
@@ -1,8 +1,7 @@
 /*  frmMain.cs $\r
-       \r
-          This file is part of the HandBrake source code.\r
-          Homepage: <http://handbrake.fr/>.\r
-          It may be used under the terms of the GNU General Public License. */\r
+    This file is part of the HandBrake source code.\r
+    Homepage: <http://handbrake.fr/>.\r
+    It may be used under the terms of the GNU General Public License. */\r
 \r
 namespace Handbrake\r
 {\r
@@ -13,13 +12,15 @@ namespace Handbrake
     using System.Drawing;\r
     using System.Globalization;\r
     using System.IO;\r
+    using System.Reflection;\r
     using System.Threading;\r
     using System.Windows.Forms;\r
-    using EncodeQueue;\r
     using Functions;\r
     using Model;\r
     using Parsing;\r
     using Presets;\r
+    using Properties;\r
+    using Services;\r
 \r
     public partial class frmMain : Form\r
     {\r
@@ -27,43 +28,75 @@ namespace Handbrake
         private Queue encodeQueue = new Queue();\r
         private PresetsHandler presetHandler = new PresetsHandler();\r
 \r
-        // Globals: Mainly used for tracking. *********************************\r
-        public Title selectedTitle;\r
+        // Windows ************************************************************\r
         private frmQueue queueWindow;\r
         private frmPreview qtpreview;\r
         private frmActivityWindow ActivityWindow;\r
-        private Form splash;\r
+        private frmSplashScreen splash = new frmSplashScreen();\r
+\r
+        // Globals: Mainly used for tracking. *********************************\r
+        public Title selectedTitle;\r
         public string sourcePath;\r
-        private string lastAction;\r
         private SourceType selectedSourceType;\r
         private string dvdDrivePath;\r
         private string dvdDriveLabel;\r
         private Preset CurrentlySelectedPreset;\r
         private DVD currentSource;\r
+        private ScanService SourceScan = new ScanService();\r
+        private List<DriveInformation> drives;\r
+        private Thread encodeMonitor;\r
 \r
         // Delegates **********************************************************\r
         private delegate void UpdateWindowHandler();\r
 \r
         // Applicaiton Startup ************************************************\r
 \r
+        #region Properties\r
+\r
+        /// <summary>\r
+        /// Gets SourceName.\r
+        /// </summary>\r
+        public string SourceName\r
+        {\r
+            get\r
+            {\r
+                if (this.selectedSourceType == SourceType.DvdDrive)\r
+                {\r
+                    return this.dvdDriveLabel;\r
+                }\r
+\r
+                if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS")\r
+                    return Path.GetFileNameWithoutExtension(this.sourcePath);\r
+\r
+                return Path.GetFileNameWithoutExtension(Path.GetDirectoryName(this.sourcePath));\r
+            }\r
+        }\r
+\r
+        #endregion\r
+\r
         #region Application Startup\r
 \r
         public frmMain()\r
         {\r
             // Load and setup the splash screen in this thread\r
-            splash = new frmSplashScreen();\r
             splash.Show(this);\r
-            Label lblStatus = new Label {Size = new Size(150, 20), Location = new Point(182, 102)};\r
+            Label lblStatus = new Label { Size = new Size(150, 20), Location = new Point(182, 102) };\r
             splash.Controls.Add(lblStatus);\r
 \r
             InitializeComponent();\r
 \r
             // Update the users config file with the CLI version data.\r
-            lblStatus.Text = "Setting Version Data ...";\r
-            Application.DoEvents();\r
+            UpdateSplashStatus(lblStatus, "Checking CLI Version Data ...");\r
             Main.SetCliVersionData();\r
+            Main.CheckForValidCliVersion();\r
+\r
+            if (Settings.Default.hb_version.Contains("svn"))\r
+            {\r
+                Version v = Assembly.GetExecutingAssembly().GetName().Version;\r
+                this.Text += " " + v.ToString(4);\r
+            }\r
 \r
-            // Show the form, but leave disabled until preloading is complete then show the main form\r
+            // Show the form, but leave disabled until preloading is complete then show the main form)\r
             this.Enabled = false;\r
             this.Show();\r
             Application.DoEvents(); // Forces frmMain to draw\r
@@ -76,9 +109,7 @@ namespace Handbrake
                 TimeSpan elapsed = now.Subtract(lastCheck);\r
                 if (elapsed.TotalDays > Properties.Settings.Default.daysBetweenUpdateCheck)\r
                 {\r
-                    lblStatus.Text = "Checking for updates ...";\r
-                    Application.DoEvents();\r
-\r
+                    UpdateSplashStatus(lblStatus, "Checking for updates ...");\r
                     Main.BeginCheckForUpdates(new AsyncCallback(UpdateCheckDone), false);\r
                 }\r
             }\r
@@ -86,15 +117,13 @@ namespace Handbrake
             // Clear the log files in the background\r
             if (Properties.Settings.Default.clearOldLogs)\r
             {\r
-                lblStatus.Text = "Clearing Old Log Files ...";\r
-                Application.DoEvents();\r
+                UpdateSplashStatus(lblStatus, "Clearing Old Log Files ..");\r
                 Thread clearLog = new Thread(Main.ClearOldLogs);\r
                 clearLog.Start();\r
             }\r
 \r
             // Setup the GUI components\r
-            lblStatus.Text = "Setting up the GUI ...";\r
-            Application.DoEvents();\r
+            UpdateSplashStatus(lblStatus, "Setting up the GUI ...");\r
             LoadPresetPanel(); // Load the Preset Panel\r
             treeView_presets.ExpandAll();\r
             lbl_encode.Text = string.Empty;\r
@@ -102,44 +131,33 @@ namespace Handbrake
             queueWindow = new frmQueue(encodeQueue, this); // Prepare the Queue\r
             if (!Properties.Settings.Default.QueryEditorTab)\r
                 tabs_panel.TabPages.RemoveAt(7); // Remove the query editor tab if the user does not want it enabled.\r
+            if (Properties.Settings.Default.tooltipEnable)\r
+                ToolTip.Active = true;\r
 \r
             // Load the user's default settings or Normal Preset\r
-            if (Properties.Settings.Default.defaultPreset != string.Empty)\r
+            if (Properties.Settings.Default.defaultPreset != string.Empty && presetHandler.GetPreset(Properties.Settings.Default.defaultPreset) != null)\r
             {\r
-                if (presetHandler.GetPreset(Properties.Settings.Default.defaultPreset) != null)\r
+                string query = presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).Query;\r
+                if (query != null)\r
                 {\r
-                    string query = presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).Query;\r
-                    bool loadPictureSettings =\r
-                        presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).PictureSettings;\r
+                    x264Panel.Reset2Defaults();\r
 \r
-                    if (query != null)\r
-                    {\r
-                        x264Panel.Reset2Defaults();\r
+                    QueryParser presetQuery = QueryParser.Parse(query);\r
+                    PresetLoader.LoadPreset(this, presetQuery, Properties.Settings.Default.defaultPreset,\r
+                                            presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).PictureSettings);\r
 \r
-                        QueryParser presetQuery = QueryParser.Parse(query);\r
-                        PresetLoader.LoadPreset(this, presetQuery, Properties.Settings.Default.defaultPreset, \r
-                                                loadPictureSettings);\r
-\r
-                        x264Panel.X264_StandardizeOptString();\r
-                        x264Panel.X264_SetCurrentSettingsInPanel();\r
-                    }\r
+                    x264Panel.X264_StandardizeOptString();\r
+                    x264Panel.X264_SetCurrentSettingsInPanel();\r
                 }\r
-                else\r
-                    loadNormalPreset();\r
             }\r
             else\r
                 loadNormalPreset();\r
 \r
-            // Enabled GUI tooltip's if Required\r
-            if (Properties.Settings.Default.tooltipEnable)\r
-                ToolTip.Active = true;\r
-\r
             // Register with Growl (if not using Growl for the encoding completion action, this wont hurt anything)\r
             GrowlCommunicator.Register();\r
 \r
             // Finished Loading\r
-            lblStatus.Text = "Loading Complete!";\r
-            Application.DoEvents();\r
+            UpdateSplashStatus(lblStatus, "Loading Complete.");\r
             splash.Close();\r
             splash.Dispose();\r
             this.Enabled = true;\r
@@ -171,10 +189,8 @@ namespace Handbrake
             }\r
             catch (Exception ex)\r
             {\r
-                if ((bool) result.AsyncState)\r
-                    MessageBox.Show(\r
-                        "Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex, \r
-                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                if ((bool)result.AsyncState)\r
+                    Main.ShowExceptiowWindow("Unable to check for updates, Please try again later.", ex.ToString());\r
             }\r
         }\r
 \r
@@ -185,7 +201,7 @@ namespace Handbrake
             {\r
                 DialogResult result =\r
                     MessageBox.Show(\r
-                        "HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?", \r
+                        "HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?",\r
                         "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
 \r
                 if (result == DialogResult.Yes)\r
@@ -200,24 +216,10 @@ namespace Handbrake
             }\r
         }\r
 \r
-        #endregion\r
-\r
-        #region Properties\r
-\r
-        public string SourceName\r
+        private void UpdateSplashStatus(Label status, string text)\r
         {\r
-            get\r
-            {\r
-                if (this.selectedSourceType == SourceType.DvdDrive)\r
-                {\r
-                    return this.dvdDriveLabel;\r
-                }\r
-\r
-                if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS")\r
-                    return Path.GetFileNameWithoutExtension(this.sourcePath);\r
-\r
-                return Path.GetFileNameWithoutExtension(Path.GetDirectoryName(this.sourcePath));\r
-            }\r
+            status.Text = text;\r
+            Application.DoEvents();\r
         }\r
 \r
         #endregion\r
@@ -235,7 +237,6 @@ namespace Handbrake
                 this.Resize += new EventHandler(frmMain_Resize);\r
 \r
             // Handle Encode Start / Finish / Pause\r
-\r
             encodeQueue.QueuePauseRequested += new EventHandler(encodePaused);\r
             encodeQueue.EncodeStarted += new EventHandler(encodeStarted);\r
             encodeQueue.EncodeEnded += new EventHandler(encodeEnded);\r
@@ -255,7 +256,7 @@ namespace Handbrake
             check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel);\r
 \r
             // Picture Settings\r
-            // PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);\r
+            PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);\r
 \r
             // Filter Settings\r
             Filters.FilterSettingsChanged += new EventHandler(changePresetLabel);\r
@@ -284,7 +285,7 @@ namespace Handbrake
             check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel);\r
 \r
             // Picture Settings\r
-            // PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);\r
+            PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);\r
 \r
             // Filter Settings\r
             Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel);\r
@@ -323,7 +324,7 @@ namespace Handbrake
 \r
             if (fileList != null)\r
             {\r
-                if (fileList[0] != string.Empty)\r
+                if (!string.IsNullOrEmpty(fileList[0]))\r
                 {\r
                     this.selectedSourceType = SourceType.VideoFile;\r
                     StartScan(fileList[0], 0);\r
@@ -337,14 +338,13 @@ namespace Handbrake
 \r
         private void encodeStarted(object sender, EventArgs e)\r
         {\r
-            lastAction = "encode";\r
             SetEncodeStarted();\r
 \r
             // Experimental HBProc Process Monitoring.\r
             if (Properties.Settings.Default.enocdeStatusInGui)\r
             {\r
-                Thread encodeMon = new Thread(EncodeMonitorThread);\r
-                encodeMon.Start();\r
+                encodeMonitor = new Thread(EncodeMonitorThread);\r
+                encodeMonitor.Start();\r
             }\r
         }\r
 \r
@@ -364,11 +364,29 @@ namespace Handbrake
 \r
         #region File Menu\r
 \r
+        /// <summary>\r
+        /// Kill The scan menu Item\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_killCLI_Click(object sender, EventArgs e)\r
         {\r
             KillScan();\r
         }\r
 \r
+        /// <summary>\r
+        /// Exit the Application Menu Item\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_exit_Click(object sender, EventArgs e)\r
         {\r
             Application.Exit();\r
@@ -378,17 +396,44 @@ namespace Handbrake
 \r
         #region Tools Menu\r
 \r
+        /// <summary>\r
+        /// Menu - Start Button\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_encode_Click(object sender, EventArgs e)\r
         {\r
             queueWindow.Show();\r
         }\r
 \r
+        /// <summary>\r
+        /// Menu - Display the Log Window\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_encodeLog_Click(object sender, EventArgs e)\r
         {\r
-            frmActivityWindow dvdInfoWindow = new frmActivityWindow(lastAction);\r
+            frmActivityWindow dvdInfoWindow = new frmActivityWindow(encodeQueue, SourceScan);\r
             dvdInfoWindow.Show();\r
         }\r
 \r
+        /// <summary>\r
+        /// Menu - Display the Options Window\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_options_Click(object sender, EventArgs e)\r
         {\r
             Form options = new frmOptions(this);\r
@@ -399,13 +444,22 @@ namespace Handbrake
 \r
         #region Presets Menu\r
 \r
+        /// <summary>\r
+        /// Reset the Built in Presets\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_presetReset_Click(object sender, EventArgs e)\r
         {\r
             presetHandler.UpdateBuiltInPresets();\r
             LoadPresetPanel();\r
             if (treeView_presets.Nodes.Count == 0)\r
                 MessageBox.Show(\r
-                    "Unable to load the presets.xml file. Please select \"Update Built-in Presets\" from the Presets Menu. \nMake sure you are running the program in Admin mode if running on Vista. See Windows FAQ for details!", \r
+                    "Unable to load the presets.xml file. Please select \"Update Built-in Presets\" from the Presets Menu. \nMake sure you are running the program in Admin mode if running on Vista. See Windows FAQ for details!",\r
                     "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
             else\r
                 MessageBox.Show("Presets have been updated!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
@@ -413,25 +467,75 @@ namespace Handbrake
             treeView_presets.ExpandAll();\r
         }\r
 \r
+        /// <summary>\r
+        /// Delete the selected preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_delete_preset_Click(object sender, EventArgs e)\r
         {\r
             presetHandler.RemoveBuiltInPresets();\r
             LoadPresetPanel(); // Reload the preset panel\r
         }\r
 \r
+        /// <summary>\r
+        /// Select the Normal preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_SelectDefault_Click(object sender, EventArgs e)\r
         {\r
             loadNormalPreset();\r
         }\r
 \r
+        /// <summary>\r
+        /// Import a plist Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_importMacPreset_Click(object sender, EventArgs e)\r
         {\r
-            importPreset();\r
+            ImportPreset();\r
         }\r
 \r
+        /// <summary>\r
+        /// Export a Plist Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void mnu_exportMacPreset_Click(object sender, EventArgs e)\r
+        {\r
+            ExportPreset();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Create a new Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_new_preset_Click(object sender, EventArgs e)\r
         {\r
-            Form preset = new frmAddPreset(this, QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null), \r
+            Form preset = new frmAddPreset(this, QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
                                            presetHandler);\r
             preset.ShowDialog();\r
         }\r
@@ -440,56 +544,44 @@ namespace Handbrake
 \r
         #region Help Menu\r
 \r
+        /// <summary>\r
+        /// Menu - Display the User Guide Web Page\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_user_guide_Click(object sender, EventArgs e)\r
         {\r
             Process.Start("http://trac.handbrake.fr/wiki/HandBrakeGuide");\r
         }\r
 \r
-        private void mnu_handbrake_home_Click(object sender, EventArgs e)\r
-        {\r
-            Process.Start("http://handbrake.fr");\r
-        }\r
-\r
+        /// <summary>\r
+        /// Menu - Check for Updates\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_UpdateCheck_Click(object sender, EventArgs e)\r
         {\r
             lbl_updateCheck.Visible = true;\r
             Main.BeginCheckForUpdates(new AsyncCallback(updateCheckDoneMenu), false);\r
         }\r
 \r
-        private void updateCheckDoneMenu(IAsyncResult result)\r
-        {\r
-            // Make sure it's running on the calling thread\r
-            if (InvokeRequired)\r
-            {\r
-                Invoke(new MethodInvoker(() => updateCheckDoneMenu(result)));\r
-                return;\r
-            }\r
-            UpdateCheckInformation info;\r
-            try\r
-            {\r
-                // Get the information about the new build, if any, and close the window\r
-                info = Main.EndCheckForUpdates(result);\r
-\r
-                if (info.NewVersionAvailable && info.BuildInformation != null)\r
-                {\r
-                    frmUpdater updateWindow = new frmUpdater(info.BuildInformation);\r
-                    updateWindow.ShowDialog();\r
-                }\r
-                else\r
-                    MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, \r
-                                    MessageBoxIcon.Information);\r
-                lbl_updateCheck.Visible = false;\r
-                return;\r
-            }\r
-            catch (Exception ex)\r
-            {\r
-                if ((bool) result.AsyncState)\r
-                    MessageBox.Show(\r
-                        "Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex, \r
-                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-            }\r
-        }\r
-\r
+        /// <summary>\r
+        /// Menu - Display the About Window\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_about_Click(object sender, EventArgs e)\r
         {\r
             using (frmAbout About = new frmAbout())\r
@@ -502,37 +594,81 @@ namespace Handbrake
 \r
         #region Preset Bar\r
 \r
-        // Right Click Menu Code\r
+        /// <summary>\r
+        /// RMenu - Expand All\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void pmnu_expandAll_Click(object sender, EventArgs e)\r
         {\r
             treeView_presets.ExpandAll();\r
         }\r
 \r
+        /// <summary>\r
+        /// RMenu - Collaspe All\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void pmnu_collapse_Click(object sender, EventArgs e)\r
         {\r
             treeView_presets.CollapseAll();\r
         }\r
 \r
+        /// <summary>\r
+        /// Menu - Import Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void pmnu_import_Click(object sender, EventArgs e)\r
         {\r
-            importPreset();\r
+            ImportPreset();\r
         }\r
 \r
+        /// <summary>\r
+        /// RMenu - Save Changes to Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void pmnu_saveChanges_Click(object sender, EventArgs e)\r
         {\r
             DialogResult result =\r
                 MessageBox.Show(\r
                     "Do you wish to include picture settings when updating the preset: " +\r
-                    treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel, \r
+                    treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel,\r
                     MessageBoxIcon.Question);\r
             if (result == DialogResult.Yes)\r
-                presetHandler.Update(treeView_presets.SelectedNode.Text, \r
+                presetHandler.Update(treeView_presets.SelectedNode.Text,\r
                                      QueryGenerator.GenerateTabbedComponentsQuery(this), true);\r
             else if (result == DialogResult.No)\r
-                presetHandler.Update(treeView_presets.SelectedNode.Text, \r
+                presetHandler.Update(treeView_presets.SelectedNode.Text,\r
                                      QueryGenerator.GenerateTabbedComponentsQuery(this), false);\r
         }\r
 \r
+        /// <summary>\r
+        /// RMenu - Delete Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void pmnu_delete_click(object sender, EventArgs e)\r
         {\r
             if (treeView_presets.SelectedNode != null)\r
@@ -543,6 +679,15 @@ namespace Handbrake
             treeView_presets.Select();\r
         }\r
 \r
+        /// <summary>\r
+        /// Preset Menu Is Opening. Setup the Menu\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void presets_menu_Opening(object sender, CancelEventArgs e)\r
         {\r
             // Make sure that the save menu is always disabled by default\r
@@ -557,15 +702,34 @@ namespace Handbrake
         }\r
 \r
         // Presets Management\r
+\r
+        /// <summary>\r
+        /// Button - Add a preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_addPreset_Click(object sender, EventArgs e)\r
         {\r
             Form preset = new frmAddPreset(this, QueryGenerator.GenerateTabbedComponentsQuery(this), presetHandler);\r
             preset.ShowDialog();\r
         }\r
 \r
+        /// <summary>\r
+        /// Button - remove a Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_removePreset_Click(object sender, EventArgs e)\r
         {\r
-            DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset", \r
+            DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",\r
                                                   MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
             if (result == DialogResult.Yes)\r
             {\r
@@ -578,11 +742,20 @@ namespace Handbrake
             treeView_presets.Select();\r
         }\r
 \r
+        /// <summary>\r
+        /// Button - Set the selected preset as the default\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_setDefault_Click(object sender, EventArgs e)\r
         {\r
             if (treeView_presets.SelectedNode != null)\r
             {\r
-                DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?", \r
+                DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?",\r
                                                       "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
                 if (result == DialogResult.Yes)\r
                 {\r
@@ -595,6 +768,15 @@ namespace Handbrake
                 MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
         }\r
 \r
+        /// <summary>\r
+        /// PresetBar Mouse Down event\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void treeview_presets_mouseUp(object sender, MouseEventArgs e)\r
         {\r
             if (e.Button == MouseButtons.Right)\r
@@ -611,16 +793,34 @@ namespace Handbrake
             treeView_presets.Select();\r
         }\r
 \r
+        /// <summary>\r
+        /// Preset Bar after selecting the preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void treeView_presets_AfterSelect(object sender, TreeViewEventArgs e)\r
         {\r
             selectPreset();\r
         }\r
 \r
+        /// <summary>\r
+        /// Preset Bar - Handle the Delete Key\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void treeView_presets_deleteKey(object sender, KeyEventArgs e)\r
         {\r
             if (e.KeyCode == Keys.Delete)\r
             {\r
-                DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset", \r
+                DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",\r
                                                       MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
                 if (result == DialogResult.Yes)\r
                 {\r
@@ -648,6 +848,9 @@ namespace Handbrake
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Select the selected preset and setup the GUI\r
+        /// </summary>\r
         private void selectPreset()\r
         {\r
             if (treeView_presets.SelectedNode != null)\r
@@ -683,6 +886,9 @@ namespace Handbrake
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Load the Normal Preset\r
+        /// </summary>\r
         private void loadNormalPreset()\r
         {\r
             foreach (TreeNode treenode in treeView_presets.Nodes)\r
@@ -695,7 +901,10 @@ namespace Handbrake
             }\r
         }\r
 \r
-        private void importPreset()\r
+        /// <summary>\r
+        /// Import a plist preset\r
+        /// </summary>\r
+        private void ImportPreset()\r
         {\r
             if (openPreset.ShowDialog() == DialogResult.OK)\r
             {\r
@@ -703,31 +912,27 @@ namespace Handbrake
                 if (presetHandler.CheckIfUserPresetExists(parsed.PresetName + " (Imported)"))\r
                 {\r
                     DialogResult result =\r
-                        MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?", \r
-                                        "Overwrite preset?", \r
+                        MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?",\r
+                                        "Overwrite preset?",\r
                                         MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
                     if (result == DialogResult.Yes)\r
                     {\r
                         PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
-                        presetHandler.Update(parsed.PresetName + " (Imported)", \r
-                                             QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null), \r
+                        presetHandler.Update(parsed.PresetName + " (Imported)",\r
+                                             QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
                                              parsed.UsesPictureSettings);\r
                     }\r
                 }\r
                 else\r
                 {\r
                     PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
-                    presetHandler.Add(parsed.PresetName, \r
-                                      QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null), \r
-                                      parsed.UsesPictureSettings);\r
-\r
-                    if (presetHandler.Add(parsed.PresetName + " (Imported)", \r
-                                          QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null), \r
+                    if (presetHandler.Add(parsed.PresetName + " (Imported)",\r
+                                          QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
                                           parsed.UsesPictureSettings))\r
                     {\r
                         TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")\r
                                                        {\r
-                                                          ForeColor = Color.Black\r
+                                                           ForeColor = Color.Black\r
                                                        };\r
                         treeView_presets.Nodes.Add(preset_treeview);\r
                     }\r
@@ -735,17 +940,73 @@ namespace Handbrake
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Export a plist Preset\r
+        /// </summary>\r
+        private void ExportPreset()\r
+        {\r
+            MessageBox.Show("This feature has not been implimented yet.", "Not Implimented", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+            return;\r
+\r
+            SaveFileDialog savefiledialog = new SaveFileDialog();\r
+            savefiledialog.Filter = "plist|*.plist";\r
+\r
+            if (treeView_presets.SelectedNode != null)\r
+            {\r
+\r
+                if (savefiledialog.ShowDialog() == DialogResult.OK)\r
+                {\r
+                    Preset preset = presetHandler.GetPreset(treeView_presets.SelectedNode.Text);\r
+                    PlistPresetHandler.Export(savefiledialog.FileName, preset);\r
+                }\r
+            }\r
+        }\r
+\r
         #endregion\r
 \r
         #region ToolStrip\r
 \r
+        /// <summary>\r
+        /// Toolbar - When the Source button is clicked, Clear any DVD drives and add any available DVD drives that can be used as a source.\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_source_Click(object sender, EventArgs e)\r
         {\r
-            mnu_dvd_drive.Visible = true;\r
+            // Remove old Drive Menu Items.\r
+            List<ToolStripMenuItem> itemsToRemove = new List<ToolStripMenuItem>();\r
+            foreach (var item in btn_source.DropDownItems)\r
+            {\r
+                if (item.GetType() == typeof(ToolStripMenuItem))\r
+                {\r
+                    ToolStripMenuItem menuItem = (ToolStripMenuItem)item;\r
+                    if (menuItem.Name.StartsWith("Drive"))\r
+                    {\r
+                        itemsToRemove.Add(menuItem);\r
+                    }\r
+                }\r
+            }\r
+\r
+            foreach (ToolStripMenuItem item in itemsToRemove)\r
+                btn_source.DropDownItems.Remove(item);\r
+\r
             Thread driveInfoThread = new Thread(SetDriveSelectionMenuItem);\r
             driveInfoThread.Start();\r
         }\r
 \r
+        /// <summary>\r
+        /// Toolbar - Start The Encode\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_start_Click(object sender, EventArgs e)\r
         {\r
             if (btn_start.Text == "Stop")\r
@@ -755,12 +1016,12 @@ namespace Handbrake
                     !Properties.Settings.Default.showCliForInGuiEncodeStatus)\r
                 {\r
                     result = MessageBox.Show(\r
-                        "Are you sure you wish to cancel the encode?\n\nPlease note, when 'Enable in-GUI encode status' is enabled, stopping this encode will render the file unplayable. ", \r
+                        "Are you sure you wish to cancel the encode?\n\nPlease note, when 'Enable in-GUI encode status' is enabled, stopping this encode will render the file unplayable. ",\r
                         "Cancel Encode?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
                 }\r
                 else\r
                 {\r
-                    result = MessageBox.Show("Are you sure you wish to cancel the encode?", "Cancel Encode?", \r
+                    result = MessageBox.Show("Are you sure you wish to cancel the encode?", "Cancel Encode?",\r
                                              MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
                 }\r
 \r
@@ -780,9 +1041,6 @@ namespace Handbrake
                     {\r
                         encodeQueue.SafelyClose();\r
                     }\r
-\r
-                    // Update the GUI\r
-                    SetEncodeFinished();\r
                 }\r
             }\r
             else\r
@@ -805,9 +1063,9 @@ namespace Handbrake
                                                               "priority over the GUI, your recently updated settings will not be taken " +\r
                                                               "into account when encoding this job." +\r
                                                               Environment.NewLine + Environment.NewLine +\r
-                                                              "Do you want to replace the manual query with the updated GUI-generated query?", \r
-                                                              "Manual Query does not Match GUI", \r
-                                                              MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk, \r
+                                                              "Do you want to replace the manual query with the updated GUI-generated query?",\r
+                                                              "Manual Query does not Match GUI",\r
+                                                              MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk,\r
                                                               MessageBoxDefaultButton.Button3);\r
 \r
                         switch (result)\r
@@ -836,13 +1094,13 @@ namespace Handbrake
                         if (File.Exists(text_destination.Text))\r
                             overwrite =\r
                                 MessageBox.Show(\r
-                                    "The destination file already exists. Are you sure you want to overwrite it?", \r
+                                    "The destination file already exists. Are you sure you want to overwrite it?",\r
                                     "Overwrite File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
 \r
                     if (overwrite == DialogResult.Yes)\r
                     {\r
                         if (encodeQueue.Count == 0)\r
-                            encodeQueue.Add(query, sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
+                            encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
 \r
                         queueWindow.SetQueue();\r
                         if (encodeQueue.Count > 1)\r
@@ -850,26 +1108,37 @@ namespace Handbrake
 \r
                         SetEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
                         encodeQueue.Start(); // Start The Queue Encoding Process\r
-                        lastAction = "encode"; // Set the last action to encode - Used for activity window.\r
                     }\r
-                    if (ActivityWindow != null)\r
-                        ActivityWindow.SetEncodeMode();\r
 \r
                     this.Focus();\r
                 }\r
                 else if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))\r
-                    MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, \r
+                    MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,\r
                                     MessageBoxIcon.Warning);\r
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Toolbar - Add the current job to the Queue\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_add2Queue_Click(object sender, EventArgs e)\r
         {\r
             if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))\r
-                MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, \r
-                                MessageBoxIcon.Warning);\r
+                MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             else\r
             {\r
+                if (!Directory.Exists(Path.GetDirectoryName(text_destination.Text)))\r
+                {\r
+                    MessageBox.Show("Destination Path does not exist.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                    return;\r
+                }\r
+\r
                 string query = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
                 if (rtf_query.Text != string.Empty)\r
                     query = rtf_query.Text;\r
@@ -878,13 +1147,13 @@ namespace Handbrake
                 {\r
                     DialogResult result =\r
                         MessageBox.Show(\r
-                            "There is already a queue item for this destination path. \n\n If you continue, the encode will be overwritten. Do you wish to continue?", \r
+                            "There is already a queue item for this destination path. \n\n If you continue, the encode will be overwritten. Do you wish to continue?",\r
                             "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
                     if (result == DialogResult.Yes)\r
-                        encodeQueue.Add(query, sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
+                        encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
                 }\r
                 else\r
-                    encodeQueue.Add(query, sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
+                    encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
 \r
                 lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";\r
 \r
@@ -892,16 +1161,34 @@ namespace Handbrake
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Toolbar - Show the Queue\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_showQueue_Click(object sender, EventArgs e)\r
         {\r
             queueWindow.Show();\r
             queueWindow.Activate();\r
         }\r
 \r
+        /// <summary>\r
+        /// Toolbar - Show the Preview Window\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void tb_preview_Click(object sender, EventArgs e)\r
         {\r
             if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))\r
-                MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, \r
+                MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,\r
                                 MessageBoxIcon.Warning);\r
             else\r
             {\r
@@ -916,28 +1203,24 @@ namespace Handbrake
                     qtpreview.Show();\r
                 }\r
                 else\r
-                    MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK, \r
+                    MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK,\r
                                     MessageBoxIcon.Warning);\r
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Toolbar - Show the Activity log Window\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_ActivityWindow_Click(object sender, EventArgs e)\r
         {\r
             if (ActivityWindow == null || !ActivityWindow.IsHandleCreated)\r
-                ActivityWindow = new frmActivityWindow(lastAction);\r
-            else\r
-                switch (lastAction)\r
-                {\r
-                    case "scan":\r
-                        ActivityWindow.SetScanMode();\r
-                        break;\r
-                    case "encode":\r
-                        ActivityWindow.SetEncodeMode();\r
-                        break;\r
-                    default:\r
-                        ActivityWindow.SetEncodeMode();\r
-                        break;\r
-                }\r
+                ActivityWindow = new frmActivityWindow(encodeQueue, SourceScan);\r
 \r
             ActivityWindow.Show();\r
             ActivityWindow.Activate();\r
@@ -947,6 +1230,15 @@ namespace Handbrake
 \r
         #region System Tray Icon\r
 \r
+        /// <summary>\r
+        /// Handle Resizing of the main window when deaing with the Notify Icon\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void frmMain_Resize(object sender, EventArgs e)\r
         {\r
             if (FormWindowState.Minimized == this.WindowState)\r
@@ -958,6 +1250,15 @@ namespace Handbrake
                 notifyIcon.Visible = false;\r
         }\r
 \r
+        /// <summary>\r
+        /// Double Click the Tray Icon\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)\r
         {\r
             this.Visible = true;\r
@@ -966,6 +1267,15 @@ namespace Handbrake
             notifyIcon.Visible = false;\r
         }\r
 \r
+        /// <summary>\r
+        /// Tray Icon - Restore Menu Item - Resture the Window\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_restore_Click(object sender, EventArgs e)\r
         {\r
             this.Visible = true;\r
@@ -976,7 +1286,7 @@ namespace Handbrake
 \r
         #endregion\r
 \r
-        #region Tab Control\r
+        #region Main Window and Tab Control\r
 \r
         // Source\r
         private void btn_dvd_source_Click(object sender, EventArgs e)\r
@@ -1003,15 +1313,27 @@ namespace Handbrake
 \r
         private void mnu_dvd_drive_Click(object sender, EventArgs e)\r
         {\r
-            if (this.dvdDrivePath == null) return;\r
-            this.selectedSourceType = SourceType.DvdDrive;\r
-            SelectSource(this.dvdDrivePath);\r
+            ToolStripMenuItem item = sender as ToolStripMenuItem;\r
+            if (item != null)\r
+            {\r
+                string driveId = item.Name.Replace("Drive", string.Empty);\r
+                int id;\r
+                if (int.TryParse(driveId, out id))\r
+                {\r
+\r
+                    this.dvdDrivePath = drives[id].RootDirectory;\r
+                    this.dvdDriveLabel = drives[id].VolumeLabel;\r
+\r
+                    if (this.dvdDrivePath == null) return;\r
+                    this.selectedSourceType = SourceType.DvdDrive;\r
+                    SelectSource(this.dvdDrivePath);\r
+                }\r
+            }\r
         }\r
 \r
         private void SelectSource(string file)\r
         {\r
             Check_ChapterMarkers.Enabled = true;\r
-            lastAction = "scan";\r
             sourcePath = string.Empty;\r
 \r
             if (file == string.Empty) // Must have a file or path\r
@@ -1028,7 +1350,7 @@ namespace Handbrake
         {\r
             if ((drp_dvdtitle.Items.Count == 1) && (drp_dvdtitle.Items[0].ToString() == "Automatic"))\r
                 MessageBox.Show(\r
-                    "There are no titles to select. Please load a source file by clicking the 'Source' button above before trying to select a title.", \r
+                    "There are no titles to select. Please load a source file by clicking the 'Source' button above before trying to select a title.",\r
                     "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
         }\r
 \r
@@ -1037,12 +1359,11 @@ namespace Handbrake
             UnRegisterPresetEventHandler();\r
             drop_mode.SelectedIndex = 0;\r
 \r
-            PictureSettings.lbl_Aspect.Text = "Select a Title"; // Reset some values on the form\r
             drop_chapterStart.Items.Clear();\r
             drop_chapterFinish.Items.Clear();\r
 \r
             // If the dropdown is set to automatic nothing else needs to be done.\r
-            // Otheriwse if its not, title data has to be loased from parsing.\r
+            // Otheriwse if its not, title data has to be loaded from parsing.\r
             if (drp_dvdtitle.Text != "Automatic")\r
             {\r
                 selectedTitle = drp_dvdtitle.SelectedItem as Title;\r
@@ -1079,7 +1400,7 @@ namespace Handbrake
                     drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
 \r
                 // Populate the Audio Channels Dropdown\r
-                AudioSettings.SetTrackList(selectedTitle);\r
+                AudioSettings.SetTrackList(selectedTitle, CurrentlySelectedPreset);\r
 \r
                 // Populate the Subtitles dropdown\r
                 Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());\r
@@ -1097,7 +1418,7 @@ namespace Handbrake
                     text_destination.Text = autoPath;\r
                 else\r
                     MessageBox.Show(\r
-                        "You currently have \"Automatically name output files\" enabled for the destination file box, but you do not have a default directory set.\n\nYou should set a \"Default Path\" in HandBrakes preferences. (See 'Tools' menu -> 'Options' -> 'General' Tab -> 'Default Path')", \r
+                        "You currently have \"Automatically name output files\" enabled for the destination file box, but you do not have a default directory set.\n\nYou should set a \"Default Path\" in HandBrakes preferences. (See 'Tools' menu -> 'Options' -> 'General' Tab -> 'Default Path')",\r
                         "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             }\r
 \r
@@ -1126,7 +1447,7 @@ namespace Handbrake
             if (drop_mode.SelectedIndex != 0) // Function is not used if we are not in chapters mode.\r
                 return;\r
 \r
-            Control ctl = (Control) sender;\r
+            Control ctl = (Control)sender;\r
             int chapterStart, chapterEnd;\r
             int.TryParse(drop_chapterStart.Text, out chapterStart);\r
             int.TryParse(drop_chapterFinish.Text, out chapterEnd);\r
@@ -1160,8 +1481,8 @@ namespace Handbrake
                             int n = data_chpt.Rows.Add();\r
                             data_chpt.Rows[n].Cells[0].Value = (i + 1);\r
                             data_chpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);\r
-                            data_chpt.Rows[n].Cells[0].ValueType = typeof (int);\r
-                            data_chpt.Rows[n].Cells[1].ValueType = typeof (string);\r
+                            data_chpt.Rows[n].Cells[0].ValueType = typeof(int);\r
+                            data_chpt.Rows[n].Cells[1].ValueType = typeof(string);\r
                             i++;\r
                         }\r
                     }\r
@@ -1210,7 +1531,7 @@ namespace Handbrake
                 case 2:\r
                     if (selectedTitle != null)\r
                     {\r
-                        duration = duration/selectedTitle.Fps;\r
+                        duration = duration / selectedTitle.Fps;\r
                         lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();\r
                     }\r
                     else\r
@@ -1259,7 +1580,7 @@ namespace Handbrake
                     if (selectedTitle != null)\r
                     {\r
                         drop_chapterStart.Text = "0";\r
-                        drop_chapterFinish.Text = (selectedTitle.Fps*selectedTitle.Duration.TotalSeconds).ToString();\r
+                        drop_chapterFinish.Text = (selectedTitle.Fps * selectedTitle.Duration.TotalSeconds).ToString();\r
                     }\r
                     return;\r
             }\r
@@ -1288,7 +1609,7 @@ namespace Handbrake
                 {\r
                     case 1:\r
                         if (\r
-                            !Path.GetExtension(DVD_Save.FileName).Equals(".mp4", \r
+                            !Path.GetExtension(DVD_Save.FileName).Equals(".mp4",\r
                                                                          StringComparison.InvariantCultureIgnoreCase))\r
                             if (Properties.Settings.Default.useM4v)\r
                                 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".m4v").Replace(".mkv", ".m4v");\r
@@ -1297,8 +1618,7 @@ namespace Handbrake
                         break;\r
                     case 2:\r
                         if (\r
-                            !Path.GetExtension(DVD_Save.FileName).Equals(".mkv", \r
-                                                                         StringComparison.InvariantCultureIgnoreCase))\r
+                            !Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase))\r
                             DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".mkv").Replace(".m4v", ".mkv");\r
                         break;\r
                     default:\r
@@ -1340,7 +1660,6 @@ namespace Handbrake
             }\r
 \r
             AudioSettings.SetContainer(drop_format.Text);\r
-            Subtitles.SetContainer(drop_format.SelectedIndex);\r
 \r
             if (drop_format.Text.Contains("MP4"))\r
             {\r
@@ -1409,29 +1728,13 @@ namespace Handbrake
 \r
                     CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");\r
                     double cqStep = Properties.Settings.Default.x264cqstep;\r
-                    double multiplier = 1.0/cqStep;\r
-                    double value = slider_videoQuality.Value*multiplier;\r
+                    double multiplier = 1.0 / cqStep;\r
+                    double value = slider_videoQuality.Value * multiplier;\r
+\r
+                    slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);\r
 \r
-                    switch (Properties.Settings.Default.x264cqstep.ToString(culture))\r
-                    {\r
-                        case "0.2":\r
-                            slider_videoQuality.Maximum = 255;\r
-                            break;\r
-                        case "0.25":\r
-                            slider_videoQuality.Maximum = 204;\r
-                            break;\r
-                        case "0.5":\r
-                            slider_videoQuality.Maximum = 102;\r
-                            break;\r
-                        case "1":\r
-                            slider_videoQuality.Maximum = 51;\r
-                            break;\r
-                        default:\r
-                            slider_videoQuality.Maximum = 51;\r
-                            break;\r
-                    }\r
                     if (value < slider_videoQuality.Maximum)\r
-                        slider_videoQuality.Value = slider_videoQuality.Maximum - (int) value;\r
+                        slider_videoQuality.Value = slider_videoQuality.Maximum - (int)value;\r
 \r
                     break;\r
                 case "VP3 (Theora)":\r
@@ -1474,38 +1777,21 @@ namespace Handbrake
         {\r
             // Work out the current RF value.\r
             double cqStep = _cachedCqStep;\r
-            double rfValue = 51.0 - slider_videoQuality.Value*cqStep;\r
+            double rfValue = 51.0 - slider_videoQuality.Value * cqStep;\r
 \r
             // Change the maximum value for the slider\r
-            switch (Properties.Settings.Default.x264cqstep.ToString(new CultureInfo("en-US")))\r
-            {\r
-                case "0.2":\r
-                    slider_videoQuality.Maximum = 255;\r
-                    break;\r
-                case "0.25":\r
-                    slider_videoQuality.Maximum = 204;\r
-                    break;\r
-                case "0.5":\r
-                    slider_videoQuality.Maximum = 102;\r
-                    break;\r
-                case "1":\r
-                    slider_videoQuality.Maximum = 51;\r
-                    break;\r
-                default:\r
-                    slider_videoQuality.Maximum = 51;\r
-                    break;\r
-            }\r
+            slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);\r
 \r
             // Reset the CQ slider to RF0\r
             slider_videoQuality.Value = slider_videoQuality.Maximum;\r
 \r
             // Reset the CQ slider back to the previous value as close as possible\r
             double cqStepNew = Properties.Settings.Default.x264cqstep;\r
-            double rfValueCurrent = 51.0 - slider_videoQuality.Value*cqStepNew;\r
+            double rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;\r
             while (rfValueCurrent < rfValue)\r
             {\r
                 slider_videoQuality.Value--;\r
-                rfValueCurrent = 51.0 - slider_videoQuality.Value*cqStepNew;\r
+                rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;\r
             }\r
 \r
             // Cache the CQ step for the next calculation\r
@@ -1521,7 +1807,7 @@ namespace Handbrake
                     lbl_SliderValue.Text = "QP:" + (32 - slider_videoQuality.Value);\r
                     break;\r
                 case "H.264 (x264)":\r
-                    double rfValue = 51.0 - slider_videoQuality.Value*cqStep;\r
+                    double rfValue = 51.0 - slider_videoQuality.Value * cqStep;\r
                     rfValue = Math.Round(rfValue, 2);\r
                     lbl_SliderValue.Text = "RF:" + rfValue.ToString(new CultureInfo("en-US"));\r
                     break;\r
@@ -1603,6 +1889,19 @@ namespace Handbrake
             }\r
         }\r
 \r
+        private void btn_export_Click(object sender, EventArgs e)\r
+        {\r
+            SaveFileDialog saveFileDialog = new SaveFileDialog();\r
+            saveFileDialog.Filter = "Csv File|*.csv";\r
+            saveFileDialog.DefaultExt = "csv";\r
+            if (saveFileDialog.ShowDialog() == DialogResult.OK)\r
+            {\r
+                string filename = saveFileDialog.FileName;\r
+\r
+                Main.SaveChapterMarkersToCsv(this, filename);\r
+            }\r
+        }\r
+\r
         private void mnu_resetChapters_Click(object sender, EventArgs e)\r
         {\r
             data_chpt.Rows.Clear();\r
@@ -1630,35 +1929,26 @@ namespace Handbrake
 \r
         #region Source Scan\r
 \r
-        public bool isScanning { get; set; }\r
-        private Scan SourceScan;\r
-\r
+        /// <summary>\r
+        /// Start the Scan Process\r
+        /// </summary>\r
+        /// <param name="filename">\r
+        /// The filename.\r
+        /// </param>\r
+        /// <param name="title">\r
+        /// The title.\r
+        /// </param>\r
         private void StartScan(string filename, int title)\r
         {\r
             // Setup the GUI components for the scan.\r
             sourcePath = filename;\r
-            foreach (Control ctrl in Controls)\r
-                if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))\r
-                    ctrl.Enabled = false;\r
 \r
-            lbl_encode.Visible = true;\r
-            lbl_encode.Text = "Scanning ...";\r
-            btn_source.Enabled = false;\r
-            btn_start.Enabled = false;\r
-            btn_showQueue.Enabled = false;\r
-            btn_add2Queue.Enabled = false;\r
-            tb_preview.Enabled = false;\r
-            mnu_killCLI.Visible = true;\r
-\r
-            if (ActivityWindow != null)\r
-                ActivityWindow.SetScanMode();\r
+            this.DisableGUI();\r
 \r
             // Start the Scan\r
             try\r
             {\r
-                isScanning = true;\r
-                SourceScan = new Scan();\r
-                SourceScan.ScanSource(sourcePath, title);\r
+                SourceScan.Scan(sourcePath, title);\r
                 SourceScan.ScanStatusChanged += new EventHandler(SourceScan_ScanStatusChanged);\r
                 SourceScan.ScanCompleted += new EventHandler(SourceScan_ScanCompleted);\r
             }\r
@@ -1668,16 +1958,37 @@ namespace Handbrake
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Update the Status label for the scan\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void SourceScan_ScanStatusChanged(object sender, EventArgs e)\r
         {\r
             UpdateScanStatusLabel();\r
         }\r
 \r
+        /// <summary>\r
+        /// Update the UI after the scan has completed\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void SourceScan_ScanCompleted(object sender, EventArgs e)\r
         {\r
             UpdateGuiAfterScan();\r
         }\r
 \r
+        /// <summary>\r
+        /// Update the Scan Status Label\r
+        /// </summary>\r
         private void UpdateScanStatusLabel()\r
         {\r
             if (InvokeRequired)\r
@@ -1685,9 +1996,12 @@ namespace Handbrake
                 BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel));\r
                 return;\r
             }\r
-            lbl_encode.Text = SourceScan.ScanStatus();\r
+            lbl_encode.Text = SourceScan.ScanStatus;\r
         }\r
 \r
+        /// <summary>\r
+        /// Reset the GUI when the scan has completed\r
+        /// </summary>\r
         private void UpdateGuiAfterScan()\r
         {\r
             if (InvokeRequired)\r
@@ -1698,20 +2012,31 @@ namespace Handbrake
 \r
             try\r
             {\r
-                currentSource = SourceScan.SouceData();\r
+                currentSource = SourceScan.SouceData;\r
 \r
                 // Setup some GUI components\r
                 drp_dvdtitle.Items.Clear();\r
                 if (currentSource.Titles.Count != 0)\r
                     drp_dvdtitle.Items.AddRange(currentSource.Titles.ToArray());\r
 \r
-                // Now select the longest title\r
-                if (currentSource.Titles.Count != 0)\r
-                    drp_dvdtitle.SelectedItem = Main.SelectLongestTitle(currentSource);\r
+                foreach (Title title in currentSource.Titles)\r
+                {\r
+                    if (title.MainTitle)\r
+                    {\r
+                        drp_dvdtitle.SelectedItem = title;\r
+                    }\r
+                }\r
+\r
+                if (drp_dvdtitle.SelectedItem == null && drp_dvdtitle.Items.Count > 0)\r
+                {\r
+                    drp_dvdtitle.SelectedIndex = 0;\r
+                }\r
 \r
                 // Enable the creation of chapter markers if the file is an image of a dvd.\r
-                if (sourcePath.ToLower().Contains(".iso") || sourcePath.Contains("VIDEO_TS") ||\r
-                    Directory.Exists(Path.Combine(sourcePath, "VIDEO_TS")))\r
+                int start, end;\r
+                int.TryParse(drop_chapterStart.Items[0].ToString(), out start);\r
+                int.TryParse(drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString(), out end);\r
+                if (end > start)\r
                     Check_ChapterMarkers.Enabled = true;\r
                 else\r
                 {\r
@@ -1724,7 +2049,7 @@ namespace Handbrake
                 if (drp_dvdtitle.Items.Count == 0)\r
                 {\r
                     MessageBox.Show(\r
-                        "No Title(s) found. \n\nYour Source may be copy protected, badly mastered or in a format which HandBrake does not support. \nPlease refer to the Documentation and FAQ (see Help Menu).", \r
+                        "No Title(s) found. \n\nYour Source may be copy protected, badly mastered or in a format which HandBrake does not support. \nPlease refer to the Documentation and FAQ (see Help Menu).",\r
                         "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
                     sourcePath = string.Empty;\r
                 }\r
@@ -1735,12 +2060,15 @@ namespace Handbrake
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK, \r
+                MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK,\r
                                 MessageBoxIcon.Error);\r
                 EnableGUI();\r
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Enable the GUI\r
+        /// </summary>\r
         private void EnableGUI()\r
         {\r
             try\r
@@ -1763,27 +2091,42 @@ namespace Handbrake
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Disable the GUI\r
+        /// </summary>\r
+        private void DisableGUI()\r
+        {\r
+            foreach (Control ctrl in Controls)\r
+                if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))\r
+                    ctrl.Enabled = false;\r
+\r
+            lbl_encode.Visible = true;\r
+            lbl_encode.Text = "Scanning ...";\r
+            btn_source.Enabled = false;\r
+            btn_start.Enabled = false;\r
+            btn_showQueue.Enabled = false;\r
+            btn_add2Queue.Enabled = false;\r
+            tb_preview.Enabled = false;\r
+            mnu_killCLI.Visible = true;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Kill the Scan\r
+        /// </summary>\r
         private void KillScan()\r
         {\r
-            try\r
-            {\r
-                SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);\r
-                EnableGUI();\r
-                ResetGUI();\r
+            SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);\r
+            EnableGUI();\r
+            ResetGUI();\r
 \r
-                if (SourceScan.ScanProcess() != null)\r
-                    SourceScan.ScanProcess().Kill();\r
+            SourceScan.Stop();\r
 \r
-                lbl_encode.Text = "Scan Cancelled!";\r
-            }\r
-            catch (Exception ex)\r
-            {\r
-                MessageBox.Show(\r
-                    "Unable to kill HandBrakeCLI.exe \nYou may need to manually kill HandBrakeCLI.exe using the Windows Task Manager if it does not close automatically within the next few minutes. \n\nError Information: \n" +\r
-                    ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-            }\r
+            lbl_encode.Text = "Scan Cancelled!";\r
         }\r
 \r
+        /// <summary>\r
+        /// Reset the GUI\r
+        /// </summary>\r
         private void ResetGUI()\r
         {\r
             drp_dvdtitle.Items.Clear();\r
@@ -1791,13 +2134,14 @@ namespace Handbrake
             drop_chapterFinish.Items.Clear();\r
             lbl_duration.Text = "Select a Title";\r
             PictureSettings.lbl_src_res.Text = "Select a Title";\r
-            PictureSettings.lbl_Aspect.Text = "Select a Title";\r
             sourcePath = String.Empty;\r
             text_destination.Text = String.Empty;\r
             selectedTitle = null;\r
-            isScanning = false;\r
         }\r
 \r
+        /// <summary>\r
+        /// Update the Source Label\r
+        /// </summary>\r
         private void UpdateSourceLabel()\r
         {\r
             labelSource.Text = string.IsNullOrEmpty(sourcePath) ? "Select \"Source\" to continue." : this.SourceName;\r
@@ -1808,11 +2152,16 @@ namespace Handbrake
                     labelSource.Text = Path.GetFileName(selectedTitle.SourceName);\r
         }\r
 \r
+        /// <summary>\r
+        /// Take a job from the Queue, rescan it, and reload the GUI for that job.\r
+        /// </summary>\r
+        /// <param name="job">\r
+        /// The job.\r
+        /// </param>\r
         public void RecievingJob(Job job)\r
         {\r
             string query = job.Query;\r
-            StartScan(job.Source, 0);\r
-\r
+            StartScan(job.Source, job.Title);\r
 \r
             if (query != null)\r
             {\r
@@ -1853,6 +2202,7 @@ namespace Handbrake
                 }\r
 \r
                 lbl_encode.Text = "Encoding Finished";\r
+                ProgressBarStatus.Visible = false;\r
                 btn_start.Text = "Start";\r
                 btn_start.ToolTipText = "Start the encoding process";\r
                 btn_start.Image = Properties.Resources.Play;\r
@@ -1883,8 +2233,9 @@ namespace Handbrake
                     BeginInvoke(new UpdateWindowHandler(SetEncodeStarted));\r
                     return;\r
                 }\r
-\r
                 lbl_encode.Visible = true;\r
+                ProgressBarStatus.Value = 0;\r
+                ProgressBarStatus.Visible = true;\r
                 lbl_encode.Text = "Encoding with " + encodeQueue.Count + " encode(s) pending";\r
                 btn_start.Text = "Stop";\r
                 btn_start.ToolTipText = "Stop the encoding process.";\r
@@ -1909,21 +2260,27 @@ namespace Handbrake
                     return;\r
                 }\r
 \r
-                List<DriveInformation> drives = Main.GetDrives();\r
+                drives = Main.GetDrives();\r
 \r
-                if (drives.Count == 0)\r
+                List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();\r
+                foreach (DriveInformation drive in drives)\r
                 {\r
-                    mnu_dvd_drive.Text = "[No DVD Drive Ready]";\r
-                    return;\r
+                    ToolStripMenuItem menuItem = new ToolStripMenuItem\r
+                        {\r
+                            Name = drive.ToString(),\r
+                            Text = drive.RootDirectory + " (" + drive.VolumeLabel + ")",\r
+                            Image = Resources.disc_small\r
+                        };\r
+                    menuItem.Click += new EventHandler(mnu_dvd_drive_Click);\r
+                    menuItems.Add(menuItem);\r
                 }\r
 \r
-                this.dvdDrivePath = drives[0].RootDirectory + "VIDEO_TS";\r
-                this.dvdDriveLabel = drives[0].VolumeLabel;\r
-                mnu_dvd_drive.Text = this.dvdDrivePath + " (" + this.dvdDriveLabel + ")";\r
+                foreach (ToolStripMenuItem item in menuItems)\r
+                    btn_source.DropDownItems.Add(item);\r
             }\r
-            catch (Exception)\r
+            catch (Exception exc)\r
             {\r
-                mnu_dvd_drive.Text = "[No DVD Drive Ready / Found]";\r
+                MessageBox.Show("Error in SetDriveSelectionMenuItem" + exc);\r
             }\r
         }\r
 \r
@@ -1934,14 +2291,72 @@ namespace Handbrake
         {\r
             if (presetHandler.CheckIfPresetsAreOutOfDate())\r
                 if (!Properties.Settings.Default.presetNotification)\r
-                    MessageBox.Show(splash, \r
-                                    "HandBrake has determined your built-in presets are out of date... These presets will now be updated.", \r
+                    MessageBox.Show(splash,\r
+                                    "HandBrake has determined your built-in presets are out of date... These presets will now be updated.",\r
                                     "Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
 \r
             presetHandler.GetPresetPanel(ref treeView_presets);\r
             treeView_presets.Update();\r
         }\r
 \r
+        /// <summary>\r
+        /// Get the title from the selected item in the title dropdown.\r
+        /// </summary>\r
+        /// <returns>\r
+        /// The title.\r
+        /// </returns>\r
+        private int getTitle()\r
+        {\r
+            int title = 0;\r
+            if (drp_dvdtitle.SelectedItem != null)\r
+            {\r
+                string[] titleInfo = drp_dvdtitle.SelectedItem.ToString().Split(' ');\r
+                int.TryParse(titleInfo[0], out title);\r
+            }\r
+\r
+            return title;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Handle the Update Check Finishing.\r
+        /// </summary>\r
+        /// <param name="result">\r
+        /// The result.\r
+        /// </param>\r
+        private void updateCheckDoneMenu(IAsyncResult result)\r
+        {\r
+            // Make sure it's running on the calling thread\r
+            if (InvokeRequired)\r
+            {\r
+                Invoke(new MethodInvoker(() => updateCheckDoneMenu(result)));\r
+                return;\r
+            }\r
+            UpdateCheckInformation info;\r
+            try\r
+            {\r
+                // Get the information about the new build, if any, and close the window\r
+                info = Main.EndCheckForUpdates(result);\r
+\r
+                if (info.NewVersionAvailable && info.BuildInformation != null)\r
+                {\r
+                    frmUpdater updateWindow = new frmUpdater(info.BuildInformation);\r
+                    updateWindow.ShowDialog();\r
+                }\r
+                else\r
+                    MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK,\r
+                                    MessageBoxIcon.Information);\r
+                lbl_updateCheck.Visible = false;\r
+                return;\r
+            }\r
+            catch (Exception ex)\r
+            {\r
+                if ((bool)result.AsyncState)\r
+                    MessageBox.Show(\r
+                        "Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex,\r
+                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+            }\r
+        }\r
+\r
         #endregion\r
 \r
         #region Overrides\r
@@ -1949,9 +2364,9 @@ namespace Handbrake
         /// <summary>\r
         /// Handle GUI shortcuts\r
         /// </summary>\r
-        /// <param name="msg"></param>\r
-        /// <param name="keyData"></param>\r
-        /// <returns></returns>\r
+        /// <param name="msg">Message</param>\r
+        /// <param name="keyData">Keys</param>\r
+        /// <returns>Bool</returns>\r
         protected override bool ProcessCmdKey(ref Message msg, Keys keyData)\r
         {\r
             if (keyData == (Keys.Control | Keys.S))\r
@@ -1971,25 +2386,38 @@ namespace Handbrake
         /// <summary>\r
         /// If the queue is being processed, prompt the user to confirm application close.\r
         /// </summary>\r
-        /// <param name="e"></param>\r
+        /// <param name="e">FormClosingEventArgs</param>\r
         protected override void OnFormClosing(FormClosingEventArgs e)\r
         {\r
             // If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.\r
-            if ((encodeQueue.IsEncoding) && (!encodeQueue.PauseRequested) && (encodeQueue.Count > 0))\r
+            if (encodeQueue.IsEncoding)\r
             {\r
                 DialogResult result =\r
                     MessageBox.Show(\r
-                        "HandBrake has queue items to process. Closing HandBrake will not stop the current encoding, but will stop processing the queue.\n\nDo you want to close HandBrake?", \r
+                        "HandBrake has queue items to process. Closing HandBrake will stop the current encoding.\n\nDo you want to close HandBrake?",\r
                         "Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+\r
                 if (result == DialogResult.No)\r
                     e.Cancel = true;\r
+\r
+                // Try to safely close out if we can, or kill the cli if using in-gui status\r
+                if (Settings.Default.enocdeStatusInGui)\r
+                    encodeQueue.Stop();\r
+                else\r
+                    encodeQueue.SafelyClose();\r
+            }\r
+\r
+            if (SourceScan.IsScanning)\r
+            {\r
+                SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);\r
+                SourceScan.Stop();\r
             }\r
             base.OnFormClosing(e);\r
         }\r
 \r
         #endregion\r
 \r
-        #region In-GUI Encode Status (Experimental)\r
+        #region In-GUI Encode Status\r
 \r
         /// <summary>\r
         /// Starts a new thread to monitor and process the CLI encode status\r
@@ -2001,7 +2429,9 @@ namespace Handbrake
                 Parser encode = new Parser(encodeQueue.HbProcess.StandardOutput.BaseStream);\r
                 encode.OnEncodeProgress += EncodeOnEncodeProgress;\r
                 while (!encode.EndOfStream)\r
-                    encode.readEncodeStatus();\r
+                    encode.ReadEncodeStatus();\r
+\r
+                SetEncodeFinished();\r
             }\r
             catch (Exception exc)\r
             {\r
@@ -2012,29 +2442,31 @@ namespace Handbrake
         /// <summary>\r
         /// Displays the Encode status in the GUI\r
         /// </summary>\r
-        /// <param name="Sender"></param>\r
-        /// <param name="CurrentTask"></param>\r
-        /// <param name="TaskCount"></param>\r
-        /// <param name="PercentComplete"></param>\r
-        /// <param name="CurrentFps"></param>\r
-        /// <param name="AverageFps"></param>\r
-        /// <param name="TimeRemaining"></param>\r
-        private void EncodeOnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, \r
-                                            float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
+        /// <param name="sender">The sender</param>\r
+        /// <param name="currentTask">The current task</param>\r
+        /// <param name="taskCount">Number of tasks</param>\r
+        /// <param name="percentComplete">Percent complete</param>\r
+        /// <param name="currentFps">Current encode speed in fps</param>\r
+        /// <param name="av">Avg encode speed</param>\r
+        /// <param name="timeRemaining">Time Left</param>\r
+        private void EncodeOnEncodeProgress(object sender, int currentTask, int taskCount, float percentComplete, float currentFps, float av, TimeSpan timeRemaining)\r
         {\r
             if (this.InvokeRequired)\r
             {\r
-                this.BeginInvoke(new EncodeProgressEventHandler(EncodeOnEncodeProgress), \r
-                                 new[]\r
-                                     {\r
-                                         Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, \r
-                                         TimeRemaining\r
-                                     });\r
+                this.BeginInvoke(\r
+                    new EncodeProgressEventHandler(EncodeOnEncodeProgress),\r
+                    new[] { sender, currentTask, taskCount, percentComplete, currentFps, av, timeRemaining });\r
                 return;\r
             }\r
             lbl_encode.Text =\r
-                string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ", \r
-                              PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
+                string.Format(\r
+                "{0:00.00}%,    FPS: {1:000.0},    Avg FPS: {2:000.0},    Time Remaining: {3}",\r
+                percentComplete,\r
+                currentFps,\r
+                av,\r
+                timeRemaining);\r
+\r
+            ProgressBarStatus.Value = (int)Math.Round(percentComplete);\r
         }\r
 \r
         #endregion\r