Пример #1
0
 private void Initialize(IPlayniteAPI api)
 {
     LibrarySettings = new SteamLibrarySettings(this, PlayniteApi)
     {
         SteamUsers = GetSteamUsers()
     };
 }
Пример #2
0
 private void Initialize(IPlayniteAPI api)
 {
     playniteApi     = api;
     LibraryIcon     = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Resources\steamicon.png");
     LibrarySettings = new SteamLibrarySettings(this, playniteApi)
     {
         SteamUsers = GetSteamUsers()
     };
 }
Пример #3
0
        internal List <GameInfo> GetLibraryGames(SteamLibrarySettings settings)
        {
            if (settings.UserId.IsNullOrEmpty())
            {
                throw new Exception(PlayniteApi.Resources.GetString("LOCNotLoggedInError"));
            }

            if (settings.IsPrivateAccount)
            {
                return(GetLibraryGames(ulong.Parse(settings.UserId), settings.ApiKey));
            }
            else
            {
                return(GetLibraryGames(ulong.Parse(settings.UserId)));
            }
        }
Пример #4
0
        internal List <GameInfo> GetLibraryGames(SteamLibrarySettings settings)
        {
            if (settings.UserId.IsNullOrEmpty())
            {
                throw new Exception(PlayniteApi.Resources.GetString("LOCNotLoggedInError"));
            }

            var userId = ulong.Parse(settings.UserId);

            if (settings.IsPrivateAccount)
            {
                return(GetLibraryGames(userId, GetPrivateOwnedGames(userId, LibrarySettings.ApiKey, LibrarySettings.IncludeFreeSubGames)?.response?.games));
            }
            else
            {
                return(GetLibraryGames(userId, ServicesClient.GetSteamLibrary(userId, LibrarySettings.IncludeFreeSubGames)));
            }
        }
Пример #5
0
        internal List <GameInfo> GetLibraryGames(SteamLibrarySettings settings)
        {
            var userName = string.Empty;

            if (settings.IdSource == SteamIdSource.Name)
            {
                userName = settings.AccountName;
            }
            else
            {
                userName = settings.AccountId.ToString();
            }

            if (settings.IsPrivateAccount)
            {
                return(GetLibraryGames(userName, settings.ApiKey));
            }
            else
            {
                return(GetLibraryGames(userName));
            }
        }
Пример #6
0
        internal SteamGameMetadata DownloadGameMetadata(uint appId, SteamLibrarySettings settings)
        {
            var metadata    = new SteamGameMetadata();
            var productInfo = GetAppInfo(appId);

            metadata.ProductDetails = productInfo;

            try
            {
                metadata.StoreDetails = GetStoreData(appId);
            }
            catch (Exception e)
            {
                logger.Error(e, $"Failed to download Steam store metadata {appId}");
            }

            // Icon
            if (productInfo != null)
            {
                var iconRoot = @"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/{0}/{1}.ico";
                var icon     = productInfo["common"]["clienticon"];
                var iconUrl  = string.Empty;
                if (!string.IsNullOrEmpty(icon.Value))
                {
                    iconUrl = string.Format(iconRoot, appId, icon.Value);
                }
                else
                {
                    var newIcon = productInfo["common"]["icon"];
                    if (!string.IsNullOrEmpty(newIcon.Value))
                    {
                        iconRoot = @"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/{0}/{1}.jpg";
                        iconUrl  = string.Format(iconRoot, appId, newIcon.Value);
                    }
                }

                // There might be no icon assigned to game
                if (!string.IsNullOrEmpty(iconUrl))
                {
                    metadata.Icon = new MetadataFile(iconUrl);
                }
            }

            // Image
            var useBanner = false;

            if (settings.DownloadVerticalCovers)
            {
                var imageRoot = @"https://steamcdn-a.akamaihd.net/steam/apps/{0}/library_600x900_2x.jpg";
                var imageUrl  = string.Format(imageRoot, appId);
                if (HttpDownloader.GetResponseCode(imageUrl) == HttpStatusCode.OK)
                {
                    metadata.CoverImage = new MetadataFile(imageUrl);
                }
                else
                {
                    useBanner = true;
                }
            }

            if (useBanner || !settings.DownloadVerticalCovers)
            {
                var imageRoot = @"https://steamcdn-a.akamaihd.net/steam/apps/{0}/header.jpg";
                var imageUrl  = string.Format(imageRoot, appId);
                if (HttpDownloader.GetResponseCode(imageUrl) == HttpStatusCode.OK)
                {
                    metadata.CoverImage = new MetadataFile(imageUrl);
                }
            }

            if (metadata.CoverImage == null)
            {
                if (productInfo != null)
                {
                    var imageRoot = @"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/{0}/{1}.jpg";
                    var image     = productInfo["common"]["logo"];
                    if (!string.IsNullOrEmpty(image.Value))
                    {
                        var imageUrl = string.Format(imageRoot, appId, image.Value);
                        metadata.CoverImage = new MetadataFile(imageUrl);
                    }
                }
            }

            // Background Image
            var bannerBk = string.Format(@"https://steamcdn-a.akamaihd.net/steam/apps/{0}/library_hero.jpg", appId);
            var storeBk  = string.Format(@"https://steamcdn-a.akamaihd.net/steam/apps/{0}/page_bg_generated_v6b.jpg", appId);

            switch (settings.BackgroundSource)
            {
            case BackgroundSource.Image:
                var bk = GetGameBackground(appId);
                if (string.IsNullOrEmpty(bk))
                {
                    if (HttpDownloader.GetResponseCode(bannerBk) == HttpStatusCode.OK)
                    {
                        metadata.BackgroundImage = new MetadataFile(bannerBk);
                    }
                }
                else
                {
                    metadata.BackgroundImage = new MetadataFile(bk);
                }
                break;

            case BackgroundSource.StoreScreenshot:
                if (metadata.StoreDetails != null)
                {
                    metadata.BackgroundImage = new MetadataFile(Regex.Replace(metadata.StoreDetails.screenshots.First().path_full, "\\?.*$", ""));
                }
                break;

            case BackgroundSource.StoreBackground:
                if (HttpDownloader.GetResponseCode(storeBk) == HttpStatusCode.OK)
                {
                    metadata.BackgroundImage = new MetadataFile(storeBk);
                }
                break;

            case BackgroundSource.Banner:
                if (HttpDownloader.GetResponseCode(bannerBk) == HttpStatusCode.OK)
                {
                    metadata.BackgroundImage = new MetadataFile(bannerBk);
                }
                break;

            default:
                break;
            }

            return(metadata);
        }