public static Process ActivateAction(GameAction action, EmulatorProfile config)
        {
            switch (action.Type)
            {
            case GameActionType.File:
            case GameActionType.URL:
                return(ActivateAction(action));

            case GameActionType.Emulator:
                logger.Info($"Activating game task {action}");
                if (config == null)
                {
                    throw new Exception("Cannot start emulated game without emulator.");
                }

                var path      = config.Executable;
                var arguments = config.Arguments;
                if (!string.IsNullOrEmpty(action.AdditionalArguments))
                {
                    arguments += " " + action.AdditionalArguments;
                }

                if (action.OverrideDefaultArgs)
                {
                    arguments = action.Arguments;
                }

                var workdir = config.WorkingDirectory;
                return(ProcessStarter.StartProcess(path, arguments, workdir));
            }

            return(null);
        }
Beispiel #2
0
        public static void ActivateTask(GameTask task, Game gameData, EmulatorProfile config)
        {
            switch (task.Type)
            {
            case GameTaskType.File:
            case GameTaskType.URL:
                ActivateTask(task, gameData);
                break;

            case GameTaskType.Emulator:
                if (config == null)
                {
                    throw new Exception("Cannot start emulated game without emulator.");
                }

                var path      = gameData.ResolveVariables(config.Executable);
                var arguments = gameData.ResolveVariables(config.Arguments);
                if (!string.IsNullOrEmpty(task.AdditionalArguments))
                {
                    arguments += " " + gameData.ResolveVariables(task.AdditionalArguments);
                }

                if (task.OverrideDefaultArgs)
                {
                    arguments = gameData.ResolveVariables(task.Arguments);
                }

                var workdir = gameData.ResolveVariables(config.WorkingDirectory);
                logger.Info($"Starting emulator: {path}, {arguments}, {workdir}");
                ProcessStarter.StartProcess(path, arguments, workdir);
                break;
            }
        }
        public GameProcess(string path, EmulatorProfile emulatorProfile, bool isPC)
        {
            this.emulatorProfile = emulatorProfile;
            if (isPC)
                gamePath = GamePathBuilder.CreatePCPath(path, emulatorProfile.Arguments);
            else
                gamePath = GamePathBuilder.CreateRomPath(emulatorProfile.EmulatorPath, emulatorProfile.Arguments, path, !emulatorProfile.MountImages, emulatorProfile.UseQuotes);

            if (!string.IsNullOrEmpty(emulatorProfile.WorkingDirectory))
                gamePath.WorkingDirectory = emulatorProfile.WorkingDirectory;

            if (emulatorProfile.StopEmulationOnKey == true || (emulatorProfile.StopEmulationOnKey == null && EmulatorsCore.Options.ReadOption(o => o.StopOnMappedKey)))
                mappedKeyData = EmulatorsCore.Options.ReadOption(o => o.MappedKey);
        }
Beispiel #4
0
        public static int SaveProfile(EmulatorProfile emulatorProfile)
        {
            if (emulatorProfile.ID == -1) //Defult profile, update Emulator
            {
                Emulator emu = getEmulator(emulatorProfile.EmulatorID);
                if (emu == null)
                {
                    Logger.LogError("Unable to save profile - Parent Emulator does not exist");
                    return(-1);
                }

                emu.PathToEmulator   = emulatorProfile.EmulatorPath;
                emu.Arguments        = emulatorProfile.Arguments;
                emu.WorkingFolder    = emulatorProfile.WorkingDirectory;
                emu.UseQuotes        = emulatorProfile.UseQuotes == true;
                emu.SuspendRendering = emulatorProfile.SuspendMP == true;
                emu.GoodmergePref1   = emulatorProfile.GoodMergePref1;
                emu.GoodmergePref2   = emulatorProfile.GoodMergePref2;
                emu.GoodmergePref3   = emulatorProfile.GoodMergePref3;
                emu.MountImages      = emulatorProfile.MountImages;

                DB.saveEmulator(emu);
            }
            else if (emulatorProfile.ID > -1)
            {
                dbExecute(
                    "UPDATE EmulatorProfiles SET " +
                    "emulator_path='" + encode(emulatorProfile.EmulatorPath) + "', " +
                    "title='" + encode(emulatorProfile.Title) + "', " +
                    "working_path='" + encode(emulatorProfile.WorkingDirectory) + "', " +
                    "usequotes='" + emulatorProfile.UseQuotes + "', " +
                    "args='" + encode(emulatorProfile.Arguments) + "', " +
                    "suspend_mp='" + emulatorProfile.SuspendMP + "', " +
                    "goodmerge_pref1='" + emulatorProfile.GoodMergePref1 + "', " +
                    "goodmerge_pref2='" + emulatorProfile.GoodMergePref2 + "', " +
                    "goodmerge_pref3='" + emulatorProfile.GoodMergePref3 + "', " +
                    "mountimages='" + emulatorProfile.MountImages + "' " +

                    " WHERE uid=" + emulatorProfile.ID

                    );
            }
            else //new Profile
            {
                emulatorProfile.ID = getNewProfileIDandInsert(emulatorProfile);
            }

            return(emulatorProfile.ID);
        }
        public override void Dispose()
        {
            isDisposed = true;
            watcherToken?.Cancel();
            playTask?.Wait(5000); // Give startup script time to gracefully shutdown.
            procMon?.Dispose();
            stopWatch?.Stop();
            if (playRuntime?.IsDisposed == false)
            {
                playRuntime?.Dispose();
            }

            watcherToken?.Dispose();
            currentEmuProfile = null;
        }
Beispiel #6
0
        static EmulatorProfile createProfile(SQLiteResultSet result, int rowNum)
        {
            EmulatorProfile profile = new EmulatorProfile(null, false);

            profile.ID               = DatabaseUtility.GetAsInt(result, rowNum, 0);
            profile.Title            = decode(DatabaseUtility.Get(result, rowNum, 1));
            profile.EmulatorID       = DatabaseUtility.GetAsInt(result, rowNum, 2);
            profile.EmulatorPath     = decode(DatabaseUtility.Get(result, rowNum, 3));
            profile.WorkingDirectory = decode(DatabaseUtility.Get(result, rowNum, 4));
            profile.UseQuotes        = Boolean.Parse(DatabaseUtility.Get(result, rowNum, 5));
            profile.Arguments        = decode(DatabaseUtility.Get(result, rowNum, 6));
            profile.SuspendMP        = Boolean.Parse(DatabaseUtility.Get(result, rowNum, 7));
            profile.GoodMergePref1   = decode(DatabaseUtility.Get(result, rowNum, 8));
            profile.GoodMergePref2   = decode(DatabaseUtility.Get(result, rowNum, 9));
            profile.GoodMergePref3   = decode(DatabaseUtility.Get(result, rowNum, 10));
            profile.MountImages      = Boolean.Parse(DatabaseUtility.Get(result, rowNum, 11));
            return(profile);
        }
Beispiel #7
0
        static int getNewProfileIDandInsert(EmulatorProfile emulatorProfile)
        {
            if (!isDBInit)
            {
                return(-2);
            }

            //get next id and insert profile within 1 lock to avoid race condition
            lock (dbLock)
            {
                if (emulatorProfile.ID < 0)
                {
                    SQLiteResultSet result = sqlDB.Execute("SELECT MAX(uid)+1 FROM EmulatorProfiles");
                    if (result.Rows.Count > 0)
                    {
                        emulatorProfile.ID = DatabaseUtility.GetAsInt(result, 0, 0);
                    }
                    else
                    {
                        emulatorProfile.ID = 0;
                    }
                }

                sqlDB.Execute(
                    "INSERT INTO EmulatorProfiles VALUES(" +
                    emulatorProfile.ID + "," +
                    "'" + encode(emulatorProfile.Title) + "'," +
                    emulatorProfile.EmulatorID + "," +
                    "'" + encode(emulatorProfile.EmulatorPath) + "'," +
                    "'" + encode(emulatorProfile.WorkingDirectory) + "'," +
                    "'" + emulatorProfile.UseQuotes + "'," +
                    "'" + encode(emulatorProfile.Arguments) + "'," +
                    "'" + emulatorProfile.SuspendMP + "'," +
                    "'" + emulatorProfile.GoodMergePref1 + "'," +
                    "'" + emulatorProfile.GoodMergePref2 + "'," +
                    "'" + emulatorProfile.GoodMergePref3 + "'," +
                    "'" + emulatorProfile.MountImages + "'" +
                    ")"
                    );
            }

            return(emulatorProfile.ID);
        }
        public static Process ActivateAction(GameAction action, EmulatorProfile config)
        {
            switch (action.Type)
            {
            case GameActionType.File:
            case GameActionType.URL:
                return(ActivateAction(action));

            case GameActionType.Emulator:
                logger.Info($"Activating game task {action}");
                if (config == null)
                {
                    throw new Exception("Cannot start emulated game without emulator.");
                }

                var path      = config.Executable;
                var arguments = config.Arguments;
                if (!string.IsNullOrEmpty(action.AdditionalArguments))
                {
                    arguments += " " + action.AdditionalArguments;
                }

                if (action.OverrideDefaultArgs)
                {
                    arguments = action.Arguments;
                }

                var workdir = config.WorkingDirectory;
                try
                {
                    return(ProcessStarter.StartProcess(path, arguments, workdir));
                }
                catch (System.ComponentModel.Win32Exception e)
                {
                    logger.Error(e, "Failed to start emulator process.");
                    throw new Exception("Emulator process cannot be started, make sure that emulator paths are configured properly.");
                }
            }

            return(null);
        }
Beispiel #9
0
        public static EmulatorProfile ExpandVariables(this EmulatorProfile profile, Game game)
        {
            var expaded = profile.CloneJson();

            if (!string.IsNullOrEmpty(expaded.Arguments))
            {
                expaded.Arguments = game.ExpandVariables(expaded.Arguments);
            }

            if (!string.IsNullOrEmpty(expaded.WorkingDirectory))
            {
                expaded.WorkingDirectory = game.ExpandVariables(expaded.WorkingDirectory, true);
            }

            if (!string.IsNullOrEmpty(expaded.Executable))
            {
                expaded.Executable = game.ExpandVariables(expaded.Executable, true);
            }

            return(expaded);
        }
        private void CheckEmulatorConfig(EmulatorProfile emulatorProfile)
        {
            if (!File.Exists(emulatorProfile.Executable))
            {
                var configExecutable = FileSystem.LookupAlternativeFilePath(emulatorProfile.Executable);
                if (!string.IsNullOrWhiteSpace(configExecutable))
                {
                    logger.Warn($"Emulator \"{configExecutable}\" does not exist for game \"{Game.Name}\"" +
                                $" and is temporarily changed to \"{configExecutable}\"");
                    emulatorProfile.Executable = configExecutable;
                }
            }

            if (!string.IsNullOrWhiteSpace(emulatorProfile.WorkingDirectory) && !Directory.Exists(emulatorProfile.WorkingDirectory))
            {
                var workingDir = FileSystem.LookupAlternativeDirectoryPath(emulatorProfile.WorkingDirectory);
                if (!string.IsNullOrWhiteSpace(workingDir))
                {
                    logger.Warn($"WorkingDir \"{emulatorProfile.WorkingDirectory}\" does not exist for emulator \"{emulatorProfile.Name}\"" +
                                $" and is temporarily changed to \"{workingDir}\"");
                    emulatorProfile.WorkingDirectory = workingDir;
                }
            }
        }
Beispiel #11
0
        public static List <IGame> SearchForGames(DirectoryInfoBase path, EmulatorProfile profile)
        {
            logger.Info($"Looking for games in {path}, using {profile.Name} emulator profile.");
            if (profile.ImageExtensions == null)
            {
                throw new Exception("Cannot scan for games, emulator doesn't support any file types.");
            }

            var games          = new List <IGame>();
            var fileEnumerator = new SafeFileEnumerator(path, "*.*", SearchOption.AllDirectories);

            foreach (var file in fileEnumerator)
            {
                if (file.Attributes.HasFlag(FileAttributes.Directory))
                {
                    continue;
                }

                foreach (var extension in profile.ImageExtensions)
                {
                    if (string.Equals(file.Extension.TrimStart('.'), extension, StringComparison.InvariantCultureIgnoreCase))
                    {
                        var newGame = new Game()
                        {
                            Name             = StringExtensions.NormalizeGameName(Path.GetFileNameWithoutExtension(file.Name)),
                            IsoPath          = file.FullName,
                            InstallDirectory = Path.GetDirectoryName(file.FullName)
                        };

                        games.Add(newGame);
                    }
                }
            }

            return(games);
        }
        static bool showProfileDialog(ref EmulatorProfile selectedProfile, List<EmulatorProfile> profiles, int windowID)
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlg != null)
            {
                dlg.Reset();
                dlg.SetHeading(Translator.Instance.selectprofile);

                int selectedLabel = 0;
                for (int x = 0; x < profiles.Count; x++)
                {
                    dlg.Add(new GUIListItem(profiles[x].Title));
                    if (profiles[x].Id == selectedProfile.Id)
                        selectedLabel = x;
                }

                dlg.SelectedLabel = selectedLabel;
                dlg.DoModal(windowID);
                selectedLabel = dlg.SelectedLabel;

                if (selectedLabel > -1)
                {
                    selectedProfile = profiles[selectedLabel];
                    return true;
                }
            }
            return false;
        }
 public GUILauncher(Game game)
 {
     this.game = game;
     emulatorProfile = game.CurrentProfile;
 }
 public static void EditProfile(EmulatorProfile profile)
 {
     var workflow = ServiceRegistration.Get<IWorkflowManager>();
     workflow.NavigatePush(Guids.EditProfileState, createNavigationConfig(KEY_PROFILE_EDIT, profile, profile.Title));
 }
Beispiel #15
0
 public static async Task <List <Game> > SearchForGames(string path, EmulatorProfile profile, CancellationTokenSource cancelToken = null)
 {
     return(await SearchForGames(new DirectoryInfo(path), profile, cancelToken));
 }
Beispiel #16
0
 public ImportableGame(Game game, Emulator emulator, EmulatorProfile emulatorProfile)
 {
     Game            = game;
     Emulator        = emulator;
     EmulatorProfile = emulatorProfile;
 }
 public void Reset()
 {
     currentProfile = null;
     EmulatorPath = null;
     Arguments = null;
     WorkingDirectory = null;
     UseQuotes = true;
     EscToExit = false;
     LaunchedFile = null;
     PreCommand = null;
     PreCommandWaitForExit = true;
     PreCommandShowWindow = false;
     PostCommand = null;
     PostCommandWaitForExit = true;
     PostCommandShowWindow = false;
     WarnNoControllers = false;
     EnableGoodmerge = false;
     GoodmergeTags = null;
 }
Beispiel #18
0
        public static async Task <List <Game> > SearchForGames(DirectoryInfoBase path, EmulatorProfile profile, CancellationTokenSource cancelToken = null)
        {
            return(await Task.Run(() =>
            {
                logger.Info($"Looking for games in {path}, using {profile.Name} emulator profile.");
                if (profile.ImageExtensions == null)
                {
                    throw new Exception("Cannot scan for games, emulator doesn't support any file types.");
                }

                var games = new List <Game>();
                var fileEnumerator = new SafeFileEnumerator(path, "*.*", SearchOption.AllDirectories);
                foreach (var file in fileEnumerator)
                {
                    if (cancelToken?.IsCancellationRequested == true)
                    {
                        return null;
                    }

                    if (file.Attributes.HasFlag(FileAttributes.Directory))
                    {
                        continue;
                    }

                    foreach (var extension in profile.ImageExtensions)
                    {
                        if (string.Equals(file.Extension.TrimStart('.'), extension, StringComparison.OrdinalIgnoreCase))
                        {
                            var newGame = new Game()
                            {
                                Name = StringExtensions.NormalizeGameName(StringExtensions.GetPathWithoutAllExtensions(Path.GetFileName(file.Name))),
                                GameImagePath = file.FullName,
                                InstallDirectory = Path.GetDirectoryName(file.FullName)
                            };

                            games.Add(newGame);
                        }
                    }
                }

                return games;
            }));
        }
 EmulatorProfile createProfile(SQLDataRow sqlRow)
 {
     EmulatorProfile profile = new EmulatorProfile();
     profile.Id = int.Parse(sqlRow.fields[0]);
     profile.Title = decode(sqlRow.fields[1]);
     profile.EmulatorPath = decode(sqlRow.fields[3]);
     profile.WorkingDirectory = decode(sqlRow.fields[4]);
     profile.UseQuotes = bool.Parse(sqlRow.fields[5]);
     profile.Arguments = decode(sqlRow.fields[6]);
     profile.SuspendMP = bool.Parse(sqlRow.fields[7]);
     profile.MountImages = bool.Parse(sqlRow.fields[8]);
     profile.EscapeToExit = bool.Parse(sqlRow.fields[9]);
     profile.CheckController = bool.Parse(sqlRow.fields[10]);
     profile.IsDefault = bool.Parse(sqlRow.fields[11]);
     profile.PreCommand = decode(sqlRow.fields[12]);
     profile.PreCommandWaitForExit = bool.Parse(sqlRow.fields[13]);
     profile.PreCommandShowWindow = bool.Parse(sqlRow.fields[14]);
     profile.PostCommand = decode(sqlRow.fields[15]);
     profile.PostCommandWaitForExit = bool.Parse(sqlRow.fields[16]);
     profile.PostCommandShowWindow = bool.Parse(sqlRow.fields[17]);
     profile.LaunchedExe = decode(sqlRow.fields[19]);
     profile.StopEmulationOnKey = boolFromInt(int.Parse(sqlRow.fields[20]));
     profile.DelayResume = bool.Parse(sqlRow.fields[21]);
     profile.ResumeDelay = int.Parse(sqlRow.fields[22]);
     profile.GoodmergeTags = decode(sqlRow.fields[23]);
     profile.EnableGoodmerge = bool.Parse(sqlRow.fields[24]);
     return profile;
 }
 public void SetProfile(EmulatorProfile profile)
 {
     if (profile == null)
     {
         Reset();
     }
     else if (profile != currentProfile)
     {
         currentProfile = profile;
         EmulatorPath = profile.EmulatorPath;
         Arguments = profile.Arguments;
         WorkingDirectory = profile.WorkingDirectory;
         UseQuotes = profile.UseQuotes;
         EscToExit = profile.EscapeToExit;
         LaunchedFile = currentProfile.LaunchedExe;
         PreCommand = currentProfile.PreCommand;
         PreCommandWaitForExit = currentProfile.PreCommandWaitForExit;
         PreCommandShowWindow = currentProfile.PreCommandShowWindow;
         PostCommand = currentProfile.PostCommand;
         PostCommandWaitForExit = currentProfile.PostCommandWaitForExit;
         PostCommandShowWindow = currentProfile.PostCommandShowWindow;
         WarnNoControllers = currentProfile.CheckController;
         EnableGoodmerge = profile.EnableGoodmerge;
         GoodmergeTags = currentProfile.GoodmergeTags;
     }
 }
        List<Game> upgradeGames(SQLData gameData)
        {
            int currentGame = 1;
            int totalGames = gameData.Rows.Count;
            List<Game> games = new List<Game>();
            foreach (SQLDataRow sqlRow in gameData.Rows)
            {
                setProgress("{0}/{1} - Parsing Games", currentGame, totalGames);
                currentGame++;
                currentItem++;

                Emulator parent;
                if (!emuLookup.TryGetValue(int.Parse(sqlRow.fields[2], culture), out parent))
                    continue;

                Game game = new Game();
                game.ParentEmulator = parent;
                game.Id = int.Parse(sqlRow.fields[0]);
                game.Title = decode(sqlRow.fields[3]);
                game.Grade = int.Parse(sqlRow.fields[4]);
                game.PlayCount = int.Parse(sqlRow.fields[5]);
                game.Year = int.Parse(sqlRow.fields[6]);
                game.Latestplay = DateTime.Parse(sqlRow.fields[7], culture);
                game.Description = decode(sqlRow.fields[8]);
                game.Genre = decode(sqlRow.fields[9]);
                game.Developer = decode(sqlRow.fields[10]);
                game.Favourite = bool.Parse(sqlRow.fields[12]);
                game.InfoChecked = bool.Parse(sqlRow.fields[15]);
                game.VideoPreview = decode(sqlRow.fields[17]);

                if (parent.IsPc())
                {
                    upgradeProfiles(game);
                    if (game.GameProfiles.Count < 1)
                    {
                        EmulatorProfile profile = new EmulatorProfile(true);
                        profile.Arguments = decode(sqlRow.fields[19]);
                        profile.SuspendMP = true;
                        game.GameProfiles.Add(profile);
                    }
                }

                int selectedProfileId = int.Parse(sqlRow.fields[14]);
                foreach (EmulatorProfile profile in game.EmulatorProfiles)
                {
                    if (profile.Id == selectedProfileId)
                    {
                        game.CurrentProfile = profile;
                        break;
                    }
                }

                upgradeDiscs(game);
                if (game.Discs.Count < 1)
                {
                    GameDisc disc = new GameDisc();
                    disc.Number = 1;
                    disc.Path = decode(sqlRow.fields[1]);
                    disc.LaunchFile = decode(sqlRow.fields[13]);
                    game.Discs.Add(disc);
                    game.CurrentDisc = disc;
                }
                else
                {
                    int discNum = int.Parse(sqlRow.fields[18]);
                    foreach (GameDisc disc in game.Discs)
                    {
                        if (discNum == disc.Number)
                        {
                            game.CurrentDisc = disc;
                            break;
                        }
                    }
                }
                games.Add(game);
            }
            return games;
        }
        public void Start(EmulationPlayAction action, bool asyncExec = true)
        {
            var emulator = database.Emulators[action.EmulatorId];

            if (emulator == null)
            {
                throw new Exception("Emulator not found.");
            }

            currentEmuProfile = null;
            if (action.SelectedEmulatorProfile is CustomEmulatorProfile customProfile)
            {
                currentEmuProfile = customProfile;
            }
            else if (action.SelectedEmulatorProfile is BuiltInEmulatorProfile builtinProfile)
            {
                currentEmuProfile = builtinProfile;
            }
            else
            {
                throw new Exception("Uknown play action configuration.");
            }

            emulator = emulator.GetClone();
            if (!emulator.InstallDir.IsNullOrEmpty())
            {
                emulator.InstallDir = Paths.FixSeparators(emulator.InstallDir.Replace(ExpandableVariables.PlayniteDirectory, PlaynitePaths.ProgramPath));
                emulator.InstallDir = CheckPath(emulator.InstallDir, nameof(emulator.InstallDir), FileSystemItem.Directory);
            }

            SourceGameAction = action;
            SelectedRomPath  = action.SelectedRomPath;

            var startupPath = "";
            var startupArgs = "";
            var startupDir  = "";
            var romPath     = Game.ExpandVariables(action.SelectedRomPath, true);

            romPath = CheckPath(romPath, "ROM", FileSystemItem.File);

            if (currentEmuProfile is CustomEmulatorProfile emuProf)
            {
                var expandedProfile = emuProf.ExpandVariables(Game, emulator.InstallDir, romPath);
                expandedProfile.Executable       = CheckPath(expandedProfile.Executable, nameof(expandedProfile.Executable), FileSystemItem.File);
                expandedProfile.WorkingDirectory = CheckPath(expandedProfile.WorkingDirectory, nameof(expandedProfile.WorkingDirectory), FileSystemItem.Directory);

                if (!emuProf.StartupScript.IsNullOrWhiteSpace())
                {
                    RunStartScript(
                        $"{emulator.Name} runtime for {Game.Name}",
                        emuProf.StartupScript,
                        emulator.InstallDir,
                        new Dictionary <string, object>
                    {
                        { "Emulator", emulator.GetClone() },
                        { "EmulatorProfile", expandedProfile.GetClone() },
                        { "RomPath", romPath }
                    },
                        asyncExec);
                }
                else
                {
                    if (action.OverrideDefaultArgs)
                    {
                        startupArgs = Game.ExpandVariables(action.Arguments, false, emulator.InstallDir, romPath);
                    }
                    else
                    {
                        startupArgs = expandedProfile.Arguments;
                        if (!action.AdditionalArguments.IsNullOrEmpty())
                        {
                            startupArgs += " " + Game.ExpandVariables(action.AdditionalArguments, false, emulator.InstallDir, romPath);
                        }
                    }

                    startupDir  = expandedProfile.WorkingDirectory;
                    startupPath = expandedProfile.Executable;
                    StartEmulatorProcess(startupPath, startupArgs, startupDir);
                }
            }
            else if (currentEmuProfile is BuiltInEmulatorProfile builtIn)
            {
                var profileDef = EmulatorDefinition.GetProfile(emulator.BuiltInConfigId, builtIn.BuiltInProfileName);
                if (profileDef == null)
                {
                    throw new Exception($"Can't find built-in {builtIn.BuiltInProfileName} emulator profile.");
                }

                if (profileDef.ScriptStartup)
                {
                    var def = EmulatorDefinition.GetDefition(emulator.BuiltInConfigId);
                    if (def == null || !File.Exists(def.StartupScriptPath))
                    {
                        throw new FileNotFoundException(ResourceProvider.GetString(LOC.ErrorEmulatorStartupScriptNotFound));
                    }

                    RunStartScriptFile(
                        $"{emulator.Name} runtime for {Game.Name}",
                        def.StartupScriptPath,
                        emulator.InstallDir,
                        new Dictionary <string, object>
                    {
                        { "Emulator", emulator.GetClone() },
                        { "EmulatorProfile", profileDef.GetClone() },
                        { "RomPath", romPath }
                    },
                        asyncExec);
                }
                else
                {
                    builtIn     = builtIn.GetClone();
                    startupDir  = emulator.InstallDir;
                    startupPath = EmulatorDefinition.GetExecutable(emulator.InstallDir, profileDef, true);
                    if (startupPath.IsNullOrEmpty())
                    {
                        throw new FileNotFoundException(ResourceProvider.GetString(LOC.ErrorEmulatorExecutableNotFound));
                    }

                    if (action.OverrideDefaultArgs)
                    {
                        startupArgs = Game.ExpandVariables(action.Arguments, false, null, romPath);
                    }
                    else
                    {
                        if (builtIn.OverrideDefaultArgs)
                        {
                            startupArgs = Game.ExpandVariables(builtIn.CustomArguments, false, null, romPath);
                        }
                        else
                        {
                            startupArgs = Game.ExpandVariables(profileDef.StartupArguments, false, null, romPath);
                        }

                        if (!action.AdditionalArguments.IsNullOrEmpty())
                        {
                            startupArgs += " " + Game.ExpandVariables(action.AdditionalArguments, false, emulator.InstallDir, romPath);
                        }
                    }

                    StartEmulatorProcess(startupPath, startupArgs, startupDir, asyncExec);
                }
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Beispiel #23
0
 public static void DeleteProfile(EmulatorProfile emulatorProfile)
 {
     dbExecute("DELETE FROM EmulatorProfiles WHERE uid=" + emulatorProfile.ID);
 }
Beispiel #24
0
 public static List <IGame> SearchForGames(string path, EmulatorProfile profile)
 {
     return(SearchForGames(new DirectoryInfo(path), profile));
 }
Beispiel #25
0
 public static Process ActivateAction(GameAction action, Game gameData, EmulatorProfile config) =>
 (Process)activateActionProxy.Invoke(null, new object[] { action, gameData, config });