public void ShowUnscraped(object sender, FilterEventArgs e) { GamesLibraryModel g = e.Item as GamesLibraryModel; if (g != null) { if (g.Coop == null && g.ESRB == null && g.Players == null) { // possibly not scraped - check for psx string system = g.System; int sysId = GSystem.GetSystemIdSubFirst(system); if (GSystem.GetSystemCode(sysId).ToLower() != "psx") { e.Accepted = true; } else { e.Accepted = false; } } else { e.Accepted = false; } } }
public static void RefreshCoreVisibilities() { // get mainwindow MainWindow mw = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); // get the current settings GlobalSettings gs = GlobalSettings.GetGlobals(); // create an array of values bool[] b = new bool[] { gs.coreVis1, gs.coreVis2, gs.coreVis3, gs.coreVis4, gs.coreVis5, gs.coreVis6, gs.coreVis7, gs.coreVis8, gs.coreVis9, gs.coreVis10, gs.coreVis11, gs.coreVis12, gs.coreVis13, gs.coreVis14, gs.coreVis15, gs.coreVis16, gs.coreVis17, gs.coreVis18 }; // iterate through each setting and set visibilities for (int i = 1; i <= b.Length; i++) { // games library filters string sysCode = GSystem.GetSystemCode(i); TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; RadioButton rb = (RadioButton)mw.FindName("btn" + textInfo.ToTitleCase(sysCode)); if (rb != null) { if (b[i - 1] == true) { rb.Visibility = Visibility.Visible; } else { rb.Visibility = Visibility.Collapsed; } } // games library actual filtering //todo // config filters RadioButton configRb = (RadioButton)mw.FindName("btnConfig" + textInfo.ToTitleCase(sysCode)); if (configRb != null) { if (b[i - 1] == true) { configRb.Visibility = Visibility.Visible; } else { configRb.Visibility = Visibility.Collapsed; } } // settings filters (game paths) Button pathBtn = (Button)mw.FindName("btnPath" + textInfo.ToTitleCase(sysCode)); TextBox pathTb = (TextBox)mw.FindName("tbPath" + textInfo.ToTitleCase(sysCode)); if (pathBtn != null) { if (b[i - 1] == true) { pathBtn.Visibility = Visibility.Visible; pathTb.Visibility = Visibility.Visible; } else { pathBtn.Visibility = Visibility.Collapsed; pathTb.Visibility = Visibility.Collapsed; } } // controls filters // config filters RadioButton controlRb = (RadioButton)mw.FindName("btnControl" + textInfo.ToTitleCase(sysCode)); if (controlRb != null) { if (b[i - 1] == true) { controlRb.Visibility = Visibility.Visible; } else { controlRb.Visibility = Visibility.Collapsed; } } } /* get selected filter buttons - if they are invisible then select a different one */ // games library filters WrapPanel wpGamesList = (WrapPanel)mw.FindName("wpGamesList"); List <RadioButton> _filterButtonsLib = UIHandler.GetLogicalChildCollection <RadioButton>(wpGamesList); RadioButton btnShowAll = (RadioButton)mw.FindName("btnShowAll"); // get selected library filter button var gSel = _filterButtonsLib.Where(a => a.IsChecked == true); if (gSel.Count() > 0) { RadioButton gSelBut = gSel.FirstOrDefault(); if (gSelBut.Visibility == Visibility.Collapsed) { // selected button is invisible - select the showall filter button btnShowAll.IsChecked = true; } } else { // no button is selected btnShowAll.IsChecked = true; } // configs // handle fast and faust RadioButton btnConfigSnes_Faust = (RadioButton)mw.FindName("btnConfigSnes_Faust"); RadioButton btnConfigPce_Fast = (RadioButton)mw.FindName("btnConfigPce_Fast"); RadioButton btnConfigSnes = (RadioButton)mw.FindName("btnConfigSnes"); RadioButton btnConfigPce = (RadioButton)mw.FindName("btnConfigPce"); if (btnConfigSnes.Visibility == Visibility.Collapsed) { btnConfigSnes_Faust.Visibility = Visibility.Collapsed; } else { btnConfigSnes_Faust.Visibility = Visibility.Visible; } if (b[17] == false) { if (btnConfigPce.Visibility == Visibility.Collapsed) { btnConfigPce_Fast.Visibility = Visibility.Collapsed; } else { btnConfigPce_Fast.Visibility = Visibility.Visible; } } else { btnConfigPce_Fast.Visibility = Visibility.Visible; btnConfigPce.Visibility = Visibility.Visible; } WrapPanel wpConfigLeftPane = (WrapPanel)mw.FindName("wpConfigLeftPane"); List <RadioButton> _filterButtons = UIHandler.GetLogicalChildCollection <RadioButton>(wpConfigLeftPane); // get selected config button var cSel = _filterButtons.Where(a => a.IsChecked == true); if (cSel.Count() > 0) { RadioButton cSelBut = cSel.FirstOrDefault(); if (cSelBut.Visibility == Visibility.Collapsed) { // selected button is invisible - find the next one that IS visible and click it SetRadioButton(_filterButtons); } } else { // no button is selected SetRadioButton(_filterButtons); } // controls // handle fast and faust RadioButton btnControlSnes_Faust = (RadioButton)mw.FindName("btnControlSnes_Faust"); RadioButton btnControlPce_Fast = (RadioButton)mw.FindName("btnControlPce_Fast"); RadioButton btnControlSnes = (RadioButton)mw.FindName("btnControlSnes"); RadioButton btnControlPce = (RadioButton)mw.FindName("btnControlPce"); if (btnControlSnes.Visibility == Visibility.Collapsed) { btnControlSnes_Faust.Visibility = Visibility.Collapsed; } else { btnControlSnes_Faust.Visibility = Visibility.Visible; } if (b[17] == false) { if (btnConfigPce.Visibility == Visibility.Collapsed) { btnControlPce_Fast.Visibility = Visibility.Collapsed; } else { btnControlPce_Fast.Visibility = Visibility.Visible; } } else { btnControlPce_Fast.Visibility = Visibility.Visible; btnControlPce.Visibility = Visibility.Visible; } if (btnControlPce.Visibility == Visibility.Collapsed) { btnControlPce_Fast.Visibility = Visibility.Collapsed; } else { btnControlPce_Fast.Visibility = Visibility.Visible; } WrapPanel wpControlLeftPane = (WrapPanel)mw.FindName("wpControlLeftPane"); List <RadioButton> _filterButtonsControl = UIHandler.GetLogicalChildCollection <RadioButton>(wpControlLeftPane); // get selected config button var contSel = _filterButtonsControl.Where(a => a.IsChecked == true); if (contSel.Count() > 0) { RadioButton contSelBut = contSel.FirstOrDefault(); if (contSelBut.Visibility == Visibility.Collapsed) { // selected button is invisible - find the next one that IS visible and click it SetRadioButton(_filterButtonsControl); } } else { // no button is selected SetRadioButton(_filterButtonsControl); } // Completely hide whole panels if NO system is visible var b2 = b.Where(a => a == true).ToList(); DataGrid dgGameList = (DataGrid)mw.FindName("dgGameList"); WrapPanel ConfigWrapPanel = (WrapPanel)mw.FindName("ConfigWrapPanel"); Grid controlGrid = (Grid)mw.FindName("controlGrid"); if (b2.Count == 0) { dgGameList.Visibility = Visibility.Collapsed; ConfigWrapPanel.Visibility = Visibility.Collapsed; controlGrid.Visibility = Visibility.Collapsed; } else { dgGameList.Visibility = Visibility.Visible; ConfigWrapPanel.Visibility = Visibility.Visible; controlGrid.Visibility = Visibility.Visible; } }
/* Methods */ public static void DoScrape(ProgressDialogController controller, Game game, string countString, ScraperSearch gs, bool rescrape) { // ignore if manual editing is set if (game.ManualEditSet == true) { return; } string gameName = game.gameName; int systemId = game.systemId; int gameId = game.gameId; // attempt local match for game controller.SetMessage("Attempting local search match for:\n" + gameName + " (" + GSystem.GetSystemCode(systemId) + ")" + "\n(" + countString); List <ScraperMaster> results = gs.SearchGameLocal(gameName, systemId, gameId).ToList(); if (results.Count == 0) { // no results returned return; } if (results.Count == 1) { // one result returned - add GdbId to the Game table Game.SetGdbId(gameId, results.Single().gid); // also add it to our locagames object (so it is not skipped in the next part) //game.gdbId = results.Single().gid; } if (results.Count > 1) { // more than one result returned - do nothing (because a definite match was not found) return; } /* Begin scraping */ bool scrapingNeeded = false; // check game directory if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + results.Single().gid.ToString())) { // directory does not exist - scraping needed scrapingNeeded = true; } else { // directory does exist - check whether json file is present if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + results.Single().gid.ToString() + @"\" + results.Single().gid.ToString() + ".json")) { // json file is not present - scraping needed scrapingNeeded = true; } } // if rescrape bool has been set - always rescrape if (rescrape == true) { scrapingNeeded = true; } if (scrapingNeeded == false) { return; } // do scrape string message = "Scraping Started....\nGetting data for: " + gameName + " (" + GSystem.GetSystemCode(systemId) + ")" + "\n(" + countString; controller.SetMessage(message); ScraperHandler sh = new ScraperHandler(results.Single().gid, gameId, false); sh.ScrapeGame(controller); //GameListBuilder.UpdateFlag(); }
/* 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(); } }