private Games CreateGamesFromMachines(List <Machine> machines) { var games = new Games(); var hiddenGames = new System.Collections.Hashtable(); if (File.Exists("Hidden.ini")) { foreach (var item in File.ReadAllLines("Hidden.ini")) { if (!hiddenGames.ContainsKey(item)) { hiddenGames.Add(item, true); } } } var parents = (from m in machines where m.cloneof == null && !hiddenGames.ContainsKey(m.name) select m); var clones = (from m in machines where m.cloneof != null && !hiddenGames.ContainsKey(m.name) select m); foreach (var machine in parents) { var game = new Game(machine); games.TryAdd(game.Name, game); } //Go through all the games and add clones to the parents. foreach (var machine in clones) { var game = new Game(machine); if (games.ContainsKey(game.ParentSet)) { games[game.ParentSet].Children.Add(game.Description, game); } } return(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. { if (s == "") { continue; } try { Game game = new Game(DatabaseManager.GetMachineByName(s)); if (game != null) { Game g = game.Copy(); g.Name = "fav_" + g.Name; g.IsFavorite = true; _gamesFavorites.TryAdd(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); }