public override void OnGameStarted(OnGameStartedEventArgs args) { var game = args.Game; if (game.IsInstalled == false) { return; } if (BuiltinExtensions.GetExtensionFromId(game.PluginId) != BuiltinExtension.SteamLibrary) { return; } string modeFeatureName = GetModeFeatureName(); if (game.Features != null) { var matchingFeature = game.Features.Where(f => f.Name == modeFeatureName); if (settings.Settings.LaunchMode == 0 && matchingFeature.Count() > 0) { logger.Info(String.Format("Stopped execution in game \"{0}\". Global mode and game has \"{1}\" feature", game.Name, modeFeatureName)); return; } else if (settings.Settings.LaunchMode == 1 && matchingFeature.Count() == 0) { logger.Info(String.Format("Stopped execution in game \"{0}\". Selective mode and game doesn't have \"{1}\" feature", game.Name, modeFeatureName)); return; } } LaunchSteam(); }
public async Task SteamIdUseTest() { var metadata = await GetMetadata(new SdkModels.Game("") { PluginId = BuiltinExtensions.GetIdFromExtension(BuiltinExtension.SteamLibrary), GameId = "7200" }); Assert.Equal("TrackMania United", metadata.name); }
public override MetadataFile GetBackgroundImage() { if (options.IsBackgroundDownload) { string gameUrl; if (options.GameData.Source != null && options.GameData.PluginId == BuiltinExtensions.GetIdFromExtension(BuiltinExtension.SteamLibrary) && options.GameData.GameId != null) { gameUrl = services.getHeroImageUrl(options.GameData.Name, convertPlayniteGamePluginIdToSGDBPlatformEnum(options.GameData.PluginId), options.GameData.GameId); } else { gameUrl = services.getHeroImageUrl(options.GameData.Name); } if (gameUrl == "bad path") { return(base.GetBackgroundImage()); } else { return(new MetadataFile(gameUrl)); } } else { if (AvailableFields.Contains(MetadataField.Name)) { if (searchSelection != null) { var heroes = services.getHeroImages(searchSelection.Name); dynamic selection = null; if (heroes != null) { selection = GetHeroManually(heroes); } if (selection == null || selection.Path == "nopath") { return(base.GetBackgroundImage()); } else { return(new MetadataFile(selection.FullRes)); } } else { return(base.GetBackgroundImage()); } } else { return(base.GetBackgroundImage()); } } }
public IEnumerable <Game> GetGamesSupportedLibraries() { List <Guid> supportedLibraries = new List <Guid>() { BuiltinExtensions.GetIdFromExtension(BuiltinExtension.EpicLibrary), BuiltinExtensions.GetIdFromExtension(BuiltinExtension.OriginLibrary), BuiltinExtensions.GetIdFromExtension(BuiltinExtension.SteamLibrary), BuiltinExtensions.GetIdFromExtension(BuiltinExtension.UplayLibrary), BuiltinExtensions.GetIdFromExtension(BuiltinExtension.GogLibrary) }; var gameDatabase = PlayniteApi.Database.Games.Where(g => supportedLibraries.Contains(g.PluginId)); return(gameDatabase); }
public XboxLibraryHelper(IPlayniteAPI api) { PlayniteApi = api; client = new HttpClient(); pluginId = BuiltinExtensions.GetIdFromExtension(BuiltinExtension.XboxLibrary); RefreshLibraryItems(); var pcPlatform = PlayniteApi.Database.Platforms.Add("PC (Windows)"); platformsList = new List <Guid> { pcPlatform.Id }; gameExpiredTag = PlayniteApi.Database.Tags.Add("Game Pass (Formerly on)"); gameAddedTag = PlayniteApi.Database.Tags.Add("Game Pass"); source = PlayniteApi.Database.Sources.Add("Xbox Game Pass"); sourceXbox = PlayniteApi.Database.Sources.Add("Xbox"); }
public string convertPlayniteGamePluginIdToSGDBPlatformEnum(Guid pluginId) { //check for platform "steam""origin""egs""bnet""uplay" switch (BuiltinExtensions.GetExtensionFromId(pluginId)) { case BuiltinExtension.SteamLibrary: return("steam"); case BuiltinExtension.OriginLibrary: return("origin"); case BuiltinExtension.EpicLibrary: return("egs"); case BuiltinExtension.BattleNetLibrary: return("bnet"); default: return(null); } }
public void TransferSteamGames(List <string> steamLibraries, string targetLibraryPath, bool deleteSourceGame, bool restartSteam) { var gameDatabase = PlayniteApi.MainView.SelectedGames.Where(g => g.PluginId == BuiltinExtensions.GetIdFromExtension(BuiltinExtension.SteamLibrary)).Where(g => g.IsInstalled == true); if (gameDatabase.Count() == 0) { PlayniteApi.Dialogs.ShowErrorMessage("There are no installed Steam games selected", "Steam Game Transfer Utility"); return; } FileInfo t = new FileInfo(targetLibraryPath); string targetDrive = System.IO.Path.GetPathRoot(t.FullName).ToLower(); int copiedGamesCount = 0; int skippedGamesCount = 0; int deletedSourceFilesCount = 0; foreach (Game game in gameDatabase) { logger.Info(string.Format("Processing game: \"{0}\"", game.Name)); // Verify that source and target library are not in the same drive FileInfo s = new FileInfo(game.InstallDirectory); string sourceDrive = System.IO.Path.GetPathRoot(s.FullName).ToLower(); if (sourceDrive == targetDrive) { string errorMessage = string.Format("Source and target library are the same drive: \"{0}\"", sourceDrive); logger.Warn(errorMessage); skippedGamesCount++; continue; } // Get steam source library that contains game string sourceLibraryPath = steamLibraries.Where(x => x.StartsWith(sourceDrive, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (sourceLibraryPath == null) { string errorMessage = string.Format("Game: {0}. Error: Steam library on drive {1} not detected", game.Name, sourceDrive); PlayniteApi.Dialogs.ShowErrorMessage(errorMessage, "Steam Game Transfer Utility"); logger.Warn(errorMessage); skippedGamesCount++; continue; } // Check if game source manifest exists string gameManifest = string.Format("appmanifest_{0}.acf", game.GameId); string sourceManifestPath = System.IO.Path.Combine(sourceLibraryPath, gameManifest); if (!File.Exists(sourceManifestPath)) { string errorMessage = string.Format("Game: {0}. Error: Source manifest doesn't exist in {1}" + "\n\nThis issue can be happen if you used this utility on this game and you have not restarted Steam" + " and updated your Playnite library to reflect the changes", game.Name, sourceManifestPath); PlayniteApi.Dialogs.ShowErrorMessage(errorMessage, "Steam Game Transfer Utility"); logger.Warn(errorMessage); skippedGamesCount++; continue; } // Check if game source directory exists string sourceGameDirectoryPath = System.IO.Path.Combine(sourceLibraryPath, "common", GetAcfAppSubItem(sourceManifestPath, "installdir")); if (!Directory.Exists(sourceGameDirectoryPath)) { string errorMessage = string.Format("Game: {0}. Error: Source directory doesn't exist in {1}" + "\n\nThis issue can be happen if you used this utility on this game and you have not restarted Steam" + " and updated your Playnite library to reflect the changes", game.Name, sourceGameDirectoryPath); PlayniteApi.Dialogs.ShowErrorMessage(errorMessage, "Steam Game Transfer Utility"); logger.Warn(errorMessage); skippedGamesCount++; continue; } // Check if game manifest already exists in target library string targetManifestPath = System.IO.Path.Combine(targetLibraryPath, gameManifest); if (File.Exists(targetManifestPath)) { int sourceBuildId = Int32.Parse(GetAcfAppSubItem(sourceManifestPath, "buildid")); int targetBuildId = Int32.Parse(GetAcfAppSubItem(targetManifestPath, "buildid")); if (sourceBuildId <= targetBuildId) { string errorMessage = string.Format("Game: {0}. Equal or greater BuldId. Source BuildId {1} - Target BuildId {2}", game.Name, sourceBuildId.ToString(), targetBuildId.ToString()); logger.Info(errorMessage); skippedGamesCount++; if (deleteSourceGame == true) { Directory.Delete(sourceGameDirectoryPath, true); File.Delete(sourceManifestPath); logger.Info("Deleted source files"); deletedSourceFilesCount++; } continue; } } //Calculate size of source game directory string sourceDirectorySize = CalculateSize(sourceGameDirectoryPath); var progRes = PlayniteApi.Dialogs.ActivateGlobalProgress((a) => { string targetGameDirectoryPath = System.IO.Path.Combine(targetLibraryPath, "common", GetAcfAppSubItem(sourceManifestPath, "installdir")); if (Directory.Exists(targetGameDirectoryPath)) { Directory.Delete(targetGameDirectoryPath, true); logger.Info(string.Format("Deleted directory: {0}", targetGameDirectoryPath)); } DirectoryCopy(sourceGameDirectoryPath, targetGameDirectoryPath, true); logger.Info(string.Format("Game copied: {0}. sourceDirName: {1}, destDirName: {2}", game.Name, sourceGameDirectoryPath, targetGameDirectoryPath)); File.Copy(sourceManifestPath, targetManifestPath, true); logger.Info(string.Format("Game manifest copied: {0}. sourceDirName: {1}, destDirName: {2}", game.Name, sourceManifestPath, targetManifestPath)); copiedGamesCount++; if (deleteSourceGame == true) { Directory.Delete(sourceGameDirectoryPath, true); File.Delete(sourceManifestPath); logger.Info("Deleted source files"); deletedSourceFilesCount++; } }, new GlobalProgressOptions(string.Format("Processing game: {0}\n\nGame size: {1}", game.Name, sourceDirectorySize))); } string results = string.Format("Finished.\n\nCopied games: {0}\nSkipped games: {1}", copiedGamesCount.ToString(), skippedGamesCount.ToString()); if (deleteSourceGame == true) { results += string.Format("\nDeleted source games: {0}", deletedSourceFilesCount.ToString()); } if (copiedGamesCount > 0 || deletedSourceFilesCount > 0) { results += "\n\nUpdate your Playnite library after restarting Steam to reflect the changes"; } PlayniteApi.Dialogs.ShowMessage(results, "Steam Game Transfer Utility"); if (restartSteam == true && (copiedGamesCount > 0 || deletedSourceFilesCount > 0)) { RestartSteam(); } }
public async Task <ServicesResponse <ExpandedGame> > Post([FromBody] SdkModels.Game game) { var isKnownPlugin = game.PluginId != Guid.Empty; var isSteamPlugin = BuiltinExtensions.GetIdFromExtension(BuiltinExtension.SteamLibrary) == game.PluginId; ulong igdbId = 0; var matchId = $"{game.GameId}{game.PluginId}".MD5(); var searchId = $"{game.Name}{game.ReleaseDate?.Year}".MD5(); logger.Debug($"IGDB metadata: {game.GameId},{game.Name},{game.PluginId},{game.ReleaseDate}"); // Check if match was previously found if (isKnownPlugin) { if (isSteamPlugin) { igdbId = await GamesBySteamIdController.GetIgdbMatch(ulong.Parse(game.GameId)); } else { var match = Database.IGBDGameIdMatches.FindById(matchId); if (match != null) { igdbId = match.IgdbId; } } } if (igdbId == 0) { var match = Database.IGDBSearchIdMatches.FindById(searchId); if (match != null) { igdbId = match.IgdbId; } } var foundMetadata = new ExpandedGame(); if (igdbId != 0) { return(new ServicesResponse <ExpandedGame>(await GameParsedController.GetExpandedGame(igdbId))); } else { igdbId = await TryMatchGame(game); if (igdbId != 0) { foundMetadata = await GameParsedController.GetExpandedGame(igdbId); } } // Update match database if match was found if (igdbId != 0) { if (isKnownPlugin && !isSteamPlugin) { Database.IGBDGameIdMatches.Upsert(new GameIdMatch { GameId = game.GameId, Id = matchId, IgdbId = igdbId, Library = game.PluginId }); } Database.IGDBSearchIdMatches.Upsert(new SearchIdMatch { Term = game.Name, Id = searchId, IgdbId = igdbId }); } return(new ServicesResponse <ExpandedGame>(foundMetadata)); }
public void MainMethod(bool showDialogs) { string featureName = "NVIDIA GeForce NOW"; GameFeature feature = PlayniteApi.Database.Features.Add(featureName); var supportedGames = DownloadGameList("https://static.nvidiagrid.net/supported-public-game-list/gfnpc.json", showDialogs); if (supportedGames.Count() == 0) { // In case download failed. // Also sometimes there are issues with the api and it doesn't return any games in the response return; } var supportedSteamGames = supportedGames.Where(g => g.Store == "Steam"); var supportedEpicGames = supportedGames.Where(g => g.Store == "Epic"); var supportedOriginGames = supportedGames.Where(g => g.Store == "Origin"); var supportedUplayGames = supportedGames.Where(g => g.Store == "Ubisoft Connect"); var supportedGogGames = supportedGames.Where(g => g.Store == "GOG"); int enabledGamesCount = 0; int featureAddedCount = 0; int featureRemovedCount = 0; int playActionAddedCount = 0; int playActionRemovedCount = 0; int setAsInstalledCount = 0; int setAsUninstalledCount = 0; var progRes = PlayniteApi.Dialogs.ActivateGlobalProgress((a) => { var gameDatabase = GetGamesSupportedLibraries(); foreach (var game in gameDatabase) { var gameName = Regex.Replace(game.Name, @"[^\p{L}\p{Nd}]", "").ToLower(); GeforceGame supportedGame = null; switch (BuiltinExtensions.GetExtensionFromId(game.PluginId)) { case BuiltinExtension.SteamLibrary: var steamUrl = String.Format("https://store.steampowered.com/app/{0}", game.GameId); supportedGame = supportedSteamGames.Where(g => g.SteamUrl == steamUrl).FirstOrDefault(); break; case BuiltinExtension.EpicLibrary: supportedGame = supportedEpicGames.Where(g => g.Title == gameName).FirstOrDefault(); break; case BuiltinExtension.OriginLibrary: supportedGame = supportedOriginGames.Where(g => g.Title == gameName).FirstOrDefault(); break; case BuiltinExtension.UplayLibrary: supportedGame = supportedUplayGames.Where(g => g.Title == gameName).FirstOrDefault(); break; case BuiltinExtension.GogLibrary: supportedGame = supportedGogGames.Where(g => g.Title == gameName).FirstOrDefault(); break; default: break; } if (supportedGame == null) { bool featureRemoved = RemoveFeature(game, feature); if (featureRemoved == true) { featureRemovedCount++; logger.Info(String.Format("Feature removed from \"{0}\"", game.Name)); if (settings.Settings.SetEnabledGamesAsInstalled == true && game.IsInstalled == true) { game.IsInstalled = true; setAsUninstalledCount++; PlayniteApi.Database.Games.Update(game); logger.Info(String.Format("Set \"{0}\" as uninstalled", game.Name)); } } } else { enabledGamesCount++; bool featureAdded = AddFeature(game, feature); if (featureAdded == true) { featureAddedCount++; logger.Info(String.Format("Feature added to \"{0}\"", game.Name)); } if (settings.Settings.SetEnabledGamesAsInstalled == true && game.IsInstalled == false) { game.IsInstalled = true; setAsInstalledCount++; PlayniteApi.Database.Games.Update(game); logger.Info(String.Format("Set \"{0}\" as installed", game.Name)); } } if (settings.Settings.UpdatePlayActions == true) { var updatePlayAction = UpdateNvidiaAction(game, supportedGame); if (updatePlayAction == "ActionAdded") { playActionAddedCount++; logger.Info(String.Format("Play Action added to \"{0}\"", game.Name)); } else if (updatePlayAction == "ActionRemoved") { playActionRemovedCount++; logger.Info(String.Format("Play Action removed from \"{0}\"", game.Name)); } } } }, new GlobalProgressOptions(ResourceProvider.GetString("LOCNgfn_Enabler_UpdatingProgressMessage"))); if (showDialogs == true) { string results = String.Format(ResourceProvider.GetString("LOCNgfn_Enabler_UpdateResults1Message"), enabledGamesCount, featureName, featureAddedCount, featureName, featureRemovedCount); if (settings.Settings.UpdatePlayActions == true) { results += String.Format(ResourceProvider.GetString("LOCNgfn_Enabler_UpdateResults2Message"), playActionAddedCount, playActionRemovedCount); } if (settings.Settings.SetEnabledGamesAsInstalled == true) { results += String.Format(ResourceProvider.GetString("LOCNgfn_Enabler_UpdateResults3Message"), setAsInstalledCount, setAsUninstalledCount); } PlayniteApi.Dialogs.ShowMessage(results, "NVIDIA GeForce NOW Enabler"); } }
public void RemoveModeFeature() { string featureName = GetModeFeatureName(); GameFeature feature = PlayniteApi.Database.Features.Add(featureName); var gameDatabase = PlayniteApi.MainView.SelectedGames.Where(g => g.PluginId == BuiltinExtensions.GetIdFromExtension(BuiltinExtension.SteamLibrary)); int featureRemovedCount = 0; foreach (var game in gameDatabase) { bool featureRemoved = RemoveFeature(game, feature); if (featureRemoved == true) { featureRemovedCount++; logger.Info(String.Format("Removed \"{0}\" feature from \"{1}\"", featureName, game.Name)); } } PlayniteApi.Dialogs.ShowMessage(String.Format("Removed \"{0}\" feature from {1} game(s).", featureName, featureRemovedCount), "Steam Launcher Utility"); }
private async Task <ulong> TryMatchGame(SdkModels.Game game) { if (BuiltinExtensions.GetExtensionFromId(game.PluginId) == BuiltinExtension.SteamLibrary) { var igdbId = await GamesBySteamIdController.GetIgdbMatch(ulong.Parse(game.GameId)); if (igdbId != 0) { return(igdbId); } } if (game.Name.IsNullOrEmpty()) { return(0); } ulong matchedGame = 0; var copyGame = game.GetClone(); copyGame.Name = StringExtensions.NormalizeGameName(game.Name); var name = copyGame.Name; name = Regex.Replace(name, @"\s+RHCP$", "", RegexOptions.IgnoreCase); name = Regex.Replace(name, @"\s+RU$", "", RegexOptions.IgnoreCase); var results = await GamesController.GetSearchResults(name); results.ForEach(a => a.name = StringExtensions.NormalizeGameName(a.name)); string testName = string.Empty; // Direct comparison matchedGame = MatchFun(game, name, results); if (matchedGame > 0) { return(matchedGame); } // Try replacing roman numerals: 3 => III testName = Regex.Replace(name, @"\d+", ReplaceNumsForRomans); matchedGame = MatchFun(game, testName, results); if (matchedGame > 0) { return(matchedGame); } // Try adding The testName = "The " + name; matchedGame = MatchFun(game, testName, results); if (matchedGame > 0) { return(matchedGame); } // Try chaning & / and testName = Regex.Replace(name, @"\s+and\s+", " & ", RegexOptions.IgnoreCase); matchedGame = MatchFun(game, testName, results); if (matchedGame > 0) { return(matchedGame); } // Try removing apostrophes var resCopy = results.GetClone(); resCopy.ForEach(a => a.name = a.name.Replace("'", "")); matchedGame = MatchFun(game, name, resCopy); if (matchedGame > 0) { return(matchedGame); } // Try removing all ":" and "-" testName = Regex.Replace(name, @"\s*(:|-)\s*", " "); resCopy = results.GetClone(); foreach (var res in resCopy) { res.name = Regex.Replace(res.name, @"\s*(:|-)\s*", " "); res.alternative_names?.ForEach(a => a.name = Regex.Replace(a.name, @"\s*(:|-)\s*", " ")); } matchedGame = MatchFun(game, testName, resCopy); if (matchedGame > 0) { return(matchedGame); } // Try without subtitle var testResult = results.OrderBy(a => a.first_release_date).FirstOrDefault(a => { if (a.first_release_date == 0) { return(false); } if (!string.IsNullOrEmpty(a.name) && a.name.Contains(":")) { return(string.Equals(name, a.name.Split(':')[0], StringComparison.InvariantCultureIgnoreCase)); } return(false); }); if (testResult != null) { return(testResult.id); } return(0); }
private void GetIgdbMetadata() { if (IgdbData != null) { return; } if (gameId != 0) { IgdbData = plugin.Client.GetIGDBGameParsed(gameId); return; } if (!options.IsBackgroundDownload) { var item = plugin.PlayniteApi.Dialogs.ChooseItemWithSearch(null, (a) => { if (a.StartsWith("http", StringComparison.OrdinalIgnoreCase)) { try { var gameId = GetGameInfoFromUrl(a); var data = plugin.Client.GetIGDBGameParsed(ulong.Parse(gameId)); return(new List <GenericItemOption> { new SearchResult(gameId, data.name) }); } catch (Exception e) { logger.Error(e, $"Failed to get game data from {a}"); return(new List <GenericItemOption>()); } } else { var res = plugin.GetSearchResults(a); return(res.Select(b => b as GenericItemOption).ToList()); } }, options.GameData.Name); if (item != null) { var searchItem = item as SearchResult; IgdbData = plugin.Client.GetIGDBGameParsed(ulong.Parse(searchItem.Id)); } else { IgdbData = new IgdbServerModels.ExpandedGame() { id = 0 }; } } else { var game = options.GameData; if (BuiltinExtensions.GetExtensionFromId(game.PluginId) == BuiltinExtension.SteamLibrary) { var igdbId = plugin.Client.GetIGDBGameBySteamId(game.GameId); if (igdbId != 0) { IgdbData = plugin.Client.GetIGDBGameParsed(igdbId); return; } } if (game.Name.IsNullOrEmpty()) { IgdbData = new IgdbServerModels.ExpandedGame() { id = 0 }; return; } var copyGame = game.GetClone(); copyGame.Name = StringExtensions.NormalizeGameName(game.Name); var name = copyGame.Name .Replace(" RHCP", "", StringComparison.OrdinalIgnoreCase) .Replace(" RU", "", StringComparison.OrdinalIgnoreCase); var results = plugin.GetSearchResults(plugin.GetIgdbSearchString(name)).ToList(); results.ForEach(a => a.Name = StringExtensions.NormalizeGameName(a.Name)); string testName = string.Empty; // Direct comparison IgdbData = matchFun(game, name, results); if (IgdbData != null) { return; } // Try replacing roman numerals: 3 => III testName = Regex.Replace(name, @"\d+", ReplaceNumsForRomans); IgdbData = matchFun(game, testName, results); if (IgdbData != null) { return; } // Try adding The testName = "The " + name; IgdbData = matchFun(game, testName, results); if (IgdbData != null) { return; } // Try chaning & / and testName = Regex.Replace(name, @"\s+and\s+", " & ", RegexOptions.IgnoreCase); IgdbData = matchFun(game, testName, results); if (IgdbData != null) { return; } // Try removing apostrophes var resCopy = results.GetClone(); resCopy.ForEach(a => a.Name = a.Name.Replace("'", "")); IgdbData = matchFun(game, name, resCopy); if (IgdbData != null) { return; } // Try removing all ":" and "-" testName = Regex.Replace(name, @"\s*(:|-)\s*", " "); resCopy = results.GetClone(); resCopy.ForEach(a => a.Name = Regex.Replace(a.Name, @"\s*(:|-)\s*", " ")); IgdbData = matchFun(game, testName, resCopy); if (IgdbData != null) { return; } // Try without subtitle var testResult = results.OrderBy(a => a.ReleaseDate).FirstOrDefault(a => { if (a.ReleaseDate == null) { return(false); } if (!string.IsNullOrEmpty(a.Name) && a.Name.Contains(":")) { return(string.Equals(name, a.Name.Split(':')[0], StringComparison.InvariantCultureIgnoreCase)); } return(false); }); if (testResult != null) { IgdbData = plugin.Client.GetIGDBGameParsed(ulong.Parse(testResult.Id)); return; } // No match found IgdbData = new IgdbServerModels.ExpandedGame() { id = 0 }; } }
private async Task <ServicesResponse <T> > GetMetadata <T>(SdkModels.Game game, Func <ulong, Task <T> > expandFunc) where T : new() { var isKnownPlugin = game.PluginId != Guid.Empty; var isSteamPlugin = BuiltinExtensions.GetIdFromExtension(BuiltinExtension.SteamLibrary) == game.PluginId; ulong igdbId = 0; var matchId = $"{game.GameId}{game.PluginId}".MD5(); var searchId = $"{game.Name}{game.ReleaseDate?.Year}".MD5(); // Check if match was previously found if (isKnownPlugin) { if (isSteamPlugin) { igdbId = await igdbApi.GetSteamIgdbMatch(ulong.Parse(game.GameId)); } else { var match = Database.IGBDGameIdMatches.FindById(matchId); if (match != null) { igdbId = match.IgdbId; } } } if (igdbId == 0) { var match = Database.IGDBSearchIdMatches.FindById(searchId); if (match != null) { igdbId = match.IgdbId; } } var foundMetadata = new T(); if (igdbId != 0) { return(new ServicesResponse <T>(await expandFunc(igdbId))); } else { igdbId = await TryMatchGame(game, false); var useAlt = settings.Settings.IGDB.AlternativeSearch && !game.Name.ContainsAny(whereQueryBlacklist); if (useAlt && igdbId == 0) { igdbId = await TryMatchGame(game, true); } if (igdbId != 0) { foundMetadata = await expandFunc(igdbId); } } // Update match database if match was found if (igdbId != 0) { if (isKnownPlugin && !isSteamPlugin) { Database.IGBDGameIdMatches.Upsert(new GameIdMatch { GameId = game.GameId, Id = matchId, IgdbId = igdbId, Library = game.PluginId }); } Database.IGDBSearchIdMatches.Upsert(new SearchIdMatch { Term = game.Name, Id = searchId, IgdbId = igdbId }); } return(new ServicesResponse <T>(foundMetadata)); }
internal void GetGameData() { if (currentMetadata != null) { return; } try { var metadataProvider = new MetadataProvider(apiClient); if (BuiltinExtensions.GetExtensionFromId(options.GameData.PluginId) == BuiltinExtension.SteamLibrary) { var appId = uint.Parse(options.GameData.GameId); currentMetadata = metadataProvider.GetGameMetadata( appId, plugin.SettingsViewModel.Settings.BackgroundSource, plugin.SettingsViewModel.Settings.DownloadVerticalCovers); } else { if (options.IsBackgroundDownload) { var matchedId = GetMatchingGame(options.GameData); if (matchedId > 0) { currentMetadata = metadataProvider.GetGameMetadata( matchedId, plugin.SettingsViewModel.Settings.BackgroundSource, plugin.SettingsViewModel.Settings.DownloadVerticalCovers); } else { currentMetadata = new SteamGameMetadata(); } } else { var selectedGame = plugin.PlayniteApi.Dialogs.ChooseItemWithSearch(null, (a) => { if (uint.TryParse(a, out var appId)) { try { var store = WebApiClient.GetStoreAppDetail(appId); return(new List <GenericItemOption> { new StoreSearchResult { GameId = appId, Name = store.name } }); } catch (Exception e) { logger.Error(e, $"Failed to get Steam app info {appId}"); return(new List <GenericItemOption>()); } } else { try { var name = StringExtensions.NormalizeGameName(a); return(new List <GenericItemOption>(UniversalSteamMetadata.GetSearchResults(name))); } catch (Exception e) { logger.Error(e, $"Failed to get Steam search data for {a}"); return(new List <GenericItemOption>()); } } }, options.GameData.Name, string.Empty); if (selectedGame == null) { currentMetadata = new SteamGameMetadata(); } else { currentMetadata = metadataProvider.GetGameMetadata( ((StoreSearchResult)selectedGame).GameId, plugin.SettingsViewModel.Settings.BackgroundSource, plugin.SettingsViewModel.Settings.DownloadVerticalCovers); } } } } catch (Exception e) { logger.Error(e, $"Failed to get Steam metadata."); currentMetadata = new SteamGameMetadata(); } }
public void MainMethod(bool showDialogs) { string featureName = "NVIDIA GeForce NOW"; GameFeature feature = PlayniteApi.Database.Features.Add(featureName); string localAppData = Environment.GetEnvironmentVariable("LocalAppData"); string geforceNowWorkingPath = Path.Combine(localAppData, "NVIDIA Corporation", "GeForceNOW", "CEF"); string geforceNowExecutablePath = Path.Combine(geforceNowWorkingPath, "GeForceNOWStreamer.exe"); var supportedGames = DownloadGameList("https://static.nvidiagrid.net/supported-public-game-list/gfnpc.json", showDialogs); if (supportedGames.Count() == 0) { return; } var supportedSteamGames = supportedGames.Where(g => g.Store == "Steam"); var supportedEpicGames = supportedGames.Where(g => g.Store == "Epic"); var supportedOriginGames = supportedGames.Where(g => g.Store == "Origin"); var supportedUplayGames = supportedGames.Where(g => g.Store == "Ubisoft Connect"); var supportedGogGames = supportedGames.Where(g => g.Store == "GOG"); int enabledGamesCount = 0; int featureAddedCount = 0; int featureRemovedCount = 0; int playActionAddedCount = 0; int playActionRemovedCount = 0; int setAsInstalledCount = 0; int setAsUninstalledCount = 0; var progRes = PlayniteApi.Dialogs.ActivateGlobalProgress((a) => { var gameDatabase = GetGamesSupportedLibraries(); foreach (var game in gameDatabase) { var gameName = Regex.Replace(game.Name, @"[^\p{L}\p{Nd}]", "").ToLower(); GeforceGame supportedGame = null; switch (BuiltinExtensions.GetExtensionFromId(game.PluginId)) { case BuiltinExtension.SteamLibrary: var steamUrl = String.Format("https://store.steampowered.com/app/{0}", game.GameId); supportedGame = supportedSteamGames.Where(g => g.SteamUrl == steamUrl).FirstOrDefault(); break; case BuiltinExtension.EpicLibrary: supportedGame = supportedEpicGames.Where(g => g.Title == gameName).FirstOrDefault(); break; case BuiltinExtension.OriginLibrary: supportedGame = supportedOriginGames.Where(g => g.Title == gameName).FirstOrDefault(); break; case BuiltinExtension.UplayLibrary: supportedGame = supportedUplayGames.Where(g => g.Title == gameName).FirstOrDefault(); break; case BuiltinExtension.GogLibrary: supportedGame = supportedGogGames.Where(g => g.Title == gameName).FirstOrDefault(); break; default: break; } if (supportedGame == null) { bool featureRemoved = RemoveFeature(game, feature); if (featureRemoved == true) { featureRemovedCount++; logger.Info(String.Format("Feature removed from \"{0}\"", game.Name)); if (settings.SetEnabledGamesAsInstalled == true && game.IsInstalled == true) { game.IsInstalled = true; setAsUninstalledCount++; PlayniteApi.Database.Games.Update(game); logger.Info(String.Format("Set \"{0}\" as uninstalled", game.Name)); } } } else { enabledGamesCount++; bool featureAdded = AddFeature(game, feature); if (featureAdded == true) { featureAddedCount++; logger.Info(String.Format("Feature added to \"{0}\"", game.Name)); } if (settings.SetEnabledGamesAsInstalled == true && game.IsInstalled == false) { game.IsInstalled = true; setAsInstalledCount++; PlayniteApi.Database.Games.Update(game); logger.Info(String.Format("Set \"{0}\" as installed", game.Name)); } } if (settings.UpdatePlayActions == true) { string updatePlayAction = UpdateNvidiaAction(game, supportedGame, geforceNowWorkingPath, geforceNowExecutablePath); if (updatePlayAction == "playActionAdded") { playActionAddedCount++; logger.Info(String.Format("Play Action added to \"{0}\"", game.Name)); } else if (updatePlayAction == "playActionRemoved") { playActionRemovedCount++; logger.Info(String.Format("Play Action removed from \"{0}\"", game.Name)); } } } }, new GlobalProgressOptions("Updating NVIDIA GeForce NOW Enabled games")); if (showDialogs == true) { string results = String.Format("NVIDIA GeForce NOW enabled games in library: {0}\n\nAdded \"{1}\" feature to {2} games.\nRemoved \"{3}\" feature from {4} games.", enabledGamesCount, featureName, featureAddedCount, featureName, featureRemovedCount); if (settings.UpdatePlayActions == true) { results += String.Format("\n\nPlay Action added to {0} games.\nPlay Action removed from {1} games.", playActionAddedCount, playActionRemovedCount); } if (settings.SetEnabledGamesAsInstalled == true) { results += String.Format("\n\nSet {0} games as Installed.\nSet {1} games as uninstalled.", setAsInstalledCount, setAsUninstalledCount); } PlayniteApi.Dialogs.ShowMessage(results, "NVIDIA GeForce NOW Enabler"); } }
public override MetadataFile GetIcon() { if (options.IsBackgroundDownload) { var logger = LogManager.GetLogger(); logger.Info("SGDBMetadataProvider GetIcon options " + options.GameData.ToString()); string gameUrl; if (options.GameData.Source != null && options.GameData.PluginId == BuiltinExtensions.GetIdFromExtension(BuiltinExtension.SteamLibrary) && options.GameData.GameId != null) { if (iconAssetSelection == "logos") { gameUrl = services.getLogoImageUrl(options.GameData.Name, convertPlayniteGamePluginIdToSGDBPlatformEnum(options.GameData.PluginId), options.GameData.GameId); } else { gameUrl = services.getIconImageUrl(options.GameData.Name, convertPlayniteGamePluginIdToSGDBPlatformEnum(options.GameData.PluginId), options.GameData.GameId); } } else { if (iconAssetSelection == "logos") { gameUrl = services.getLogoImageUrl(options.GameData.Name); } else { gameUrl = services.getIconImageUrl(options.GameData.Name); } } if (gameUrl == "bad path") { return(base.GetIcon()); } else { return(new MetadataFile(gameUrl)); } } else { if (AvailableFields.Contains(MetadataField.Name)) { if (searchSelection != null) { List <MediaModel> icons; if (iconAssetSelection == "logos") { icons = services.getLogoImages(searchSelection.Name); } else { icons = services.getIconImages(searchSelection.Name); } dynamic selection = null; if (icons != null) { selection = GetIconManually(icons); } if (selection == null || selection.Path == "nopath") { return(base.GetIcon()); } else { return(new MetadataFile(selection.FullRes)); } } else { return(base.GetIcon()); } } else { return(base.GetIcon()); } } }