Esempio n. 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)
        {
            GBPlatform gbPlatform = platform.GBPlatform;

            XDocument xDocument;

            Reporter.Tic("Attempting to cache " + gbPlatform.Title + "...", out int tic1);

            using (WebClient webClient = new WebClient())
            {
                string url = GBURL + $"platform/{gbPlatform.ID}/?api_key ={Keys.GiantBomb}";

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

                    gbPlatform.Title        = xDocument.SafeGetB("results", "name");
                    gbPlatform.Abbreviation = xDocument.SafeGetB("results", "abbreviation");
                    if (long.TryParse(xDocument.SafeGetB("results", "company"), out long company))
                    {
                        gbPlatform.Company = company;
                    }
                    gbPlatform.Deck  = xDocument.SafeGetB("results", "deck");
                    gbPlatform.Price = xDocument.SafeGetB("results", "original_price");
                    gbPlatform.Date  = DateTimeRoutines.SafeGetDate(xDocument.SafeGetB("results", "release_date"));
                    Reporter.Toc(tic1);
                }

                else
                {
                    Reporter.Toc(tic1, "Error communicating with GiantBomb.");
                }
            }            // end using webclient
        }
Esempio n. 2
0
        public GamesDB()
        {
            Reporter.Tic("Opening Games DB cache...", out int tic1);

            R.Data.GDBPlatforms.Load();
            R.Data.GDBReleases.Load();
            Reporter.Toc(tic1);
        }
Esempio n. 3
0
        public GiantBomb()
        {
            Reporter.Tic("Opening GiantBomb cache...", out int tic1);

            R.Data.GBPlatforms.Load();
            R.Data.GBReleases.Load();
            R.Data.GBGames.Load();
            Reporter.Toc(tic1);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public OpenVGDB()
        {
            Reporter.Tic("Opening Open VGDB cache...", out int tic1);

            R.Data.OVGPlatforms.Load();
            R.Data.OVGReleases.Load();
            //R.Data.Releases.Include(x => x.OVGRelease);

            Reporter.Toc(tic1);
        }
Esempio n. 6
0
        public Launchbox()
        {
            Reporter.Tic("Loading LaunchBox local cache...", out int tic1);

            R.Data.LBPlatforms.Load();
            R.Data.LBImages.Load();
            R.Data.LBReleases.Load();
            R.Data.LBGames.Load();

            Reporter.Toc(tic1);
        }
Esempio n. 7
0
        /// <summary>
        /// Get the xml file containing hte entire Launchbox database. Use existing downloaded file if it was modified today. Load the xml file to memory as property launchboxFile.
        /// </summary>
        void GetLaunchBoxFile()
        {
            using (WebClient webclient = new WebClient())
            {
                if (File.Exists(LaunchBoxDataZipFile) && (File.GetLastWriteTime(LaunchBoxDataZipFile).Date == DateTime.Today))
                {
                    Reporter.Report("Found up to date LaunchBox zip file.");
                }
                else
                {
                    Reporter.Tic("Updating LaunchBox zip file...", out int tic1);

                    webclient.DownloadFileFromDB(@"http://gamesdb.launchbox-app.com/Metadata.zip", LaunchBoxDataZipFile);
                    Reporter.Toc(tic1);
                }
            }

            Reporter.Tic("Extracting info from zip file...", out int tic2);
            try
            {
                using (ZipArchive archive = ZipFile.Open(LaunchBoxDataZipFile, ZipArchiveMode.Read))
                    using (var dattext = archive.GetEntry("Metadata.xml").Open())
                    {
                        launchboxFile = XDocument.Load(dattext);
                    }
            }

            catch (InvalidDataException)
            {
                Reporter.Report("Error in LaunchBox Metadata file.");
                File.Delete(LaunchBoxDataZipFile);
                launchboxFile = null;
            }

            gameElementLookupByPlatform  = launchboxFile.Root.Elements("Game").ToLookup(x => x.Element("Platform").Value);
            releaseElementLookupByGameID = launchboxFile.Root.Elements("GameAlternateName").ToLookup(x => x.Element("DatabaseID").Value);
            imageElementLookupByGameID   = launchboxFile.Root.Elements("GameImage").ToLookup(x => x.Element("DatabaseID").Value);
            platformElements             = launchboxFile.Root.Elements("Platform").ToList();

            Reporter.Toc(tic2);
        }
Esempio n. 8
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;
        }
Esempio n. 9
0
        /// <summary>
        /// Audits existance of roms for patforms that are not mame. Cycles through all roms under the platform, checks the existance of a file under ROM.filename, checks the  crc
        /// </summary>
        /// <returns>A list of Audit.Result </returns>
        static TitledCollection <Result> AuditNonMameRoms(Platform platform)
        {
            TitledCollection <Result> returner = new TitledCollection <Result>(platform.Title);

            // Record all files in the directory to keep track of which have been audited
            HashSet <string> files = new HashSet <string>(Directory.GetFiles(platform.RomDirectory));

            int headerLength = (int)platform.HeaderLength;
            int romCount     = platform.Roms.Count;

            Reporter.Tic($"Auditing {romCount} {platform.Title} database ROMs...", out int tic1);
            // First audit all ROMS in the database
            foreach (Rom rom in platform.Roms)
            {
                var result = new Result(rom);
                returner.Add(result);

                if (File.Exists(rom.FilePath))
                {
                    if (rom.CRC32 != null)
                    {
                        if (rom.CRC32 == GetHash(rom.FilePath, HashOption.CRC32, headerLength) ||
                            rom.CRC32 == GetHash(rom.FilePath, HashOption.CRC32, 0))
                        {
                            result.Status = Status.Good;
                        }
                        else
                        {
                            result.Status = Status.Bad;
                        }
                    }

                    else if (rom.MD5 != null)
                    {
                        if (rom.MD5 == GetHash(rom.FilePath, HashOption.MD5, headerLength) ||
                            rom.MD5 == GetHash(rom.FilePath, HashOption.MD5, 0))
                        {
                            result.Status = Status.Good;
                        }
                        else
                        {
                            result.Status = Status.Bad;
                        }
                    }

                    else if (rom.SHA1 != null)
                    {
                        if (rom.SHA1 == GetHash(rom.FilePath, HashOption.SHA1, headerLength) ||
                            rom.SHA1 == GetHash(rom.FilePath, HashOption.SHA1, 0))
                        {
                            result.Status = Status.Good;
                        }
                        else
                        {
                            result.Status = Status.Bad;
                        }
                    }

                    else
                    {
                        result.Status = Status.Unknown;
                    }
                }

                else
                {
                    result.Status = Status.Missing;
                }

                // Remove from the list so we don't check again below
                files.Remove(rom.FilePath);
            }
            Reporter.Toc(tic1);

            // Then go through all files in the folder not checked yet and mark as superfluous
            Reporter.Tic("Creating hash sets...", out int tic2);
            HashSet <string> crcs  = new HashSet <string>(returner.Select(x => x.CRC32));
            HashSet <string> sha1s = new HashSet <string>(returner.Select(x => x.SHA1));
            HashSet <string> md5s  = new HashSet <string>(returner.Select(x => x.MD5));

            Reporter.Toc(tic2);

            Reporter.Tic("Auditing orpan files on disks...", out int tic3);
            foreach (string file in files)
            {
                Result result = new Result
                {
                    Status   = Status.Extra,
                    FilePath = file
                };

                if (crcs.Contains(GetHash(file, HashOption.CRC32, (int)platform.HeaderLength)) ||
                    crcs.Contains(GetHash(file, HashOption.CRC32, 0)) ||
                    md5s.Contains(GetHash(file, HashOption.MD5, (int)platform.HeaderLength)) ||
                    md5s.Contains(GetHash(file, HashOption.MD5, 0)) ||
                    sha1s.Contains(GetHash(file, HashOption.SHA1, (int)platform.HeaderLength)) ||
                    sha1s.Contains(GetHash(file, HashOption.SHA1, 0)))
                {
                    result.Status = Status.Duplicate;
                }
            }
            Reporter.Toc(tic3);

            return(returner);
        }
Esempio n. 10
0
        public void CachePlatformReleases(Platform platform)
        {
            Reporter.Tic($"Cache {platform.LBPlatform.Title} releases begun...", out int tic1);
            CachePlatformGames(platform);

            if (launchboxFile == null)
            {
                GetLaunchBoxFile();
            }

            // Create a dictionary of existing LBReleases to speed lookups
            Dictionary <long, LBRelease> existingLBReleaseDict = R.Data.LBReleases.ToDictionary(x => x.ID);

            // Create a Hashset of LBReleases to store any new LBReleases that we discover
            HashSet <LBRelease> newLBReleases = new HashSet <LBRelease>();

            int gameCount = platform.LBPlatform.LBGames.Count;
            int j         = 0;

            foreach (LBGame lbGame in platform.LBPlatform.LBGames)
            {
                // Reporting only
                if ((gameCount / 10) != 0 && ++j % (gameCount / 10) == 0)
                {
                    Reporter.Report($"  Working {j} / {gameCount} {platform.LBPlatform.Title} games.");
                }

                var gameReleaseElements = releaseElementLookupByGameID[lbGame.ID.ToString()];

                // Cache releases for this game from the launchbox file
                foreach (XElement releaseElement in gameReleaseElements)
                {
                    string regionText = releaseElement.Element("Region")?.Value;
                    long   regionID;

                    if (regionText == null)
                    {
                        regionID = CONSTANTS.UNKNOWN_REGION_ID;
                    }

                    else if (!RegionDictionary.TryGetValue(regionText, out regionID))
                    {
                        regionID = CONSTANTS.UNKNOWN_REGION_ID;
                        Reporter.Report($"Couldn't find {regionText} in LB image dictionary.");
                    }
#if DEBUG
                    Stopwatch watch1 = Stopwatch.StartNew();
#endif
                    LBRelease lbRelease = lbGame.LBReleases.FirstOrDefault(x => x.Region_ID == regionID);
#if DEBUG
                    Debug.WriteLine($"RA: " + watch1.ElapsedMilliseconds); watch1.Restart();
#endif
                    if (lbRelease == null)
                    {
                        lbRelease = new LBRelease();
                        lbGame.LBReleases.Add(lbRelease);
                        lbRelease.Region_ID = regionID;
                    }

                    lbRelease.Title = releaseElement.Element("AlternateName").Value;
                }
            }
            CachePlatformImages(platform);
            Reporter.Toc(tic1, $"Cache {platform.LBPlatform.Title} releases finished.");
        }
Esempio n. 11
0
        /// <summary>
        /// Cache data for a selected LBPlatforms in the local database from an xml file downloaded from Launchbox.
        /// </summary>
        /// <param name="platform">Robin.Platform associated with the LBPlatform to cache.</param>
        public void CachePlatformData(Platform platform)
        {
            Reporter.Tic($"Caching data for {platform.Title}...", out int tic1);
            if (launchboxFile == null)
            {
                GetLaunchBoxFile();
            }

            // Create a dictionary of existing LBPlatforms to speed lookups
            Dictionary <string, LBPlatform> platformDictionary = R.Data.LBPlatforms.ToDictionary(x => x.Title);

            // Create a Hashset of LBPlatforms to store any new LBPlatforms that we discover
            HashSet <LBPlatform> newLBPlatforms = new HashSet <LBPlatform>();

            foreach (XElement platformElement in platformElements)
            {
                string tempTitle = platformElement.Element("Name").Value;

                // If a bad titl is found or the title is gamewave, just bail
                if (string.IsNullOrEmpty(tempTitle) || Regex.IsMatch(tempTitle, @"Game*.Wave", RegexOptions.IgnoreCase))
                {
                    continue;
                }

#if DEBUG
                Stopwatch watch1 = Stopwatch.StartNew();
#endif
                // Check whether the LBPlatform exists before trying to add it. LBPlatforms have no ID, so check by title. If the title isn't found, this might be because the LBPlatform is new or because the title has been changed. The merge window lets the user decide.
                if (!platformDictionary.TryGetValue(tempTitle, out LBPlatform lbPlatform))
                {
                    lbPlatform = new LBPlatform();

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        MergeWindow mergeWindow = new MergeWindow(tempTitle);

                        switch (mergeWindow.ShowDialog())
                        {
                        case true:                                 // Merge the new platform with existing
                            lbPlatform = mergeWindow.SelectedLBPlatform;
                            break;

                        case false:                                 // Add the new platform
                            newLBPlatforms.Add(lbPlatform);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    });
                }
#if DEBUG
                Debug.WriteLine("PB: " + watch1.ElapsedMilliseconds); watch1.Restart();
#endif
                // Whether the LBPlatorm is new or old, overwrite everything with the newest data
                lbPlatform.Title        = tempTitle;
                lbPlatform.Date         = DateTimeRoutines.SafeGetDate(platformElement.SafeGetA("Date"));
                lbPlatform.Developer    = platformElement.Element("Developer")?.Value ?? lbPlatform.Developer;
                lbPlatform.Manufacturer = platformElement.Element("Manufacturer")?.Value ?? lbPlatform.Manufacturer;
                lbPlatform.Cpu          = platformElement.Element("Cpu")?.Value ?? lbPlatform.Cpu;
                lbPlatform.Memory       = platformElement.Element("Memory")?.Value ?? lbPlatform.Memory;
                lbPlatform.Graphics     = platformElement.Element("Graphics")?.Value ?? lbPlatform.Graphics;
                lbPlatform.Sound        = platformElement.Element("Sound")?.Value ?? lbPlatform.Sound;
                lbPlatform.Display      = platformElement.Element("Display")?.Value ?? lbPlatform.Display;
                lbPlatform.Media        = platformElement.Element("Media")?.Value ?? lbPlatform.Media;
                lbPlatform.Display      = platformElement.Element("Display")?.Value ?? lbPlatform.Display;
                lbPlatform.Controllers  = platformElement.Element("MaxControllers")?.Value ?? lbPlatform.Controllers;
                lbPlatform.Category     = platformElement.Element("Category")?.Value ?? lbPlatform.Category;
#if DEBUG
                Debug.WriteLine("PC: " + watch1.ElapsedMilliseconds); watch1.Restart();
#endif
            }

            R.Data.LBPlatforms.AddRange(newLBPlatforms);
            Reporter.Toc(tic1, "all platforms cached.");
        }