summaryrefslogtreecommitdiffstats
path: root/win/C#/Functions/RssReader.cs
blob: 36d105d8d428d435f978f4e752abe11308a0469f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Text.RegularExpressions;

namespace Handbrake.Functions
{
    class RssReader
    {
        XmlTextReader rssReader;
        XmlDocument rssDoc;
        XmlNode nodeRss;
        XmlNode nodeChannel;
        XmlNode nodeItem;
        string t;

        private string readRss()
        {
            rssReader = new XmlTextReader("http://handbrake.m0k.org/appcast.xml");
            rssDoc = new XmlDocument();
            rssDoc.Load(rssReader);

            for (int i = 0; i < rssDoc.ChildNodes.Count; i++)
            {
                if (rssDoc.ChildNodes[i].Name == "rss")
                {
                    nodeRss = rssDoc.ChildNodes[i];
                }
            }

            for (int i = 0; i < nodeRss.ChildNodes.Count; i++)
            {
                if (nodeRss.ChildNodes[i].Name == "channel")
                {
                    nodeChannel = nodeRss.ChildNodes[i];
                }
            }

            string latestTitle = "";
            for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
            {
 
                if (nodeChannel.ChildNodes[i].Name == "item")
                {
                    nodeItem = nodeChannel.ChildNodes[i];
                    latestTitle = nodeItem["title"].InnerText;
                }
            }
            return latestTitle;
        }


        public string versionInfo()
        {
            readRss();
            string vinfo = "";
            for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
            {
                if (nodeChannel.ChildNodes[6].Name == "item")
                {
                    nodeItem = nodeChannel.ChildNodes[0];
                    t = readRss();
                    if (nodeItem["title"].InnerText == t)
                    {
                        vinfo = nodeItem["description"].InnerText;
                        break;
                    }
                }
            }

            return vinfo;
         }

        public string version()
        {
            readRss();
            string vinfo = "";
            for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
            {
                if (nodeChannel.ChildNodes[6].Name == "item")
                {
                    nodeItem = nodeChannel.ChildNodes[0];
                    string t = readRss();
                    if (nodeItem["title"].InnerText == t)
                    {
                        string input = nodeItem.InnerXml;
                        Match ver = Regex.Match(input, @"sparkle:shortVersionString=""([0-9].[0-9].[0-9]*)\""");
                        vinfo = ver.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", "");

                        break;
                    }
                }
            }
            return vinfo;
        }

        public string build()
        {
            readRss();
            string vinfo = "";
            for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
            {
                if (nodeChannel.ChildNodes[6].Name == "item")
                {
                    nodeItem = nodeChannel.ChildNodes[0];
                    string t = readRss();
                    if (nodeItem["title"].InnerText == t)
                    {
                        string input = nodeItem.InnerXml; 
                        Match ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\""");
                        vinfo = ver.ToString().Replace("sparkle:version=", "").Replace("\"", "");
                        break;
                    }
                }
            }
            return vinfo;
        }

        public string downloadFile()
        {
            readRss();
            string file = "";
            for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
            {
                if (nodeChannel.ChildNodes[6].Name == "item")
                {
                    nodeItem = nodeChannel.ChildNodes[0];
                    t = readRss();
                    if (nodeItem["title"].InnerText == t)
                    {
                        file = nodeItem["windows"].InnerText;
                        break;
                    }
                }
            }

            return file;
         }
    }
}