OSDN Git Service

94425859760626743ebd6be5e5775dc7807c6e9c
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / AppcastReader.cs
1 /*  RssReader.cs $\r
2         \r
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
6 \r
7 using System;\r
8 using System.Xml;\r
9 using System.Text.RegularExpressions;\r
10 \r
11 namespace Handbrake.Functions\r
12 {\r
13     public class AppcastReader\r
14     {\r
15         /// <summary>\r
16         /// Get the build information from the required appcasts. Run before accessing the public vars.\r
17         /// </summary>\r
18         public void getInfo()\r
19         {\r
20             // Get the correct Appcast and set input.\r
21             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));\r
22             string input = nodeItem.InnerXml;\r
23 \r
24             // Regular Expressions\r
25             Match ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");\r
26             Match verShort = Regex.Match(input, @"sparkle:shortVersionString=""([0-9].[0-9].[0-9]*)\""");\r
27 \r
28             build = ver.ToString().Replace("sparkle:version=", "").Replace("\"", "");\r
29             version = verShort.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");\r
30             downloadFile = nodeItem["windows"].InnerText;\r
31             descriptionUrl = new Uri(nodeItem["sparkle:releaseNotesLink"].InnerText);\r
32         }\r
33 \r
34         /// <summary>\r
35         /// Read the RSS file.\r
36         /// </summary>\r
37         /// <param name="rssReader"></param>\r
38         private static XmlNode readRss(XmlReader rssReader)\r
39         {\r
40             XmlNode nodeItem = null;\r
41             XmlNode nodeChannel = null;\r
42             XmlNode nodeRss = null;\r
43 \r
44             XmlDocument rssDoc = new XmlDocument();\r
45             rssDoc.Load(rssReader);\r
46 \r
47             for (int i = 0; i < rssDoc.ChildNodes.Count; i++)\r
48             {\r
49                 if (rssDoc.ChildNodes[i].Name == "rss")\r
50                     nodeRss = rssDoc.ChildNodes[i];\r
51             }\r
52 \r
53             if (nodeRss != null)\r
54                 for (int i = 0; i < nodeRss.ChildNodes.Count; i++)\r
55                 {\r
56                     if (nodeRss.ChildNodes[i].Name == "channel")\r
57                         nodeChannel = nodeRss.ChildNodes[i];\r
58                 }\r
59 \r
60             if (nodeChannel != null)\r
61                 for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)\r
62                 {\r
63                     if (nodeChannel.ChildNodes[i].Name == "item")\r
64                         nodeItem = nodeChannel.ChildNodes[i];\r
65                 }\r
66 \r
67             return nodeItem;\r
68         }\r
69 \r
70         /// <summary>\r
71         /// Get Information about an update to HandBrake\r
72         /// </summary>\r
73         public Uri descriptionUrl { get; set; }\r
74 \r
75         /// <summary>\r
76         /// Get HandBrake's version from the appcast.xml file.\r
77         /// </summary>\r
78         public string version { get; set; }\r
79 \r
80         /// <summary>\r
81         /// Get HandBrake's Build from the appcast.xml file.\r
82         /// </summary>\r
83         public string build { get; set; }\r
84 \r
85         /// <summary>\r
86         /// Get's the URL for update file.\r
87         /// </summary>\r
88         public string downloadFile { get; set; }\r
89     }\r
90 }