OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / AppcastReader.cs
index 6e9d97e..ea9cac1 100644 (file)
           It may be used under the terms of the GNU General Public License. */\r
 \r
 using System;\r
-using System.Collections.Generic;\r
-using System.ComponentModel;\r
-using System.Data;\r
-using System.Drawing;\r
-using System.Text;\r
-using System.Windows.Forms;\r
-using System.IO;\r
 using System.Xml;\r
 using System.Text.RegularExpressions;\r
+using System.IO;\r
 \r
 namespace Handbrake.Functions\r
 {\r
-    class AppcastReader\r
+    public class AppcastReader\r
     {\r
-        XmlTextReader rssReader;\r
-        XmlDocument rssDoc;\r
-        XmlNode nodeRss;\r
-        XmlNode nodeChannel;\r
-        XmlNode nodeItem;\r
-        private string hb_versionInfo;\r
-        private string hb_version;\r
-        private string hb_build;\r
-        private string hb_file;\r
-\r
-        // Rss Reading Code.\r
-        private void readRss(XmlTextReader rssReader)\r
+        /// <summary>\r
+        /// Get the build information from the required appcasts. Run before accessing the public vars.\r
+        /// </summary>\r
+        public void GetInfo(string input)\r
         {\r
-            rssDoc = new XmlDocument();\r
-            rssDoc.Load(rssReader);\r
-\r
-            for (int i = 0; i < rssDoc.ChildNodes.Count; i++)\r
+            try\r
             {\r
-                if (rssDoc.ChildNodes[i].Name == "rss")\r
-                    nodeRss = rssDoc.ChildNodes[i];\r
-            }\r
-\r
-            for (int i = 0; i < nodeRss.ChildNodes.Count; i++)\r
+                // Get the correct Appcast and set input.\r
+                XmlNode nodeItem = readRss(new XmlTextReader(new StringReader(input)));\r
+                string result = nodeItem.InnerXml;\r
+\r
+                // Regular Expressions\r
+                Match ver = Regex.Match(result, @"sparkle:version=""([0-9]*)\""");\r
+                Match verShort = Regex.Match(result, @"sparkle:shortVersionString=""(([svn]*)([0-9.\s]*))\""");\r
+\r
+                Build = ver.ToString().Replace("sparkle:version=", "").Replace("\"", "");\r
+                Version = verShort.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");\r
+                DownloadFile = nodeItem["windows"].InnerText;\r
+                DescriptionUrl = new Uri(nodeItem["sparkle:releaseNotesLink"].InnerText);\r
+            } \r
+            catch( Exception)\r
             {\r
-                if (nodeRss.ChildNodes[i].Name == "channel")\r
-                    nodeChannel = nodeRss.ChildNodes[i];\r
-            }\r
-\r
-            for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)\r
-            {\r
-                if (nodeChannel.ChildNodes[i].Name == "item")\r
-                    nodeItem = nodeChannel.ChildNodes[i];\r
+                return;\r
             }\r
         }\r
 \r
-\r
-        // Get's the information required out the RSS file.\r
-        private void getInfo()\r
+        /// <summary>\r
+        /// Read the RSS file.\r
+        /// </summary>\r
+        /// <param name="rssReader"></param>\r
+        private static XmlNode readRss(XmlReader rssReader)\r
         {\r
-            Match ver;\r
-            int unstable_build = 0;\r
-            string input;\r
+            XmlNode nodeItem = null;\r
+            XmlNode nodeChannel = null;\r
+            XmlNode nodeRss = null;\r
 \r
-            // Check the stable appcast and get the build nuber\r
-            rssReader = new XmlTextReader(Properties.Settings.Default.appcast);\r
-            readRss(rssReader);\r
-            input = nodeItem.InnerXml;\r
-            ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");\r
-            int stable_build = int.Parse(ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""));\r
+            XmlDocument rssDoc = new XmlDocument();\r
+            rssDoc.Load(rssReader);\r
 \r
-            // If the pref to enable unstable appcast checking is enabled    OR\r
-            // this is a snapshot release, \r
-            // then check the unstable appcast.\r
-            if (Properties.Settings.Default.checkSnapshot == "Checked" || Properties.Settings.Default.hb_build.ToString().EndsWith("1"))\r
+            foreach (XmlNode t in rssDoc.ChildNodes)\r
             {\r
-                // Get the stable build\r
-                rssReader = new XmlTextReader(Properties.Settings.Default.appcast_unstable);\r
-                readRss(rssReader);\r
-                input = nodeItem.InnerXml;\r
-                ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");\r
-                unstable_build = int.Parse(ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""));\r
+                if (t.Name == "rss")\r
+                    nodeRss = t;\r
             }\r
 \r
-            if (stable_build >= unstable_build)\r
-                rssReader = new XmlTextReader(Properties.Settings.Default.appcast);\r
-            else\r
-                rssReader = new XmlTextReader(Properties.Settings.Default.appcast_unstable);\r
-\r
-            // Get the Version Information\r
-            hb_versionInfo = nodeItem["description"].InnerText;\r
-\r
-            // Get the version\r
-            string inputNode = nodeItem.InnerXml;\r
-            ver = Regex.Match(inputNode, @"sparkle:shortVersionString=""([0-9].[0-9].[0-9]*)\""");\r
-            hb_version = ver.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");\r
-\r
-            ver = Regex.Match(inputNode, @"sparkle:version=""([0-9]*)\""");\r
-            hb_build = ver.ToString().Replace("sparkle:version=", "").Replace("\"", "");\r
-\r
-            // Get the update file\r
-            hb_file = nodeItem["windows"].InnerText;\r
+            if (nodeRss != null)\r
+                foreach (XmlNode t in nodeRss.ChildNodes)\r
+                {\r
+                    if (t.Name == "channel")\r
+                        nodeChannel = t;\r
+                }\r
+\r
+            if (nodeChannel != null)\r
+                foreach (XmlNode t in nodeChannel.ChildNodes)\r
+                {\r
+                    if (t.Name == "item")\r
+                        nodeItem = t;\r
+                }\r
+\r
+            return nodeItem;\r
         }\r
 \r
         /// <summary>\r
         /// Get Information about an update to HandBrake\r
         /// </summary>\r
-        /// <returns></returns>\r
-        public string versionInfo()\r
-        {\r
-            getInfo();\r
-            return hb_versionInfo;\r
-        }\r
+        public Uri DescriptionUrl { get; set; }\r
 \r
         /// <summary>\r
         /// Get HandBrake's version from the appcast.xml file.\r
         /// </summary>\r
-        /// <returns></returns>\r
-        public string version()\r
-        {\r
-            getInfo();\r
-            return hb_version;\r
-        }\r
+        public string Version { get; set; }\r
 \r
         /// <summary>\r
         /// Get HandBrake's Build from the appcast.xml file.\r
         /// </summary>\r
-        /// <returns></returns>\r
-        public string build()\r
-        {\r
-            getInfo();\r
-            return hb_build;\r
-        }\r
+        public string Build { get; set; }\r
 \r
         /// <summary>\r
         /// Get's the URL for update file.\r
         /// </summary>\r
-        /// <returns></returns>\r
-        public string downloadFile()\r
-        {\r
-            getInfo();\r
-            return hb_file;\r
-        }\r
+        public string DownloadFile { get; set; }\r
     }\r
 }
\ No newline at end of file