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.Xml;\r
8 using System.Text.RegularExpressions;\r
9 \r
10 namespace Handbrake.Functions\r
11 {\r
12     public class AppcastReader\r
13     {\r
14         XmlDocument rssDoc;\r
15         XmlNode nodeRss;\r
16         XmlNode nodeChannel;\r
17         XmlNode nodeItem;\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
22 \r
23         /// <summary>\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
26         /// </summary>\r
27         public void getInfo()\r
28         {\r
29             int unstable_build = 0;\r
30             string unstable_description = "", unstable_version = "";\r
31             string unstable_file = "";\r
32 \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
42 \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
45             {\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
55             }\r
56 \r
57             // Set the global version information\r
58             if (stable_build >= unstable_build)\r
59             {\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
64             }\r
65             else\r
66             {\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
71             }\r
72         }\r
73 \r
74         /// <summary>\r
75         /// Read the RSS file.\r
76         /// </summary>\r
77         /// <param name="rssReader"></param>\r
78         private void readRss(XmlReader rssReader)\r
79         {\r
80             rssDoc = new XmlDocument();\r
81             rssDoc.Load(rssReader);\r
82 \r
83             for (int i = 0; i < rssDoc.ChildNodes.Count; i++)\r
84             {\r
85                 if (rssDoc.ChildNodes[i].Name == "rss")\r
86                     nodeRss = rssDoc.ChildNodes[i];\r
87             }\r
88 \r
89             for (int i = 0; i < nodeRss.ChildNodes.Count; i++)\r
90             {\r
91                 if (nodeRss.ChildNodes[i].Name == "channel")\r
92                     nodeChannel = nodeRss.ChildNodes[i];\r
93             }\r
94 \r
95             for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)\r
96             {\r
97                 if (nodeChannel.ChildNodes[i].Name == "item")\r
98                     nodeItem = nodeChannel.ChildNodes[i];\r
99             }\r
100         }\r
101 \r
102         /// <summary>\r
103         /// Get Information about an update to HandBrake\r
104         /// </summary>\r
105         /// <returns></returns>\r
106         public string versionInfo()\r
107         {\r
108             return hb_description;\r
109         }\r
110 \r
111         /// <summary>\r
112         /// Get HandBrake's version from the appcast.xml file.\r
113         /// </summary>\r
114         /// <returns></returns>\r
115         public string version()\r
116         {\r
117             return hb_version;\r
118         }\r
119 \r
120         /// <summary>\r
121         /// Get HandBrake's Build from the appcast.xml file.\r
122         /// </summary>\r
123         /// <returns></returns>\r
124         public string build()\r
125         {\r
126             return hb_build;\r
127         }\r
128 \r
129         /// <summary>\r
130         /// Get's the URL for update file.\r
131         /// </summary>\r
132         /// <returns></returns>\r
133         public string downloadFile()\r
134         {\r
135             return hb_file;\r
136         }\r
137     }\r
138 }