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.Collections.Generic;\r
9 using System.IO;\r
10 using System.Xml;\r
11 using System.Text.RegularExpressions;\r
12 \r
13 namespace Handbrake.Functions\r
14 {\r
15     public class AppcastReader\r
16     {\r
17         XmlDocument rssDoc;\r
18         XmlNode nodeRss;\r
19         XmlNode nodeChannel;\r
20         XmlNode nodeItem;\r
21         private string hb_description;\r
22         private string hb_version;\r
23         private string hb_build;\r
24         private string hb_file;\r
25 \r
26         /// <summary>\r
27         /// Get the build information from the required appcasts.\r
28         /// This must be run before calling any of the public return functions.\r
29         /// </summary>\r
30         public void getInfo()\r
31         {\r
32             Match ver;\r
33             int stable_build, unstable_build = 0;\r
34             string input, unstable_description = "", stable_description, unstable_version = "", stable_version;\r
35             string stable_file, unstable_file = "";\r
36 \r
37             // Check the stable appcast and get the stable build number\r
38             readRss(new XmlTextReader(Properties.Settings.Default.appcast));\r
39             input = nodeItem.InnerXml;\r
40             ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");\r
41             stable_build = int.Parse(ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""));\r
42             ver = Regex.Match(input, @"sparkle:shortVersionString=""([0-9].[0-9].[0-9]*)\""");\r
43             stable_version = ver.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");\r
44             stable_description = nodeItem["description"].InnerText;\r
45             stable_file = nodeItem["windows"].InnerText;\r
46 \r
47             // If this is a snapshot release, or the user wants to check for snapshot releases\r
48             if (Properties.Settings.Default.checkSnapshot == "Checked" || Properties.Settings.Default.hb_build.ToString().EndsWith("1"))\r
49             {\r
50                 // Get the stable build\r
51                 readRss(new XmlTextReader(Properties.Settings.Default.appcast_unstable));\r
52                 input = nodeItem.InnerXml;\r
53                 ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");\r
54                 unstable_build = int.Parse(ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""));\r
55                 ver = Regex.Match(input, @"sparkle:shortVersionString=""([0-9a-zA-Z.]*)\""");\r
56                 unstable_version = ver.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");\r
57                 unstable_description = nodeItem["description"].InnerText;\r
58                 unstable_file = nodeItem["windows"].InnerText;\r
59             }\r
60 \r
61 \r
62             // Set the global version information\r
63             if (stable_build >= unstable_build)\r
64             {\r
65                 hb_description = stable_description;\r
66                 hb_version = stable_version;\r
67                 hb_build = stable_build.ToString();\r
68                 hb_file = stable_file;\r
69             }\r
70             else\r
71             {\r
72                 hb_description = unstable_description;\r
73                 hb_version = unstable_version;\r
74                 hb_build = unstable_build.ToString();\r
75                 hb_file = unstable_file;\r
76             }\r
77         }\r
78 \r
79         /// <summary>\r
80         /// Read the RSS file.\r
81         /// </summary>\r
82         /// <param name="rssReader"></param>\r
83         private void readRss(XmlTextReader rssReader)\r
84         {\r
85             rssDoc = new XmlDocument();\r
86             rssDoc.Load(rssReader);\r
87 \r
88             for (int i = 0; i < rssDoc.ChildNodes.Count; i++)\r
89             {\r
90                 if (rssDoc.ChildNodes[i].Name == "rss")\r
91                     nodeRss = rssDoc.ChildNodes[i];\r
92             }\r
93 \r
94             for (int i = 0; i < nodeRss.ChildNodes.Count; i++)\r
95             {\r
96                 if (nodeRss.ChildNodes[i].Name == "channel")\r
97                     nodeChannel = nodeRss.ChildNodes[i];\r
98             }\r
99 \r
100             for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)\r
101             {\r
102                 if (nodeChannel.ChildNodes[i].Name == "item")\r
103                     nodeItem = nodeChannel.ChildNodes[i];\r
104             }\r
105         }\r
106 \r
107         /// <summary>\r
108         /// Get Information about an update to HandBrake\r
109         /// </summary>\r
110         /// <returns></returns>\r
111         public string versionInfo()\r
112         {\r
113             return hb_description;\r
114         }\r
115 \r
116         /// <summary>\r
117         /// Get HandBrake's version from the appcast.xml file.\r
118         /// </summary>\r
119         /// <returns></returns>\r
120         public string version()\r
121         {\r
122             return hb_version;\r
123         }\r
124 \r
125         /// <summary>\r
126         /// Get HandBrake's Build from the appcast.xml file.\r
127         /// </summary>\r
128         /// <returns></returns>\r
129         public string build()\r
130         {\r
131             return hb_build;\r
132         }\r
133 \r
134         /// <summary>\r
135         /// Get's the URL for update file.\r
136         /// </summary>\r
137         /// <returns></returns>\r
138         public string downloadFile()\r
139         {\r
140             return hb_file;\r
141         }\r
142     }\r
143 }