コード例 #1
0
        public GameMetadata UpdateGameWithMetadata(Game game)
        {
            var metadata = new GameMetadata();
            var program  = Twitch.GetUninstallRecord(game.GameId);

            if (program == null)
            {
                return(metadata);
            }

            if (!string.IsNullOrEmpty(program.DisplayIcon) && File.Exists(program.DisplayIcon))
            {
                var iconPath = program.DisplayIcon;
                var iconFile = Path.GetFileName(iconPath);
                if (iconPath.EndsWith("ico", StringComparison.OrdinalIgnoreCase))
                {
                    var data = File.ReadAllBytes(iconPath);
                    metadata.Icon = new MetadataFile(iconFile, data);
                }
                else
                {
                    var exeIcon = IconExtension.ExtractIconFromExe(iconPath, true);
                    if (exeIcon != null)
                    {
                        var iconName = Guid.NewGuid() + ".png";
                        metadata.Icon = new MetadataFile(iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png));
                    }
                }
            }

            game.Name = StringExtensions.NormalizeGameName(program.DisplayName);
            return(metadata);
        }
コード例 #2
0
        public OriginGameMetadata UpdateGameWithMetadata(Game game)
        {
            var metadata = DownloadGameMetadata(game.ProviderId);

            game.Name  = StringExtensions.NormalizeGameName(metadata.StoreDetails.i18n.displayName);
            game.Links = new ObservableCollection <Link>()
            {
                new Link("Store", @"https://www.origin.com/store" + metadata.StoreDetails.offerPath),
                new Link("Wiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name)
            };

            if (!string.IsNullOrEmpty(metadata.StoreDetails.i18n.gameForumURL))
            {
                game.Links.Add(new Link("Forum", metadata.StoreDetails.i18n.gameForumURL));
            }

            game.Description = metadata.StoreDetails.i18n.longDescription;
            game.Developers  = new ComparableList <string>()
            {
                metadata.StoreDetails.developerFacetKey
            };
            game.Publishers = new ComparableList <string>()
            {
                metadata.StoreDetails.publisherFacetKey
            };
            game.Genres      = new ComparableList <string>(metadata.StoreDetails.genreFacetKey?.Split(','));
            game.ReleaseDate = metadata.StoreDetails.platforms.First(a => a.platform == "PCWIN").releaseDate;

            if (!string.IsNullOrEmpty(metadata.StoreDetails.i18n.gameManualURL))
            {
                game.OtherTasks = new ObservableCollection <GameTask>()
                {
                    new GameTask()
                    {
                        IsBuiltIn = true,
                        Type      = GameTaskType.URL,
                        Path      = metadata.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 exeIcon = IconExtension.ExtractIconFromExe(game.PlayTask.Path, true);
                if (exeIcon != null)
                {
                    var iconName = Guid.NewGuid() + ".png";

                    metadata.Icon = new FileDefinition(
                        string.Format("images/origin/{0}/{1}", game.ProviderId.Replace(":", ""), iconName),
                        iconName,
                        exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png)
                        );
                }
            }

            return(metadata);
        }
コード例 #3
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 = 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
                    {
                        var exeIcon = IconExtension.ExtractIconFromExe(iconPath, true);
                        if (exeIcon != null)
                        {
                            var iconName = Guid.NewGuid() + ".png";
                            metadata.Icon = new MetadataFile(iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png));
                        }
                    }
                }
            }

            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);
        }
コード例 #4
0
        private static string AddNewFile(string path, Guid libraryId, GameDatabase database)
        {
            var          fileName = Guid.NewGuid().ToString() + Path.GetExtension(path);
            var          fileId   = $"{libraryId.ToString()}/{fileName}";
            MetadataFile metaFile = null;

            try
            {
                if (path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                {
                    metaFile = new MetadataFile(fileId, fileName, HttpDownloader.DownloadData(path));
                }
                else
                {
                    if (File.Exists(path))
                    {
                        if (path.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
                        {
                            var icon = IconExtension.ExtractIconFromExe(path, true);
                            if (icon == null)
                            {
                                return(null);
                            }

                            fileName = Path.ChangeExtension(fileName, ".png");
                            fileId   = Path.ChangeExtension(fileId, ".png");
                            metaFile = new MetadataFile(fileId, fileName, icon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png));
                        }
                        else
                        {
                            metaFile = new MetadataFile(fileId, fileName, File.ReadAllBytes(path));
                        }
                    }
                    else
                    {
                        logger.Error($"Can't add game file during game import, file doesn't exists: {path}");
                    }
                }
            }
            catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(e, $"Failed to import game file during game import from {path}");
            }

            if (metaFile != null)
            {
                if (metaFile.FileName.EndsWith(".tga", StringComparison.OrdinalIgnoreCase))
                {
                    metaFile.FileName = Path.ChangeExtension(metaFile.FileName, ".png");
                    metaFile.FileId   = Path.ChangeExtension(metaFile.FileId, ".png");
                    metaFile.Content  = BitmapExtensions.TgaToBitmap(metaFile.Content).ToPngArray();
                }

                database.AddFile(metaFile);
                return(metaFile.FileId);
            }

            return(null);
        }
コード例 #5
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 = 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
                    {
                        var exeIcon = IconExtension.ExtractIconFromExe(iconPath, true);
                        if (exeIcon != null)
                        {
                            var iconName = Guid.NewGuid() + ".png";
                            metadata.Icon = new MetadataFile(iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png));
                        }
                    }
                }
            }

            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);
                    }

                    if (entitlement.product.productDetail?.details?.backgroundUrl2 != null)
                    {
                        metadata.BackgroundImage = new MetadataFile(entitlement.product.productDetail.details.backgroundUrl2);
                    }
                }
            }

            return(metadata);
        }
コード例 #6
0
        private string SaveFileIconToTemp(string exePath)
        {
            var ico = IconExtension.ExtractIconFromExe(exePath, true);

            if (ico == null)
            {
                return(string.Empty);
            }

            var tempPath = Path.Combine(Paths.TempPath, "tempico.png");

            if (ico != null)
            {
                if (File.Exists(tempPath))
                {
                    File.Delete(tempPath);
                }

                ico.ToBitmap().Save(tempPath, System.Drawing.Imaging.ImageFormat.Png);
            }

            return(tempPath);
        }
コード例 #7
0
        public override GameMetadata GetMetadata(Game game)
        {
            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("Store", @"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("Forum", 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 = api.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);
                }

                var exeIcon = IconExtension.ExtractIconFromExe(executable, true);
                if (exeIcon != null)
                {
                    var iconName = Guid.NewGuid() + ".png";
                    metadata.Icon = new MetadataFile(iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png));
                }
            }

            return(metadata);
        }
コード例 #8
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 product = client.GetProductInfo(catalogs[0].productSlug).GetAwaiter().GetResult();
                    if (product.pages.HasItems())
                    {
                        var page = product.pages[0];
                        gameInfo.Description = page.data.about.description;
                        gameInfo.Developers  = new List <string>()
                        {
                            page.data.about.developerAttribution
                        };
                        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/" + catalogs[0].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 (!gameInfo.Description.IsNullOrEmpty())
                        {
                            gameInfo.Description = gameInfo.Description.Replace("\n", "\n<br>");
                        }
                    }
                }
            }

            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 playAction = api.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);
                }

                var exeIcon = IconExtension.ExtractIconFromExe(executable, true);
                if (exeIcon != null)
                {
                    var iconName = Guid.NewGuid() + ".png";
                    metadata.Icon = new MetadataFile(iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png));
                }
            }

            return(metadata);
        }