Ejemplo n.º 1
0
        public override GameMetadata GetMetadata(Game game)
        {
            var gameInfo = new GameInfo
            {
                Links = new List <Link>()
            };

            var metadata = new GameMetadata()
            {
                GameInfo = gameInfo
            };

            gameInfo.Links.Add(new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name));

            var program = AmazonGames.GetUninstallRecord(game.GameId);

            if (program != null)
            {
                gameInfo.Name = StringExtensions.NormalizeGameName(program.DisplayName);
                if (!string.IsNullOrEmpty(program.DisplayIcon) && File.Exists(program.DisplayIcon))
                {
                    var iconPath = program.DisplayIcon;
                    if (iconPath.EndsWith("ico", StringComparison.OrdinalIgnoreCase))
                    {
                        metadata.Icon = new MetadataFile(program.DisplayIcon);
                    }
                    else
                    {
                        using (var ms = new MemoryStream())
                        {
                            if (IconExtractor.ExtractMainIconFromFile(iconPath, ms))
                            {
                                var iconName = Guid.NewGuid() + ".ico";
                                metadata.Icon = new MetadataFile(iconName, ms.ToArray());
                            }
                        }
                    }
                }
            }

            return(metadata);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts file to an image file.
        /// </summary>
        /// <param name="imagePath"></param>
        /// <param name="outFileRoot">Resulting file name without extension.</param>
        /// <returns>File path to converted image if conversion was successful or original path if file is alreadny an image.</returns>
        public static string ConvertToCompatibleFormat(string imagePath, string outFileRoot)
        {
            if (imagePath.IsNullOrEmpty() || !File.Exists(imagePath))
            {
                return(null);
            }

            FileSystem.CreateDirectory(Path.GetDirectoryName(outFileRoot));
            if (imagePath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
            {
                var icoPath = outFileRoot + ".ico";
                if (IconExtractor.ExtractMainIconFromFile(imagePath, icoPath))
                {
                    return(icoPath);
                }
                else
                {
                    return(null);
                }
            }
            else if (imagePath.EndsWith(".tga", StringComparison.OrdinalIgnoreCase))
            {
                var pngPath = outFileRoot + ".png";
                try
                {
                    File.WriteAllBytes(pngPath, BitmapExtensions.TgaToBitmap(imagePath).ToPngArray());
                }
                catch (Exception e)
                {
                    logger.Error(e, $"Failed to covert {imagePath} to png.");
                    return(null);
                }
            }

            return(imagePath);
        }
Ejemplo n.º 3
0
        public override GameMetadata GetMetadata(Game game)
        {
            var gameInfo = new GameInfo()
            {
                Links = new List <Link>()
            };
            var metadata = new GameMetadata()
            {
                GameInfo = gameInfo
            };

            using (var client = new WebStoreClient())
            {
                var catalogs = client.QuerySearch(game.Name).GetAwaiter().GetResult();
                if (catalogs.HasItems())
                {
                    var catalog = catalogs.FirstOrDefault(a => a.title.Equals(game.Name, StringComparison.InvariantCultureIgnoreCase));
                    if (catalog == null)
                    {
                        catalog = catalogs[0];
                    }

                    var product = client.GetProductInfo(catalog.productSlug).GetAwaiter().GetResult();
                    if (product.pages.HasItems())
                    {
                        var page = product.pages.FirstOrDefault(a => a.type is string type && type == "productHome");
                        if (page == null)
                        {
                            page = product.pages[0];
                        }

                        gameInfo.Developers = page.data.about.developerAttribution?.
                                              Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).
                                              Select(a => a.Trim()).ToList();
                        gameInfo.Publishers = page.data.about.publisherAttribution?.
                                              Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).
                                              Select(a => a.Trim()).ToList();
                        metadata.BackgroundImage = new MetadataFile(page.data.hero.backgroundImageUrl);
                        gameInfo.Links.Add(new Link(
                                               library.PlayniteApi.Resources.GetString("LOCCommonLinksStorePage"),
                                               "https://www.epicgames.com/store/en-US/product/" + catalog.productSlug));

                        if (page.data.socialLinks.HasItems())
                        {
                            var links = page.data.socialLinks.
                                        Where(a => a.Key.StartsWith("link") && !a.Value.IsNullOrEmpty()).
                                        Select(a => new Link(a.Key.Replace("link", ""), a.Value)).ToList();
                            if (links.HasItems())
                            {
                                gameInfo.Links.AddRange(links);
                            }
                        }

                        if (!page.data.about.description.IsNullOrEmpty())
                        {
                            gameInfo.Description = Markup.MarkdownToHtml(page.data.about.description);
                        }
                    }
                }
            }

            gameInfo.Links.Add(new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name));

            // There's not icon available on Epic servers so we will load one from EXE
            if (game.IsInstalled && string.IsNullOrEmpty(game.Icon))
            {
                var manifest = EpicLauncher.GetInstalledManifests().FirstOrDefault(a => a.AppName == game.GameId);
                if (manifest != null)
                {
                    var exePath = Path.Combine(manifest.InstallLocation, manifest.LaunchExecutable);
                    if (File.Exists(exePath))
                    {
                        using (var ms = new MemoryStream())
                        {
                            if (IconExtractor.ExtractMainIconFromFile(exePath, ms))
                            {
                                var iconName = Guid.NewGuid() + ".ico";
                                metadata.Icon = new MetadataFile(iconName, ms.ToArray());
                            }
                        }
                    }
                }
            }

            return(metadata);
        }
Ejemplo n.º 4
0
        public override GameMetadata GetMetadata(Game game)
        {
            var resources     = library.PlayniteApi.Resources;
            var storeMetadata = DownloadGameMetadata(game.GameId);
            var gameInfo      = new GameInfo
            {
                Name        = StringExtensions.NormalizeGameName(storeMetadata.StoreDetails.i18n.displayName),
                Description = storeMetadata.StoreDetails.i18n.longDescription,
                ReleaseDate = storeMetadata.StoreDetails.platforms.First(a => a.platform == "PCWIN").releaseDate,
                Links       = new List <Link>()
                {
                    new Link(resources.GetString("LOCCommonLinksStorePage"), @"https://www.origin.com/store" + storeMetadata.StoreDetails.offerPath),
                    new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name)
                }
            };

            if (!storeMetadata.StoreDetails.publisherFacetKey.IsNullOrEmpty())
            {
                gameInfo.Publishers = new List <string>()
                {
                    storeMetadata.StoreDetails.publisherFacetKey
                };
            }

            if (!storeMetadata.StoreDetails.developerFacetKey.IsNullOrEmpty())
            {
                gameInfo.Developers = new List <string>()
                {
                    storeMetadata.StoreDetails.developerFacetKey
                };
            }

            if (!storeMetadata.StoreDetails.genreFacetKey.IsNullOrEmpty())
            {
                gameInfo.Genres = new List <string>(storeMetadata.StoreDetails.genreFacetKey?.Split(','));
            }

            var metadata = new GameMetadata()
            {
                GameInfo        = gameInfo,
                Icon            = storeMetadata.Icon,
                CoverImage      = storeMetadata.CoverImage,
                BackgroundImage = storeMetadata.BackgroundImage
            };

            if (!string.IsNullOrEmpty(storeMetadata.StoreDetails.i18n.gameForumURL))
            {
                gameInfo.Links.Add(new Link(resources.GetString("LOCCommonLinksForum"), storeMetadata.StoreDetails.i18n.gameForumURL));
            }

            if (!string.IsNullOrEmpty(storeMetadata.StoreDetails.i18n.gameManualURL))
            {
                game.OtherActions = new ObservableCollection <GameAction>()
                {
                    new GameAction()
                    {
                        IsHandledByPlugin = false,
                        Type = GameActionType.URL,
                        Path = storeMetadata.StoreDetails.i18n.gameManualURL,
                        Name = "Manual"
                    }
                };
            }

            // There's not icon available on Origin servers so we will load one from EXE
            if (game.IsInstalled && string.IsNullOrEmpty(game.Icon))
            {
                var playAction = library.PlayniteApi.ExpandGameVariables(game, game.PlayAction);
                var executable = string.Empty;
                if (File.Exists(playAction.Path))
                {
                    executable = playAction.Path;
                }
                else if (!string.IsNullOrEmpty(playAction.WorkingDir))
                {
                    executable = Path.Combine(playAction.WorkingDir, playAction.Path);
                }

                if (string.IsNullOrEmpty(executable))
                {
                    return(storeMetadata);
                }

                using (var ms = new MemoryStream())
                {
                    if (IconExtractor.ExtractMainIconFromFile(executable, ms))
                    {
                        var iconName = Guid.NewGuid() + ".ico";
                        metadata.Icon = new MetadataFile(iconName, ms.ToArray());
                    }
                }
            }

            return(metadata);
        }
Ejemplo n.º 5
0
        public override GameMetadata GetMetadata(Game game)
        {
            if (entitlements == null)
            {
                var token = library.GetAuthToken();
                if (!token.IsNullOrEmpty())
                {
                    try
                    {
                        entitlements = AmazonEntitlementClient.GetAccountEntitlements(token);
                    }
                    catch (Exception e)
                    {
                        entitlements = new List <Entitlement>();
                        logger.Error(e, "Failed to get entitlements for Twitch metadata.");
                    }
                }
            }

            var gameInfo = new GameInfo
            {
                Links = new List <Link>()
            };

            var metadata = new GameMetadata()
            {
                GameInfo = gameInfo
            };

            gameInfo.Links.Add(new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name));

            var program = Twitch.GetUninstallRecord(game.GameId);

            if (program != null)
            {
                gameInfo.Name = StringExtensions.NormalizeGameName(program.DisplayName);
                if (!string.IsNullOrEmpty(program.DisplayIcon) && File.Exists(program.DisplayIcon))
                {
                    var iconPath = program.DisplayIcon;
                    if (iconPath.EndsWith("ico", StringComparison.OrdinalIgnoreCase))
                    {
                        metadata.Icon = new MetadataFile(program.DisplayIcon);
                    }
                    else
                    {
                        using (var ms = new MemoryStream())
                        {
                            if (IconExtractor.ExtractMainIconFromFile(iconPath, ms))
                            {
                                var iconName = Guid.NewGuid() + ".ico";
                                metadata.Icon = new MetadataFile(iconName, ms.ToArray());
                            }
                        }
                    }
                }
            }

            if (entitlements?.Any() == true)
            {
                var entitlement = entitlements.FirstOrDefault(a => a.product.id == game.GameId);
                if (entitlement != null)
                {
                    if (entitlement.product.productDetail?.iconUrl != null)
                    {
                        metadata.CoverImage = new MetadataFile(entitlement.product.productDetail.iconUrl);
                    }

                    // Ignore Getting Over It background, which is set if the publisher didn't assigned any
                    // https://github.com/JosefNemec/Playnite/issues/1376
                    var backgroundUrl = entitlement.product.productDetail?.details?.backgroundUrl2;
                    if (!backgroundUrl.IsNullOrEmpty() && backgroundUrl != "https://images-na.ssl-images-amazon.com/images/I/A1VAra5JJvL.jpg")
                    {
                        metadata.BackgroundImage = new MetadataFile(entitlement.product.productDetail.details.backgroundUrl2);
                    }
                }
            }

            return(metadata);
        }