/// <summary> /// Read basic game and clone info from MAME and create our initial gamelist & database. /// </summary> public void MakeQuickDat() { _mameInfo = CreateMameInfo(); SettingsManager.MameCommands = _mameInfo.Commands; var machinesDictionary = new Dictionary <string, Machine>(); var clonesDictionary = new Dictionary <string, List <string> >(); var clonesHashtable = new Hashtable(); using (StreamReader listClones = ExecuteMameCommand("-listclones").StandardOutput) { // Read the header line. var line = listClones.ReadLine(); var regex = new Regex(@"^(\S+)\s+(\S+)\s*$"); while ((line = listClones.ReadLine()) != null) { var match = regex.Match(line); var clone = match.Groups[1].Value; var parent = match.Groups[2].Value; clonesHashtable.Add(clone, true); if (clonesDictionary.ContainsKey(parent)) { clonesDictionary[parent].Add(clone); } else { clonesDictionary.Add(parent, new List <string>() { clone }); } } } using (StreamReader listFull = ExecuteMameCommand("-listfull").StandardOutput) { // Read the header line. var line = listFull.ReadLine(); var regex = new Regex(@"^(\S*)\s+""(.*)""$"); while ((line = listFull.ReadLine()) != null) { var match = regex.Match(line); var name = match.Groups[1].Value; var description = match.Groups[2].Value; machinesDictionary.Add(name, new Machine() { description = description, name = name }); } } var sortedParents = machinesDictionary.Values.Where(x => !clonesHashtable.ContainsKey(x.name)).OrderBy(x => x.description); var results = new List <Machine>(); foreach (var parent in sortedParents) { results.Add(parent); if (clonesDictionary.ContainsKey(parent.name)) { foreach (var clone in clonesDictionary[parent.name]) { machinesDictionary[clone].cloneof = parent.name; results.Add(machinesDictionary[clone]); } } } DatabaseManager.SaveMachines(results); DatabaseManager.SaveMameInfo(_mameInfo); _games = CreateGamesFromMachines(results); _games.TotalGames = results.Count; }
/// <summary> /// Reads the IV/Play Data file, technically should work with a compressed mame data file as well. /// </summary> public void ReadDat() { _games = CreateGamesFromMachines(DatabaseManager.GetMachines()); _mameInfo = DatabaseManager.GetMameInfo(); SettingsManager.MameCommands = _mameInfo.Commands; }
private void updateList(Games games) { _gameList.LoadGames(games); _gameList.LoadSettings(); _gameList.Filter = _gameList.Filter; }
protected override void OnKeyDown(KeyEventArgs e) { if (e.Control) { ControlKeyPressed = true; } Invalidate(); base.OnKeyDown(e); switch (e.KeyCode) { case Keys.R: if (e.Control) { Random rand = new Random(DateTime.Now.Millisecond); int iRand = rand.Next(0, Games.Count); SelectedGame = GetNodeAtRow(iRand); } break; case Keys.Back: if (e.Control && Filter.Length != 0) { Filter = ""; } break; case Keys.Down: if (e.Control) { ScrollInfoText(3, InfoScrollMode.Line); } else { NavigateForward(1); } break; case Keys.Up: if (e.Control) { ScrollInfoText(-3, InfoScrollMode.Line); } else { NavigateBackward(1); } break; case Keys.PageDown: if (e.Control) { ScrollInfoText(1, InfoScrollMode.Page); } else { NavigateForward(ClientRectangle.Height / RowHeight); } break; case Keys.PageUp: if (e.Control) { ScrollInfoText(-1, InfoScrollMode.Page); } else { NavigateBackward(ClientRectangle.Height / RowHeight); } break; case Keys.Home: if (e.Control) { ScrollInfoText(-1, InfoScrollMode.All); } else if (SelectedGame != null && FavoritesMode == FavoritesMode.FavoritesAndGames) { Game lastFavorite = GetNodeAtRow(CountFavorites); if (SelectedGame.IsFavorite || SelectedGame == lastFavorite) { SelectedGame = Games.First().Value; } else { SelectedGame = lastFavorite; } } else { SelectedGame = Games.First().Value; } break; case Keys.End: if (e.Control) { ScrollInfoText(1, InfoScrollMode.All); } else if (SelectedGame != null && FavoritesMode == FavoritesMode.FavoritesAndGames) { Game lastFavorite = GetNodeAtRow(CountFavorites - 1); if (!SelectedGame.IsFavorite || SelectedGame == lastFavorite) { SelectedGame = Games.Last().Value; } else { SelectedGame = lastFavorite; } } else { SelectedGame = Games.Last().Value; } break; case Keys.Enter: if (Focused) { StartGame(); } break; case Keys.D0: case Keys.D1: case Keys.D2: case Keys.D3: case Keys.D4: case Keys.D5: case Keys.D6: case Keys.D7: case Keys.D8: case Keys.D9: if (e.Alt) { int artType = e.KeyValue - (int)Keys.D0; if (artType < SettingsManager.ArtPaths.Count) { Settings.Default.art_type = artType; ArtType = Settings.Default.art_type; RefreshImage(); } e.SuppressKeyPress = true; } break; } }
internal void LoadGames(Games games) { _games = games; }
/// <summary> /// Loads our favorites from favorites.ini /// </summary> /// <returns>How many favorites have been added already to our internal list.</returns> private int LoadFavorites() { _gamesFavorites = new Games(); _countFavorites = 0; if (File.Exists(Settings.Default.favorites_ini)) { string[] favs = File.ReadAllLines(Settings.Default.favorites_ini); foreach (string s in favs) //Some of the lines are not favorites, just ignores them. { try { Game game = XmlParser.Games.FindGame(s); if (game != null) { Game g = game.Copy(); g.Name = "fav_" + g.Name; g.IsFavorite = true; _gamesFavorites.Add(g.Name, g); } } catch (Exception) { //Not a game, do nothing. } } //Sorts out the list by description alphabetically and filters it according to what the user set. var sortedDict = (from entry in _gamesFavorites where entry.Value.Name.Contains(_filter, StringComparison.InvariantCultureIgnoreCase) || entry.Value.Manufacturer.Contains(_filter, StringComparison.InvariantCultureIgnoreCase) || entry.Value.Year.Contains(_filter, StringComparison.InvariantCultureIgnoreCase) || entry.Value.SourceFile.Contains(_filter, StringComparison.InvariantCultureIgnoreCase) || entry.Value.Description.Contains(_filter, StringComparison.InvariantCultureIgnoreCase) orderby entry.Value.Description.ToLower() ascending select entry); //Add the filtered favorites to our game list. Game prevGame = null; int i = 0; foreach (var fGame in sortedDict) { fGame.Value.Index = i++; Games.Add(fGame.Key, fGame.Value); _countFavorites++; if (prevGame != null) { prevGame.NextGame = fGame.Value; } fGame.Value.PreviousGame = prevGame; prevGame = fGame.Value; } return(i); } return(0); }