예제 #1
0
        /// <summary>
        /// Implements IDB.CachePlatformdata() Update the local DB cache of platform associated metadata
        /// </summary>
        /// <param name="platform">Robin.Platform associated with the DBPlatorm to update.</param>
        public void CachePlatformData(Platform platform)
        {
            Reporter.Tic("Getting " + platform.Title + " data from Games DB...", out int tic1);

            GDBPlatform gdbPlatform = platform.GDBPlatform;

            XDocument xdoc;
            string    url;

            string urlbase = $"{baseUrl}GetPlatform.php?id=";

            using (WebClient webclient = new WebClient())
            {
                // Assemble the platformsdb url from the platform data and the base API url
                url = urlbase + gdbPlatform.ID;

                // Pull down the xml file containing platform data from gamesdb
                if (webclient.SafeDownloadStringDB(url, out string downloadtext))
                {
                    xdoc = XDocument.Parse(downloadtext);

                    gdbPlatform.Title        = xdoc.SafeGetB("Platform", "Platform");
                    gdbPlatform.Developer    = xdoc.SafeGetB("Platform", "developer");
                    gdbPlatform.Manufacturer = xdoc.SafeGetB("Platform", "manufacturer");
                    gdbPlatform.Cpu          = xdoc.SafeGetB("Platform", "cpu");
                    gdbPlatform.Sound        = xdoc.SafeGetB("Platform", "sound");
                    gdbPlatform.Display      = xdoc.SafeGetB("Platform", "display");
                    gdbPlatform.Media        = xdoc.SafeGetB("Platform", "media");
                    gdbPlatform.Controllers  = xdoc.SafeGetB("Platform", "maxcontrollers");
                    gdbPlatform.Rating       = decimal.Parse(xdoc.SafeGetB("Platform", "rating") ?? "0");
                    gdbPlatform.Overview     = xdoc.SafeGetB("Platform", "overview");

                    string BaseImageUrl = xdoc.SafeGetB("baseImgUrl");

                    if (BaseImageUrl != null)
                    {
                        string BoxFrontUrl   = xdoc.SafeGetBoxArt("front", type: "Platform");
                        string BoxBackUrl    = xdoc.SafeGetBoxArt("back", type: "Platform");
                        string BannerUrl     = xdoc.SafeGetB("Platform", "Images", "banner");
                        string ConsoleUrl    = xdoc.SafeGetB("Platform", "Images", "consoleart");
                        string ControllerUrl = xdoc.SafeGetB("Platform", "Images", "controllerart");

                        gdbPlatform.BoxFrontURL   = BoxFrontUrl != null ? BaseImageUrl + BoxFrontUrl : null;
                        gdbPlatform.BoxBackURL    = BoxBackUrl != null ? BaseImageUrl + BoxBackUrl : null;
                        gdbPlatform.BannerURL     = BannerUrl != null ? BaseImageUrl + BannerUrl : null;
                        gdbPlatform.ConsoleURL    = ConsoleUrl != null ? BaseImageUrl + ConsoleUrl : null;
                        gdbPlatform.ControllerURL = ControllerUrl != null ? BaseImageUrl + ControllerUrl : null;
                    }
                }
                else
                {
                    Reporter.Warn("Failure getting " + gdbPlatform.Title + " data from Games DB.");
                }
            }
            Reporter.Toc(tic1);
        }
예제 #2
0
        /// <summary>
        /// Implement IDB.CachePlatfomrReleases(). Go out to gamesdb.com and cache all known releases for the specified platform. Update the list of releases and store metadata for each one.
        /// </summary>
        /// <param name="platform">Robin.Platform associated with the GDBPlatform to cache.</param>
        public void CachePlatformReleases(Platform platform)
        {
            Reporter.Tic($"Getting {platform.Title} release list from Games DB...", out int tic1);
            GDBPlatform gdbPlatform = platform.GDBPlatform;

            // Update list of GDBReleases for this platform from xml file
            using (WebClient webclient = new WebClient())
            {
                // API to get xml file containing all gamesdb releases for this platform.
                string url = $"{baseUrl}GetPlatformGames.php?platform=" + gdbPlatform.ID;

                // Put existing GDBReleases in a dictionary for lookup performance
                var existingGDBReleaseDict          = R.Data.GDBReleases.ToDictionary(x => x.ID);
                HashSet <GDBRelease> newGDBReleases = new HashSet <GDBRelease>();

                if (webclient.SafeDownloadStringDB(url, out string downloadText))
                {
                    XDocument xDocument = XDocument.Parse(downloadText);

                    foreach (XElement element in xDocument.Root.Elements("Game"))
                    {
                        // Don't create this game if the title is null
                        string title = element.Element("GameTitle")?.Value;
                        if (string.IsNullOrEmpty(title))
                        {
                            continue;
                        }

                        // Check if gbdRelease exists before creating new one. Whether it exists or not, overwrite properties with properties from xml file.
                        long id = long.Parse(element.Element("id")?.Value);
                        if (!existingGDBReleaseDict.TryGetValue(id, out GDBRelease gdbRelease))
                        {
                            gdbRelease = new GDBRelease {
                                ID = id
                            };
                            newGDBReleases.Add(gdbRelease);
                        }

                        gdbRelease.Title = title;
                        gdbRelease.Date  = DateTimeRoutines.SafeGetDate(element.SafeGetA("ReleaseDate") ?? "01-01-1901");

                        // If a release has changed platforms, catch it and zero out match
                        if (gdbRelease.GDBPlatform_ID != gdbPlatform.ID)
                        {
                            gdbRelease.GDBPlatform_ID = gdbPlatform.ID;
                            Release release = R.Data.Releases.FirstOrDefault(x => x.ID_GDB == id);
                            if (release != null)
                            {
                                release.ID_GDB = null;
                            }
                        }
                    }
                }
                gdbPlatform.GDBReleases.UnionWith(newGDBReleases);
                Reporter.Toc(tic1);
            }

            // Temporarily set wait time to 1 ms while caching tens of thousands of games. Sorry GDB.
            int waitTimeHolder = DBTimers.GamesDB.WaitTime;

            DBTimers.GamesDB.WaitTime = 1;

            int releaseCount = gdbPlatform.GDBReleases.Count;
            int i            = 0;

            // Cache metadata for each individual game
            foreach (GDBRelease gdbRelease in gdbPlatform.GDBReleases)
            {
                if (releaseCount / 10 != 0 && i++ % (releaseCount / 10) == 0)
                {
                    Reporter.Report($"{i} / {releaseCount}");
                }

                CacheReleaseData(gdbRelease);
            }
            DBTimers.GamesDB.WaitTime = waitTimeHolder;
        }