/// <summary> /// Generate database achivements for the game if achievement exist and game not exist in database. /// </summary> /// <param name="GameAdded"></param> public void Add(Game GameAdded, SuccessStorySettings settings) { GameAchievements GameAchievements = new GameAchievements(); Guid GameId = GameAdded.Id; Guid GameSourceId = GameAdded.SourceId; string GameSourceName = PlayniteTools.GetSourceName(GameAdded, _PlayniteApi); string PluginDatabaseGamePath = PluginDatabasePath + GameId.ToString() + ".json"; List <Achievements> Achievements = new List <Achievements>(); // Generate database only this source if (VerifToAddOrShow(_plugin, _PlayniteApi, GameSourceName, settings, _PluginUserDataPath)) { // Generate only not exist if (!File.Exists(PluginDatabaseGamePath)) { #if DEBUG logger.Debug($"SuccessStory - VerifToAddOrShow({GameAdded.Name}, {GameSourceName}) - OK"); #endif // TODO one func if (GameSourceName.ToLower() == "gog") { if (gogAPI == null) { gogAPI = new GogAchievements(_PlayniteApi, settings, _PluginUserDataPath); } GameAchievements = gogAPI.GetAchievements(GameAdded); } if (GameSourceName.ToLower() == "steam") { SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, settings, _PluginUserDataPath); GameAchievements = steamAPI.GetAchievements(GameAdded); } if (GameSourceName.ToLower() == "origin") { if (originAPI == null) { originAPI = new OriginAchievements(_PlayniteApi, settings, _PluginUserDataPath); } GameAchievements = originAPI.GetAchievements(GameAdded); } if (GameSourceName.ToLower() == "xbox") { if (xboxAPI == null) { xboxAPI = new XboxAchievements(_PlayniteApi, settings, _PluginUserDataPath); } GameAchievements = xboxAPI.GetAchievements(GameAdded); } if (GameSourceName.ToLower() == "playnite") { SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, settings, _PluginUserDataPath); steamAPI.SetLocal(); GameAchievements = steamAPI.GetAchievements(GameAdded); } if (GameSourceName.ToLower() == "retroachievements") { RetroAchievements retroAchievementsAPI = new RetroAchievements(_PlayniteApi, settings, _PluginUserDataPath); GameAchievements = retroAchievementsAPI.GetAchievements(GameAdded); } #if DEBUG logger.Debug($"SuccessStory - Achievements for {GameAdded.Name} - {GameSourceName} - {JsonConvert.SerializeObject(GameAchievements)}"); #endif if (GameAchievements != null) { File.WriteAllText(PluginDatabaseGamePath, JsonConvert.SerializeObject(GameAchievements)); } } } else { #if DEBUG logger.Debug($"SuccessStory - VerifToAddOrShow({GameAdded.Name}, {GameSourceName}) - KO"); #endif } }
/// <summary> /// Generate database achivements for the game if achievement exist and game not exist in database. /// </summary> /// <param name="game"></param> public GameAchievements GetFromWeb(Game game) { GameAchievements gameAchievements = GetDefault(game); Guid GameId = game.Id; Guid GameSourceId = game.SourceId; string GameSourceName = PlayniteTools.GetSourceName(_PlayniteApi, game); List <Achievements> Achievements = new List <Achievements>(); // Generate database only this source if (VerifToAddOrShow(_plugin, _PlayniteApi, PluginSettings, PluginUserDataPath, GameSourceName)) { #if DEBUG logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShow({game.Name}, {GameSourceName}) - OK"); #endif // TODO one func if (GameSourceName.ToLower() == "gog") { if (gogAPI == null) { gogAPI = new GogAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath); } gameAchievements = gogAPI.GetAchievements(game); } if (GameSourceName.ToLower() == "steam") { SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath); gameAchievements = steamAPI.GetAchievements(game); } if (GameSourceName.ToLower() == "origin") { if (originAPI == null) { originAPI = new OriginAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath); } gameAchievements = originAPI.GetAchievements(game); } if (GameSourceName.ToLower() == "xbox") { if (xboxAPI == null) { xboxAPI = new XboxAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath); } gameAchievements = xboxAPI.GetAchievements(game); } if (GameSourceName.ToLower() == "playnite" || GameSourceName.ToLower() == "hacked") { SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath); steamAPI.SetLocal(); gameAchievements = steamAPI.GetAchievements(game); } if (GameSourceName.ToLower() == "retroachievements") { RetroAchievements retroAchievementsAPI = new RetroAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath); gameAchievements = retroAchievementsAPI.GetAchievements(game); } if (GameSourceName.ToLower() == "rpcs3") { Rpcs3Achievements rpcs3Achievements = new Rpcs3Achievements(_PlayniteApi, PluginSettings, PluginUserDataPath); gameAchievements = rpcs3Achievements.GetAchievements(game); } #if DEBUG logger.Debug($"SuccessStory [Ignored] - Achievements for {game.Name} - {GameSourceName} - {JsonConvert.SerializeObject(gameAchievements)}"); #endif } else { #if DEBUG logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShow({game.Name}, {GameSourceName}) - KO"); #endif } return(gameAchievements); }
/// <summary> /// Generate database achivements for the game if achievement exist and game not exist in database. /// </summary> /// <param name="GameAdded"></param> public void Add(Game GameAdded, SuccessStorySettings settings) { GameAchievements GameAchievements = new GameAchievements(); Guid GameId = GameAdded.Id; Guid GameSourceId = GameAdded.SourceId; string GameSourceName = ""; List <Guid> ListEmulators = new List <Guid>(); foreach (var item in PlayniteApi.Database.Emulators) { ListEmulators.Add(item.Id); } if (GameSourceId != Guid.Parse("00000000-0000-0000-0000-000000000000")) { GameSourceName = GameAdded.Source.Name; if (GameAdded.PlayAction != null && GameAdded.PlayAction.EmulatorId != null && ListEmulators.Contains(GameAdded.PlayAction.EmulatorId)) { GameSourceName = "RetroAchievements"; } } else { if (GameAdded.PlayAction != null && GameAdded.PlayAction.EmulatorId != null && ListEmulators.Contains(GameAdded.PlayAction.EmulatorId)) { GameSourceName = "RetroAchievements"; } else { GameSourceName = "Playnite"; } } string PluginDatabaseGamePath = PluginDatabasePath + GameId.ToString() + ".json"; List <Achievements> Achievements = new List <Achievements>(); // Generate database only this source if (VerifToAddOrShow(GameSourceName, settings, PluginUserDataPath)) { // Generate only not exist if (!File.Exists(PluginDatabaseGamePath)) { // TODO one func if (GameSourceName.ToLower() == "gog") { if (gogAPI == null) { gogAPI = new GogAchievements(PlayniteApi); } GameAchievements = gogAPI.GetAchievements(PlayniteApi, GameId); } if (GameSourceName.ToLower() == "steam") { SteamAchievements steamAPI = new SteamAchievements(); GameAchievements = steamAPI.GetAchievements(PlayniteApi, GameId, PluginUserDataPath); } if (GameSourceName.ToLower() == "origin") { if (originAPI == null) { originAPI = new OriginAchievements(PlayniteApi); } GameAchievements = originAPI.GetAchievements(PlayniteApi, GameId); } if (GameSourceName.ToLower() == "playnite") { SteamAchievements steamAPI = new SteamAchievements(); GameAchievements = steamAPI.GetAchievements(PlayniteApi, GameId, PluginUserDataPath, settings.EnableLocal); } if (GameSourceName.ToLower() == "retroachievements") { RetroAchievements retroAchievementsAPI = new RetroAchievements(settings); GameAchievements = retroAchievementsAPI.GetAchievements(PlayniteApi, GameId, PluginUserDataPath); } if (GameAchievements != null) { File.WriteAllText(PluginDatabaseGamePath, JsonConvert.SerializeObject(GameAchievements)); } } } }