// update favorites toggle public static void FavoriteToggle(int Id) { using (var romaContext = new MyDbContext()) { Game rom = (from r in romaContext.Game where r.gameId == Id select r).SingleOrDefault(); if (rom != null) { if (GetFavoriteStatus(Id) == 1) { // Rom is marked as a favorite - make isFavorite as false rom.isFavorite = false; } else { // rom is not marked as favorite - make isFavorite true rom.isFavorite = true; } } // update ROM UpdateRom(rom); GameListBuilder.UpdateFlag(); romaContext.Dispose(); } }
// mark single game as hidden public void MarkRomAsHidden(int gameId) { Game game = (from g in Games where g.gameId == gameId select g).ToList().SingleOrDefault(); if (game == null) { // no game found } else { Game newGame = game; if (newGame.hidden == false) { newGame.hidden = true; // add to GamesToUpdate to be processed later RomsToUpdate.Add(newGame); HiddenStats++; GameListBuilder.UpdateFlag(); } else { // game is already hidden UntouchedStats++; } } }
// mark all ROMS from a system as hidden (as long as it is not a disk based game) public void MarkAllRomsAsHidden(int systemId) { List <Game> gamesAll = (from g in Games where g.systemId == systemId select g).ToList(); List <Game> games = (from g in gamesAll where g.isDiskBased == false select g).ToList(); if (games == null) { // no games found } else { // iterate through each game foreach (Game game in games) { Game newGame = game; if (newGame.hidden == false) { newGame.hidden = true; // add to GamesToUpdate to be processed later RomsToUpdate.Add(newGame); HiddenStats++; GameListBuilder.UpdateFlag(); } else { // game is already marked as hidden UntouchedStats++; } } } }
// update game data for games datagrid including search public static void GetGames(DataGrid datagrid, int systemId, string search) { // get the full dataset from application App _App = ((App)Application.Current); //List<DataGridGamesView> allGames = _App.GamesList.AllGames; var result = GameListBuilder.Filter(systemId, search); }
public LayoutBuilder(GameListBuilder gameListBuilder, TitleFactory titleFactory, LayoutFactory layoutFactory) { _gameListBuilder = gameListBuilder; _titleFactory = titleFactory; _layoutFactory = layoutFactory; var tempPath = Path.GetTempPath(); _tempDirectory = Directory.CreateDirectory(Path.Combine(tempPath, "Mamesaver", "Layouts")); _artPaths = new Lazy <List <string> >(() => _gameListBuilder.GetArtPaths()); }
public GameListViewModel( GameList gameList, GameListBuilder gameListBuilder, GameListStore gameListStore) { _gameList = gameList; _gameListBuilder = gameListBuilder; _gameListStore = gameListStore; _games = new List <GameViewModel>(); _filteredGames = new List <GameViewModel>(); }
// remove ALL GAMES from db for all systems public static void RemoveAllGames() { MessageBoxResult result = MessageBox.Show("This operation will wipe out ALL the games in your games library database (but they will not be deleted from disk)\n\nAre you sure you wish to continue?", "WARNING", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.OK) { // get all roms for specific system using (var context = new MyDbContext()) { List <Game> roms = (from a in context.Game select a).ToList(); Game.DeleteGames(roms); GameListBuilder.UpdateFlag(); } } }
// attempt to add game to Game database public static int AddGame(Rom systemRom, string fullPath, string relPath, string fileName, string extension, string romName) { // check whether ROM already exists in database using (var romContext = new MyDbContext()) { var rom = (from r in romContext.Game where (r.gameName == romName) && (r.systemId == systemRom.gameSystem.systemId) select r).SingleOrDefault(); if (rom != null) { // Rom already exists in database. Check whether it needs updating if (rom.gamePath == relPath) { // path is correct in database - skip updating return(0); } else { // path is incorrect in database - update record Game g = rom; g.gamePath = relPath; UpdateRom(g); GameListBuilder.UpdateFlag(); return(2); } } else { // Rom does not exist. Add to database. Game g = new Game(); g.gameName = romName; g.gamePath = relPath; g.systemId = systemRom.gameSystem.systemId; //g.GameSystem.systemId = systemRom.gameSystem.systemId; g.isFavorite = false; g.configId = 1; g.hidden = false; InsertRom(g); GameListBuilder.UpdateFlag(); return(1); } } }
// remove all disk-based games from db for a certain system public static void RemoveDisks(int sysId) { MessageBoxResult result = MessageBox.Show("This operation will wipe out ALL the " + GSystem.GetSystemName(sysId) + " games in your library database (but they will not be deleted from disk)\n\nAre you sure you wish to continue?", "WARNING", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.OK) { // get all disks for specific system using (var context = new MyDbContext()) { List <Game> disks = (from a in context.Game where a.systemId == sysId select a).ToList(); Game.DeleteGames(disks); GameListBuilder.UpdateFlag(); } } }
public static void UnlinkGameData(DataGrid dgGameList) { // get selected row var row = (DataGridGamesView)dgGameList.SelectedItem; if (dgGameList.SelectedItem == null) { // game is not selected return; } int GameId = row.ID; Game.SetGdbId(GameId, 0); GameListBuilder.UpdateFlag(); GamesLibraryVisualHandler.UpdateSidebar(GameId); }
public void BeginManualImport(int sysId) { // Start manual import process for a game based on sysId DiskGameFile gameFile = SelectGameFile(sysId); if (gameFile == null) { MessageBox.Show("No valid file was selected", "MedLaunch: Error"); return; } else { // Add or update the returned GameFile to the database InsertOrUpdateDisk(gameFile, sysId); SaveToDatabase(); MessageBox.Show("Game: " + gameFile.FileName + " has added to (or updated in) the library", "MedLaunch: Import or Update Completed"); GameListBuilder.UpdateFlag(); } }
// Start ROM scan and import process for specific system public void BeginRomImport(int systemId, ProgressDialogController dialog) { // get path to ROM folder string romFolderPath = GetPath(systemId); //MessageBoxResult result2 = MessageBox.Show(romFolderPath); // get allowed file types for this particular system HashSet <string> exts = GetAllowedFileExtensions(systemId); // get a list of games for this system currently already in the database List <Game> presentGames = (from g in Games where g.systemId == systemId select g).ToList(); // get all files from romfolderpath and sub directories that have an allowed extension IEnumerable <string> romFiles = GetFiles(romFolderPath, true); // if romfiles is null break if (romFiles == null) { return; } List <string> allowedFiles = new List <string>(); foreach (string s in exts) { foreach (string p in romFiles) { if (p.EndsWith(s)) { //MessageBoxResult result5 = MessageBox.Show(p); allowedFiles.Add(p); } } /* * List<string> fi = (from a in romFiles * where a.EndsWith(s) * select a).ToList(); * if (fi == null || fi.Count < 1) { continue; } * allowedFiles.AddRange(fi); */ } // calculate the number of files to be processed int numFiles = allowedFiles.Count; // set the progress bar limits //dialog.Minimum = 0; //dialog.Maximum = numFiles; int progress = 0; // set base dialog message string strBase = "Scanning: "; // create new final list to be populated with approved files List <Game> finalGames = new List <Game>(); // now we have a list of allowed files, loop through them foreach (string file in allowedFiles) { // get the relative path string relPath = PathUtil.GetRelativePath(romFolderPath, file); // get just the filename string fileName = System.IO.Path.GetFileName(file); // get just the extension string extension = System.IO.Path.GetExtension(file).ToLower(); // get rom name wihout extension string romName = fileName.Replace(extension, ""); // update UI progress++; string uiUpdate = strBase + fileName + "\n(" + progress + " of " + numFiles + ")"; dialog.SetMessage(uiUpdate); //dialog.SetProgress(progress); Game newGame = new Game(); string hash = String.Empty; // inspect archive files if (extension == ".zip" || extension == ".7z") { bool isAllowed = false; try { Archiving arch = new Archiving(file, systemId); arch.ProcessArchive(); hash = arch.MD5Hash; isAllowed = arch.IsAllowed; if (hash == null) { continue; } } catch (System.IO.InvalidDataException ex) { // problem with the archive file } finally { } if (isAllowed == false) { continue; } } else { // file is not an archive - calculate md5 //hash = Crypto.Crc32.ComputeFileHash(file); hash = Crypto.checkMD5(file); } // check whether game already exists (by gameName and systemId) Game chkGame = (from g in Games where g.systemId == systemId && g.gameName == romName select g).FirstOrDefault(); // lookup game in master dat //var sysFilter = DAT.Where(p => p.SystemId == systemId); // var lookup = DAT.Where(p => p.Roms.Any(x => x.MD5.ToUpper().Trim() == hash.ToUpper().Trim())).ToList(); //var lookup = DAT.Where(p => p.Roms.Any(x => x.MD5.ToUpper() == hash)).ToList(); string nHash = hash.ToUpper().Trim().ToString(); List <DATMerge> lookup = (from i in DAT where i.SystemId == systemId && i.Roms.Any(l => l.MD5.ToUpper().Trim() == hash) select i).ToList(); if (chkGame == null) { // does not already exist - create new game newGame.configId = 1; if (lookup != null && lookup.Count > 0) { newGame.gameNameFromDAT = lookup.First().GameName; newGame.Publisher = lookup.First().Publisher; newGame.Year = lookup.First().Year; // get rom we are interested in var rom = (from ro in lookup.First().Roms where ro.MD5.ToUpper().Trim() == hash.ToUpper().Trim() select ro).First(); newGame.romNameFromDAT = rom.RomName; newGame.Copyright = rom.Copyright; newGame.Country = rom.Country; newGame.DevelopmentStatus = rom.DevelopmentStatus; newGame.Language = rom.Language; newGame.OtherFlags = rom.OtherFlags; if (rom.Year != null && rom.Year != "") { newGame.Year = rom.Year; } if (rom.Publisher != null && rom.Publisher != "") { newGame.Publisher = rom.Publisher; } } newGame.gameName = romName; newGame.gamePath = relPath; newGame.hidden = false; newGame.isDiskBased = false; newGame.isFavorite = false; newGame.systemId = systemId; newGame.CRC32 = hash; // add to finaGames list RomsToAdd.Add(newGame); // increment the added counter AddedStats++; } else { // matching game found - update it if (chkGame.gamePath == relPath && chkGame.hidden == false && chkGame.CRC32 == hash) { //nothing to update - increment untouched counter UntouchedStats++; } else { newGame = chkGame; // update path in case it has changed location newGame.gamePath = relPath; // mark as not hidden newGame.hidden = false; newGame.CRC32 = hash; if (lookup != null && lookup.Count > 0) { newGame.gameNameFromDAT = lookup.First().GameName; newGame.Publisher = lookup.First().Publisher; newGame.Year = lookup.First().Year; // get rom we are interested in var rom = (from ro in lookup.First().Roms where ro.MD5.ToUpper().Trim() == hash.ToUpper().Trim() select ro).First(); newGame.romNameFromDAT = rom.RomName; newGame.Copyright = rom.Copyright; newGame.Country = rom.Country; newGame.DevelopmentStatus = rom.DevelopmentStatus; newGame.Language = rom.Language; newGame.OtherFlags = rom.OtherFlags; if (rom.Year != null && rom.Year != "") { newGame.Year = rom.Year; } if (rom.Publisher != null && rom.Publisher != "") { newGame.Publisher = rom.Publisher; } } // add to finalGames list RomsToUpdate.Add(newGame); // increment updated counter UpdatedStats++; } // remove game from presentGames list - remaining games in this list will be marked as hidden at the end presentGames.Remove(chkGame); } } // whatever games are left in the presentGames list should be marked as hidden as they have not been found if (presentGames.Count > 0) { foreach (Game g in presentGames) { g.hidden = true; RomsToUpdate.Add(g); } } GameListBuilder.UpdateFlag(); }
public void InsertOrUpdateDisk(DiskGameFile f, int sysId) { // check whether game already exists (by gameName and systemId) Game chkGame = (from g in Games where g.systemId == sysId && g.gameName == f.GameName select g).SingleOrDefault(); // create new Game object for import Game newGame = new Game(); string hash = string.Empty; // calculate MD5 checksum hashes if (f.Extension.Contains("m3u")) { // this is an m3u playlist - inspect and get relevant cue files string[] lines = File.ReadAllLines(f.FullPath); if (lines.Length > 0) { // get hash for first cue/toc/ccd hash = Crypto.checkMD5(f.FolderPath + "\\" + lines[0]); } } else { hash = Crypto.checkMD5(f.FullPath); } // lookup md5 in master DAT List <DATMerge> lookup = (from i in DAT where i.SystemId == sysId && i.Roms.Any(l => l.MD5.ToUpper().Trim() == hash) select i).ToList(); if (chkGame == null) { // does not already exist - create new game newGame.configId = 1; newGame.gameName = f.GameName; newGame.gamePath = f.FullPath; newGame.hidden = false; newGame.isDiskBased = true; newGame.isFavorite = false; newGame.systemId = sysId; if (lookup != null && lookup.Count > 0) { newGame.gameNameFromDAT = lookup.First().GameName; newGame.Publisher = lookup.First().Publisher; newGame.Year = lookup.First().Year; // get rom we are interested in var rom = (from ro in lookup.First().Roms where ro.MD5.ToUpper().Trim() == hash.ToUpper().Trim() select ro).First(); newGame.romNameFromDAT = rom.RomName; newGame.Copyright = rom.Copyright; newGame.Country = rom.Country; newGame.DevelopmentStatus = rom.DevelopmentStatus; newGame.Language = rom.Language; newGame.OtherFlags = rom.OtherFlags; if (rom.Year != null && rom.Year != "") { newGame.Year = rom.Year; } if (rom.Publisher != null && rom.Publisher != "") { newGame.Publisher = rom.Publisher; } } // add to finaGames list DisksToAdd.Add(newGame); // increment the added counter AddedStats++; GameListBuilder.UpdateFlag(); } else { // matching game found - update it if ((chkGame.gamePath == f.FullPath || chkGame.gamePath == f.FullPath) && chkGame.hidden == false) { //nothing to update - Path is either identical either absoultely or relatively (against the systemPath set in the database) UntouchedStats++; } else { newGame = chkGame; // update path in case it has changed location newGame.gamePath = f.FullPath; // mark as not hidden newGame.hidden = false; newGame.isDiskBased = true; if (lookup != null && lookup.Count > 0) { newGame.gameNameFromDAT = lookup.First().GameName; newGame.Publisher = lookup.First().Publisher; newGame.Year = lookup.First().Year; // get rom we are interested in var rom = (from ro in lookup.First().Roms where ro.MD5.ToUpper().Trim() == hash.ToUpper().Trim() select ro).First(); newGame.romNameFromDAT = rom.RomName; newGame.Copyright = rom.Copyright; newGame.Country = rom.Country; newGame.DevelopmentStatus = rom.DevelopmentStatus; newGame.Language = rom.Language; newGame.OtherFlags = rom.OtherFlags; if (rom.Year != null && rom.Year != "") { newGame.Year = rom.Year; } if (rom.Publisher != null && rom.Publisher != "") { newGame.Publisher = rom.Publisher; } } // add to finalGames list DisksToUpdate.Add(newGame); // increment updated counter UpdatedStats++; GameListBuilder.UpdateFlag(); } } }
private void ApplicationStart(object sender, StartupEventArgs e) { // unhandled exception events AppDomain.CurrentDomain.UnhandledException += (s, exception) => LogUnhandledException((Exception)exception.ExceptionObject, "AppDomain.CurrentDomain.UnhandledException"); DispatcherUnhandledException += (s, exception) => LogUnhandledException(exception.Exception, "Application.Current.DispatcherUnhandledException"); TaskScheduler.UnobservedTaskException += (s, exception) => LogUnhandledException(exception.Exception, "TaskScheduler.UnobservedException"); var splashScreen = new SplashScreen(@"Data\Graphics\mediconsplash-new.png"); splashScreen.Show(false); Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; // show the initialisation window and begin checks ShowInitWindow(); Thread.Sleep(1000); // init should have completed - run MainWindow // instantiate GamesList object GamesList = new GameListBuilder(); MainWindow mw = new MedLaunch.MainWindow(); Current.ShutdownMode = ShutdownMode.OnMainWindowClose; Application.Current.MainWindow = mw; mw.Show(); // instantiate GamesList object //GamesList = new GameListBuilder(); splashScreen.Close(TimeSpan.FromSeconds(1)); // instantiate ScrapedContent Object ScrapedData = new GamesLibraryScrapedContent(); // set color scheme from database Tuple <AppTheme, Accent> appStyle = ThemeManager.DetectAppStyle(Application.Current); if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Data\Settings\MedLaunch.db")) { // database already exists var gs = GlobalSettings.GetGlobals(); ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.GetAccent(gs.colorAccent), ThemeManager.GetAppTheme(gs.colorBackground)); } else { // database hasnt been generated yet - set default ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.GetAccent("Emerald"), ThemeManager.GetAppTheme("BaseDark")); } }
/* 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(); } }