Esempio n. 1
0
        public static void SetGdbId(int GameId, int GdbId)
        {
            Game game = GetGame(GameId);

            game.gdbId = GdbId;
            SetGame(game);
            // GameListBuilder.UpdateFlag();
            GamesLibraryVisualHandler.DoGameUpdate(new List <Game> {
                game
            });
        }
Esempio n. 2
0
 public static void SetGame(Game game, bool init)
 {
     using (var cfDef = new MyDbContext())
     {
         cfDef.Entry(game).State = Microsoft.Data.Entity.EntityState.Modified;
         cfDef.SaveChanges();
         GamesLibraryVisualHandler.DoGameUpdate(new List <Game> {
             game
         });
     }
 }
Esempio n. 3
0
 public static void DeleteGames(List <Game> games)
 {
     using (var cont = new MyDbContext())
     {
         cont.Game.RemoveRange(games);
         cont.SaveChanges();
         //GamesLibData.ForceUpdate();
         // GameListBuilder.UpdateFlag();
         GamesLibraryVisualHandler.DoGameDelete(games);
     }
 }
Esempio n. 4
0
        public static void SetStartedPlaying(int gameId)
        {
            Game game = GetGame(gameId);

            game.gameLastPlayed = DateTime.Now;

            SetGame(game);
            // GameListBuilder.UpdateFlag();
            GamesLibraryVisualHandler.DoGameUpdate(new List <Game> {
                game
            });
        }
Esempio n. 5
0
        private static void UpdateRom(Game rom)
        {
            using (var uR = new MyDbContext())
            {
                uR.Game.Update(rom);
                uR.SaveChanges();
                uR.Dispose();
            }
            List <Game> games = new List <Game>();

            games.Add(rom);
            GamesLibraryVisualHandler.DoGameUpdate(games);
        }
Esempio n. 6
0
        public void FilterByFilterButton(int fn)
        {
            if (fn == 0)
            {
                // get selected filter as none was provided
                fn = GamesLibraryVisualHandler.GetSelectedFilterNumber();
            }
            else
            {
            }

            MultipleFilter.SetMainFilter(fn);
            LibraryView.SortDescriptions.Add(new SortDescription("Game", ListSortDirection.Descending));
        }
Esempio n. 7
0
        private static void InsertRom(Game rom)
        {
            using (var iR = new MyDbContext())
            {
                // add game to database and save changes
                iR.Game.Add(rom);
                iR.SaveChanges();
                iR.Dispose();
            }
            List <Game> games = new List <Game>();

            games.Add(rom);
            GamesLibraryVisualHandler.DoGameAdd(games);
        }
Esempio n. 8
0
 public static void DeleteGame(Game game)
 {
     using (var cont = new MyDbContext())
     {
         cont.Game.Remove(game);
         cont.SaveChanges();
         //GamesLibData.ForceUpdate();
         //GameListBuilder.UpdateFlag();
         List <Game> games = new List <Game>();
         games.Add(game);
         GamesLibraryVisualHandler.DoGameDelete(new List <Game> {
             game
         });
     }
 }
Esempio n. 9
0
        public static void UnlinkGameData(DataGrid dgGameList)
        {
            // get selected row
            var row = (GamesLibraryModel)dgGameList.SelectedItem;

            if (dgGameList.SelectedItem == null)
            {
                // game is not selected
                return;
            }
            int GameId = row.ID;

            Game.SetGdbId(GameId, 0);

            //GameListBuilder.UpdateFlag();
            GamesLibraryVisualHandler.UpdateSidebar(GameId);
        }
Esempio n. 10
0
        /// <summary>
        /// Choose a game from the local master list to link to an imported medlaunch game
        /// based on medlaunch GameId
        /// </summary>
        /// <param name="GameId"></param>
        public static async void PickLocalGame(int GameId)
        {
            MainWindow mw       = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();
            Grid       RootGrid = (Grid)mw.FindName("RootGrid");

            await mw.ShowChildWindowAsync(new ListBoxChildWindow()
            {
                IsModal         = true,
                AllowMove       = false,
                Title           = "Pick a Game",
                CloseOnOverlay  = false,
                ShowCloseButton = false
            }, RootGrid);

            GamesLibraryVisualHandler.UpdateSidebar(GameId);
            //GamesLibraryVisualHandler.RefreshGamesLibrary();
        }
Esempio n. 11
0
        public static void SaveToDatabase(List <Game> games, bool init)
        {
            using (var db = new MyDbContext())
            {
                // get current database context
                var current = db.Game.AsNoTracking().ToList();

                List <Game> toAdd    = new List <Game>();
                List <Game> toUpdate = new List <Game>();

                // iterate through the games list and separete out games to be added and games to be updated
                foreach (var g in games)
                {
                    Game t = (from a in current
                              where a.gameId == g.gameId
                              select a).SingleOrDefault();
                    if (t == null)
                    {
                        toAdd.Add(g);
                    }
                    else
                    {
                        toUpdate.Add(g);
                    }
                }
                db.Game.UpdateRange(toUpdate);
                db.Game.AddRange(toAdd);
                db.SaveChanges();

                App _App = (App)Application.Current;
                if (_App.GamesLibrary == null)
                {
                    return;
                }

                if (toAdd.Count > 0)
                {
                    GamesLibraryVisualHandler.DoGameAdd(toAdd);
                }
                if (toUpdate.Count > 0)
                {
                    GamesLibraryVisualHandler.DoGameUpdate(toUpdate);
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Scrape multiple games that have been selected in the games library (either scrape unscraped, or re-scrape all)
        /// </summary>
        /// <param name="list"></param>
        /// <param name="scrapeType"></param>
        public async static void ScrapeMultiple(List <GamesLibraryModel> list, ScrapeType scrapeType, int systemId)
        {
            // instantiate instance of this class
            ScraperSearch gs = new ScraperSearch();

            // get mainwindow
            MainWindow MWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();

            // popup progress dialog
            var mySettings = new MetroDialogSettings()
            {
                NegativeButtonText = "Cancel Scraping",
                AnimateShow        = false,
                AnimateHide        = false
            };
            var controller = await MWindow.ShowProgressAsync("Scraping Data", "Initialising...", true, settings : mySettings);

            controller.SetCancelable(true);
            await Task.Delay(100);

            await Task.Run(() =>
            {
                // check whether list is null and generate it if it is (so scraping/rescraping whole systems or favorites)
                if (list == null)
                {
                    list = new List <GamesLibraryModel>();
                    List <Game> games = new List <Game>();
                    if (scrapeType == ScrapeType.Favorites || scrapeType == ScrapeType.RescrapeFavorites)
                    {
                        games = Game.GetGames().Where(a => a.isFavorite == true && a.hidden != true).ToList();
                    }
                    else
                    {
                        // get all games that have matching systemId and are not marked as hidden
                        games = Game.GetGames(systemId).Where(a => a.hidden != true).ToList();
                    }

                    // populate list
                    foreach (var g in games)
                    {
                        GamesLibraryModel glm = new GamesLibraryModel();
                        glm.ID = g.gameId;
                        list.Add(glm);
                    }
                }


                // iterate through each game in list - match local then scrape
                int iter           = 0;
                int maxCount       = list.Count();
                int skip           = 0;
                controller.Minimum = iter;
                controller.Maximum = maxCount;
                foreach (var game in list)
                {
                    if (controller.IsCanceled)
                    {
                        controller.CloseAsync();
                        return;
                    }

                    iter++;
                    controller.SetProgress(iter);
                    // game game object from the database
                    Game g = Game.GetGame(game.ID);

                    string countString = iter + " of " + maxCount + " (" + skip + " skipped)";

                    switch (scrapeType)
                    {
                    // scrape selected games (that have no been scraped yet)
                    case ScrapeType.Selected:
                    case ScrapeType.Favorites:
                    case ScrapeType.ScrapeSystem:
                        if (g.gdbId == null || g.gdbId == 0 || Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + g.gdbId.ToString()) == false)
                        {
                            // scraping can happen
                            DoScrape(controller, g, countString, gs, false);
                        }
                        else
                        {
                            // the game already has a valid gdbid set AND has a game directory on disc.
                            skip++;
                        }
                        break;

                    // rescrape all selected games
                    case ScrapeType.SelectedRescrape:
                    case ScrapeType.RescrapeFavorites:
                    case ScrapeType.RescrapeSystem:
                        // scraping must always happen
                        DoScrape(controller, g, countString, gs, true);
                        break;
                    }
                }
            });

            await controller.CloseAsync();

            if (controller.IsCanceled)
            {
                await MWindow.ShowMessageAsync("MedLaunch Scraper", "Scraping Cancelled");

                GamesLibraryVisualHandler.RefreshGamesLibrary();
            }
            else
            {
                await MWindow.ShowMessageAsync("MedLaunch Scraper", "Scraping Completed");

                GamesLibraryVisualHandler.RefreshGamesLibrary();
            }
        }
Esempio n. 13
0
        /* Methods */

        public async static void ScrapeGamesMultiple(List <DataGridGamesView> list, ScrapeType scrapeType)
        {
            // instantiate instance of this class
            ScraperMainSearch gs = new ScraperMainSearch();

            // get mainwindow
            MainWindow MWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();

            // popup progress dialog
            var mySettings = new MetroDialogSettings()
            {
                NegativeButtonText = "Cancel Scraping",
                AnimateShow        = false,
                AnimateHide        = false
            };
            var controller = await MWindow.ShowProgressAsync("Scraping Data", "Initialising...", true, settings : mySettings);

            controller.SetCancelable(true);
            await Task.Delay(100);

            await Task.Run(() =>
            {
                gs.LocalGames = new List <Game>();

                // iterate through each game, look it up and pass it to gs.LocalGames
                foreach (var game in list)
                {
                    Game g = Game.GetGame(game.ID);

                    if (scrapeType == ScrapeType.Selected)
                    {
                        if (g.gdbId == null || g.gdbId == 0 || Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + g.gdbId.ToString()) == false)
                        {
                            // scraping can happen
                            gs.LocalGames.Add(g);
                        }
                    }

                    if (scrapeType == ScrapeType.SelectedRescrape)
                    {
                        gs.LocalGames.Add(g);
                    }
                }

                // count number of games to scan for
                int numGames       = gs.LocalGames.Count;
                controller.Minimum = 0;
                controller.Maximum = numGames;
                int i = 0;
                // iterate through each local game and attempt to match it with the master list
                foreach (var g in gs.LocalGames)
                {
                    if (controller.IsCanceled)
                    {
                        controller.CloseAsync();
                        return;
                    }
                    i++;
                    controller.SetProgress(i);
                    controller.SetMessage("Attempting local search match for:\n" + g.gameName + " (" + GSystem.GetSystemCode(g.systemId) + ")" + "\n(" + i + " of " + numGames + ")");
                    List <ScraperMaster> results = gs.SearchGameLocal(g.gameName, g.systemId, g.gameId).ToList();

                    if (results.Count == 0)
                    {
                        // no results returned
                    }
                    if (results.Count == 1)
                    {
                        // one result returned - add GdbId to the Game table
                        Game.SetGdbId(g.gameId, results.Single().GamesDbId);
                    }
                }

                /* Begin actual scraping */

                // Get all games that have a GdbId set and determine if they need scraping (is json file present for them)
                var gamesTmp  = gs.LocalGames;
                gs.LocalGames = new List <Game>();
                foreach (var g in gamesTmp)
                {
                    if (g.gdbId == null || g.gdbId == 0)
                    {
                        continue;
                    }

                    if (scrapeType == ScrapeType.SelectedRescrape)
                    {
                        gs.LocalGames.Add(g);
                        continue;
                    }

                    // check each game directory
                    if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + g.gdbId.ToString()))
                    {
                        // directory does not exist - scraping needed
                        gs.LocalGames.Add(g);
                    }
                    else
                    {
                        // directory does exist - check whether json file is present
                        if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + g.gdbId.ToString() + @"\" + g.gdbId.ToString() + ".json"))
                        {
                            // json file is not present - scraping needed
                            gs.LocalGames.Add(g);
                        }
                    }
                }

                int gamesCount = gs.LocalGames.Count;
                i = 0;
                controller.Minimum = 0;
                controller.Maximum = gamesCount;
                foreach (var g in gs.LocalGames)
                {
                    if (controller.IsCanceled)
                    {
                        controller.CloseAsync();
                        return;
                    }

                    // iterate through each game that requires scraping and attempt to download the data and import to database
                    i++;
                    controller.SetProgress(i);
                    string message = "Scraping Started....\nGetting data for: " + g.gameName + " (" + GSystem.GetSystemCode(g.systemId) + ")" + "\n(" + i + " of " + gamesCount + ")\n\n";
                    controller.SetMessage(message);

                    // do actual scraping
                    ScraperHandler sh = new ScraperHandler(g.gdbId.Value, g.gameId, false);
                    sh.ScrapeGame(controller);
                    GameListBuilder.UpdateFlag();
                }
            });

            await controller.CloseAsync();

            if (controller.IsCanceled)
            {
                await MWindow.ShowMessageAsync("MedLaunch Scraper", "Scraping Cancelled");

                GamesLibraryVisualHandler.RefreshGamesLibrary();
            }
            else
            {
                await MWindow.ShowMessageAsync("MedLaunch Scraper", "Scraping Completed");

                GamesLibraryVisualHandler.RefreshGamesLibrary();
            }
        }