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.Text.RegularExpressions;
\r
10 namespace Handbrake.Functions
\r
12 public class AppcastReader
\r
16 XmlNode nodeChannel;
\r
18 private string hb_description;
\r
19 private string hb_version;
\r
20 private string hb_build;
\r
21 private string hb_file;
\r
24 /// Get the build information from the required appcasts.
\r
25 /// This must be run before calling any of the public return functions.
\r
27 public void getInfo()
\r
29 int unstable_build = 0;
\r
30 string unstable_description = "", unstable_version = "";
\r
31 string unstable_file = "";
\r
33 // Check the stable appcast and get the stable build number
\r
34 readRss(new XmlTextReader(Properties.Settings.Default.appcast));
\r
35 string input = nodeItem.InnerXml;
\r
36 Match ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");
\r
37 int stable_build = int.Parse(ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""));
\r
38 ver = Regex.Match(input, @"sparkle:shortVersionString=""([0-9].[0-9].[0-9]*)\""");
\r
39 string stable_version = ver.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");
\r
40 string stable_description = nodeItem["description"].InnerText;
\r
41 string stable_file = nodeItem["windows"].InnerText;
\r
43 // If this is a snapshot release, or the user wants to check for snapshot releases
\r
44 if (Properties.Settings.Default.checkSnapshot == "Checked" || Properties.Settings.Default.hb_build.ToString().EndsWith("1"))
\r
46 // Get the stable build
\r
47 readRss(new XmlTextReader(Properties.Settings.Default.appcast_unstable));
\r
48 input = nodeItem.InnerXml;
\r
49 ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");
\r
50 unstable_build = int.Parse(ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""));
\r
51 ver = Regex.Match(input, @"sparkle:shortVersionString=""([0-9a-zA-Z.]*)\""");
\r
52 unstable_version = ver.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");
\r
53 unstable_description = nodeItem["description"].InnerText;
\r
54 unstable_file = nodeItem["windows"].InnerText;
\r
57 // Set the global version information
\r
58 if (stable_build >= unstable_build)
\r
60 hb_description = stable_description;
\r
61 hb_version = stable_version;
\r
62 hb_build = stable_build.ToString();
\r
63 hb_file = stable_file;
\r
67 hb_description = unstable_description;
\r
68 hb_version = unstable_version;
\r
69 hb_build = unstable_build.ToString();
\r
70 hb_file = unstable_file;
\r
75 /// Read the RSS file.
\r
77 /// <param name="rssReader"></param>
\r
78 private void readRss(XmlReader rssReader)
\r
80 rssDoc = new XmlDocument();
\r
81 rssDoc.Load(rssReader);
\r
83 for (int i = 0; i < rssDoc.ChildNodes.Count; i++)
\r
85 if (rssDoc.ChildNodes[i].Name == "rss")
\r
86 nodeRss = rssDoc.ChildNodes[i];
\r
89 for (int i = 0; i < nodeRss.ChildNodes.Count; i++)
\r
91 if (nodeRss.ChildNodes[i].Name == "channel")
\r
92 nodeChannel = nodeRss.ChildNodes[i];
\r
95 for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
\r
97 if (nodeChannel.ChildNodes[i].Name == "item")
\r
98 nodeItem = nodeChannel.ChildNodes[i];
\r
103 /// Get Information about an update to HandBrake
\r
105 /// <returns></returns>
\r
106 public string versionInfo()
\r
108 return hb_description;
\r
112 /// Get HandBrake's version from the appcast.xml file.
\r
114 /// <returns></returns>
\r
115 public string version()
\r
121 /// Get HandBrake's Build from the appcast.xml file.
\r
123 /// <returns></returns>
\r
124 public string build()
\r
130 /// Get's the URL for update file.
\r
132 /// <returns></returns>
\r
133 public string downloadFile()
\r