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.ComponentModel;\r
10 using System.Data;\r
11 using System.Drawing;\r
12 using System.Text;\r
13 using System.Windows.Forms;\r
14 using System.IO;\r
15 using System.Xml;\r
16 using System.Text.RegularExpressions;\r
17 \r
18 namespace Handbrake.Functions\r
19 {\r
20     class AppcastReader\r
21     {\r
22         XmlTextReader rssReader;\r
23         XmlDocument rssDoc;\r
24         XmlNode nodeRss;\r
25         XmlNode nodeChannel;\r
26         XmlNode nodeItem;\r
27         private string hb_versionInfo;\r
28         private string hb_version;\r
29         private string hb_build;\r
30         private string hb_file;\r
31 \r
32         // Rss Reading Code.\r
33         private void readRss(XmlTextReader rssReader)\r
34         {\r
35             rssDoc = new XmlDocument();\r
36             rssDoc.Load(rssReader);\r
37 \r
38             for (int i = 0; i < rssDoc.ChildNodes.Count; i++)\r
39             {\r
40                 if (rssDoc.ChildNodes[i].Name == "rss")\r
41                     nodeRss = rssDoc.ChildNodes[i];\r
42             }\r
43 \r
44             for (int i = 0; i < nodeRss.ChildNodes.Count; i++)\r
45             {\r
46                 if (nodeRss.ChildNodes[i].Name == "channel")\r
47                     nodeChannel = nodeRss.ChildNodes[i];\r
48             }\r
49 \r
50             for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)\r
51             {\r
52                 if (nodeChannel.ChildNodes[i].Name == "item")\r
53                     nodeItem = nodeChannel.ChildNodes[i];\r
54             }\r
55         }\r
56 \r
57 \r
58         // Get's the information required out the RSS file.\r
59         private void getInfo()\r
60         {\r
61             Match ver;\r
62             int unstable_build = 0;\r
63             string input;\r
64 \r
65             // Check the stable appcast and get the build nuber\r
66             rssReader = new XmlTextReader(Properties.Settings.Default.appcast);\r
67             readRss(rssReader);\r
68             input = nodeItem.InnerXml;\r
69             ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");\r
70             int stable_build = int.Parse(ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""));\r
71 \r
72             // If the pref to enable unstable appcast checking is enabled    OR\r
73             // this is a snapshot release, \r
74             // then check the unstable appcast.\r
75             if (Properties.Settings.Default.checkSnapshot == "Checked" || Properties.Settings.Default.hb_build.ToString().EndsWith("1"))\r
76             {\r
77                 // Get the stable build\r
78                 rssReader = new XmlTextReader(Properties.Settings.Default.appcast_unstable);\r
79                 readRss(rssReader);\r
80                 input = nodeItem.InnerXml;\r
81                 ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");\r
82                 unstable_build = int.Parse(ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""));\r
83             }\r
84 \r
85             if (stable_build >= unstable_build)\r
86                 rssReader = new XmlTextReader(Properties.Settings.Default.appcast);\r
87             else\r
88                 rssReader = new XmlTextReader(Properties.Settings.Default.appcast_unstable);\r
89 \r
90             // Get the Version Information\r
91             hb_versionInfo = nodeItem["description"].InnerText;\r
92 \r
93             // Get the version\r
94             string inputNode = nodeItem.InnerXml;\r
95             ver = Regex.Match(inputNode, @"sparkle:shortVersionString=""([0-9].[0-9].[0-9]*)\""");\r
96             hb_version = ver.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");\r
97 \r
98             ver = Regex.Match(inputNode, @"sparkle:version=""([0-9]*)\""");\r
99             hb_build = ver.ToString().Replace("sparkle:version=", "").Replace("\"", "");\r
100 \r
101             // Get the update file\r
102             hb_file = nodeItem["windows"].InnerText;\r
103         }\r
104 \r
105         /// <summary>\r
106         /// Get Information about an update to HandBrake\r
107         /// </summary>\r
108         /// <returns></returns>\r
109         public string versionInfo()\r
110         {\r
111             getInfo();\r
112             return hb_versionInfo;\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             getInfo();\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             getInfo();\r
132             return hb_build;\r
133         }\r
134 \r
135         /// <summary>\r
136         /// Get's the URL for update file.\r
137         /// </summary>\r
138         /// <returns></returns>\r
139         public string downloadFile()\r
140         {\r
141             getInfo();\r
142             return hb_file;\r
143         }\r
144     }\r
145 }