3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Collections.Generic;
\r
11 using System.Text.RegularExpressions;
\r
13 namespace Handbrake.Functions
\r
15 public class AppcastReader
\r
19 XmlNode nodeChannel;
\r
21 private string hb_description;
\r
22 private string hb_version;
\r
23 private string hb_build;
\r
24 private string hb_file;
\r
27 /// Get the build information from the required appcasts.
\r
28 /// This must be run before calling any of the public return functions.
\r
30 public void getInfo()
\r
33 int stable_build, unstable_build = 0;
\r
34 string input, unstable_description = "", stable_description, unstable_version = "", stable_version;
\r
35 string stable_file, unstable_file = "";
\r
37 // Check the stable appcast and get the stable build number
\r
38 readRss(new XmlTextReader(Properties.Settings.Default.appcast));
\r
39 input = nodeItem.InnerXml;
\r
40 ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");
\r
41 stable_build = int.Parse(ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""));
\r
42 ver = Regex.Match(input, @"sparkle:shortVersionString=""([0-9].[0-9].[0-9]*)\""");
\r
43 stable_version = ver.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");
\r
44 stable_description = nodeItem["description"].InnerText;
\r
45 stable_file = nodeItem["windows"].InnerText;
\r
47 // If this is a snapshot release, or the user wants to check for snapshot releases
\r
48 if (Properties.Settings.Default.checkSnapshot == "Checked" || Properties.Settings.Default.hb_build.ToString().EndsWith("1"))
\r
50 // Get the stable build
\r
51 readRss(new XmlTextReader(Properties.Settings.Default.appcast_unstable));
\r
52 input = nodeItem.InnerXml;
\r
53 ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");
\r
54 unstable_build = int.Parse(ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""));
\r
55 ver = Regex.Match(input, @"sparkle:shortVersionString=""([0-9a-zA-Z.]*)\""");
\r
56 unstable_version = ver.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");
\r
57 unstable_description = nodeItem["description"].InnerText;
\r
58 unstable_file = nodeItem["windows"].InnerText;
\r
62 // Set the global version information
\r
63 if (stable_build >= unstable_build)
\r
65 hb_description = stable_description;
\r
66 hb_version = stable_version;
\r
67 hb_build = stable_build.ToString();
\r
68 hb_file = stable_file;
\r
72 hb_description = unstable_description;
\r
73 hb_version = unstable_version;
\r
74 hb_build = unstable_build.ToString();
\r
75 hb_file = unstable_file;
\r
80 /// Read the RSS file.
\r
82 /// <param name="rssReader"></param>
\r
83 private void readRss(XmlTextReader rssReader)
\r
85 rssDoc = new XmlDocument();
\r
86 rssDoc.Load(rssReader);
\r
88 for (int i = 0; i < rssDoc.ChildNodes.Count; i++)
\r
90 if (rssDoc.ChildNodes[i].Name == "rss")
\r
91 nodeRss = rssDoc.ChildNodes[i];
\r
94 for (int i = 0; i < nodeRss.ChildNodes.Count; i++)
\r
96 if (nodeRss.ChildNodes[i].Name == "channel")
\r
97 nodeChannel = nodeRss.ChildNodes[i];
\r
100 for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
\r
102 if (nodeChannel.ChildNodes[i].Name == "item")
\r
103 nodeItem = nodeChannel.ChildNodes[i];
\r
108 /// Get Information about an update to HandBrake
\r
110 /// <returns></returns>
\r
111 public string versionInfo()
\r
113 return hb_description;
\r
117 /// Get HandBrake's version from the appcast.xml file.
\r
119 /// <returns></returns>
\r
120 public string version()
\r
126 /// Get HandBrake's Build from the appcast.xml file.
\r
128 /// <returns></returns>
\r
129 public string build()
\r
135 /// Get's the URL for update file.
\r
137 /// <returns></returns>
\r
138 public string downloadFile()
\r