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 \r
11 namespace Handbrake.Functions\r
12 {\r
13     public class AppcastReader\r
14     {\r
15         XmlDocument rssDoc;\r
16         XmlNode nodeRss;\r
17         XmlNode nodeChannel;\r
18         XmlNode nodeItem;\r
19         private Uri hb_description;\r
20         private string hb_version;\r
21         private string hb_build;\r
22         private string hb_file;\r
23 \r
24         /// <summary>\r
25         /// Get the build information from the required appcasts.\r
26         /// This must be run before calling any of the public return functions.\r
27         /// </summary>\r
28         public void getInfo()\r
29         {\r
30             // Get the correct Appcast and set input.\r
31             if (Properties.Settings.Default.hb_build.ToString().EndsWith("1"))\r
32                 readRss(new XmlTextReader(Properties.Settings.Default.appcast_unstable));\r
33             else \r
34                 readRss(new XmlTextReader(Properties.Settings.Default.appcast));\r
35 \r
36             string input = nodeItem.InnerXml;\r
37 \r
38             // Regular Expressions\r
39             Match ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");\r
40             Match verShort = Regex.Match(input, @"sparkle:shortVersionString=""([0-9].[0-9].[0-9]*)\""");\r
41 \r
42             if (nodeItem != null)\r
43             {\r
44                 hb_build = ver.ToString().Replace("sparkle:version=", "").Replace("\"", "");\r
45                 hb_version = verShort.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");\r
46                 hb_file = nodeItem["windows"].InnerText;\r
47                 hb_description = new Uri(nodeItem["sparkle:releaseNotesLink"].InnerText);\r
48             }\r
49 \r
50         }\r
51 \r
52         /// <summary>\r
53         /// Read the RSS file.\r
54         /// </summary>\r
55         /// <param name="rssReader"></param>\r
56         private void readRss(XmlReader rssReader)\r
57         {\r
58             rssDoc = new XmlDocument();\r
59             rssDoc.Load(rssReader);\r
60 \r
61             for (int i = 0; i < rssDoc.ChildNodes.Count; i++)\r
62             {\r
63                 if (rssDoc.ChildNodes[i].Name == "rss")\r
64                     nodeRss = rssDoc.ChildNodes[i];\r
65             }\r
66 \r
67             for (int i = 0; i < nodeRss.ChildNodes.Count; i++)\r
68             {\r
69                 if (nodeRss.ChildNodes[i].Name == "channel")\r
70                     nodeChannel = nodeRss.ChildNodes[i];\r
71             }\r
72 \r
73             for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)\r
74             {\r
75                 if (nodeChannel.ChildNodes[i].Name == "item")\r
76                     nodeItem = nodeChannel.ChildNodes[i];\r
77             }\r
78         }\r
79 \r
80         /// <summary>\r
81         /// Get Information about an update to HandBrake\r
82         /// </summary>\r
83         /// <returns></returns>\r
84         public System.Uri descriptionUrl()\r
85         {\r
86             return hb_description;\r
87         }\r
88 \r
89         /// <summary>\r
90         /// Get HandBrake's version from the appcast.xml file.\r
91         /// </summary>\r
92         /// <returns></returns>\r
93         public string version()\r
94         {\r
95             return hb_version;\r
96         }\r
97 \r
98         /// <summary>\r
99         /// Get HandBrake's Build from the appcast.xml file.\r
100         /// </summary>\r
101         /// <returns></returns>\r
102         public string build()\r
103         {\r
104             return hb_build;\r
105         }\r
106 \r
107         /// <summary>\r
108         /// Get's the URL for update file.\r
109         /// </summary>\r
110         /// <returns></returns>\r
111         public string downloadFile()\r
112         {\r
113             return hb_file;\r
114         }\r
115     }\r
116 }