Example #1
0
        public void GetModList(string type)
        {
            lock(this)
            {
                if (!File.Exists(xmlFile.fullName))
                    CreateXmlFile(xmlFile);

                string url = "";
                if (type == "cars")
                    url = "http://www.racedepartment.com/downloads/categories/sce-cars.82/";
                else if (type == "tracks")
                    url = "http://www.racedepartment.com/downloads/categories/sce-tracks.22/";
                else if (type == "skins")
                    url = "http://www.racedepartment.com/downloads/categories/sce-skins.23/";
                else if (type == "misc")
                    url = "http://www.racedepartment.com/downloads/categories/sce-misc.24/";
                WebClient wc = new WebClient();
                string html = wc.DownloadString(url);

                MatchCollection mColl = Regex.Matches(html, "<span class=\"pageNavHeader\">Page 1 of (.+?)</span>", RegexOptions.Singleline);
                int pageCount = Convert.ToInt32(mColl[0].Groups[1].Value);

                for (int i = 1; i <= pageCount; i++)
                {
                    html = wc.DownloadString(url + "?page=" + i);
                    MatchCollection mName = Regex.Matches(html, "<h3 class=\"title\">\\s*(.+?)<div class=\"listBlock resourceStats\">", RegexOptions.Singleline);

                    foreach (Match m in mName)
                    {
                        Mod mod = new Mod();
                        string substring = m.Groups[1].Value;
                        string pat;
                        string subhtml;
                        Regex r;
                        Match submatch;

                        pat = ">(.+?)</a>";
                        r = new Regex(pat, RegexOptions.Singleline);
                        submatch = r.Match(substring);
                        mod.name = HttpUtility.HtmlDecode(submatch.Groups[1].Value);


                        pat = "\"version\">(.+?)</span>";
                        r = new Regex(pat, RegexOptions.Singleline);
                        submatch = r.Match(substring);
                        mod.version = submatch.Groups[1].Value;

                        pat = "\"auto\">(.+?)</a>";
                        r = new Regex(pat, RegexOptions.Singleline);
                        submatch = r.Match(substring);
                        mod.author = submatch.Groups[1].Value;

                        pat = "([a-zA-Z]{3}\\s[0-9]{1,2},\\s[0-9]{4})";
                        r = new Regex(pat, RegexOptions.Singleline);
                        submatch = r.Match(substring);
                        mod.date = submatch.Groups[1].Value;

                        pat = "\"(.+?)/\"";
                        r = new Regex(pat, RegexOptions.Singleline);
                        submatch = r.Match(substring);

                        subhtml = wc.DownloadString("http://www.racedepartment.com/" + submatch.Groups[1].Value);

                        pat = "<label\\sclass=\"downloadButton\\s\">\\s*<a\\shref=\"(.+?)\"";
                        r = new Regex(pat, RegexOptions.Singleline);
                        submatch = r.Match(subhtml);
                        mod.downloadLink = "http://www.racedepartment.com/" + submatch.Groups[1].Value;

                        mod.fileName = GetFileName(mod.downloadLink);

                        pat = "<small\\sclass=\"minorText\">(.+?)\\sMB";
                        r = new Regex(pat, RegexOptions.Singleline);
                        submatch = r.Match(subhtml);
                        mod.size = submatch.Groups[1].Value;

                        if (mod.size == "")
                            mod.size = "<1.0";

                        mod.type = type;

                        NewXmlEntry(mod);
                        switch (type)
                        {
                            case "cars":
                                carsLabel.Invoke((MethodInvoker)delegate { carsLabel.Text = (Convert.ToInt32(carsLabel.Text) + 1).ToString(); });
                                break;
                            case "tracks":
                                tracksLabel.Invoke((MethodInvoker)delegate { tracksLabel.Text = (Convert.ToInt32(tracksLabel.Text) + 1).ToString(); });
                                break;
                            case "skins":
                                skinsLabel.Invoke((MethodInvoker)delegate { skinsLabel.Text = (Convert.ToInt32(skinsLabel.Text) + 1).ToString(); });
                                break;
                            case "misc":
                                miscLabel.Invoke((MethodInvoker)delegate { miscLabel.Text = (Convert.ToInt32(miscLabel.Text) + 1).ToString(); });
                                break;
                        }
                    }
                }
            }
        }
Example #2
0
 private void NewXmlEntry(Mod mod)
 {
     XDocument xmlDoc = XDocument.Load(xmlFile.fullName);
     XElement cars = xmlDoc.Element("root").Element("cars");
     XElement tracks = xmlDoc.Element("root").Element("tracks");
     XElement skins = xmlDoc.Element("root").Element("skins");
     XElement misc = xmlDoc.Element("root").Element("misc");
     switch (mod.type)
     {
         case "cars":
             cars.Add(new XElement("mod",
                 new XElement("name", mod.name),
                 new XElement("version", mod.version),
                 new XElement("author", mod.author),
                 new XElement("downloadLink", mod.downloadLink),
                 new XElement("fileName", mod.fileName),
                 new XElement("size", mod.size),
                 new XElement("date", mod.date)));
             break;
         case "tracks":
             tracks.Add(new XElement("mod",
                 new XElement("name", mod.name),
                 new XElement("version", mod.version),
                 new XElement("author", mod.author),
                 new XElement("downloadLink", mod.downloadLink),
                 new XElement("fileName", mod.fileName),
                 new XElement("size", mod.size),
                 new XElement("date", mod.date)));
             break;
         case "skins":
             skins.Add(new XElement("mod",
                 new XElement("name", mod.name),
                 new XElement("version", mod.version),
                 new XElement("author", mod.author),
                 new XElement("downloadLink", mod.downloadLink),
                 new XElement("fileName", mod.fileName),
                 new XElement("size", mod.size),
                 new XElement("date", mod.date)));
             break;
         case "misc":
             misc.Add(new XElement("mod",
                 new XElement("name", mod.name),
                 new XElement("version", mod.version),
                 new XElement("author", mod.author),
                 new XElement("downloadLink", mod.downloadLink),
                 new XElement("fileName", mod.fileName),
                 new XElement("size", mod.size),
                 new XElement("date", mod.date)));
             break;
         default:
             break;
     }
     xmlDoc.Save(xmlFile.fullName);
 }