OSDN Git Service

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