public void SearchForEmulatorsTest() { var defs = EmulatorDefinition.GetDefinitions(); var emulators = EmulatorFinder.SearchForEmulators(@"d:\Emulators\", defs); CollectionAssert.IsNotEmpty(emulators); }
public LiteDatabase OpenDatabase() { if (string.IsNullOrEmpty(Path)) { throw new Exception("Database path cannot be empty."); } var dbExists = File.Exists(Path); logger.Info("Opening db " + Path); CloseDatabase(); Database = new LiteDatabase($"Filename={Path};Mode=Exclusive"); // To force litedb to try to open file, should throw exceptuion if something is wrong with db file Database.GetCollectionNames(); if (!dbExists) { Database.Engine.UserVersion = DBVersion; } else { if (Database.Engine.UserVersion > DBVersion) { throw new Exception($"Database version {Database.Engine.UserVersion} is not supported."); } if (GetMigrationRequired(Database)) { throw new Exception("Database must be migrated before opening."); } } GamesCollection = Database.GetCollection <IGame>("games"); PlatformsCollection = Database.GetCollection <Platform>("platforms"); EmulatorsCollection = Database.GetCollection <Emulator>("emulators"); if (!dbExists) { GamesCollection.EnsureIndex(a => a.Id); PlatformsCollection.EnsureIndex(a => a.Id); EmulatorsCollection.EnsureIndex(a => a.Id); // Generate default platforms if (File.Exists(EmulatorDefinition.DefinitionsPath)) { var platforms = EmulatorDefinition.GetDefinitions() .SelectMany(a => a.Profiles.SelectMany(b => b.Platforms)).Distinct() .Select(a => new Platform(a)).ToList(); AddPlatform(platforms); } } DatabaseOpened?.Invoke(this, null); IsOpen = true; return(Database); }
public void SearchForGames() { var def = EmulatorDefinition.GetDefinitions().First(a => a.Name == "PCSX2"); var emulator = new Emulator("Test") { ImageExtensions = def.ImageExtensions }; var games = EmulatorFinder.SearchForGames(@"d:\Emulators\_Games\PS2\", emulator); CollectionAssert.IsNotEmpty(games); }
public async Task SearchForGamesTest() { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { @"c:\EmulatedGames\PS2\Devil May Cry 3.iso", MockFileData.NullObject }, { @"c:\EmulatedGames\PS2\Silen Hill 2.iso", MockFileData.NullObject }, { @"c:\EmulatedGames\PS2\Summoner 2.iso", MockFileData.NullObject }, { @"c:\EmulatedGames\PS2\WRC II Extreme.iso", MockFileData.NullObject } }); var dirInfo = new MockDirectoryInfo(fileSystem, @"c:\EmulatedGames\"); var def = EmulatorDefinition.GetDefinitions().First(a => a.Name == "PCSX2"); var games = await EmulatorFinder.SearchForGames(dirInfo, def.Profiles.First().ToEmulatorConfig()); Assert.AreEqual(4, games.Count); }
public async Task SearchForEmulatorsTest() { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { @"c:\Emulators\WiiU\cemu_1.10.0\Cemu.exe", MockFileData.NullObject }, { @"c:\Emulators\Genesis\Fusion364\Fusion.exe", MockFileData.NullObject }, { @"c:\Emulators\PSP\PPSSPP\PPSSPPWindows.exe", MockFileData.NullObject }, { @"c:\Emulators\GameCube_Wii\Dolphin\Dolphin.exe", MockFileData.NullObject } }); var dirInfo = new MockDirectoryInfo(fileSystem, @"c:\Emulators\"); var defs = EmulatorDefinition.GetDefinitions(); var emulators = await EmulatorFinder.SearchForEmulators(dirInfo, defs); Assert.AreEqual(4, emulators.Count); }
public async Task SearchForGamesTest() { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { @"c:\EmulatedGames\PS2\Devil May Cry 3.iso", MockFileData.NullObject }, { @"c:\EmulatedGames\PS2\Silen Hill 2.iso", MockFileData.NullObject }, { @"c:\EmulatedGames\PS2\Summoner 2.iso", MockFileData.NullObject }, { @"c:\EmulatedGames\PS2\WRC II Extreme.ISO", MockFileData.NullObject }, { @"c:\EmulatedGames\PS2\Xenosaga Episode III - Also sprach Zarathustra (USA) (Disc 1).ISO.gz", MockFileData.NullObject } }); var dirInfo = new MockDirectoryInfo(fileSystem, @"c:\EmulatedGames\"); var def = EmulatorDefinition.GetDefinitions().First(a => a.Name == "PCSX2"); var games = await EmulatorFinder.SearchForGames(dirInfo, def.Profiles.First().ToEmulatorConfig()); Assert.AreEqual(5, games.Count); Assert.IsTrue(games[3].Name.EndsWith("Extreme")); Assert.IsTrue(games[4].Name.EndsWith("Zarathustra")); }
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(); } }
public void GetDefinitionsTest() { var defs = EmulatorDefinition.GetDefinitions(); CollectionAssert.IsNotEmpty(defs); }