Ejemplo n.º 1
0
        public async void StartInstallWatcher()
        {
            watcherToken = new CancellationTokenSource();

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

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

                await Task.Delay(2000);
            }
        }
Ejemplo n.º 2
0
        public override void Uninstall()
        {
            var uninstallInfo = AmazonGames.GetUninstallRecord(Game.GameId);

            if (uninstallInfo != null)
            {
                var uninstallString = uninstallInfo.UninstallString.Replace(@"\\", @"\");
                var removerFileName = "Amazon Game Remover.exe";
                var split           = uninstallString.Split(new string[] { removerFileName }, StringSplitOptions.RemoveEmptyEntries);
                var path            = (split[0] + removerFileName).Trim('"');
                var args            = split[1].Trim('"');
                ProcessStarter.StartProcess(path, args);
                StartUninstallWatcher();
            }
        }
Ejemplo n.º 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 = 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.º 4
0
        public async void StartUninstallWatcher()
        {
            watcherToken = new CancellationTokenSource();

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

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

                await Task.Delay(2000);
            }
        }
Ejemplo n.º 5
0
        public override void Play()
        {
            OnStarting(this, new GameControllerEventArgs(this, 0));
            var startViaLauncher         = true;
            GameConfiguration gameConfig = null;

            if (library.LibrarySettings.StartGamesWithoutLauncher)
            {
                try
                {
                    gameConfig = AmazonGames.GetGameConfiguration(Game.InstallDirectory);
                    if (AmazonGames.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($"amazon-games://play/{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));
            }
        }
Ejemplo n.º 6
0
 public override void Install()
 {
     AmazonGames.StartClient();
     StartInstallWatcher();
 }