Exemplo n.º 1
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));
                }
            }
        }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
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.Emulators.ToList();
            var profile   = GameActionActivator.GetGameActionEmulatorConfig(playAction, emulators)?.ExpandVariables(Game);
            var proc      = GameActionActivator.ActivateAction(playAction, profile);

            if (playAction.Type != GameActionType.URL)
            {
                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));
                }
            }
        }