]> granicus.if.org Git - handbrake/commitdiff
WinGui:
authorsr55 <sr55.hb@outlook.com>
Fri, 28 Nov 2008 19:57:05 +0000 (19:57 +0000)
committersr55 <sr55.hb@outlook.com>
Fri, 28 Nov 2008 19:57:05 +0000 (19:57 +0000)
- Fixes a problem with res calc.
- Cleans up the Main.cs file a bit.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1967 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/C#/Functions/Main.cs
win/C#/frmMain.cs

index 4018ea8969b88b1806f5ef44592e7bac4d1f7b14..52e4e0e046acc3ad76b6d5d681ebdec3648eaecc 100644 (file)
@@ -63,43 +63,47 @@ namespace Handbrake.Functions
         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
+            int aw = 0;\r
+            int ah = 0;\r
             if (aspect.ToString() == "1.78")\r
             {\r
                 aw = 16;\r
                 ah = 9;\r
             }\r
-            else\r
+            else if (aspect.ToString() == "1.33")\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
+            if (aw != 0)\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
+                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
+                // If it's not Mod 16, make it mod 16\r
+                if ((y % 16) != 0)\r
                 {\r
-                    y = y - mod16;\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
 \r
-            //16 * (421 / 16)\r
-            //double z = ( 16 * (( y + 8 ) / 16 ) );\r
-            int x = int.Parse(y.ToString());\r
-            return x;\r
+                //16 * (421 / 16)\r
+                //double z = ( 16 * (( y + 8 ) / 16 ) );\r
+                int x = int.Parse(y.ToString());\r
+                return x;\r
+            }\r
+            return 0;\r
         }\r
 \r
         /// <summary>\r
@@ -158,36 +162,26 @@ namespace Handbrake.Functions
         /// <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
+            int i = 0, rowCount = 0, start = 0, finish = 0;\r
 \r
-                if (chapter_start != "Auto")\r
-                    start = int.Parse(chapter_start);\r
+            if (chapter_end != "Auto")\r
+                int.TryParse(chapter_end, out finish);\r
 \r
-                rowCount = finish - (start - 1);\r
+            if (chapter_start != "Auto")\r
+                int.TryParse(chapter_start, out start);\r
 \r
-                while (i < rowCount)\r
-                {\r
-                    DataGridViewRow row = new DataGridViewRow();\r
+            rowCount = finish - (start - 1);\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
+            while (i < rowCount)\r
             {\r
-                MessageBox.Show("chapterNaming() Error has occured: \n" + exc.ToString());\r
-                return null;\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
 \r
         /// <summary>\r
@@ -197,49 +191,38 @@ namespace Handbrake.Functions
         /// <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
+                // Get the Source Name - THIS NEEDS FIXED\r
                 string[] sourceName = source.Split('\\');\r
                 source = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");\r
+                source.Replace(".wmv", "").Replace(".mp4", "").Replace(".m4v", "").Replace(".avi", "").Replace(".ogm", "").Replace(".tivo", "").Replace(".img", "");\r
+                source.Replace(".mov", "").Replace(".rm", "");\r
 \r
                 // Get the Selected Title Number\r
-                string title = drp_dvdtitle.Text;\r
-                string[] titlesplit = title.Split(' ');\r
-                title = titlesplit[0];\r
+                string[] titlesplit = drp_dvdtitle.Text.Split(' ');\r
+                string dvdTitle = titlesplit[0].Replace("Automatic", "");\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
+                string chapterStart = chapter_start.Replace("Auto", "");\r
+                string chapterFinish = chatper_end.Replace("Auto", "");\r
+                string combinedChapterTag = chapterStart;\r
+                if (chapterFinish != chapterStart && chapterFinish != "")\r
+                    combinedChapterTag = chapterStart + "-" + chapterFinish;\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
+                    destination_filename = destination_filename.Replace("{source}", source).Replace("{title}", dvdTitle).Replace("{chapters}", combinedChapterTag);\r
                 }\r
                 else\r
-                    destination_filename = source + "_T" + title + "_C" + cs + dash + cf;\r
+                    destination_filename = source + "_T" + dvdTitle + "_C" + combinedChapterTag;\r
 \r
-                // If the text box is blank\r
+                // Now work out the path where the file will be stored.\r
+                // First case: If the destination box doesn't already contain a path, make one.\r
                 if (!dest.Contains("\\"))\r
                 {\r
                     string filePath = "";\r
@@ -260,7 +243,7 @@ namespace Handbrake.Functions
                     else if (format == 4)\r
                         AutoNamePath = filePath + destination_filename + ".ogm";\r
                 }\r
-                else // If the text box already has a path and file\r
+                else // Otherwise, use the path that is already there.\r
                 {\r
                     string destination = AutoNamePath;\r
                     string[] destName = dest.Split('\\');\r
@@ -280,6 +263,7 @@ namespace Handbrake.Functions
                     return fullDest;\r
                 }\r
             }\r
+\r
             return AutoNamePath;\r
         }\r
 \r
@@ -361,7 +345,7 @@ namespace Handbrake.Functions
             {\r
                 MessageBox.Show("Unable to retrieve version information from the CLI. \nError:\n" + e);\r
             }\r
-     \r
+\r
             cliVersionData.Add(0);\r
             cliVersionData.Add("0");\r
             return cliVersionData;\r
index e7f31f688d62d4e08bb03d9250f2106e053ae2a3..fd9aa78aa6fdbec7f8497cbed9e437e3450d3802 100644 (file)
@@ -948,7 +948,7 @@ namespace Handbrake
         //Picture Tab\r
         private void text_width_TextChanged(object sender, EventArgs e)\r
         {\r
-            maxWidth = 0;  // Reset max width so that it's not using the MaxWidth -X. Quick hack to allow -X for preset usage.\r
+            maxWidth = 0; maxHeight = 0;  // Reset max width so that it's not using the MaxWidth -X. Quick hack to allow -X for preset usage.\r
 \r
             int width;\r
             Boolean parsed = int.TryParse(text_width.Text, out width);\r
@@ -960,12 +960,13 @@ namespace Handbrake
                     text_width.BackColor = Color.LightGreen;\r
 \r
 \r
-                if (lbl_Aspect.Text != "Select a Title" && maxWidth != 0 && maxHeight != 0)\r
+                if (lbl_Aspect.Text != "Select a Title" && maxWidth == 0 && maxHeight == 0)\r
                 {\r
                     if (drp_anamorphic.Text == "None")\r
                     {\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
+                        if (height != 0)\r
+                            text_height.Text = height.ToString();\r
                     }\r
                 }\r
             }\r