private void MainWindow_Loaded(object sender, RoutedEventArgs e)
 {
     ShowProgress();
     Task.Factory.StartNew(() =>
     {
         var webOps = new WebOps();
         webOps.ProgressCompleted += WebOps_ProgressCompleted;
         webOps.ReadDataFromServer();
     });
 }
Exemplo n.º 2
0
        /// <summary>
        /// Pull Back Webpage as a string
        /// </summary>
        /// <param name="BaseUrl"></param>
        /// <param name="Params"></param>
        /// <param name="Timeout"></param>
        /// <returns></returns>
        public static string ReturnWebpage(string BaseUrl, string Params, int Timeout)
        {
            WebOps wo = new WebOps();

            if (Params == null)
            {
                Params = "";
            }
            if (Timeout == 0)
            {
                Timeout = 10000;
            }
            wo.BaseUrl = BaseUrl;
            wo.Timeout = Timeout;
            wo.Params  = Params;
            string result = wo.ApiCall();

            wo = null;
            return(result);
        }
Exemplo n.º 3
0
        public static void ScrapeBasicDocsList(ProgressDialogController controller)
        {
            List <ReplacementDocs> rdlist = new List <ReplacementDocs>();

            // iterate through mednafen systems
            var systems = GSystem.GetSystems();

            foreach (var sys in systems)
            {
                controller.SetMessage("Getting manual links for: " + sys.systemName + "\n");
                if (sys.systemId == 16 || sys.systemId == 17 || sys.systemId == 18)
                {
                    continue;
                }
                List <int> rdsystems = ConvertSystemId2RDSystemId(sys.systemId);

                // iterate through replacementdocs systems
                foreach (int s in rdsystems)
                {
                    // get the whole page for this system
                    WebOps wo = new WebOps();
                    wo.BaseUrl = "http://www.replacementdocs.com/download.php?";
                    wo.Params  = "1.list." + s.ToString() + ".1000.download_name.ASC";
                    wo.Timeout = 20000;
                    string result = wo.ApiCall();

                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(result);

                    HtmlNode table = doc.DocumentNode.SelectSingleNode("//table[contains(@class, 'fborder')]");

                    // iterate through each table row
                    foreach (HtmlNode row in table.ChildNodes)
                    {
                        if (row.ChildNodes.Count > 0)
                        {
                            HtmlNode[] cells = (from a in row.SelectNodes("td")
                                                select a).ToArray();
                            if (cells[0].InnerHtml.Contains("download.php?view."))
                            {
                                // this is a data cell
                                string   title  = cells[0].InnerText.Replace("\t", "").Trim();
                                string   url    = cells[0].InnerHtml.Replace("\t", "").Trim().Replace("<a href='download.php?view.", "");
                                string[] urlArr = url.Split('\'');
                                string   fileId = urlArr[0];

                                var recordcheck = (from a in rdlist
                                                   where a.GameName == title && a.TGBSystemName == ConvertRDSystemId2TGBPlatformName(s)
                                                   select a).ToList();

                                if (recordcheck.Count > 0)
                                {
                                    ReplacementDocs r = recordcheck.FirstOrDefault();
                                    r.Urls.Add("http://www.replacementdocs.com/request.php?" + fileId);
                                    r.Urls.Distinct();
                                    rdlist.Add(r);
                                }
                                else
                                {
                                    ReplacementDocs r = new ReplacementDocs();
                                    r.GameName      = title;
                                    r.TGBSystemName = ConvertRDSystemId2TGBPlatformName(s);
                                    r.Urls.Add("http://www.replacementdocs.com/request.php?" + fileId);
                                    r.Urls.Distinct();
                                    rdlist.Add(r);
                                }

                                rdlist.Distinct();
                            }
                        }
                    }
                }
            }

            // save rdlist to json
            string json = JsonConvert.SerializeObject(rdlist, Formatting.Indented);

            File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Data\System\replacementdocs-manuals.json", json);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets all the games for a platform. The Platform field will not be filled.
        /// </summary>
        /// <param name="ID">The platform ID to return games for (can be found by using GetPlatformsList)</param>
        /// <returns>A collection of all the games on the platform</returns>
        public static ICollection <GDBNETGameSearchResult> GetPlatformGames(int ID)
        {
            WebOps wo = new WebOps();

            wo.Params  = "/GetPlatformGames.php?platform=" + ID;
            wo.Timeout = 20000;
            string result = wo.ApiCall();

            // string returned
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(result);

            /*
             * XmlDocument doc = new XmlDocument();
             * try
             * {
             *  doc.Load(@"http://thegamesdb.net/api/GetPlatformGames.php?platform=" + ID);
             * }
             * catch (Exception ex)
             * {
             *  return new List<GDBNETGameSearchResult>();
             * }
             * finally { }
             */

            XmlNode     root  = doc.DocumentElement;
            IEnumerator ienum = root.GetEnumerator();

            List <GDBNETGameSearchResult> games = new List <GDBNETGameSearchResult>();

            // Iterate through all games
            XmlNode gameNode;

            while (ienum.MoveNext())
            {
                GDBNETGameSearchResult game = new GDBNETGameSearchResult();
                gameNode = (XmlNode)ienum.Current;

                IEnumerator ienumGame = gameNode.GetEnumerator();
                XmlNode     attributeNode;
                while (ienumGame.MoveNext())
                {
                    attributeNode = (XmlNode)ienumGame.Current;

                    // Iterate through all game attributes
                    switch (attributeNode.Name)
                    {
                    case "id":
                        int.TryParse(attributeNode.InnerText, out game.ID);
                        break;

                    case "GameTitle":
                        game.Title = attributeNode.InnerText;
                        break;

                    case "ReleaseDate":
                        game.ReleaseDate = attributeNode.InnerText;
                        break;
                    }
                }

                games.Add(game);
            }

            return(games);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the data for a specific game.
        /// </summary>
        /// <param name="ID">The game ID to return data for</param>
        /// <returns>A Game-object containing all the data about the game, or null if no game was found</returns>
        public static GDBNETGame GetGame(int ID)
        {
            WebOps wo = new WebOps();

            wo.Params  = "/GetGame.php?id=" + ID;
            wo.Timeout = 30000;
            string result = wo.ApiCall();

            // save to xml locally
            //GamesLibraryScrapedContent glsc = new Classes.GamesLibraryScrapedContent();
            //glsc.CreateFolderStructure(ID);
            //File.WriteAllText(System.AppDomain.CurrentDomain.BaseDirectory + @"\Data\Graphics\thegamesdb\" + ID + @"\" + ID  + "-external.xml", result);

            /*
             * wo.GDBApiCall();
             * if (wo.BodyAsString == null)
             * {
             *  // no body returned within the specified timeout periods
             *  return null;
             * }
             */

            // string returned
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(result);

            /*
             * XmlDocument doc = new XmlDocument();
             * try
             * {
             *  doc.Load(@"http://thegamesdb.net/api/GetGame.php?id=" + ID);
             * }
             *
             * catch (Exception ex)
             * {
             *  return new GDBNETGame();
             * }
             * finally { }
             */

            XmlNode     root  = doc.DocumentElement;
            IEnumerator ienum = root.GetEnumerator();

            XmlNode    platformNode = root.FirstChild.NextSibling;
            GDBNETGame game         = new GDBNETGame();

            IEnumerator ienumGame = platformNode.GetEnumerator();
            XmlNode     attributeNode;

            while (ienumGame.MoveNext())
            {
                attributeNode = (XmlNode)ienumGame.Current;

                // Iterate through all platform attributes
                switch (attributeNode.Name)
                {
                case "id":
                    int.TryParse(attributeNode.InnerText, out game.ID);
                    break;

                case "Overview":
                    game.Overview = attributeNode.InnerText;
                    break;

                case "GameTitle":
                    game.Title = attributeNode.InnerText;
                    break;

                case "Platform":
                    game.Platform = attributeNode.InnerText;
                    break;

                case "ReleaseDate":
                    game.ReleaseDate = attributeNode.InnerText;
                    break;

                case "overview":
                    game.Overview = attributeNode.InnerText;
                    break;

                case "ESRB":
                    game.ESRB = attributeNode.InnerText;
                    break;

                case "Players":
                    game.Players = attributeNode.InnerText;
                    break;

                case "Co-op":
                    game.Coop = attributeNode.InnerText;
                    break;

                case "Publisher":
                    game.Publisher = attributeNode.InnerText;
                    break;

                case "Developer":
                    game.Developer = attributeNode.InnerText;
                    break;

                case "Rating":
                    //double.TryParse(attributeNode.InnerText, out game.Rating);
                    game.Rating = attributeNode.InnerText;
                    break;

                case "AlternateTitles":
                    IEnumerator ienumAlternateTitles = attributeNode.GetEnumerator();
                    while (ienumAlternateTitles.MoveNext())
                    {
                        game.AlternateTitles.Add(((XmlNode)ienumAlternateTitles.Current).InnerText);
                    }
                    break;

                case "Genres":
                    IEnumerator ienumGenres = attributeNode.GetEnumerator();
                    while (ienumGenres.MoveNext())
                    {
                        game.Genres.Add(((XmlNode)ienumGenres.Current).InnerText);
                    }
                    break;

                case "Images":
                    game.Images.FromXmlNode(attributeNode);
                    break;
                }
            }

            return(game);
        }