// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // Appcast Reader - Used for parsing HandBrakes update file // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrake.ApplicationServices.Utilities { using System; using System.IO; using System.Text.RegularExpressions; using System.Xml; /// /// Appcast Reader - Used for parsing HandBrakes update file /// public class AppcastReader { /// /// Gets Information about an update to HandBrake /// public Uri DescriptionUrl { get; private set; } /// /// Gets HandBrake's version from the appcast.xml file. /// public string Version { get; private set; } /// /// Gets HandBrake's Build from the appcast.xml file. /// public string Build { get; private set; } /// /// Gets the URL for update file. /// public string DownloadFile { get; private set; } /// /// Get the build information from the required appcasts. Run before accessing the public vars. /// /// /// The input. /// public void GetUpdateInfo(string input) { try { // Get the correct Appcast and set input. XmlNode nodeItem = ReadRss(new XmlTextReader(new StringReader(input))); string result = nodeItem.InnerXml; // Regular Expressions Match ver = Regex.Match(result, @"sparkle:version=""([0-9]*)\"""); Match verShort = Regex.Match(result, @"sparkle:shortVersionString=""(([svn]*)([0-9.\s]*))\"""); this.Build = ver.ToString().Replace("sparkle:version=", string.Empty).Replace("\"", string.Empty); this.Version = verShort.ToString().Replace("sparkle:shortVersionString=", string.Empty).Replace( "\"", string.Empty); this.DownloadFile = nodeItem["windows"].InnerText; this.DescriptionUrl = new Uri(nodeItem["sparkle:releaseNotesLink"].InnerText); } catch (Exception) { return; } } /// /// Read the RSS file. /// /// /// The RSS reader /// /// /// The read rss. /// private static XmlNode ReadRss(XmlReader rssReader) { XmlNode nodeItem = null; XmlNode nodeChannel = null; XmlNode nodeRss = null; XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(rssReader); foreach (XmlNode t in rssDoc.ChildNodes) { if (t.Name == "rss") { nodeRss = t; } } if (nodeRss != null) { foreach (XmlNode t in nodeRss.ChildNodes) { if (t.Name == "channel") { nodeChannel = t; } } } if (nodeChannel != null) { foreach (XmlNode t in nodeChannel.ChildNodes) { if (t.Name == "item") { nodeItem = t; } } } return nodeItem; } } }