diff options
author | sr55 <[email protected]> | 2014-11-29 17:59:31 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2014-11-29 17:59:31 +0000 |
commit | 7c0af498a9d5f7aae1e5c8d06b939c8189edcfbe (patch) | |
tree | 74d348fb0cd83d48d13d4ae1007909e032a5a807 /win/CS/HandBrakeWPF/Utilities/AppcastReader.cs | |
parent | d364449a2ec863db317422645d5c7a927d294654 (diff) |
WinGui: Re-factoring the services library.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6567 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/Utilities/AppcastReader.cs')
-rw-r--r-- | win/CS/HandBrakeWPF/Utilities/AppcastReader.cs | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/win/CS/HandBrakeWPF/Utilities/AppcastReader.cs b/win/CS/HandBrakeWPF/Utilities/AppcastReader.cs new file mode 100644 index 000000000..49d7f4714 --- /dev/null +++ b/win/CS/HandBrakeWPF/Utilities/AppcastReader.cs @@ -0,0 +1,123 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="AppcastReader.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Appcast Reader - Used for parsing HandBrakes update file
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Utilities
+{
+ using System;
+ using System.IO;
+ using System.Text.RegularExpressions;
+ using System.Xml;
+
+ /// <summary>
+ /// Appcast Reader - Used for parsing HandBrakes update file
+ /// </summary>
+ public class AppcastReader
+ {
+ /// <summary>
+ /// Gets Information about an update to HandBrake
+ /// </summary>
+ public Uri DescriptionUrl { get; private set; }
+
+ /// <summary>
+ /// Gets HandBrake's version from the appcast.xml file.
+ /// </summary>
+ public string Version { get; private set; }
+
+ /// <summary>
+ /// Gets HandBrake's Build from the appcast.xml file.
+ /// </summary>
+ public string Build { get; private set; }
+
+ /// <summary>
+ /// Gets the URL for update file.
+ /// </summary>
+ public string DownloadFile { get; private set; }
+
+ /// <summary>
+ /// Get the build information from the required appcasts. Run before accessing the public vars.
+ /// </summary>
+ /// <param name="input">
+ /// The input.
+ /// </param>
+ 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;
+ }
+ }
+
+ /// <summary>
+ /// Read the RSS file.
+ /// </summary>
+ /// <param name="rssReader">
+ /// The RSS reader
+ /// </param>
+ /// <returns>
+ /// The read rss.
+ /// </returns>
+ 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;
+ }
+ }
+}
\ No newline at end of file |