OSDN Git Service

WinGui:
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Mon, 13 Oct 2008 21:54:27 +0000 (21:54 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Mon, 13 Oct 2008 21:54:27 +0000 (21:54 +0000)
- Started to decouple this code a bit. Common.cs (now Main.cs) no longer relies on the frmMain window being passed into it. frmAddPreset no longer requires to access  QueryGenerator.cs
- QueryGenerator.cs, x264Panel.cs, PresetLoader.cs all moved into their own "frmMain" folder as that is the only place they should be used.
- Rearranged the base of frmMain.cs a bit.

git-svn-id: svn://localhost/HandBrake/trunk@1830 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/C#/Functions/Main.cs [new file with mode: 0644]
win/C#/HandBrakeCS.csproj
win/C#/frmAddPreset.cs
win/C#/frmMain.Designer.cs
win/C#/frmMain.cs
win/C#/frmMain.resx
win/C#/frmMain/PresetLoader.cs [moved from win/C#/Functions/Common.cs with 51% similarity]
win/C#/frmMain/QueryGenerator.cs [moved from win/C#/Functions/QueryGenerator.cs with 97% similarity]
win/C#/frmMain/x264Panel.cs [moved from win/C#/Functions/x264Panel.cs with 97% similarity]
win/C#/frmReadDVD.cs

diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs
new file mode 100644 (file)
index 0000000..1fba55e
--- /dev/null
@@ -0,0 +1,405 @@
+/*  Common.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
+\r
+using System;\r
+using System.Collections;\r
+using System.Text;\r
+using System.Windows.Forms;\r
+using System.Globalization;\r
+using System.IO;\r
+using System.Drawing;\r
+using System.Diagnostics;\r
+using System.Text.RegularExpressions;\r
+\r
+namespace Handbrake.Functions\r
+{\r
+    class Main\r
+    {\r
+        /// <summary>\r
+        /// Take in a File destination and change it's file extension to a new Extension\r
+        /// </summary>\r
+        /// <param name="destination"></param>\r
+        /// <param name="newExtension"></param>\r
+        /// <returns>String of the new file path and extension</returns>\r
+        public string setExtension(string destination, string newExtension)\r
+        {\r
+            destination.Replace(".mp4", newExtension);\r
+            destination.Replace(".m4v", newExtension);\r
+            destination.Replace(".mkv", newExtension);\r
+            destination.Replace(".avi", newExtension);\r
+            destination.Replace(".ogm", newExtension);\r
+\r
+            return destination;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculate the duration of the selected title and chapters\r
+        /// </summary>\r
+        public TimeSpan calculateDuration(string chapter_start, string chapter_end, Parsing.Title selectedTitle)\r
+        {\r
+            TimeSpan Duration = TimeSpan.FromSeconds(0.0);\r
+\r
+            // Get the durations between the 2 chapter points and add them together.\r
+            if (chapter_start != "Auto" && chapter_end != "Auto")\r
+            {\r
+                int start_chapter, end_chapter = 0;\r
+                int.TryParse(chapter_start, out start_chapter);\r
+                int.TryParse(chapter_end, out end_chapter);\r
+\r
+                int position = start_chapter - 1;\r
+\r
+                if (start_chapter <= end_chapter)\r
+                {\r
+                    if (end_chapter > selectedTitle.Chapters.Count)\r
+                        end_chapter = selectedTitle.Chapters.Count;\r
+\r
+                    while (position != end_chapter)\r
+                    {\r
+                        TimeSpan dur = selectedTitle.Chapters[position].Duration;\r
+                        Duration = Duration + dur;\r
+                        position++;\r
+                    }\r
+                }\r
+            }\r
+            return Duration;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculate the non-anamorphic resoltuion of the source\r
+        /// </summary>\r
+        /// <param name="width"></param>\r
+        /// <returns></returns>\r
+        public int cacluateNonAnamorphicHeight(int width, decimal top, decimal bottom, decimal left, decimal right, Parsing.Title selectedTitle)\r
+        {\r
+            float aspect = selectedTitle.AspectRatio;\r
+            int aw;\r
+            int ah;\r
+            if (aspect.ToString() == "1.78")\r
+            {\r
+                aw = 16;\r
+                ah = 9;\r
+            }\r
+            else\r
+            {\r
+                aw = 4;\r
+                ah = 3;\r
+            }\r
+\r
+            double a = width * selectedTitle.Resolution.Width * ah * (selectedTitle.Resolution.Height - (double)top - (double)bottom);\r
+            double b = selectedTitle.Resolution.Height * aw * (selectedTitle.Resolution.Width - (double)left - (double)right);\r
+\r
+            double y = a / b;\r
+\r
+            // If it's not Mod 16, make it mod 16\r
+            if ((y % 16) != 0)\r
+            {\r
+                double mod16 = y % 16;\r
+                if (mod16 >= 8)\r
+                {\r
+                    mod16 = 16 - mod16;\r
+                    y = y + mod16;\r
+                }\r
+                else\r
+                {\r
+                    y = y - mod16;\r
+                }\r
+            }\r
+\r
+            //16 * (421 / 16)\r
+            //double z = ( 16 * (( y + 8 ) / 16 ) );\r
+            int x = int.Parse(y.ToString());\r
+            return x;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Select the longest title in the DVD title dropdown menu on frmMain\r
+        /// </summary>\r
+        public Handbrake.Parsing.Title selectLongestTitle(ComboBox drp_dvdtitle)\r
+        {\r
+            int current_largest = 0;\r
+            Handbrake.Parsing.Title title2Select;\r
+\r
+            // Check if there are titles in the DVD title dropdown menu and make sure, it's not just "Automatic"\r
+            if (drp_dvdtitle.Items[0].ToString() != "Automatic")\r
+                title2Select = (Handbrake.Parsing.Title)drp_dvdtitle.Items[0];\r
+            else\r
+                title2Select = null;\r
+\r
+            // So, If there are titles in the DVD Title dropdown menu, lets select the longest.\r
+            if (title2Select != null)\r
+            {\r
+                foreach (Handbrake.Parsing.Title x in drp_dvdtitle.Items)\r
+                {\r
+                    string title = x.ToString();\r
+                    if (title != "Automatic")\r
+                    {\r
+                        string[] y = title.Split(' ');\r
+                        string time = y[1].Replace("(", "").Replace(")", "");\r
+                        string[] z = time.Split(':');\r
+\r
+                        int hours = int.Parse(z[0]) * 60 * 60;\r
+                        int minutes = int.Parse(z[1]) * 60;\r
+                        int seconds = int.Parse(z[2]);\r
+                        int total_sec = hours + minutes + seconds;\r
+\r
+                        if (current_largest == 0)\r
+                        {\r
+                            current_largest = hours + minutes + seconds;\r
+                            title2Select = x;\r
+                        }\r
+                        else\r
+                        {\r
+                            if (total_sec > current_largest)\r
+                            {\r
+                                current_largest = total_sec;\r
+                                title2Select = x;\r
+                            }\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+            return title2Select;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Set's up the DataGridView on the Chapters tab (frmMain)\r
+        /// </summary>\r
+        /// <param name="mainWindow"></param>\r
+        public DataGridView chapterNaming(DataGridView data_chpt, string chapter_start, string chapter_end)\r
+        {\r
+            try\r
+            {\r
+                int i = 0;\r
+                int rowCount = 0;\r
+                int start = 0;\r
+                int finish = 0;\r
+                if (chapter_end != "Auto")\r
+                    finish = int.Parse(chapter_end);\r
+\r
+                if (chapter_start != "Auto")\r
+                    start = int.Parse(chapter_start);\r
+\r
+                rowCount = finish - (start - 1);\r
+\r
+                while (i < rowCount)\r
+                {\r
+                    DataGridViewRow row = new DataGridViewRow();\r
+\r
+                    data_chpt.Rows.Insert(i, row);\r
+                    data_chpt.Rows[i].Cells[0].Value = (i + 1);\r
+                    data_chpt.Rows[i].Cells[1].Value = "Chapter " + (i + 1);\r
+                    i++;\r
+                }\r
+                return data_chpt;\r
+            }\r
+            catch (Exception exc)\r
+            {\r
+                MessageBox.Show("chapterNaming() Error has occured: \n" + exc.ToString());\r
+                return null;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Function which generates the filename and path automatically based on \r
+        /// the Source Name, DVD title and DVD Chapters\r
+        /// </summary>\r
+        /// <param name="mainWindow"></param>\r
+        public string autoName(ComboBox drp_dvdtitle, string chapter_start, string chatper_end, string source, string dest, int format)\r
+        {\r
+\r
+            string AutoNamePath = string.Empty;\r
+\r
+            if (drp_dvdtitle.Text != "Automatic")\r
+            {\r
+                // Todo: This code is a tad messy. Clean it up at some point.\r
+                // Get the Source Name\r
+                string[] sourceName = source.Split('\\');\r
+                source = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");\r
+\r
+                // Get the Selected Title Number\r
+                string title = drp_dvdtitle.Text;\r
+                string[] titlesplit = title.Split(' ');\r
+                title = titlesplit[0];\r
+\r
+                // Get the Chapter Start and Chapter End Numbers\r
+                string cs = chapter_start;\r
+                string cf = chatper_end;\r
+\r
+                // Just incase the above are set to their default Automatic values, set the varible to ""\r
+                if (title == "Automatic")\r
+                    title = "";\r
+                if (cs == "Auto")\r
+                    cs = "";\r
+                if (cf == "Auto")\r
+                    cf = "";\r
+\r
+                // If both CS and CF are populated, set the dash varible\r
+                string dash = "";\r
+                if (cf != "Auto")\r
+                    dash = "-";\r
+\r
+                // Get the destination filename.\r
+                string destination_filename = "";\r
+                if (Properties.Settings.Default.autoNameFormat != "")\r
+                {\r
+                    destination_filename = Properties.Settings.Default.autoNameFormat;\r
+                    destination_filename = destination_filename.Replace("{source}", source).Replace("{title}", title).Replace("{chapters}", cs + dash + cf);\r
+                }\r
+                else\r
+                    destination_filename = source + "_T" + title + "_C" + cs + dash + cf;\r
+\r
+                // If the text box is blank\r
+                if (!dest.Contains("\\"))\r
+                {\r
+                    string filePath = "";\r
+                    if (Properties.Settings.Default.autoNamePath.Trim() != "")\r
+                    {\r
+                        if (Properties.Settings.Default.autoNamePath.Trim() != "Click 'Browse' to set the default location")\r
+                            filePath = Properties.Settings.Default.autoNamePath + "\\";\r
+                    }\r
+\r
+                    if (format == 0)\r
+                        AutoNamePath = filePath + destination_filename + ".mp4";\r
+                    else if (format == 1)\r
+                        AutoNamePath = filePath + destination_filename + ".m4v";\r
+                    else if (format == 2)\r
+                        AutoNamePath = filePath + destination_filename + ".mkv";\r
+                    else if (format == 3)\r
+                        AutoNamePath = filePath + destination_filename + ".avi";\r
+                    else if (format == 4)\r
+                        AutoNamePath = filePath + destination_filename + ".ogm";\r
+                }\r
+                else // If the text box already has a path and file\r
+                {\r
+                    string destination = AutoNamePath;\r
+                    string[] destName = dest.Split('\\');\r
+                    string[] extension = dest.Split('.');\r
+                    string ext = extension[extension.Length - 1];\r
+\r
+                    destName[destName.Length - 1] = destination_filename + "." + ext;\r
+\r
+                    string fullDest = "";\r
+                    foreach (string part in destName)\r
+                    {\r
+                        if (fullDest != "")\r
+                            fullDest = fullDest + "\\" + part;\r
+                        else\r
+                            fullDest = fullDest + part;\r
+                    }\r
+                    return fullDest;\r
+                }\r
+            }\r
+            return AutoNamePath;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Checks for updates and returns true if an update is available.\r
+        /// </summary>\r
+        /// <param name="debug">Turns on debug mode. Don't use on program startup</param>\r
+        /// <returns>Boolean True = Update available</returns>\r
+        public Boolean updateCheck(Boolean debug)\r
+        {\r
+            try\r
+            {\r
+                Functions.AppcastReader rssRead = new Functions.AppcastReader();\r
+                rssRead.getInfo(); // Initializes the class.\r
+                string build = rssRead.build();\r
+\r
+                int latest = int.Parse(build);\r
+                int current = Properties.Settings.Default.hb_build;\r
+                int skip = Properties.Settings.Default.skipversion;\r
+\r
+                if (latest == skip)\r
+                    return false;\r
+                else\r
+                {\r
+                    Boolean update = (latest > current);\r
+                    return update;\r
+                }\r
+            }\r
+            catch (Exception exc)\r
+            {\r
+                if (debug == true)\r
+                    MessageBox.Show("Unable to check for updates, Please try again later. \n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                return false;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Get's HandBrakes version data from the CLI.\r
+        /// </summary>\r
+        /// <returns>Arraylist of Version Data. 0 = hb_version 1 = hb_build</returns>\r
+        public ArrayList getCliVersionData()\r
+        {\r
+            ArrayList cliVersionData = new ArrayList();\r
+            // 0 = SVN Build / Version\r
+            // 1 = Build Date\r
+\r
+            Process cliProcess = new Process();\r
+            ProcessStartInfo handBrakeCLI = new ProcessStartInfo("HandBrakeCLI.exe", " -u");\r
+            handBrakeCLI.UseShellExecute = false;\r
+            handBrakeCLI.RedirectStandardError = true;\r
+            handBrakeCLI.RedirectStandardOutput = true;\r
+            handBrakeCLI.CreateNoWindow = true;\r
+            cliProcess.StartInfo = handBrakeCLI;\r
+            cliProcess.Start();\r
+\r
+            // Retrieve standard output and report back to parent thread until the process is complete\r
+            String line;\r
+            TextReader stdOutput = cliProcess.StandardError;\r
+\r
+            while (!cliProcess.HasExited)\r
+            {\r
+                line = stdOutput.ReadLine();\r
+                Match m = Regex.Match(line, @"HandBrake [0-9\.]*svn[0-9]*[M]* \([0-9]*\)");\r
+                if (m.Success != false)\r
+                {\r
+                    string data = line.Replace("(", "").Replace(")", "").Replace("HandBrake ", "");\r
+                    string[] arr = data.Split(' ');\r
+                    cliVersionData.Add(arr[0]);\r
+                    cliVersionData.Add(arr[1]);\r
+                    return cliVersionData;\r
+                }\r
+            }\r
+            return null;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Check if the queue recovery file contains records.\r
+        /// If it does, it means the last queue did not complete before HandBrake closed.\r
+        /// So, return a boolean if true. \r
+        /// </summary>\r
+        public Boolean check_queue_recovery()\r
+        {\r
+            try\r
+            {\r
+                string tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");\r
+                using (StreamReader reader = new StreamReader(tempPath))\r
+                {\r
+                    string queue_item = reader.ReadLine();\r
+                    if (queue_item == null)\r
+                    {\r
+                        reader.Close();\r
+                        reader.Dispose();\r
+                        return false;\r
+                    }\r
+                    else // There exists an item in the recovery queue file, so try and recovr it.\r
+                    {\r
+                        reader.Close();\r
+                        reader.Dispose();\r
+                        return true;\r
+                    }\r
+                }\r
+            }\r
+            catch (Exception)\r
+            {\r
+                // Keep quiet about the error.\r
+                return false;\r
+            }\r
+        }\r
+\r
+    }\r
+}
\ No newline at end of file
index a1809da..5a4c605 100644 (file)
     <Compile Include="frmUpdater.designer.cs">\r
       <DependentUpon>frmUpdater.cs</DependentUpon>\r
     </Compile>\r
-    <Compile Include="Functions\QueryGenerator.cs" />\r
+    <Compile Include="frmMain\PresetLoader.cs" />\r
+    <Compile Include="frmMain\QueryGenerator.cs" />\r
     <Compile Include="Functions\SystemInfo.cs" />\r
-    <Compile Include="Functions\Common.cs" />\r
+    <Compile Include="Functions\Main.cs" />\r
     <Compile Include="Functions\Presets.cs" />\r
     <Compile Include="Functions\Queue.cs" />\r
     <Compile Include="Functions\AppcastReader.cs" />\r
     <Compile Include="Functions\Encode.cs" />\r
     <Compile Include="Functions\QueryParser.cs" />\r
-    <Compile Include="Functions\x264Panel.cs" />\r
+    <Compile Include="frmMain\x264Panel.cs" />\r
     <Compile Include="Parsing\AudioTrack.cs" />\r
     <Compile Include="Parsing\Chapter.cs" />\r
     <Compile Include="Parsing\DVD.cs" />\r
index c2f754f..bc27437 100644 (file)
@@ -17,21 +17,20 @@ namespace Handbrake
 {\r
     public partial class frmAddPreset : Form\r
     {\r
-        Functions.QueryGenerator queryGen = new Functions.QueryGenerator();\r
         private frmMain frmMainWindow;\r
         Functions.Presets presetCode;\r
-\r
-        public frmAddPreset(frmMain fmw, Functions.Presets presetHandler)\r
+        private string query = "";\r
+   \r
+        public frmAddPreset(frmMain fmw, string query_string, Functions.Presets presetHandler)\r
         {\r
             InitializeComponent();\r
             frmMainWindow = fmw;\r
             presetCode = presetHandler;\r
+            this.query = query_string;\r
         }\r
 \r
         private void btn_add_Click(object sender, EventArgs e)\r
         {\r
-            String query = queryGen.generateTabbedComponentsQuery(frmMainWindow);\r
-\r
             if (presetCode.addPreset(txt_preset_name.Text.Trim(), query) == true)\r
             {\r
                 frmMainWindow.loadPresetPanel();\r
index 09ecf5e..ec99539 100644 (file)
@@ -38,7 +38,7 @@ namespace Handbrake
             System.Windows.Forms.Label Label38;\r
             System.Windows.Forms.ContextMenuStrip notifyIconMenu;\r
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain));\r
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();\r
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();\r
             this.btn_restore = new System.Windows.Forms.ToolStripMenuItem();\r
             this.DVD_Save = new System.Windows.Forms.SaveFileDialog();\r
             this.File_Save = new System.Windows.Forms.SaveFileDialog();\r
@@ -641,9 +641,9 @@ namespace Handbrake
             // \r
             // number\r
             // \r
-            dataGridViewCellStyle2.Format = "N0";\r
-            dataGridViewCellStyle2.NullValue = null;\r
-            this.number.DefaultCellStyle = dataGridViewCellStyle2;\r
+            dataGridViewCellStyle1.Format = "N0";\r
+            dataGridViewCellStyle1.NullValue = null;\r
+            this.number.DefaultCellStyle = dataGridViewCellStyle1;\r
             this.number.HeaderText = "Chapter Number";\r
             this.number.MaxInputLength = 3;\r
             this.number.Name = "number";\r
@@ -3384,7 +3384,6 @@ namespace Handbrake
         private System.Windows.Forms.ToolStripMenuItem btn_new_preset;\r
         private System.Windows.Forms.ToolStripMenuItem mnu_handbrake_forums;\r
         private System.Windows.Forms.ToolStripMenuItem mnu_user_guide;\r
-        private System.Windows.Forms.ToolStripMenuItem mnu_dvd_drive;\r
         private System.Windows.Forms.ToolStripDropDownButton btn_source;\r
         private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;\r
         private System.Windows.Forms.ToolStripMenuItem btn_dvd_source;\r
@@ -3402,6 +3401,7 @@ namespace Handbrake
         internal System.Windows.Forms.Label label8;\r
         internal System.Windows.Forms.OpenFileDialog ISO_Open;\r
         internal System.Windows.Forms.FolderBrowserDialog DVD_Open;\r
+        internal System.Windows.Forms.ToolStripMenuItem mnu_dvd_drive;\r
 \r
     }\r
 }
\ No newline at end of file
index 5c74029..7b91e2e 100644 (file)
@@ -22,13 +22,18 @@ namespace Handbrake
     public partial class frmMain : Form\r
     {\r
         // Declarations *******************************************************\r
-        Functions.Common hb_common_func = new Functions.Common();\r
-        Functions.x264Panel x264PanelFunctions = new Functions.x264Panel();\r
+        // Objects which may be used by one or more other objects\r
+        Functions.Main hb_common_func = new Functions.Main();\r
         Functions.Encode cliObj = new Functions.Encode();\r
         Functions.Queue encodeQueue = new Functions.Queue();\r
         Functions.Presets presetHandler = new Functions.Presets();\r
-        Functions.QueryGenerator queryGen = new Functions.QueryGenerator();\r
         Parsing.Title selectedTitle;\r
+\r
+        // Objects belonging to this window only\r
+        PresetLoader presetLoader = new PresetLoader();\r
+        x264Panel x264PanelFunctions = new x264Panel();\r
+        QueryGenerator queryGen = new QueryGenerator();\r
+\r
         internal Process hbProc;\r
         private Parsing.DVD thisDVD;\r
         private frmQueue queueWindow;\r
@@ -47,7 +52,6 @@ namespace Handbrake
 \r
             // Initialize the queue window.\r
             queueWindow = new frmQueue(this);\r
-\r
             //Create a label that can be updated from the parent thread.\r
             Label lblStatus = new Label();\r
             lblStatus.Size = new Size(250, 20);\r
@@ -166,7 +170,7 @@ namespace Handbrake
             else\r
             {\r
                 Functions.QueryParser presetQuery = Functions.QueryParser.Parse(userDefaults);\r
-                hb_common_func.presetLoader(this, presetQuery, "User Defaults ");\r
+                presetLoader.presetLoader(this, presetQuery, "User Defaults ");\r
             }\r
         }\r
         private void queueRecovery()\r
@@ -250,7 +254,7 @@ namespace Handbrake
         }\r
         private void btn_new_preset_Click(object sender, EventArgs e)\r
         {\r
-            Form preset = new frmAddPreset(this, presetHandler);\r
+            Form preset = new frmAddPreset(this, queryGen.GenerateTheQuery(this), presetHandler);\r
             preset.ShowDialog();\r
         }\r
         #endregion\r
@@ -528,16 +532,21 @@ namespace Handbrake
             }\r
 \r
             // Run the autoName & chapterNaming functions\r
-            hb_common_func.autoName(this);\r
-            hb_common_func.chapterNaming(this);\r
+            if (Properties.Settings.Default.autoNaming == "Checked")\r
+                text_destination.Text = hb_common_func.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, text_source.Text, text_destination.Text, drop_format.SelectedIndex);\r
+\r
+            data_chpt.Rows.Clear();\r
+            DataGridView chapterGridView = hb_common_func.chapterNaming(data_chpt, drop_chapterStart.Text, drop_chapterFinish.Text);\r
+            if (chapterGridView != null)\r
+                data_chpt = chapterGridView;\r
         }\r
         private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
             int c_start, c_end = 1;\r
 \r
             if (drop_chapterFinish.Text == "Auto" && drop_chapterFinish.Items.Count != 0)\r
-                drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count-1;\r
-           \r
+                drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;\r
+\r
             int.TryParse(drop_chapterStart.Text, out c_start);\r
             int.TryParse(drop_chapterFinish.Text, out c_end);\r
 \r
@@ -547,10 +556,11 @@ namespace Handbrake
                     drop_chapterFinish.Text = c_start.ToString();\r
             }\r
 \r
-            calculateDuration();\r
+            lbl_duration.Text = hb_common_func.calculateDuration(drop_chapterStart.Text, drop_chapterFinish.Text, selectedTitle).ToString();\r
 \r
             // Run the Autonaming function\r
-            hb_common_func.autoName(this);\r
+            if (Properties.Settings.Default.autoNaming == "Checked")\r
+                text_destination.Text = hb_common_func.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, text_source.Text, text_destination.Text, drop_format.SelectedIndex);\r
         }\r
         private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
@@ -568,10 +578,11 @@ namespace Handbrake
                     drop_chapterFinish.Text = c_start.ToString();\r
             }\r
 \r
-            calculateDuration();\r
+            lbl_duration.Text = hb_common_func.calculateDuration(drop_chapterStart.Text, drop_chapterFinish.Text, selectedTitle).ToString();\r
 \r
             // Run the Autonaming function\r
-            hb_common_func.autoName(this);\r
+            if (Properties.Settings.Default.autoNaming == "Checked")\r
+                text_destination.Text =  hb_common_func.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, text_source.Text, text_destination.Text, drop_format.SelectedIndex);\r
         }\r
 \r
         //Destination\r
@@ -617,17 +628,16 @@ namespace Handbrake
         // Output Settings\r
         private void drop_format_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
-\r
             if (drop_format.SelectedIndex == 0)\r
-                setExtension(".mp4");\r
+                text_destination.Text = hb_common_func.setExtension(text_destination.Text, ".mp4");\r
             else if (drop_format.SelectedIndex == 1)\r
-                setExtension(".m4v");\r
+                text_destination.Text = hb_common_func.setExtension(text_destination.Text, ".m4v");\r
             else if (drop_format.SelectedIndex == 2)\r
-                setExtension(".mkv");\r
+                text_destination.Text = hb_common_func.setExtension(text_destination.Text, ".mkv");\r
             else if (drop_format.SelectedIndex == 3)\r
-                setExtension(".avi");\r
+                text_destination.Text = hb_common_func.setExtension(text_destination.Text, ".avi");\r
             else if (drop_format.SelectedIndex == 4)\r
-                setExtension(".ogm");\r
+                text_destination.Text = hb_common_func.setExtension(text_destination.Text, ".ogm");\r
         }\r
 \r
         //Video Tab\r
@@ -730,7 +740,7 @@ namespace Handbrake
                 {\r
                     if (drp_anamorphic.Text == "None")\r
                     {\r
-                        int height = cacluateNonAnamorphicHeight(width);\r
+                        int height = hb_common_func.cacluateNonAnamorphicHeight(width, text_top.Value, text_bottom.Value,text_left.Value, text_right.Value, selectedTitle);\r
                         text_height.Text = height.ToString();\r
                     }\r
                 }\r
@@ -1212,7 +1222,9 @@ namespace Handbrake
                 text_destination.Text = destination;\r
                 data_chpt.Rows.Clear();\r
                 data_chpt.Enabled = true;\r
-                hb_common_func.chapterNaming(this);\r
+                DataGridView chapterGridView = hb_common_func.chapterNaming(data_chpt, drop_chapterStart.Text, drop_chapterFinish.Text);\r
+                if (chapterGridView != null)\r
+                    data_chpt = chapterGridView;\r
             }\r
             else\r
             {\r
@@ -1337,7 +1349,7 @@ namespace Handbrake
         // Presets\r
         private void btn_addPreset_Click(object sender, EventArgs e)\r
         {\r
-            Form preset = new frmAddPreset(this, presetHandler);\r
+            Form preset = new frmAddPreset(this, queryGen.GenerateTheQuery(this), presetHandler);\r
             preset.ShowDialog();\r
         }\r
         private void btn_removePreset_Click(object sender, EventArgs e)\r
@@ -1373,7 +1385,7 @@ namespace Handbrake
             Functions.QueryParser presetQuery = Functions.QueryParser.Parse(query);\r
 \r
             // Now load the preset\r
-            hb_common_func.presetLoader(this, presetQuery, presetName);\r
+            presetLoader.presetLoader(this, presetQuery, presetName);\r
 \r
             // The x264 widgets will need updated, so do this now:\r
             x264PanelFunctions.X264_StandardizeOptString(this);\r
@@ -1397,97 +1409,60 @@ namespace Handbrake
         #endregion\r
 \r
         #region Functions\r
-        // Replace File extenstion.\r
-        public void setExtension(string newExtension)\r
-        {\r
-            text_destination.Text = text_destination.Text.Replace(".mp4", newExtension);\r
-            text_destination.Text = text_destination.Text.Replace(".m4v", newExtension);\r
-            text_destination.Text = text_destination.Text.Replace(".mkv", newExtension);\r
-            text_destination.Text = text_destination.Text.Replace(".avi", newExtension);\r
-            text_destination.Text = text_destination.Text.Replace(".ogm", newExtension);\r
-        }\r
-\r
-        // DVD Parsing\r
-        public void setStreamReader(Parsing.DVD dvd)\r
+        private void loadNormalPreset()\r
         {\r
-            this.thisDVD = dvd;\r
+            foreach (TreeNode treenode in treeView_presets.Nodes)\r
+            {\r
+                if (treenode.Text.ToString().Equals("Normal"))\r
+                    treeView_presets.SelectedNode = treeView_presets.Nodes[treenode.Index];\r
+            }\r
         }\r
-\r
-        // Chapter Selection Duration calculation\r
-        public void calculateDuration()\r
+        #endregion\r
+        \r
+        #region Drive Detection\r
+        // Source Button Drive Detection\r
+        private delegate void ProgressUpdateHandler();\r
+        private void getDriveInfoThread()\r
         {\r
-            TimeSpan Duration = TimeSpan.FromSeconds(0.0);\r
-\r
-            // Get the durations between the 2 chapter points and add them together.\r
-            if (drop_chapterStart.Text != "Auto" && drop_chapterFinish.Text != "Auto")\r
+            try\r
             {\r
-                int start_chapter, end_chapter = 0;\r
-                int.TryParse(drop_chapterStart.Text, out start_chapter);\r
-                int.TryParse(drop_chapterFinish.Text, out end_chapter);\r
-\r
-                int position = start_chapter - 1;\r
-\r
-                if (start_chapter <= end_chapter)\r
+                if (this.InvokeRequired)\r
                 {\r
-                    if (end_chapter > selectedTitle.Chapters.Count)\r
-                        end_chapter = selectedTitle.Chapters.Count;\r
+                    this.BeginInvoke(new ProgressUpdateHandler(getDriveInfoThread));\r
+                    return;\r
+                }\r
 \r
-                    while (position != end_chapter)\r
+                Boolean foundDrive = false;\r
+                DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();\r
+                foreach (DriveInfo curDrive in theCollectionOfDrives)\r
+                {\r
+                    if (curDrive.DriveType == DriveType.CDRom)\r
                     {\r
-                        TimeSpan dur = selectedTitle.Chapters[position].Duration;\r
-                        Duration = Duration + dur;\r
-                        position++;\r
+                        if (curDrive.IsReady)\r
+                        {\r
+                            if (File.Exists(curDrive.RootDirectory.ToString() + "VIDEO_TS\\VIDEO_TS.IFO"))\r
+                                mnu_dvd_drive.Text = curDrive.RootDirectory.ToString() + "VIDEO_TS (" + curDrive.VolumeLabel + ")";\r
+                            else\r
+                                mnu_dvd_drive.Text = "[No DVD Drive Ready]";\r
+\r
+                            foundDrive = true;\r
+\r
+                        }\r
                     }\r
                 }\r
-            }\r
 \r
-            // Set the Duration\r
-            lbl_duration.Text = Duration.ToString();\r
-        }\r
-        public int cacluateNonAnamorphicHeight(int width)\r
-        {\r
-            float aspect = selectedTitle.AspectRatio;\r
-            int aw;\r
-            int ah;\r
-            if (aspect.ToString() == "1.78")\r
-            {\r
-                aw = 16;\r
-                ah = 9;\r
-            }\r
-            else\r
-            {\r
-                aw = 4;\r
-                ah = 3;\r
+                if (foundDrive == false)\r
+                    mnu_dvd_drive.Text = "[No DVD Drive Ready]";\r
             }\r
-\r
-            double a = width * selectedTitle.Resolution.Width * ah * (selectedTitle.Resolution.Height - (double)text_top.Value - (double)text_bottom.Value);\r
-            double b = selectedTitle.Resolution.Height * aw * (selectedTitle.Resolution.Width - (double)text_left.Value - (double)text_right.Value);\r
-\r
-            double y = a / b;\r
-\r
-            // If it's not Mod 16, make it mod 16\r
-            if ((y % 16) != 0)\r
+            catch (Exception)\r
             {\r
-                double mod16 = y % 16;\r
-                if (mod16 >= 8)\r
-                {\r
-                    mod16 = 16 - mod16;\r
-                    y = y + mod16;\r
-                }\r
-                else\r
-                {\r
-                    y = y - mod16;\r
-                }\r
+                mnu_dvd_drive.Text = "[No DVD Drive Ready / Found]";\r
             }\r
-\r
-            //16 * (421 / 16)\r
-            //double z = ( 16 * (( y + 8 ) / 16 ) );\r
-            int x = int.Parse(y.ToString());\r
-            return x;\r
         }\r
+        #endregion\r
 \r
-        // Audio system functions\r
-        private void setAudioByContainer(String path)\r
+        #region Audio Panel Stuff\r
+        public void setAudioByContainer(String path)\r
         {\r
             string oldval = "";\r
 \r
@@ -1636,7 +1611,7 @@ namespace Handbrake
                 }\r
             }\r
         }\r
-        private void setVideoByContainer(String path)\r
+        public void setVideoByContainer(String path)\r
         {\r
             string oldval = "";\r
 \r
@@ -1688,7 +1663,7 @@ namespace Handbrake
                 drp_videoEncoder.Text = oldval;\r
             }\r
         }\r
-        private void setBitrateSelections384(ComboBox dropDown)\r
+        public void setBitrateSelections384(ComboBox dropDown)\r
         {\r
             dropDown.Items.Clear();\r
             dropDown.Items.Add("32");\r
@@ -1707,7 +1682,7 @@ namespace Handbrake
             dropDown.Items.Add("320");\r
             dropDown.Items.Add("384");\r
         }\r
-        private void setBitrateSelections320(ComboBox dropDown)\r
+        public void setBitrateSelections320(ComboBox dropDown)\r
         {\r
             dropDown.Items.Clear();\r
             dropDown.Items.Add("32");\r
@@ -1725,7 +1700,7 @@ namespace Handbrake
             dropDown.Items.Add("256");\r
             dropDown.Items.Add("320");\r
         }\r
-        private void setBitrateSelections160(ComboBox dropDown)\r
+        public void setBitrateSelections160(ComboBox dropDown)\r
         {\r
             dropDown.Items.Clear();\r
             dropDown.Items.Add("32");\r
@@ -1739,84 +1714,6 @@ namespace Handbrake
             dropDown.Items.Add("128");\r
             dropDown.Items.Add("160");\r
         }\r
-\r
-        // Preset system functions\r
-        private void loadNormalPreset()\r
-        {\r
-            foreach (TreeNode treenode in treeView_presets.Nodes)\r
-            {\r
-                if (treenode.Text.ToString().Equals("Normal"))\r
-                    treeView_presets.SelectedNode = treeView_presets.Nodes[treenode.Index];\r
-            }\r
-        }\r
-        public void loadPresetPanel()\r
-        {\r
-            presetHandler.loadPresetFiles();\r
-\r
-            treeView_presets.Nodes.Clear();\r
-            List<string> presetNameList = new List<string>();\r
-            TreeNode preset_treeview = new TreeNode();          \r
-\r
-            presetNameList = presetHandler.getBuildInPresetNames();\r
-            foreach (string preset in presetNameList)\r
-            {\r
-                preset_treeview = new TreeNode(preset);\r
-\r
-                // Now Fill Out List View with Items\r
-                treeView_presets.Nodes.Add(preset_treeview);\r
-            }\r
-\r
-            presetNameList = presetHandler.getUserPresetNames();\r
-            foreach (string preset in presetNameList)\r
-            {\r
-                preset_treeview = new TreeNode(preset);\r
-                preset_treeview.ForeColor = Color.Black;\r
-\r
-                // Now Fill Out List View with Items\r
-                treeView_presets.Nodes.Add(preset_treeview);\r
-            }\r
-        }\r
-\r
-        // Source Button Drive Detection\r
-        private delegate void ProgressUpdateHandler();\r
-        private void getDriveInfoThread()\r
-        {\r
-            try\r
-            {\r
-                if (this.InvokeRequired)\r
-                {\r
-                    this.BeginInvoke(new ProgressUpdateHandler(getDriveInfoThread));\r
-                    return;\r
-                }\r
-\r
-                Boolean foundDrive = false;\r
-                DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();\r
-                foreach (DriveInfo curDrive in theCollectionOfDrives)\r
-                {\r
-                    if (curDrive.DriveType == DriveType.CDRom)\r
-                    {\r
-                        if (curDrive.IsReady)\r
-                        {\r
-                            if (File.Exists(curDrive.RootDirectory.ToString() + "VIDEO_TS\\VIDEO_TS.IFO"))\r
-                                mnu_dvd_drive.Text = curDrive.RootDirectory.ToString() + "VIDEO_TS (" + curDrive.VolumeLabel + ")";\r
-                            else\r
-                                mnu_dvd_drive.Text = "[No DVD Drive Ready]";\r
-\r
-                            foundDrive = true;\r
-\r
-                        }\r
-                    }\r
-                }\r
-\r
-                if (foundDrive == false)\r
-                    mnu_dvd_drive.Text = "[No DVD Drive Ready]";\r
-            }\r
-            catch (Exception)\r
-            {\r
-                mnu_dvd_drive.Text = "[No DVD Drive Ready / Found]";\r
-            }\r
-        }\r
-\r
         #endregion\r
 \r
         #region Encoding\r
@@ -1876,6 +1773,7 @@ namespace Handbrake
             else\r
                 return true;\r
         }\r
+\r
         /// <summary>\r
         /// Action can be "encode" or "scan"\r
         /// Set the last action varible in the main window.\r
@@ -1886,6 +1784,48 @@ namespace Handbrake
         {\r
             this.lastAction = last;\r
         }\r
+\r
+        /// <summary>\r
+        /// DVD parseing. Pass in a parsed DVD.\r
+        /// </summary>\r
+        /// <param name="dvd"></param>\r
+        public void setStreamReader(Parsing.DVD dvd)\r
+        {\r
+            this.thisDVD = dvd;\r
+        }\r
+\r
+\r
+        /// <summary>\r
+        /// Reload the preset panel display\r
+        /// </summary>\r
+        public void loadPresetPanel()\r
+        {\r
+            presetHandler.loadPresetFiles();\r
+\r
+            treeView_presets.Nodes.Clear();\r
+            List<string> presetNameList = new List<string>();\r
+            TreeNode preset_treeview = new TreeNode();\r
+\r
+            presetNameList = presetHandler.getBuildInPresetNames();\r
+            foreach (string preset in presetNameList)\r
+            {\r
+                preset_treeview = new TreeNode(preset);\r
+\r
+                // Now Fill Out List View with Items\r
+                treeView_presets.Nodes.Add(preset_treeview);\r
+            }\r
+\r
+            presetNameList = presetHandler.getUserPresetNames();\r
+            foreach (string preset in presetNameList)\r
+            {\r
+                preset_treeview = new TreeNode(preset);\r
+                preset_treeview.ForeColor = Color.Black;\r
+\r
+                // Now Fill Out List View with Items\r
+                treeView_presets.Nodes.Add(preset_treeview);\r
+            }\r
+        }\r
+\r
         #endregion\r
 \r
         #region Taskbar Tray Icon\r
index ed1b7ad..7636871 100644 (file)
@@ -155,12 +155,6 @@ Make sure you have selected a "Title" from the "Source" box above otherwise
 the list will not be populated with the correct amount of chapters.\r
 Note: Do not change any of the chapter numbers!</value>\r
   </data>\r
-  <metadata name="number.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">\r
-    <value>True</value>\r
-  </metadata>\r
-  <metadata name="name.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">\r
-    <value>True</value>\r
-  </metadata>\r
   <data name="check_Cabac.ToolTip" xml:space="preserve">\r
     <value>CABAC, or context adaptive binary arithmetic coding, is used by x264 to reduce the bitrate needed for a given quality by 15%. \r
 This makes it very cool and very useful, and it should be left on whenever possible. However, it is incompatible with the iPod 5.5G, and makes the AppleTV struggle. \r
similarity index 51%
rename from win/C#/Functions/Common.cs
rename to win/C#/frmMain/PresetLoader.cs
index 2748400..c42f820 100644 (file)
@@ -1,24 +1,13 @@
-/*  Common.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
-\r
-using System;\r
-using System.Collections;\r
+using System;\r
+using System.Collections.Generic;\r
 using System.Text;\r
 using System.Windows.Forms;\r
-using System.Globalization;\r
-using System.IO;\r
 using System.Drawing;\r
-using System.Diagnostics;\r
-using System.Text.RegularExpressions;\r
 \r
-namespace Handbrake.Functions\r
+namespace Handbrake\r
 {\r
-    class Common\r
+    class PresetLoader\r
     {\r
-\r
         /// <summary>\r
         /// This function takes in a Query which has been parsed by QueryParser and\r
         /// set's all the GUI widgets correctly.\r
@@ -358,295 +347,5 @@ namespace Handbrake.Functions
             mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";\r
             #endregion\r
         }\r
-\r
-        /// <summary>\r
-        /// Select the longest title in the DVD title dropdown menu on frmMain\r
-        /// </summary>\r
-        public void selectLongestTitle(frmMain mainWindow)\r
-        {\r
-            int current_largest = 0;\r
-            Handbrake.Parsing.Title title2Select;\r
-\r
-            // Check if there are titles in the DVD title dropdown menu and make sure, it's not just "Automatic"\r
-            if (mainWindow.drp_dvdtitle.Items[0].ToString() != "Automatic")\r
-                title2Select = (Handbrake.Parsing.Title)mainWindow.drp_dvdtitle.Items[0];\r
-            else\r
-                title2Select = null;\r
-\r
-            // So, If there are titles in the DVD Title dropdown menu, lets select the longest.\r
-            if (title2Select != null)\r
-            {\r
-                foreach (Handbrake.Parsing.Title x in mainWindow.drp_dvdtitle.Items)\r
-                {\r
-                    string title = x.ToString();\r
-                    if (title != "Automatic")\r
-                    {\r
-                        string[] y = title.Split(' ');\r
-                        string time = y[1].Replace("(", "").Replace(")", "");\r
-                        string[] z = time.Split(':');\r
-\r
-                        int hours = int.Parse(z[0]) * 60 * 60;\r
-                        int minutes = int.Parse(z[1]) * 60;\r
-                        int seconds = int.Parse(z[2]);\r
-                        int total_sec = hours + minutes + seconds;\r
-\r
-                        if (current_largest == 0)\r
-                        {\r
-                            current_largest = hours + minutes + seconds;\r
-                            title2Select = x;\r
-                        }\r
-                        else\r
-                        {\r
-                            if (total_sec > current_largest)\r
-                            {\r
-                                current_largest = total_sec;\r
-                                title2Select = x;\r
-                            }\r
-                        }\r
-                    }\r
-                }\r
-\r
-                // Now set the longest title in the gui.\r
-                mainWindow.drp_dvdtitle.SelectedItem = title2Select;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Set's up the DataGridView on the Chapters tab (frmMain)\r
-        /// </summary>\r
-        /// <param name="mainWindow"></param>\r
-        public void chapterNaming(frmMain mainWindow)\r
-        {\r
-            try\r
-            {\r
-                mainWindow.data_chpt.Rows.Clear();\r
-                int i = 0;\r
-                int rowCount = 0;\r
-                int start = 0;\r
-                int finish = 0;\r
-                if (mainWindow.drop_chapterFinish.Text != "Auto")\r
-                    finish = int.Parse(mainWindow.drop_chapterFinish.Text);\r
-\r
-                if (mainWindow.drop_chapterStart.Text != "Auto")\r
-                    start = int.Parse(mainWindow.drop_chapterStart.Text);\r
-\r
-                rowCount = finish - (start - 1);\r
-\r
-                while (i < rowCount)\r
-                {\r
-                    DataGridViewRow row = new DataGridViewRow();\r
-\r
-                    mainWindow.data_chpt.Rows.Insert(i, row);\r
-                    mainWindow.data_chpt.Rows[i].Cells[0].Value = (i + 1);\r
-                    mainWindow.data_chpt.Rows[i].Cells[1].Value = "Chapter " + (i + 1);\r
-                    i++;\r
-                }\r
-            }\r
-            catch (Exception exc)\r
-            {\r
-                MessageBox.Show("chapterNaming() Error has occured: \n" + exc.ToString());\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Function which generates the filename and path automatically based on \r
-        /// the Source Name, DVD title and DVD Chapters\r
-        /// </summary>\r
-        /// <param name="mainWindow"></param>\r
-        public void autoName(frmMain mainWindow)\r
-        {\r
-            if (Properties.Settings.Default.autoNaming == "Checked")\r
-            {\r
-                if (mainWindow.drp_dvdtitle.Text != "Automatic")\r
-                {\r
-                    // Todo: This code is a tad messy. Clean it up at some point.\r
-                    // Get the Source Name\r
-                    string source = mainWindow.text_source.Text;\r
-                    string[] sourceName = source.Split('\\');\r
-                    source = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");\r
-\r
-                    // Get the Selected Title Number\r
-                    string title = mainWindow.drp_dvdtitle.Text;\r
-                    string[] titlesplit = title.Split(' ');\r
-                    title = titlesplit[0];\r
-\r
-                    // Get the Chapter Start and Chapter End Numbers\r
-                    string cs = mainWindow.drop_chapterStart.Text;\r
-                    string cf = mainWindow.drop_chapterFinish.Text;\r
-\r
-                    // Just incase the above are set to their default Automatic values, set the varible to ""\r
-                    if (title == "Automatic")\r
-                        title = "";\r
-                    if (cs == "Auto")\r
-                        cs = "";\r
-                    if (cf == "Auto")\r
-                        cf = "";\r
-\r
-                    // If both CS and CF are populated, set the dash varible\r
-                    string dash = "";\r
-                    if (cf != "Auto")\r
-                        dash = "-";\r
-\r
-                    // Get the destination filename.\r
-                    string destination_filename = "";\r
-                    if (Properties.Settings.Default.autoNameFormat != "")\r
-                    {\r
-                        destination_filename = Properties.Settings.Default.autoNameFormat;\r
-                        destination_filename = destination_filename.Replace("{source}", source).Replace("{title}", title).Replace("{chapters}", cs + dash + cf);\r
-                    }\r
-                    else\r
-                        destination_filename = source + "_T" + title + "_C" + cs + dash + cf;\r
-\r
-                    // If the text box is blank\r
-                    if (!mainWindow.text_destination.Text.Contains("\\"))\r
-                    {\r
-                        string filePath = "";\r
-                        if (Properties.Settings.Default.autoNamePath.Trim() != "")\r
-                        {\r
-                            if (Properties.Settings.Default.autoNamePath.Trim() != "Click 'Browse' to set the default location")\r
-                                filePath = Properties.Settings.Default.autoNamePath + "\\";\r
-                        }\r
-\r
-                        if (mainWindow.drop_format.SelectedIndex == 0)\r
-                            mainWindow.text_destination.Text = filePath + destination_filename + ".mp4";\r
-                        else if (mainWindow.drop_format.SelectedIndex == 1)\r
-                            mainWindow.text_destination.Text = filePath + destination_filename + ".m4v";\r
-                        else if (mainWindow.drop_format.SelectedIndex == 2)\r
-                            mainWindow.text_destination.Text = filePath + destination_filename + ".mkv";\r
-                        else if (mainWindow.drop_format.SelectedIndex == 3)\r
-                            mainWindow.text_destination.Text = filePath + destination_filename + ".avi";\r
-                        else if (mainWindow.drop_format.SelectedIndex == 4)\r
-                            mainWindow.text_destination.Text = filePath + destination_filename + ".ogm";\r
-                    }\r
-                    else // If the text box already has a path and file\r
-                    {\r
-                        string dest = mainWindow.text_destination.Text;\r
-                        string[] destName = dest.Split('\\');\r
-                        string[] extension = dest.Split('.');\r
-                        string ext = extension[extension.Length - 1];\r
-\r
-                        destName[destName.Length - 1] = destination_filename + "." + ext;\r
-\r
-                        string fullDest = "";\r
-                        foreach (string part in destName)\r
-                        {\r
-                            if (fullDest != "")\r
-                                fullDest = fullDest + "\\" + part;\r
-                            else\r
-                                fullDest = fullDest + part;\r
-                        }\r
-\r
-                        mainWindow.text_destination.Text = fullDest;\r
-                    }\r
-                }\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Checks for updates and returns true if an update is available.\r
-        /// </summary>\r
-        /// <param name="debug">Turns on debug mode. Don't use on program startup</param>\r
-        /// <returns>Boolean True = Update available</returns>\r
-        public Boolean updateCheck(Boolean debug)\r
-        {\r
-            try\r
-            {\r
-                Functions.AppcastReader rssRead = new Functions.AppcastReader();\r
-                rssRead.getInfo(); // Initializes the class.\r
-                string build = rssRead.build();\r
-\r
-                int latest = int.Parse(build);\r
-                int current = Properties.Settings.Default.hb_build;\r
-                int skip = Properties.Settings.Default.skipversion;\r
-\r
-                if (latest == skip)\r
-                    return false;\r
-                else\r
-                {\r
-                    Boolean update = (latest > current);\r
-                    return update;\r
-                }\r
-            }\r
-            catch (Exception exc)\r
-            {\r
-                if (debug == true)\r
-                    MessageBox.Show("Unable to check for updates, Please try again later. \n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-                return false;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Get's HandBrakes version data from the CLI.\r
-        /// </summary>\r
-        /// <returns>Arraylist of Version Data. 0 = hb_version 1 = hb_build</returns>\r
-        public ArrayList getCliVersionData()\r
-        {\r
-            ArrayList cliVersionData = new ArrayList();\r
-            // 0 = SVN Build / Version\r
-            // 1 = Build Date\r
-\r
-            Process cliProcess = new Process();\r
-            ProcessStartInfo handBrakeCLI = new ProcessStartInfo("HandBrakeCLI.exe", " -u");\r
-            handBrakeCLI.UseShellExecute = false;\r
-            handBrakeCLI.RedirectStandardError = true;\r
-            handBrakeCLI.RedirectStandardOutput = true;\r
-            handBrakeCLI.CreateNoWindow = true;\r
-            cliProcess.StartInfo = handBrakeCLI;\r
-            cliProcess.Start();\r
-\r
-            // Retrieve standard output and report back to parent thread until the process is complete\r
-            String line;\r
-            TextReader stdOutput = cliProcess.StandardError;\r
-\r
-            while (!cliProcess.HasExited)\r
-            {\r
-                line = stdOutput.ReadLine();\r
-                Match m = Regex.Match(line, @"HandBrake [0-9\.]*svn[0-9]*[M]* \([0-9]*\)");\r
-                if (m.Success != false)\r
-                {\r
-                    string data = line.Replace("(", "").Replace(")", "").Replace("HandBrake ", "");\r
-                    string[] arr = data.Split(' ');\r
-                    cliVersionData.Add(arr[0]);\r
-                    cliVersionData.Add(arr[1]);\r
-                    return cliVersionData;\r
-                }\r
-            }\r
-            return null;\r
-        }\r
-\r
-        /// <summary>\r
-        /// Check if the queue recovery file contains records.\r
-        /// If it does, it means the last queue did not complete before HandBrake closed.\r
-        /// So, return a boolean if true. \r
-        /// </summary>\r
-        public Boolean check_queue_recovery()\r
-        {\r
-            try\r
-            {\r
-                string tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");\r
-                using (StreamReader reader = new StreamReader(tempPath))\r
-                {\r
-                    string queue_item = reader.ReadLine();\r
-                    if (queue_item == null)\r
-                    {\r
-                        reader.Close();\r
-                        reader.Dispose();\r
-                        return false;\r
-                    }\r
-                    else // There exists an item in the recovery queue file, so try and recovr it.\r
-                    {\r
-                        reader.Close();\r
-                        reader.Dispose();\r
-                        return true;\r
-                    }\r
-                }\r
-            }\r
-            catch (Exception)\r
-            {\r
-                // Keep quiet about the error.\r
-                return false;\r
-            }\r
-        }\r
-\r
     }\r
-}
\ No newline at end of file
+}\r
similarity index 97%
rename from win/C#/Functions/QueryGenerator.cs
rename to win/C#/frmMain/QueryGenerator.cs
index aa4bdd3..b66e3f0 100644 (file)
@@ -5,7 +5,7 @@ using System.Windows.Forms;
 using System.Globalization;\r
 using System.IO;\r
 \r
-namespace Handbrake.Functions\r
+namespace Handbrake\r
 {\r
     class QueryGenerator\r
     {\r
similarity index 97%
rename from win/C#/Functions/x264Panel.cs
rename to win/C#/frmMain/x264Panel.cs
index 2701757..1358066 100644 (file)
@@ -3,11 +3,10 @@ using System.Collections.Generic;
 using System.Text;\r
 using System.Windows.Forms;\r
 \r
-namespace Handbrake.Functions\r
+namespace Handbrake\r
 {\r
     class x264Panel\r
     {\r
-\r
         /// <summary>\r
         /// Reset all components to defaults and clears the x264 rtf box\r
         /// </summary>\r
index ec9b318..4763934 100644 (file)
@@ -26,7 +26,7 @@ namespace Handbrake
         private Parsing.DVD thisDvd;\r
         private delegate void UpdateUIHandler();\r
         Process hbproc;\r
-        Functions.Common hb_common_func = new Functions.Common();\r
+        Functions.Main hb_common_func = new Functions.Main();\r
         Functions.Encode process = new Functions.Encode();\r
 \r
         public frmReadDVD(string inputFile, frmMain parent)\r
@@ -49,6 +49,7 @@ namespace Handbrake
                 MessageBox.Show("frmReadDVD.cs - startScan " + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
             }\r
         }\r
+\r
         private void startProc(object state)\r
         {\r
             try\r
@@ -112,7 +113,7 @@ namespace Handbrake
 \r
                 // Now select the longest title\r
                 if (thisDvd.Titles.Count != 0)\r
-                    hb_common_func.selectLongestTitle(mainWindow);\r
+                    mainWindow.drp_dvdtitle.SelectedItem = hb_common_func.selectLongestTitle(mainWindow.drp_dvdtitle);\r
 \r
                 this.Close();\r
             }\r
@@ -122,6 +123,7 @@ namespace Handbrake
                 this.Close();\r
             }\r
         }\r
+\r
         private void closeWindowAfterError()\r
         {\r
             try\r