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             // Set the global version information\r
62             if (stable_build >= unstable_build)\r
63             {\r
64                 hb_description = stable_description;\r
65                 hb_version = stable_version;\r
66                 hb_build = stable_build.ToString();\r
67                 hb_file = stable_file;\r
68             }\r
69             else\r
70             {\r
71                 hb_description = unstable_description;\r
72                 hb_version = unstable_version;\r
73                 hb_build = unstable_build.ToString();\r
74                 hb_file = unstable_file;\r
75             }\r
76         }\r
77 \r
78         /// <summary>\r
79         /// Read the RSS file.\r
80         /// </summary>\r
81         /// <param name="rssReader"></param>\r
82         private void readRss(XmlTextReader rssReader)\r
83         {\r
84             rssDoc = new XmlDocument();\r
85             rssDoc.Load(rssReader);\r
86 \r
87             for (int i = 0; i < rssDoc.ChildNodes.Count; i++)\r
88             {\r
89                 if (rssDoc.ChildNodes[i].Name == "rss")\r
90                     nodeRss = rssDoc.ChildNodes[i];\r
91             }\r
92 \r
93             for (int i = 0; i < nodeRss.ChildNodes.Count; i++)\r
94             {\r
95                 if (nodeRss.ChildNodes[i].Name == "channel")\r
96                     nodeChannel = nodeRss.ChildNodes[i];\r
97             }\r
98 \r
99             for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)\r
100             {\r
101                 if (nodeChannel.ChildNodes[i].Name == "item")\r
102                     nodeItem = nodeChannel.ChildNodes[i];\r
103             }\r
104         }\r
105 \r
106         /// <summary>\r
107         /// Get Information about an update to HandBrake\r
108         /// </summary>\r
109         /// <returns></returns>\r
110         public string versionInfo()\r
111         {\r
112             return hb_description;\r
113         }\r
114 \r
115         /// <summary>\r
116         /// Get HandBrake's version from the appcast.xml file.\r
117         /// </summary>\r
118         /// <returns></returns>\r
119         public string version()\r
120         {\r
121             return hb_version;\r
122         }\r
123 \r
124         /// <summary>\r
125         /// Get HandBrake's Build from the appcast.xml file.\r
126         /// </summary>\r
127         /// <returns></returns>\r
128         public string build()\r
129         {\r
130             return hb_build;\r
131         }\r
132 \r
133         /// <summary>\r
134         /// Get's the URL for update file.\r
135         /// </summary>\r
136         /// <returns></returns>\r
137         public string downloadFile()\r
138         {\r
139             return hb_file;\r
140         }\r
141     }\r
142 }