From 17bd4de6ba10409ff2a218c3365aa8466c5457c2 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 19 Jun 2009 15:19:01 +0000 Subject: WinGui: - Cleans up the appcast reader code a bit more, removing all globals. - Small fix to preset loader to make sure audio bit-rate is set to auto for AC3 tracks. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2576 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Functions/AppcastReader.cs | 86 ++++++++++++++------------------------- win/C#/Functions/Main.cs | 2 +- win/C#/Functions/PresetLoader.cs | 5 ++- win/C#/frmUpdater.cs | 8 ++-- 4 files changed, 39 insertions(+), 62 deletions(-) (limited to 'win/C#') diff --git a/win/C#/Functions/AppcastReader.cs b/win/C#/Functions/AppcastReader.cs index e86259ff7..944258597 100644 --- a/win/C#/Functions/AppcastReader.cs +++ b/win/C#/Functions/AppcastReader.cs @@ -12,50 +12,36 @@ namespace Handbrake.Functions { public class AppcastReader { - XmlDocument rssDoc; - XmlNode nodeRss; - XmlNode nodeChannel; - XmlNode nodeItem; - private Uri hb_description; - private string hb_version; - private string hb_build; - private string hb_file; - /// - /// Get the build information from the required appcasts. - /// This must be run before calling any of the public return functions. + /// Get the build information from the required appcasts. Run before accessing the public vars. /// public void getInfo() { // Get the correct Appcast and set input. - if (Properties.Settings.Default.hb_build.ToString().EndsWith("1")) - readRss(new XmlTextReader(Properties.Settings.Default.appcast_unstable)); - else - readRss(new XmlTextReader(Properties.Settings.Default.appcast)); - + XmlNode nodeItem = Properties.Settings.Default.hb_build.ToString().EndsWith("1") ? readRss(new XmlTextReader(Properties.Settings.Default.appcast_unstable)) : readRss(new XmlTextReader(Properties.Settings.Default.appcast)); string input = nodeItem.InnerXml; // Regular Expressions Match ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\"""); Match verShort = Regex.Match(input, @"sparkle:shortVersionString=""([0-9].[0-9].[0-9]*)\"""); - if (nodeItem != null) - { - hb_build = ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""); - hb_version = verShort.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", ""); - hb_file = nodeItem["windows"].InnerText; - hb_description = new Uri(nodeItem["sparkle:releaseNotesLink"].InnerText); - } - + build = ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""); + version = verShort.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", ""); + downloadFile = nodeItem["windows"].InnerText; + descriptionUrl = new Uri(nodeItem["sparkle:releaseNotesLink"].InnerText); } /// /// Read the RSS file. /// /// - private void readRss(XmlReader rssReader) + private static XmlNode readRss(XmlReader rssReader) { - rssDoc = new XmlDocument(); + XmlNode nodeItem = null; + XmlNode nodeChannel = null; + XmlNode nodeRss = null; + + XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(rssReader); for (int i = 0; i < rssDoc.ChildNodes.Count; i++) @@ -64,53 +50,41 @@ namespace Handbrake.Functions nodeRss = rssDoc.ChildNodes[i]; } - for (int i = 0; i < nodeRss.ChildNodes.Count; i++) - { - if (nodeRss.ChildNodes[i].Name == "channel") - nodeChannel = nodeRss.ChildNodes[i]; - } + if (nodeRss != null) + for (int i = 0; i < nodeRss.ChildNodes.Count; i++) + { + if (nodeRss.ChildNodes[i].Name == "channel") + nodeChannel = nodeRss.ChildNodes[i]; + } - for (int i = 0; i < nodeChannel.ChildNodes.Count; i++) - { - if (nodeChannel.ChildNodes[i].Name == "item") - nodeItem = nodeChannel.ChildNodes[i]; - } + if (nodeChannel != null) + for (int i = 0; i < nodeChannel.ChildNodes.Count; i++) + { + if (nodeChannel.ChildNodes[i].Name == "item") + nodeItem = nodeChannel.ChildNodes[i]; + } + + return nodeItem; } /// /// Get Information about an update to HandBrake /// - /// - public System.Uri descriptionUrl() - { - return hb_description; - } + public Uri descriptionUrl { get; set; } /// /// Get HandBrake's version from the appcast.xml file. /// - /// - public string version() - { - return hb_version; - } + public string version { get; set; } /// /// Get HandBrake's Build from the appcast.xml file. /// - /// - public string build() - { - return hb_build; - } + public string build { get; set; } /// /// Get's the URL for update file. /// - /// - public string downloadFile() - { - return hb_file; - } + public string downloadFile { get; set; } } } \ No newline at end of file diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index f6c85b1cf..95a17cfb3 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -199,7 +199,7 @@ namespace Handbrake.Functions { AppcastReader rssRead = new AppcastReader(); rssRead.getInfo(); // Initializes the class. - string build = rssRead.build(); + string build = rssRead.build; int latest = int.Parse(build); int current = Properties.Settings.Default.hb_build; diff --git a/win/C#/Functions/PresetLoader.cs b/win/C#/Functions/PresetLoader.cs index 251735aec..4952e5d3d 100644 --- a/win/C#/Functions/PresetLoader.cs +++ b/win/C#/Functions/PresetLoader.cs @@ -243,7 +243,10 @@ namespace Handbrake.Functions newTrack.SubItems.Add(track.Encoder); newTrack.SubItems.Add(track.MixDown); newTrack.SubItems.Add(track.SampleRate); - newTrack.SubItems.Add(track.Bitrate); + if (track.Encoder.Contains("AC3")) + newTrack.SubItems.Add("Auto"); + else + newTrack.SubItems.Add(track.Bitrate); newTrack.SubItems.Add(track.DRC); mainWindow.audioPanel.addTrackForPreset(newTrack); } diff --git a/win/C#/frmUpdater.cs b/win/C#/frmUpdater.cs index 463ab5676..97a5c9a64 100644 --- a/win/C#/frmUpdater.cs +++ b/win/C#/frmUpdater.cs @@ -24,19 +24,19 @@ namespace Handbrake private void getRss() { - wBrowser.Url = appcast.descriptionUrl(); + wBrowser.Url = appcast.descriptionUrl; } private void setVersions() { string old = "(You have: " + Properties.Settings.Default.hb_version.Trim() + " / " + Properties.Settings.Default.hb_build.ToString().Trim() + ")"; - string newBuild = appcast.version().Trim() + " (" + appcast.build() + ")"; + string newBuild = appcast.version.Trim() + " (" + appcast.build + ")"; lbl_update_text.Text = "HandBrake " + newBuild + " is now available. " + old; } private void btn_installUpdate_Click(object sender, EventArgs e) { - frmDownload download = new frmDownload(appcast.downloadFile()); + frmDownload download = new frmDownload(appcast.downloadFile); download.Show(); this.Close(); } @@ -48,7 +48,7 @@ namespace Handbrake private void btn_skip_Click(object sender, EventArgs e) { - Properties.Settings.Default.skipversion = int.Parse(appcast.build()); + Properties.Settings.Default.skipversion = int.Parse(appcast.build); Properties.Settings.Default.Save(); this.Close(); -- cgit v1.2.3