示例#1
0
        public SteamGameMetadata UpdateGameWithMetadata(IGame game)
        {
            var metadata = DownloadGameMetadata(int.Parse(game.ProviderId));

            game.Name  = metadata.ProductDetails["common"]["name"].Value;
            game.Links = new ObservableCollection <Link>()
            {
                new Link("Forum", @"https://steamcommunity.com/app/" + game.ProviderId),
                new Link("Store", @"http://store.steampowered.com/app/" + game.ProviderId),
                new Link("Wiki", @"http://pcgamingwiki.com/api/appid.php?appid=" + game.ProviderId)
            };

            if (metadata.StoreDetails?.categories?.FirstOrDefault(a => a.id == 30) != null)
            {
                game.Links.Add(new Link("Workshop", GetGameWorkshopUrl(int.Parse(game.ProviderId))));
            }

            if (metadata.StoreDetails != null)
            {
                game.Description = metadata.StoreDetails.detailed_description;
                game.Genres      = new ComparableList <string>(metadata.StoreDetails.genres?.Select(a => a.description));
                game.Developers  = new ComparableList <string>(metadata.StoreDetails.developers);
                game.Publishers  = new ComparableList <string>(metadata.StoreDetails.publishers);
                game.ReleaseDate = metadata.StoreDetails.release_date.date;
            }

            var tasks      = new ObservableCollection <GameTask>();
            var launchList = metadata.ProductDetails["config"]["launch"].Children;

            foreach (var task in launchList.Skip(1))
            {
                var properties = task["config"];
                if (properties.Name != null)
                {
                    if (properties["oslist"].Name != null)
                    {
                        if (properties["oslist"].Value != "windows")
                        {
                            continue;
                        }
                    }
                }

                // Ignore action without name  - shoudn't be visible to end user
                if (task["description"].Name != null)
                {
                    var newTask = new GameTask()
                    {
                        Name       = task["description"].Value,
                        Arguments  = task["arguments"].Value ?? string.Empty,
                        Path       = task["executable"].Value,
                        IsBuiltIn  = true,
                        WorkingDir = game.InstallDirectory
                    };

                    tasks.Add(newTask);
                }
            }

            var manual = metadata.ProductDetails["extended"]["gamemanualurl"];

            if (manual.Name != null)
            {
                tasks.Add((new GameTask()
                {
                    Name = "Manual",
                    Type = GameTaskType.URL,
                    Path = manual.Value,
                    IsBuiltIn = true
                }));
            }

            game.OtherTasks = tasks;

            if (metadata.Image != null)
            {
                using (var imageStream = new MemoryStream())
                {
                    using (var tempStream = new MemoryStream(metadata.Image.Data))
                    {
                        using (var backStream = Application.GetResourceStream(new Uri("pack://application:,,,/Playnite;component/Resources/Images/steam_cover_background.png")).Stream)
                        {
                            CoverCreator.CreateCover(backStream, tempStream, imageStream);
                            imageStream.Seek(0, SeekOrigin.Begin);
                            metadata.Image.Data = imageStream.ToArray();
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(metadata.BackgroundImage))
            {
                game.BackgroundImage = metadata.BackgroundImage;
            }

            game.IsProviderDataUpdated = true;
            return(metadata);
        }
示例#2
0
        public GogGameMetadata UpdateGameWithMetadata(IGame game)
        {
            var currentUrl = string.Empty;

            if (game.Links != null)
            {
                currentUrl = game.Links.Any(a => a.Name == "Store") ? game.Links.First(a => a.Name == "Store").Url : string.Empty;
            }

            var metadata = DownloadGameMetadata(game.ProviderId, currentUrl);

            game.Name        = metadata.GameDetails.title;
            game.Description = metadata.GameDetails.description.full;
            game.Links       = new ObservableCollection <Link>()
            {
                new Link("Wiki", @"http://pcgamingwiki.com/w/index.php?search=" + metadata.GameDetails.title)
            };

            if (!string.IsNullOrEmpty(metadata.GameDetails.links.forum))
            {
                game.Links.Add(new Link("Forum", metadata.GameDetails.links.forum));
            }
            ;

            if (string.IsNullOrEmpty(currentUrl) && !string.IsNullOrEmpty(metadata.GameDetails.links.product_card))
            {
                game.Links.Add(new Link("Store", metadata.GameDetails.links.product_card));
            }
            ;

            if (metadata.StoreDetails != null)
            {
                game.Genres     = new ComparableList <string>(metadata.StoreDetails.genres.Select(a => a.name));
                game.Developers = new ComparableList <string>()
                {
                    metadata.StoreDetails.developer.name
                };
                game.Publishers = new ComparableList <string>()
                {
                    metadata.StoreDetails.publisher.name
                };

                if (game.ReleaseDate == null && metadata.StoreDetails.releaseDate != null)
                {
                    game.ReleaseDate = DateTimeOffset.FromUnixTimeSeconds(metadata.StoreDetails.releaseDate.Value).DateTime;
                }
            }

            using (var imageStream = new MemoryStream())
            {
                using (var tempStream = new MemoryStream(metadata.Image.Data))
                {
                    using (var backStream = Application.GetResourceStream(new Uri("pack://application:,,,/Playnite;component/Resources/Images/gog_cover_background.png")).Stream)
                    {
                        CoverCreator.CreateCover(backStream, tempStream, imageStream);
                        imageStream.Seek(0, SeekOrigin.Begin);
                        metadata.Image.Data = imageStream.ToArray();
                    }
                }
            }

            if (!string.IsNullOrEmpty(metadata.BackgroundImage))
            {
                game.BackgroundImage = metadata.BackgroundImage;
            }

            game.IsProviderDataUpdated = true;
            return(metadata);
        }