Exemplo n.º 1
0
        /*
         *
         * public async void StartGameScrape(ProgressDialogController controller)
         * {
         *   if (controller == null)
         *   {
         *       // create UI dialog
         *       var mySettings = new MetroDialogSettings()
         *       {
         *           NegativeButtonText = "Cancel Scraping",
         *           AnimateShow = false,
         *           AnimateHide = false
         *       };
         *       controller = await mw.ShowProgressAsync("Scraping Data", "Initialising...", true, settings: mySettings);
         *       controller.SetCancelable(true);
         *       await Task.Delay(100);
         *   }
         *
         *   await Task.Run(() =>
         *   {
         *       ScrapeGame(controller);
         *   });
         */
        /*
         * await controller.CloseAsync();
         *
         * if (controller.IsCanceled)
         * {
         *  await mw.ShowMessageAsync("MedLaunch Scraper", "Scraping Cancelled");
         * }
         * else
         * {
         *  await mw.ShowMessageAsync("MedLaunch Scraper", "Scraping Completed");
         * }
         *
         * await Task.Delay(300);
         */
        //GamesLibraryVisualHandler.RefreshGamesLibrary();

        // }
        /// <summary>
        /// Extension method to handle no controller being passed
        /// </summary>
        ///

        /*
         * public void StartGameScrape()
         * {
         *  StartGameScrape(null);
         * }
         */



        /// <summary>
        /// Creates a new entry in the GDBLink table (linking MedLaunch gameId to scraped data (thegamesdb.net) ID)
        /// also deletes any rows that have the same GameId (so that duplicates are not possible)
        /// </summary>
        /// <param name="gameId"></param>
        /// <param name="gamesDbId"></param>
        ///

        /*
         * public static void CreateDatabaseLink(int gameId, int gamesDbId)
         * {
         *  GDBLink link = new GDBLink();
         *  link.GameId = gameId;
         *  link.GdbId = gamesDbId;
         *  // delete any existing links with the same GameId
         *  GDBLink l = GDBLink.GetRecord(gameId);
         *  if (l != null)
         *  {
         *      GDBLink.DeleteRecord(l);
         *  }
         *  GDBLink.SaveToDatabase(link);
         *  PopulateLibraryData(link);
         *  GameListBuilder.UpdateFlag();
         * }
         */

        /// <summary>
        /// create data in the LibraryDataGDBLink table
        /// </summary>
        /// <param name="link"></param>
        public static void PopulateLibraryData(int gameId, int gdbId)
        {
            var data = LibraryDataGDBLink.GetLibraryData(gdbId);

            if (data == null)
            {
                data = new LibraryDataGDBLink();
            }

            //ScrapeDB gd = new ScrapeDB();
            ScrapedGameObject o = ScrapeDB.GetScrapedGameObject(gameId, gdbId);

            data.GDBId     = o.GdbId;
            data.Coop      = o.Data.Coop;
            data.Developer = o.Data.Developer;
            data.ESRB      = o.Data.ESRB;
            data.Players   = o.Data.Players;
            data.Publisher = o.Data.Publisher;
            data.Year      = o.Data.Released;

            // save library data
            LibraryDataGDBLink.SaveToDataBase(data);

            // set isScraped flag in Game table
            Game ga = Game.GetGame(gameId);

            // ignore if manual editing is set
            if (ga.ManualEditSet == true)
            {
                return;
            }

            ga.isScraped = true;
            ga.gdbId     = gdbId;

            // populate new extended fields
            ga.Coop      = o.Data.Coop;
            ga.Developer = o.Data.Developer;
            ga.ESRB      = o.Data.ESRB;
            ga.Overview  = o.Data.Overview;
            ga.Players   = o.Data.Players;
            ga.Publisher = o.Data.Publisher;
            ga.Year      = o.Data.Released;

            StringBuilder sbAT = new StringBuilder();

            for (int i = 0; i < o.Data.AlternateTitles.Count(); i++)
            {
                sbAT.Append(o.Data.AlternateTitles[i]);
                if (i < (o.Data.AlternateTitles.Count() - 1))
                {
                    sbAT.Append(", ");
                }
            }
            ga.AlternateTitles = sbAT.ToString();

            StringBuilder sbGE = new StringBuilder();

            for (int i = 0; i < o.Data.AlternateTitles.Count(); i++)
            {
                sbGE.Append(o.Data.AlternateTitles[i]);
                if (i < (o.Data.AlternateTitles.Count() - 1))
                {
                    sbGE.Append(", ");
                }
            }
            ga.AlternateTitles = sbGE.ToString();

            Game.SetGame(ga);
        }
Exemplo n.º 2
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);
        }