Пример #1
0
        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());
         }
     }
 }
Пример #3
0
        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);
        }
Пример #4
0
        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 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();
            }
        }
Пример #6
0
        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 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");
        }
Пример #8
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));
        }
 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());
         }
     }
 }