예제 #1
0
 void onExit(ExecutorItem exeItem, List <int> pIds, bool started = true)
 {
     Dispose();
     if (started)
     {
         waitForLaunchedProc(exeItem.LaunchedExe, pIds);
     }
     if (exeItem.Mount)
     {
         unMount();
     }
     if (exeItem.PostCommand != null)
     {
         exeItem.PostCommand.Run();
     }
     //resume Mediaportal rendering
     if (exeItem.Suspend)
     {
         if (started && exeItem.ResumeDelay > 0)
         {
             Thread.Sleep(exeItem.ResumeDelay);
         }
         suspendMP(false);
     }
     if (StatusChanged != null)
     {
         StatusChanged(false);
     }
 }
예제 #2
0
 void initProc(ExecutorItem item, EventHandler procExit)
 {
     proc                            = new Process();
     proc.StartInfo                  = new ProcessStartInfo();
     proc.StartInfo.FileName         = item.Path;
     proc.StartInfo.Arguments        = item.Arguments;
     proc.StartInfo.WorkingDirectory = item.WorkingDirectory;
     proc.EnableRaisingEvents        = true;
     proc.Exited                    += procExit;
 }
예제 #3
0
        /// <summary>
        /// Launches the specified game using the specified profile. If the specified profile is null
        /// the game's configured profile is used. If isConfig is true then any suspend settings are ignored
        /// and the specified game's playcount and playdate are not updated.
        /// </summary>
        /// <param name="game"></param>
        /// <param name="isConfig">Whether the game is being launched by Configuration. Default false.</param>
        /// <param name="profile">The profile to use when launching the game.</param>
        public void LaunchGame(string path, EmulatorProfile profile, ExecutorLaunchProgressHandler launchProgressChanged = null)
        {
            if (profile == null)
            {
                throw new LaunchException("Profile cannot be null");
            }

            bool isPC     = profile.EmulatorID == -1;
            bool isConfig = Emulators2Settings.Instance.IsConfig;

            ExecutorItem exeItem = new ExecutorItem(isPC);

            exeItem.Arguments = profile.Arguments;
            exeItem.Suspend   = !isConfig && profile.SuspendMP == true;
            if (profile.DelayResume && profile.ResumeDelay > 0)
            {
                exeItem.ResumeDelay = profile.ResumeDelay;
            }

            if (isPC)
            {
                exeItem.Path = path;
                if (!string.IsNullOrEmpty(profile.LaunchedExe))
                {
                    try { exeItem.LaunchedExe = Path.GetFileNameWithoutExtension(profile.LaunchedExe); }
                    catch { exeItem.LaunchedExe = profile.LaunchedExe; }
                }
            }
            else
            {
                exeItem.Path    = profile.EmulatorPath;
                exeItem.RomPath = path;
                exeItem.Mount   = profile.MountImages && DaemonTools.IsImageFile(Path.GetExtension(path));
                exeItem.ShouldReplaceWildcards = !exeItem.Mount;
                exeItem.UseQuotes          = profile.UseQuotes == true;
                exeItem.CheckController    = profile.CheckController;
                exeItem.StopEmulationOnKey = profile.StopEmulationOnKey.HasValue ? profile.StopEmulationOnKey.Value : Options.Instance.GetBoolOption("domap");
                exeItem.EscapeToExit       = profile.EscapeToExit;
            }
            exeItem.PreCommand = new LaunchCommand()
            {
                Command = profile.PreCommand, WaitForExit = profile.PreCommandWaitForExit, ShowWindow = profile.PreCommandShowWindow
            };
            exeItem.PostCommand = new LaunchCommand()
            {
                Command = profile.PostCommand, WaitForExit = profile.PostCommandWaitForExit, ShowWindow = profile.PostCommandShowWindow
            };
            exeItem.Init();

            //stop any media playing
            if (!isConfig && Options.Instance.GetBoolOption("stopmediaplayback") && MediaPortal.Player.g_Player.Playing)
            {
                Logger.LogDebug("Stopping playing media...");
                MediaPortal.Player.g_Player.Stop();
            }

            lock (launchSync)
            {
                launchGame(exeItem, launchProgressChanged);
            }
        }
예제 #4
0
        void launchGame(ExecutorItem exeItem, ExecutorLaunchProgressHandler launchProgressChanged)
        {
            Dispose();

            if (exeItem.Mount)
            {
                if (launchProgressChanged != null)
                {
                    launchProgressChanged("Mounting...", 75);
                }
                mountImage(exeItem.RomPath);
            }
            else if (launchProgressChanged != null)
            {
                launchProgressChanged("Launching...", 75);
            }

            List <int> pIds = new List <int>();

            initProc(exeItem, new EventHandler((o, e) => { onExit(exeItem, pIds); }));

            Logger.LogInfo("Launching with arguments '{1} {2}'", exeItem.Path, exeItem.Arguments);
            if (launchProgressChanged != null)
            {
                launchProgressChanged("Launching...", 100);
            }

            if (exeItem.CheckController && !ControllerHandler.CheckControllerState())
            {
                Emulators2Settings.Instance.ShowMPDialog(Translator.Instance.nocontrollerconnected);
            }

            if (exeItem.Suspend)
            {
                suspendMP(true); //suspend MediaPortal rendering
            }
            //run pre-command
            exeItem.PreCommand.Run();

            //if we're a launcher get id of all processes currently running with the same name so they can be excluded when looking for launched process
            if (!string.IsNullOrEmpty(exeItem.LaunchedExe))
            {
                foreach (Process p in Process.GetProcessesByName(exeItem.LaunchedExe))
                {
                    pIds.Add(p.Id);
                }
            }

            //start emulator
            bool result;

            try
            {
                result = proc.Start();
            }
            catch (Exception ex)
            {
                result = false;
                Logger.LogError("Exception starting {0} - {1}", exeItem.Path, ex.Message);
            }

            if (!result)
            {
                Logger.LogWarn("Failed to start {0}", exeItem.Path);
                onExit(exeItem, null, false);
                throw new LaunchException("{0} did not start", exeItem.Path);
            }

            //send status changed event
            if (StatusChanged != null)
            {
                StatusChanged(true);
            }

            //setup keyboard hook if configured and we're not launching a PC Game (they should have their own way of exiting)
            if (exeItem.StopEmulationOnKey)
            {
                setupKeyboardHook(exeItem.EscapeToExit);
            }
        }