OSDN Git Service

WinGui:
[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 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             // Get the correct Appcast and set input.\r
22             XmlNode nodeItem = readRss(new XmlTextReader(new StringReader(input)));\r
23             string result = nodeItem.InnerXml;\r
24 \r
25             // Regular Expressions\r
26             Match ver = Regex.Match(result, @"sparkle:version=""([0-9]*)\""");\r
27             Match verShort = Regex.Match(result, @"sparkle:shortVersionString=""([0-9].[0-9].[0-9]*)\""");\r
28 \r
29             build = ver.ToString().Replace("sparkle:version=", "").Replace("\"", "");\r
30             version = verShort.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");\r
31             downloadFile = nodeItem["windows"].InnerText;\r
32             descriptionUrl = new Uri(nodeItem["sparkle:releaseNotesLink"].InnerText);\r
33         }\r
34 \r
35         /// <summary>\r
36         /// Read the RSS file.\r
37         /// </summary>\r
38         /// <param name="rssReader"></param>\r
39         private static XmlNode readRss(XmlReader rssReader)\r
40         {\r
41             XmlNode nodeItem = null;\r
42             XmlNode nodeChannel = null;\r
43             XmlNode nodeRss = null;\r
44 \r
45             XmlDocument rssDoc = new XmlDocument();\r
46             rssDoc.Load(rssReader);\r
47 \r
48             for (int i = 0; i < rssDoc.ChildNodes.Count; i++)\r
49             {\r
50                 if (rssDoc.ChildNodes[i].Name == "rss")\r
51                     nodeRss = rssDoc.ChildNodes[i];\r
52             }\r
53 \r
54             if (nodeRss != null)\r
55                 for (int i = 0; i < nodeRss.ChildNodes.Count; i++)\r
56                 {\r
57                     if (nodeRss.ChildNodes[i].Name == "channel")\r
58                         nodeChannel = nodeRss.ChildNodes[i];\r
59                 }\r
60 \r
61             if (nodeChannel != null)\r
62                 for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)\r
63                 {\r
64                     if (nodeChannel.ChildNodes[i].Name == "item")\r
65                         nodeItem = nodeChannel.ChildNodes[i];\r
66                 }\r
67 \r
68             return nodeItem;\r
69         }\r
70 \r
71         /// <summary>\r
72         /// Get Information about an update to HandBrake\r
73         /// </summary>\r
74         public Uri descriptionUrl { get; set; }\r
75 \r
76         /// <summary>\r
77         /// Get HandBrake's version from the appcast.xml file.\r
78         /// </summary>\r
79         public string version { get; set; }\r
80 \r
81         /// <summary>\r
82         /// Get HandBrake's Build from the appcast.xml file.\r
83         /// </summary>\r
84         public string build { get; set; }\r
85 \r
86         /// <summary>\r
87         /// Get's the URL for update file.\r
88         /// </summary>\r
89         public string downloadFile { get; set; }\r
90     }\r
91 }