/// <summary> /// Initialize database / create directory. /// </summary> /// <param name="PlayniteApi"></param> /// <param name="PluginUserDataPath"></param> public void Initialize() { ListErrors = new CumulErrors(); Parallel.ForEach(Directory.EnumerateFiles(PluginDatabasePath, "*.json"), (objectFile) => { try { // Get game achievements. Guid gameId = Guid.Parse(objectFile.Replace(PluginDatabasePath, "").Replace(".json", "")); bool IncludeGame = true; if (!Settings.IncludeHiddenGames) { Game tempGame = PlayniteApi.Database.Games.Get(gameId); if (tempGame != null) { IncludeGame = !tempGame.Hidden; } else { IncludeGame = false; logger.Info($"SuccessStory - {gameId} is null"); } } if (IncludeGame) { GameAchievements objGameAchievements = JsonConvert.DeserializeObject <GameAchievements>(File.ReadAllText(objectFile)); // Set game achievements in database. PluginDatabase.TryAdd(gameId, objGameAchievements); } } catch (Exception ex) { Common.LogError(ex, "SuccessStory", $"Failed to load item from { objectFile}"); ListErrors.Add($"SuccessStory - Failed to load item from {objectFile}"); } }); if (ListErrors.Get() != "") { PlayniteApi.Dialogs.ShowErrorMessage(ListErrors.Get(), "SuccessStory errors"); } ListErrors = new CumulErrors(); }
/// <summary> /// Initialize database / create directory. /// </summary> /// <param name="PlayniteApi"></param> /// <param name="PluginUserDataPath"></param> public void Initialize(bool ignore = true) { ListErrors = new CumulErrors(); PluginDatabase = new ConcurrentDictionary <Guid, GameAchievements>(); Parallel.ForEach(Directory.EnumerateFiles(PluginDatabasePath, "*.json"), (objectFile) => { try { // Get game achievements. Guid gameId = Guid.Parse(objectFile.Replace(PluginDatabasePath, string.Empty).Replace(".json", string.Empty)); bool IncludeGame = true; if (!_settings.IncludeHiddenGames) { Game tempGame = _PlayniteApi.Database.Games.Get(gameId); if (tempGame != null) { IncludeGame = !tempGame.Hidden; } else { IncludeGame = false; #if DEBUG logger.Debug($"SuccessStory - {gameId} is null"); #endif } } if (IncludeGame) { GameAchievements objGameAchievements = JsonConvert.DeserializeObject <GameAchievements>(File.ReadAllText(objectFile)); // Set game achievements in database. PluginDatabase.TryAdd(gameId, objGameAchievements); } } catch (Exception ex) { Common.LogError(ex, "SuccessStory", $"Failed to load item from { objectFile}"); ListErrors.Add($"SuccessStory - Failed to load item from {objectFile}"); } }); // Filters if (_settings.EnableRetroAchievementsView && !ignore) { if (_isRetroachievements) { var a = PluginDatabase.Where(x => IsEmulatedGame(x)); var b = a.ToDictionary(x => x.Key, x => x.Value); PluginDatabase = ToConcurrent(b); } else { var a = PluginDatabase.Where(x => !IsEmulatedGame(x)); var b = a.ToDictionary(x => x.Key, x => x.Value); PluginDatabase = ToConcurrent(b); } } if (ListErrors.Get() != string.Empty) { _PlayniteApi.Dialogs.ShowErrorMessage(ListErrors.Get(), "SuccessStory errors"); } ListErrors = new CumulErrors(); }