Exemple #1
0
        /// <summary>
        /// Game scraping logic
        /// </summary>
        /// <param name="controller"></param>
        public ScrapedGameObjectWeb ScrapeGameInspector(ProgressDialogController controller)
        {
            string message = "";

            // create data object for results that are returned
            //ScrapeDB glsc = new ScrapeDB();
            ScrapedGameData      gameData   = new ScrapedGameData();
            ScrapedGameObjectWeb gameObject = new ScrapedGameObjectWeb();

            gameObject.Data  = gameData;
            gameObject.GdbId = MasterRecord.gid;

            // check for manuals
            if (_GlobalSettings.scrapeManuals == true)
            {
                if (gameObject.Manuals == null)
                {
                    gameObject.Manuals = new List <string>();
                }

                gameObject.Manuals = MasterRecord.Game_Docs;
            }


            // enumerate globalsettings
            switch (_GlobalSettings.primaryScraper)
            {
            case 1:
                // gamesdb.net is primary scraper
                GDBScraper.ScrapeGame(gameObject, ScraperOrder.Primary, controller, MasterRecord, message);
                if (_GlobalSettings.enabledSecondaryScraper == true)
                {
                    MobyScraper.ScrapeGame(gameObject, ScraperOrder.Secondary, controller, MasterRecord, message);
                }
                break;

            case 2:
                // moby is primary scraper
                MobyScraper.ScrapeGame(gameObject, ScraperOrder.Primary, controller, MasterRecord, message);
                if (_GlobalSettings.enabledSecondaryScraper == true)
                {
                    GDBScraper.ScrapeGame(gameObject, ScraperOrder.Secondary, controller, MasterRecord, message);
                }
                break;
            }

            if (controller.IsCanceled == true)
            {
                controller.CloseAsync();
                return(null);
            }

            // gameObject should now be populated - create folder structure on disk if it does not already exist
            controller.SetMessage(message + "Determining local folder structure");
            ScrapeDB.CreateFolderStructure(gameObject.GdbId);

            // save the object to json
            controller.SetMessage(message + "Saving game information");
            ScrapeDB.SaveJson(gameObject);

            // Download all the files
            if (_GlobalSettings.scrapeBanners == true || _GlobalSettings.scrapeBoxart == true || _GlobalSettings.scrapeFanart == true || _GlobalSettings.scrapeManuals == true ||
                _GlobalSettings.scrapeMedia == true || _GlobalSettings.scrapeScreenshots == true)
            {
                controller.SetMessage(message + "Downloading media");
                ContentDownloadManager(gameObject, controller, message + "Downloading media...\n");
            }


            // Return data
            return(gameObject);
            //PopulateLibraryData(GameId, gameObject.GdbId);
            //CreateDatabaseLink(GameId, gameObject.GdbId);
        }
Exemple #2
0
        /// <summary>
        /// looks up and returns scrapeddataobject based on Internal GameId (not gamesdb id)
        /// </summary>
        /// <param name="GameId"></param>
        /// <param name="GdbId"></param>
        /// <returns></returns>
        public static ScrapedGameObject GetScrapedGameObject(int GameId, int GdbId)
        {
            //Game link = Game.GetGame(GameId);

            // we have a link record - proceed and generate object
            ScrapedGameObject sgo = new ScrapedGameObject();

            if (GdbId < 1)
            {
                return(null);
            }
            sgo.GdbId = GdbId;

            // attempt to load game data json
            string gPath = AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + sgo.GdbId.ToString() + @"\" + sgo.GdbId.ToString() + ".json";

            if (File.Exists(gPath))
            {
                ScrapedGameObjectWeb sgoweb = new ScrapedGameObjectWeb();
                ScrapedGameData      sg     = new ScrapedGameData();
                string jsonString           = File.ReadAllText(gPath);
                try
                {
                    sgoweb = JsonConvert.DeserializeObject <ScrapedGameObjectWeb>(jsonString);
                }
                catch (Exception e)
                {
                    // there was a problem with the file - do nothing
                    Console.WriteLine(e);
                }
                finally
                {
                    sgo.Data = sgoweb.Data;
                    if (sgo.Data.AlternateTitles == null)
                    {
                        sgo.Data.AlternateTitles = new List <string>();
                    }
                    if (sgo.Data.Genres == null)
                    {
                        sgo.Data.AlternateTitles = new List <string>();
                    }
                }
            }
            else
            {
                sgo.Data = new ScrapedGameData();
            }

            // populate lists in object
            string baseGameDir = AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + sgo.GdbId.ToString();

            sgo.BackCovers  = GetAllFolderFiles(baseGameDir + @"\BackCover");
            sgo.Banners     = GetAllFolderFiles(baseGameDir + @"\Banners");
            sgo.FanArts     = GetAllFolderFiles(baseGameDir + @"\FanArt");
            sgo.FrontCovers = GetAllFolderFiles(baseGameDir + @"\FrontCover");
            sgo.Manuals     = GetAllFolderFiles(baseGameDir + @"\Manual");
            sgo.Medias      = GetAllFolderFiles(baseGameDir + @"\Media");
            sgo.Screenshots = GetAllFolderFiles(baseGameDir + @"\Screenshots");

            // return object
            return(sgo);
        }