public override void Entry(IModHelper helper) { this.Config = helper.ReadConfig <ModConfig>(); this.RetroAchievement = new RetroAchievements(helper, this.Monitor, this.Config); this.RetroSpecials = new RetroSpecials(helper, this.Monitor, this.Config); this.RetroMail = new RetroMail(helper, this.Monitor, this.Config); helper.Events.GameLoop.DayStarted += this.RetroAchievement.DayStarted; helper.Events.GameLoop.DayStarted += this.RetroSpecials.DayStarted; helper.Events.GameLoop.DayStarted += this.RetroMail.DayStarted; }
/// <summary> /// /// </summary> /// <param name="GameSourceName"></param> /// <param name="settings"></param> /// <returns></returns> public static bool VerifToAddOrShow(SuccessStory plugin, IPlayniteAPI PlayniteApi, SuccessStorySettings settings, string PluginUserDataPath, string GameSourceName) { if (settings.EnableSteam && GameSourceName.ToLower() == "steam") { if (PlayniteTools.IsDisabledPlaynitePlugins("SteamLibrary", PlayniteApi.Paths.ConfigurationPath)) { logger.Warn("SuccessStory - Steam is enable then disabled"); PlayniteApi.Notifications.Add(new NotificationMessage( "SuccessStory-Steam-disabled", $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsSteamDisabled")}", NotificationType.Error, () => plugin.OpenSettingsView() )); return(false); } else { SteamAchievements steamAchievements = new SteamAchievements(PlayniteApi, settings, PluginUserDataPath); if (!steamAchievements.IsConfigured()) { logger.Warn("SuccessStory - Bad Steam configuration"); PlayniteApi.Notifications.Add(new NotificationMessage( "SuccessStory-Steam-NoConfig", $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsSteamBadConfig")}", NotificationType.Error, () => plugin.OpenSettingsView() )); return(false); } } return(true); } if (settings.EnableGog && GameSourceName.ToLower() == "gog") { if (PlayniteTools.IsDisabledPlaynitePlugins("GogLibrary", PlayniteApi.Paths.ConfigurationPath)) { logger.Warn("SuccessStory - GOG is enable then disabled"); PlayniteApi.Notifications.Add(new NotificationMessage( "SuccessStory-GOG-disabled", $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsGogDisabled")}", NotificationType.Error, () => plugin.OpenSettingsView() )); return(false); } else { GogAchievements gogAchievements = new GogAchievements(PlayniteApi, settings, PluginUserDataPath); if (VerifToAddOrShowGog == null) { VerifToAddOrShowGog = gogAchievements.IsConnected(); } if (!(bool)VerifToAddOrShowGog) { logger.Warn("SuccessStory - Gog user is not authenticate"); PlayniteApi.Notifications.Add(new NotificationMessage( "SuccessStory-Gog-NoAuthenticated", $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsGogNoAuthenticate")}", NotificationType.Error, () => plugin.OpenSettingsView() )); return(false); } } return(true); } if (settings.EnableOrigin && GameSourceName.ToLower() == "origin") { if (PlayniteTools.IsDisabledPlaynitePlugins("OriginLibrary", PlayniteApi.Paths.ConfigurationPath)) { logger.Warn("SuccessStory - Origin is enable then disabled"); PlayniteApi.Notifications.Add(new NotificationMessage( "SuccessStory-Origin-disabled", $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsOriginDisabled")}", NotificationType.Error, () => plugin.OpenSettingsView() )); return(false); } else { OriginAchievements originAchievements = new OriginAchievements(PlayniteApi, settings, PluginUserDataPath); if (VerifToAddOrShowOrigin == null) { VerifToAddOrShowOrigin = originAchievements.IsConnected(); } if (!(bool)VerifToAddOrShowOrigin) { logger.Warn("SuccessStory - Origin user is not authenticated"); PlayniteApi.Notifications.Add(new NotificationMessage( "SuccessStory-Origin-NoAuthenticate", $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsOriginNoAuthenticate")}", NotificationType.Error, () => plugin.OpenSettingsView() )); return(false); } } return(true); } if (settings.EnableXbox && GameSourceName.ToLower() == "xbox") { if (PlayniteTools.IsDisabledPlaynitePlugins("XboxLibrary", PlayniteApi.Paths.ConfigurationPath)) { logger.Warn("SuccessStory - Xbox is enable then disabled"); PlayniteApi.Notifications.Add(new NotificationMessage( "SuccessStory-Xbox-disabled", $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsXboxDisabled")}", NotificationType.Error, () => plugin.OpenSettingsView() )); return(false); } else { XboxAchievements xboxAchievements = new XboxAchievements(PlayniteApi, settings, PluginUserDataPath); #if DEBUG logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShowXbox: {VerifToAddOrShowXbox}"); #endif if (VerifToAddOrShowXbox == null) { VerifToAddOrShowXbox = xboxAchievements.IsConnected(); } #if DEBUG logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShowXbox: {VerifToAddOrShowXbox}"); #endif if (!(bool)VerifToAddOrShowXbox) { logger.Warn("SuccessStory - Xbox user is not authenticated"); PlayniteApi.Notifications.Add(new NotificationMessage( "SuccessStory-Xbox-NoAuthenticate", $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsXboxNotAuthenticate")}", NotificationType.Error, () => plugin.OpenSettingsView() )); return(false); } } return(true); } if (settings.EnableLocal && (GameSourceName.ToLower() == "playnite" || GameSourceName.ToLower() == "hacked")) { return(true); } if (settings.EnableRetroAchievements && GameSourceName.ToLower() == "retroachievements") { RetroAchievements retroAchievements = new RetroAchievements(PlayniteApi, settings, PluginUserDataPath); if (!retroAchievements.IsConfigured()) { logger.Warn("SuccessStory - Bad RetroAchievements configuration"); PlayniteApi.Notifications.Add(new NotificationMessage( "SuccessStory-RetroAchievements-NoConfig", $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsRetroAchievementsBadConfig")}", NotificationType.Error, () => plugin.OpenSettingsView() )); return(false); } return(true); } if (settings.EnableRpcs3Achievements && GameSourceName.ToLower() == "rpcs3") { Rpcs3Achievements rpcs3Achievements = new Rpcs3Achievements(PlayniteApi, settings, PluginUserDataPath); if (!rpcs3Achievements.IsConfigured()) { logger.Warn("SuccessStory - Bad RPCS3 configuration"); PlayniteApi.Notifications.Add(new NotificationMessage( "SuccessStory-Rpcs3-NoConfig", $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsRpcs3BadConfig")}", NotificationType.Error, () => plugin.OpenSettingsView() )); return(false); } return(true); } logger.Warn($"SuccessStory - VerifToAddOrShow() find no action for {GameSourceName}"); return(false); }
/// <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 = 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="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)); } } } }