示例#1
0
        public async void StartInstallWatcher()
        {
            watcherToken = new CancellationTokenSource();

            while (true)
            {
                if (watcherToken.IsCancellationRequested)
                {
                    return;
                }
                var program = Twitch.GetUninstallRecord(Game.GameId);
                if (program != null)
                {
                    var installInfo = new GameInfo()
                    {
                        PlayAction       = TwitchLibrary.GetPlayAction(Game.GameId),
                        InstallDirectory = Paths.FixSeparators(program.InstallLocation)
                    };

                    OnInstalled(this, new GameInstalledEventArgs(installInfo, this, 0));
                    return;
                }

                await Task.Delay(2000);
            }
        }
        public async void StartInstallWatcher()
        {
            watcherToken = new CancellationTokenSource();
            await Task.Run(async() =>
            {
                while (true)
                {
                    if (watcherToken.IsCancellationRequested)
                    {
                        return;
                    }
                    var program = Twitch.GetUninstallRecord(Game.GameId);
                    if (program != null)
                    {
                        if (Game.PlayAction == null)
                        {
                            Game.PlayAction = TwitchLibrary.GetPlayAction(Game.GameId);
                        }

                        Game.InstallDirectory = Paths.FixSeparators(program.InstallLocation);
                        OnInstalled(this, new GameControllerEventArgs(this, 0));
                        return;
                    }


                    await Task.Delay(2000);
                }
            });
        }
        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);
        }
示例#4
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);
        }
示例#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
        public async void StartUninstallWatcher()
        {
            watcherToken = new CancellationTokenSource();

            while (true)
            {
                if (watcherToken.IsCancellationRequested)
                {
                    return;
                }

                var program = Twitch.GetUninstallRecord(Game.GameId);
                if (program == null)
                {
                    OnUninstalled(this, new GameControllerEventArgs(this, 0));
                    return;
                }

                await Task.Delay(2000);
            }
        }
示例#7
0
        public override void Play()
        {
            OnStarting(this, new GameControllerEventArgs(this, 0));
            var startViaLauncher         = true;
            GameConfiguration gameConfig = null;

            if (library.SettingsViewModel.Settings.StartGamesWithoutLauncher)
            {
                try
                {
                    gameConfig = Twitch.GetGameConfiguration(Game.InstallDirectory);
                    if (Twitch.GetGameRequiresClient(gameConfig))
                    {
                        startViaLauncher = true;
                    }
                    else
                    {
                        startViaLauncher = false;
                    }
                }
                catch (Exception e) when(!Debugger.IsAttached)
                {
                    logger.Error(e, "Failed to get local game configuration.");
                }
            }

            if (startViaLauncher)
            {
                ProcessStarter.StartUrl($"twitch://fuel-launch/{Game.GameId}");
            }
            else
            {
                var exePath = Path.Combine(Game.InstallDirectory, gameConfig.Main.Command);
                var workDir = Game.InstallDirectory;
                if (!gameConfig.Main.WorkingSubdirOverride.IsNullOrEmpty())
                {
                    workDir = Path.Combine(Game.InstallDirectory, gameConfig.Main.WorkingSubdirOverride);
                }

                string args = null;
                if (gameConfig.Main.Args.HasNonEmptyItems())
                {
                    args = string.Join(" ", gameConfig.Main.Args);
                }

                ProcessStarter.StartProcess(exePath, args, workDir);
            }

            if (Directory.Exists(Game.InstallDirectory))
            {
                stopWatch              = Stopwatch.StartNew();
                procMon                = new ProcessMonitor();
                procMon.TreeStarted   += ProcMon_TreeStarted;
                procMon.TreeDestroyed += Monitor_TreeDestroyed;
                procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
            }
            else
            {
                OnStopped(this, new GameControllerEventArgs(this, 0));
            }
        }
示例#8
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);
        }