コード例 #1
0
 public override void Play()
 {
     ReleaseResources();
     if (Game.PlayAction.Type == GameActionType.URL && Game.PlayAction.Path.StartsWith("bethesda", StringComparison.OrdinalIgnoreCase))
     {
         OnStarting(this, new GameControllerEventArgs(this, 0));
         GameActionActivator.ActivateAction(Game.PlayAction);
         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));
         }
     }
     else
     {
         throw new Exception("Unknown Play action configuration.");
     }
 }
コード例 #2
0
        public override void Play()
        {
            ReleaseResources();
            if (Game.PlayAction.Type == GameActionType.Emulator)
            {
                throw new NotSupportedException();
            }

            var playAction = api.ExpandGameVariables(Game, Game.PlayAction);

            OnStarting(this, new GameControllerEventArgs(this, 0));
            var proc = GameActionActivator.ActivateAction(playAction);

            OnStarted(this, new GameControllerEventArgs(this, 0));

            if (Game.PlayAction.Type != GameActionType.URL)
            {
                stopWatch              = Stopwatch.StartNew();
                procMon                = new ProcessMonitor();
                procMon.TreeDestroyed += Monitor_TreeDestroyed;
                procMon.WatchProcessTree(proc);
            }
            else
            {
                OnStopped(this, new GameControllerEventArgs(this, 0));
            }
        }
コード例 #3
0
        public async void StartBnetRunningWatcher()
        {
            if (!BattleNet.IsRunning)
            {
                logger.Info("Battle.net is not running, starting it first.");
                BattleNet.StartClient();
                while (BattleNet.RunningProcessesCount < 3)
                {
                    await Task.Delay(500);
                }
            }

            var task = new GameAction()
            {
                Path      = BattleNet.ClientExecPath,
                Arguments = string.Format("--exec=\"launch {0}\"", Game.GameId)
            };

            GameActionActivator.ActivateAction(task);
            if (Directory.Exists(Game.InstallDirectory))
            {
                procMon.TreeStarted += ProcMon_TreeStarted;
                procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
            }
            else
            {
                OnStopped(this, new GameControllerEventArgs(this, 0));
            }
        }
コード例 #4
0
        public override void Play()
        {
            if (Game.PlayAction == null)
            {
                throw new Exception("Cannot start game without play action.");
            }

            var playAction = Game.PlayAction.ExpandVariables(Game);

            Dispose();
            OnStarting(this, new GameControllerEventArgs(this, 0));
            var emulators = database.GetEmulators();
            var profile   = GameActionActivator.GetGameActionEmulatorConfig(playAction, emulators)?.ExpandVariables(Game);
            var proc      = GameActionActivator.ActivateAction(playAction, Game, profile);

            OnStarted(this, new GameControllerEventArgs(this, 0));

            if (playAction.Type != GameActionType.URL)
            {
                stopWatch              = Stopwatch.StartNew();
                procMon                = new ProcessMonitor();
                procMon.TreeDestroyed += Monitor_TreeDestroyed;

                // Handle Windows store apps
                if (playAction.Path == "explorer.exe" &&
                    playAction.Arguments.StartsWith("shell:") &&
                    !string.IsNullOrEmpty(Game.InstallDirectory))
                {
                    if (Directory.Exists(Game.InstallDirectory))
                    {
                        procMon.WatchDirectoryProcesses(Game.InstallDirectory, false, true);
                    }
                    else
                    {
                        OnStopped(this, new GameControllerEventArgs(this, 0));
                    }
                }
                else
                {
                    procMon.WatchProcessTree(proc);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(Game.InstallDirectory) && Directory.Exists(Game.InstallDirectory))
                {
                    stopWatch              = Stopwatch.StartNew();
                    procMon                = new ProcessMonitor();
                    procMon.TreeDestroyed += Monitor_TreeDestroyed;
                    procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
                }
                else
                {
                    OnStopped(this, new GameControllerEventArgs(this, 0));
                }
            }
        }
コード例 #5
0
        void StartGame()
        {
            // First know if the game is already running
            var process = ProcessAlreadyRunning();

            if (process != null)
            {
                ShowWindow(process.MainWindowHandle, 9);
                SetForegroundWindow(process.MainWindowHandle);
                return;
            }
            GameActionActivator.ActivateAction(Game.PlayAction.ExpandVariables(Game));
        }
コード例 #6
0
        public override async void Play()
        {
            ReleaseResources();
            stopWatch              = Stopwatch.StartNew();
            procMon                = new ProcessMonitor();
            procMon.TreeDestroyed += Monitor_TreeDestroyed;
            var app = BattleNetGames.GetAppDefinition(Game.GameId);

            if (Game.PlayAction.Type == GameActionType.URL && Game.PlayAction.Path.StartsWith("battlenet", StringComparison.OrdinalIgnoreCase))
            {
                if (!BattleNet.IsInstalled)
                {
                    throw new Exception("Cannot start game, Battle.net launcher is not installed properly.");
                }

                var bnetRunning = BattleNet.IsRunning;
                if (!bnetRunning)
                {
                    logger.Info("Battle.net is not running, starting it first.");
                    BattleNet.StartClient();
                    while (BattleNet.RunningProcessesCount < 3)
                    {
                        await Task.Delay(500);
                    }
                }

                OnStarting(this, new GameControllerEventArgs(this, 0));
                var task = new GameAction()
                {
                    Path      = BattleNet.ClientExecPath,
                    Arguments = string.Format("--exec=\"launch {0}\"", Game.GameId)
                };

                GameActionActivator.ActivateAction(task, Game);
                procMon.TreeStarted += ProcMon_TreeStarted;
                procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
            }
            else if (app.Type == BNetAppType.Classic && Game.PlayAction.Path.Contains(app.ClassicExecutable))
            {
                OnStarting(this, new GameControllerEventArgs(this, 0));
                var proc = GameActionActivator.ActivateAction(Game.PlayAction, Game);
                procMon.WatchDirectoryProcesses(Game.InstallDirectory, true);
                OnStarted(this, new GameControllerEventArgs(this, 0));
            }
            else
            {
                throw new Exception("Unknoww Play action configuration");
            }
        }
コード例 #7
0
        public override void Play()
        {
            ReleaseResources();
            OnStarting(this, new GameControllerEventArgs(this, 0));
            var runsViaOrigin = Origin.GetGameRequiresOrigin(Game);
            var playAction    = api.ExpandGameVariables(Game, Game.PlayAction);

            stopWatch              = Stopwatch.StartNew();
            procMon                = new ProcessMonitor();
            procMon.TreeDestroyed += ProcMon_TreeDestroyed;
            procMon.TreeStarted   += ProcMon_TreeStarted;
            var proc = GameActionActivator.ActivateAction(playAction, Game);

            StartRunningWatcher(runsViaOrigin);
        }
コード例 #8
0
ファイル: GamesEditor.cs プロジェクト: southrop/Playnite
 public void ActivateAction(Game game, GameAction action)
 {
     try
     {
         var emulators = database.Emulators.ToList();
         var profile   = GameActionActivator.GetGameActionEmulatorConfig(action, emulators)?.ExpandVariables(game);
         GameActionActivator.ActivateAction(action.ExpandVariables(game), game, profile);
     }
     catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
     {
         dialogs.ShowMessage(
             string.Format(resources.FindString("LOCGameStartActionError"), exc.Message),
             resources.FindString("LOCGameError"),
             MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
コード例 #9
0
        public override void Play()
        {
            ReleaseResources();
            if (settings.Settings.StartGamesUsingGalaxy == true)
            {
                OnStarting(this, new GameControllerEventArgs(this, 0));
                stopWatch              = Stopwatch.StartNew();
                procMon                = new ProcessMonitor();
                procMon.TreeStarted   += ProcMon_TreeStarted;
                procMon.TreeDestroyed += Monitor_TreeDestroyed;
                var args = string.Format(@"/gameId={0} /command=runGame /path=""{1}""", Game.GameId, Game.InstallDirectory);
                ProcessStarter.StartProcess(Path.Combine(Gog.InstallationPath, "GalaxyClient.exe"), args);
                if (Directory.Exists(Game.InstallDirectory))
                {
                    procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
                }
                else
                {
                    OnStopped(this, new GameControllerEventArgs(this, 0));
                }
            }
            else
            {
                if (Game.PlayAction.Type == GameActionType.Emulator)
                {
                    throw new NotSupportedException();
                }

                var playAction = api.ExpandGameVariables(Game, Game.PlayAction);
                OnStarting(this, new GameControllerEventArgs(this, 0));
                var proc = GameActionActivator.ActivateAction(playAction);
                OnStarted(this, new GameControllerEventArgs(this, 0));

                if (Game.PlayAction.Type != GameActionType.URL)
                {
                    stopWatch              = Stopwatch.StartNew();
                    procMon                = new ProcessMonitor();
                    procMon.TreeDestroyed += Monitor_TreeDestroyed;
                    procMon.WatchProcessTree(proc);
                }
                else
                {
                    OnStopped(this, new GameControllerEventArgs(this, 0));
                }
            }
        }
コード例 #10
0
 public override void Play()
 {
     ReleaseResources();
     OnStarting(this, new GameControllerEventArgs(this, 0));
     if (Directory.Exists(Game.InstallDirectory))
     {
         var playAction = api.ExpandGameVariables(Game, Game.PlayAction);
         stopWatch              = Stopwatch.StartNew();
         procMon                = new ProcessMonitor();
         procMon.TreeDestroyed += ProcMon_TreeDestroyed;
         procMon.TreeStarted   += ProcMon_TreeStarted;
         GameActionActivator.ActivateAction(playAction, Game);
         StartRunningWatcher();
     }
     else
     {
         OnStopped(this, new GameControllerEventArgs(this, 0));
     }
 }
コード例 #11
0
        public override void Play()
        {
            CheckItchInstallStatus();
            ReleaseResources();
            if (Game.PlayAction.Path == DynamicLaunchActionStr ||
                Game.PlayAction.Type == GameActionType.File ||
                Game.PlayAction.Type == GameActionType.URL)
            {
                OnStarting(this, new GameControllerEventArgs(this, 0));

                if (Game.PlayAction.Path == DynamicLaunchActionStr)
                {
                    butler = new Butler();
                    butler.RequestReceived      += Butler_RequestReceived;
                    butler.NotificationReceived += Butler_NotificationReceived;
                    butler.LaunchAsync(Game.PlayAction.Arguments);
                }
                else
                {
                    if (!Directory.Exists(Game.InstallDirectory))
                    {
                        throw new DirectoryNotFoundException(api.Resources.GetString("LOCInstallDirNotFoundError"));
                    }

                    GameActionActivator.ActivateAction(api.ExpandGameVariables(Game, Game.PlayAction));
                    if (Directory.Exists(Game.InstallDirectory))
                    {
                        procMon                = new ProcessMonitor();
                        procMon.TreeStarted   += ProcMon_TreeStarted;
                        procMon.TreeDestroyed += Monitor_TreeDestroyed;
                        procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
                    }
                    else
                    {
                        OnStopped(this, new GameControllerEventArgs(this, 0));
                    }
                }
            }
            else
            {
                throw new Exception(api.Resources.GetString("LOCInvalidGameActionSettings"));
            }
        }
コード例 #12
0
        public override async void Play()
        {
            ReleaseResources();
            OnStarting(this, new GameControllerEventArgs(this, 0));
            var runsViaOrigin = Origin.GetGameRequiresOrigin(Game);
            var playAction    = api.ExpandGameVariables(Game, Game.PlayAction);

            stopWatch              = Stopwatch.StartNew();
            procMon                = new ProcessMonitor();
            procMon.TreeDestroyed += ProcMon_TreeDestroyed;
            procMon.TreeStarted   += ProcMon_TreeStarted;

            var proc = GameActionActivator.ActivateAction(playAction, Game);

            if (runsViaOrigin)
            {
                // Solves issues with game process being started/shutdown multiple times during startup via Origin
                await Task.Delay(5000);
            }

            procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
        }
コード例 #13
0
        public override void Play()
        {
            ReleaseResources();
            stopWatch              = Stopwatch.StartNew();
            procMon                = new ProcessMonitor();
            procMon.TreeDestroyed += Monitor_TreeDestroyed;
            var app = BattleNetGames.GetAppDefinition(Game.GameId);

            if (Game.PlayAction.Type == GameActionType.URL && Game.PlayAction.Path.StartsWith("battlenet", StringComparison.OrdinalIgnoreCase))
            {
                if (!BattleNet.IsInstalled)
                {
                    throw new Exception("Cannot start game, Battle.net launcher is not installed properly.");
                }

                OnStarting(this, new GameControllerEventArgs(this, 0));
                StartBnetRunningWatcher();
            }
            else if (app.Type == BNetAppType.Classic && Game.PlayAction.Path.Contains(app.ClassicExecutable))
            {
                var playAction = api.ExpandGameVariables(Game, Game.PlayAction);
                OnStarting(this, new GameControllerEventArgs(this, 0));
                GameActionActivator.ActivateAction(playAction);
                OnStarted(this, new GameControllerEventArgs(this, 0));
                if (Directory.Exists(Game.InstallDirectory))
                {
                    procMon.WatchDirectoryProcesses(Game.InstallDirectory, true, true);
                }
                else
                {
                    OnStopped(this, new GameControllerEventArgs(this, 0));
                }
            }
            else
            {
                throw new Exception("Unknown Play action configuration.");
            }
        }
コード例 #14
0
        public override void Play()
        {
            if (Game.PlayAction == null)
            {
                throw new Exception("Cannot start game without play action.");
            }

            var playAction = Game.PlayAction.ExpandVariables(Game);

            Dispose();
            OnStarting(this, new GameControllerEventArgs(this, 0));
            var proc = GameActionActivator.ActivateAction(playAction);

            if (playAction.Type != GameActionType.URL && playAction.Type != GameActionType.CMD)
            {
                stopWatch              = Stopwatch.StartNew();
                procMon                = new ProcessMonitor();
                procMon.TreeDestroyed += Monitor_TreeDestroyed;

                // Handle Windows store apps
                var uwpMatch = Regex.Match(playAction.Arguments ?? string.Empty, @"shell:AppsFolder\\(.+)!.+");
                if (playAction.Path == "explorer.exe" && uwpMatch.Success)
                {
                    var scanDirectory = Game.InstallDirectory;
                    procMon.TreeStarted += ProcMon_TreeStarted;

                    if (!Game.GameId.IsNullOrEmpty())
                    {
                        var prg = Programs.GetUWPApps().FirstOrDefault(a => a.AppId == Game.GameId);
                        if (prg != null)
                        {
                            scanDirectory = prg.WorkDir;
                        }
                    }

                    // TODO switch to WatchUwpApp once we are building as 64bit app
                    //procMon.WatchUwpApp(uwpMatch.Groups[1].Value, false);
                    if (Directory.Exists(scanDirectory) && ProcessMonitor.IsWatchableByProcessNames(scanDirectory))
                    {
                        procMon.WatchDirectoryProcesses(scanDirectory, false, true);
                    }
                    else
                    {
                        OnStopped(this, new GameControllerEventArgs(this, 0));
                    }
                }
                else
                {
                    if (proc != null)
                    {
                        OnStarted(this, new GameControllerEventArgs(this, 0));
                        procMon.WatchProcessTree(proc);
                    }
                    else
                    {
                        OnStopped(this, new GameControllerEventArgs(this, 0));
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(Game.InstallDirectory) && Directory.Exists(Game.InstallDirectory))
                {
                    OnStarted(this, new GameControllerEventArgs(this, 0));
                    stopWatch              = Stopwatch.StartNew();
                    procMon                = new ProcessMonitor();
                    procMon.TreeDestroyed += Monitor_TreeDestroyed;
                    procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
                }
                else
                {
                    OnStopped(this, new GameControllerEventArgs(this, 0));
                }
            }
        }