From 80eb2f5952cf5d0250be389f507355b31d42de6c Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 28 Nov 2008 19:57:05 +0000 Subject: [PATCH] WinGui: - 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 | 130 +++++++++++++++++---------------------- win/C#/frmMain.cs | 7 ++- 2 files changed, 61 insertions(+), 76 deletions(-) diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index 4018ea896..52e4e0e04 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -63,43 +63,47 @@ namespace Handbrake.Functions public int cacluateNonAnamorphicHeight(int width, decimal top, decimal bottom, decimal left, decimal right, Parsing.Title selectedTitle) { float aspect = selectedTitle.AspectRatio; - int aw; - int ah; + int aw = 0; + int ah = 0; if (aspect.ToString() == "1.78") { aw = 16; ah = 9; } - else + else if (aspect.ToString() == "1.33") { aw = 4; ah = 3; } - double a = width * selectedTitle.Resolution.Width * ah * (selectedTitle.Resolution.Height - (double)top - (double)bottom); - double b = selectedTitle.Resolution.Height * aw * (selectedTitle.Resolution.Width - (double)left - (double)right); + if (aw != 0) + { + double a = width * selectedTitle.Resolution.Width * ah * (selectedTitle.Resolution.Height - (double)top - (double)bottom); + double b = selectedTitle.Resolution.Height * aw * (selectedTitle.Resolution.Width - (double)left - (double)right); - double y = a / b; + double y = a / b; - // If it's not Mod 16, make it mod 16 - if ((y % 16) != 0) - { - double mod16 = y % 16; - if (mod16 >= 8) - { - mod16 = 16 - mod16; - y = y + mod16; - } - else + // If it's not Mod 16, make it mod 16 + if ((y % 16) != 0) { - y = y - mod16; + double mod16 = y % 16; + if (mod16 >= 8) + { + mod16 = 16 - mod16; + y = y + mod16; + } + else + { + y = y - mod16; + } } - } - //16 * (421 / 16) - //double z = ( 16 * (( y + 8 ) / 16 ) ); - int x = int.Parse(y.ToString()); - return x; + //16 * (421 / 16) + //double z = ( 16 * (( y + 8 ) / 16 ) ); + int x = int.Parse(y.ToString()); + return x; + } + return 0; } /// @@ -158,36 +162,26 @@ namespace Handbrake.Functions /// public DataGridView chapterNaming(DataGridView data_chpt, string chapter_start, string chapter_end) { - try - { - int i = 0; - int rowCount = 0; - int start = 0; - int finish = 0; - if (chapter_end != "Auto") - finish = int.Parse(chapter_end); + int i = 0, rowCount = 0, start = 0, finish = 0; - if (chapter_start != "Auto") - start = int.Parse(chapter_start); + if (chapter_end != "Auto") + int.TryParse(chapter_end, out finish); - rowCount = finish - (start - 1); + if (chapter_start != "Auto") + int.TryParse(chapter_start, out start); - while (i < rowCount) - { - DataGridViewRow row = new DataGridViewRow(); + rowCount = finish - (start - 1); - data_chpt.Rows.Insert(i, row); - data_chpt.Rows[i].Cells[0].Value = (i + 1); - data_chpt.Rows[i].Cells[1].Value = "Chapter " + (i + 1); - i++; - } - return data_chpt; - } - catch (Exception exc) + while (i < rowCount) { - MessageBox.Show("chapterNaming() Error has occured: \n" + exc.ToString()); - return null; + DataGridViewRow row = new DataGridViewRow(); + + data_chpt.Rows.Insert(i, row); + data_chpt.Rows[i].Cells[0].Value = (i + 1); + data_chpt.Rows[i].Cells[1].Value = "Chapter " + (i + 1); + i++; } + return data_chpt; } /// @@ -197,49 +191,38 @@ namespace Handbrake.Functions /// public string autoName(ComboBox drp_dvdtitle, string chapter_start, string chatper_end, string source, string dest, int format) { - string AutoNamePath = string.Empty; - if (drp_dvdtitle.Text != "Automatic") { - // Todo: This code is a tad messy. Clean it up at some point. - // Get the Source Name + // Get the Source Name - THIS NEEDS FIXED string[] sourceName = source.Split('\\'); source = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", ""); + source.Replace(".wmv", "").Replace(".mp4", "").Replace(".m4v", "").Replace(".avi", "").Replace(".ogm", "").Replace(".tivo", "").Replace(".img", ""); + source.Replace(".mov", "").Replace(".rm", ""); // Get the Selected Title Number - string title = drp_dvdtitle.Text; - string[] titlesplit = title.Split(' '); - title = titlesplit[0]; + string[] titlesplit = drp_dvdtitle.Text.Split(' '); + string dvdTitle = titlesplit[0].Replace("Automatic", ""); // Get the Chapter Start and Chapter End Numbers - string cs = chapter_start; - string cf = chatper_end; - - // Just incase the above are set to their default Automatic values, set the varible to "" - if (title == "Automatic") - title = ""; - if (cs == "Auto") - cs = ""; - if (cf == "Auto") - cf = ""; - - // If both CS and CF are populated, set the dash varible - string dash = ""; - if (cf != "Auto") - dash = "-"; + string chapterStart = chapter_start.Replace("Auto", ""); + string chapterFinish = chatper_end.Replace("Auto", ""); + string combinedChapterTag = chapterStart; + if (chapterFinish != chapterStart && chapterFinish != "") + combinedChapterTag = chapterStart + "-" + chapterFinish; // Get the destination filename. string destination_filename = ""; if (Properties.Settings.Default.autoNameFormat != "") { destination_filename = Properties.Settings.Default.autoNameFormat; - destination_filename = destination_filename.Replace("{source}", source).Replace("{title}", title).Replace("{chapters}", cs + dash + cf); + destination_filename = destination_filename.Replace("{source}", source).Replace("{title}", dvdTitle).Replace("{chapters}", combinedChapterTag); } else - destination_filename = source + "_T" + title + "_C" + cs + dash + cf; + destination_filename = source + "_T" + dvdTitle + "_C" + combinedChapterTag; - // If the text box is blank + // Now work out the path where the file will be stored. + // First case: If the destination box doesn't already contain a path, make one. if (!dest.Contains("\\")) { string filePath = ""; @@ -260,7 +243,7 @@ namespace Handbrake.Functions else if (format == 4) AutoNamePath = filePath + destination_filename + ".ogm"; } - else // If the text box already has a path and file + else // Otherwise, use the path that is already there. { string destination = AutoNamePath; string[] destName = dest.Split('\\'); @@ -280,6 +263,7 @@ namespace Handbrake.Functions return fullDest; } } + return AutoNamePath; } @@ -361,7 +345,7 @@ namespace Handbrake.Functions { MessageBox.Show("Unable to retrieve version information from the CLI. \nError:\n" + e); } - + cliVersionData.Add(0); cliVersionData.Add("0"); return cliVersionData; diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index e7f31f688..fd9aa78aa 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -948,7 +948,7 @@ namespace Handbrake //Picture Tab private void text_width_TextChanged(object sender, EventArgs e) { - maxWidth = 0; // Reset max width so that it's not using the MaxWidth -X. Quick hack to allow -X for preset usage. + maxWidth = 0; maxHeight = 0; // Reset max width so that it's not using the MaxWidth -X. Quick hack to allow -X for preset usage. int width; Boolean parsed = int.TryParse(text_width.Text, out width); @@ -960,12 +960,13 @@ namespace Handbrake text_width.BackColor = Color.LightGreen; - if (lbl_Aspect.Text != "Select a Title" && maxWidth != 0 && maxHeight != 0) + if (lbl_Aspect.Text != "Select a Title" && maxWidth == 0 && maxHeight == 0) { if (drp_anamorphic.Text == "None") { int height = hb_common_func.cacluateNonAnamorphicHeight(width, text_top.Value, text_bottom.Value, text_left.Value, text_right.Value, selectedTitle); - text_height.Text = height.ToString(); + if (height != 0) + text_height.Text = height.ToString(); } } } -- 2.40.0