public void Compose(IModule module, Loader.IServiceRepository serviceContainer) { var physicalFs = serviceContainer.Get <IFileSystem>(); var contentDirectory = serviceContainer.Get <IContentDirectoryProvider>(); string sqlitePath = Path.Combine(contentDirectory.ApplicationData.FullName, "library.db"); var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>(); optionsBuilder .UseSqlite($"Data Source={sqlitePath}"); using (var context = new DatabaseContext(optionsBuilder.Options)) { var connection = context.Database.GetDbConnection(); connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = "PRAGMA journal_mode=WAL;"; command.ExecuteNonQuery(); } } // game library dependency tree var gameRecordLibrary = new GameRecordLibrary(optionsBuilder); var gameLibrary = new GameLibrary(gameRecordLibrary); var configStore = new ConfigurationCollectionStore(optionsBuilder); var fileLibrary = new FileRecordLibrary(optionsBuilder); var appDataPath = physicalFs.ConvertPathFromInternal(contentDirectory.ApplicationData.FullName); var gameFs = physicalFs.GetOrCreateSubFileSystem(appDataPath / "games"); // Add default extensions gameLibrary.AddExtension <IGameFileExtensionProvider, IGameFileExtension>(new GameFileExtensionProvider(fileLibrary, gameFs)); gameLibrary.AddExtension <IGameConfigurationExtensionProvider, IGameConfigurationExtension>(new GameConfigurationExtensionProvider(configStore)); // register game library. serviceContainer.Get <IServiceRegistrationProvider>() .RegisterService <IGameLibrary>(gameLibrary); var pluginLibrary = new PluginConfigurationStore(optionsBuilder); // plugin config store serviceContainer.Get <IServiceRegistrationProvider>() .RegisterService <IPluginConfigurationStore>(pluginLibrary); // controller elements var inputStore = new ControllerElementMappingsStore(optionsBuilder); serviceContainer.Get <IServiceRegistrationProvider>() .RegisterService <IControllerElementMappingsStore>(inputStore); }
public async Task TestCopyInstaller_IntegrationTest() { using var testStream = TestUtilities.GetResource("TestRoms.test.nes"); using var fileStream = File.Create(Path.GetTempFileName() + ".nes"); await testStream.CopyToAsync(fileStream); string fname = fileStream.Name; fileStream.Dispose(); var path = new DirectoryInfo(Path.GetTempPath()) .CreateSubdirectory(Path.GetFileNameWithoutExtension(Path.GetTempFileName())); var fs = new PhysicalFileSystem(); var gfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(path.FullName)); var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>(); optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}"); var glib = new GameRecordLibrary(optionsBuilder); var flib = new FileRecordLibrary(optionsBuilder); var gl = new GameLibrary(glib); gl.AddExtension <GameFileExtensionProvider, IGameFileExtension >(new GameFileExtensionProvider(flib, gfs)); var game = gl.CreateGame("NINTENDO_NES"); var stone = new StoneProvider(); var install = new SingleFileCopyInstaller(stone); var installables = install.GetInstallables("NINTENDO_NES", new List <FileSystemInfo>() { new FileInfo(fname) }); Assert.True(installables.Select(i => i.Source).All(i => i == install.Name)); foreach (var i in installables) { await foreach (var res in install.Install(game, i.Artifacts)) { } } Assert.NotEmpty(game.WithFiles().GetFileRecords()); }
public async Task GameLibraryIntegrationConfigAsync_Test() { var path = new DirectoryInfo(Path.GetTempPath()) .CreateSubdirectory(Path.GetFileNameWithoutExtension(Path.GetTempFileName())); var fs = new PhysicalFileSystem(); var gfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(path.FullName)); var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>(); optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}"); var glib = new GameRecordLibrary(optionsBuilder); var ccs = new ConfigurationCollectionStore(optionsBuilder); var gl = new GameLibrary(glib); gl.AddExtension <IGameConfigurationExtensionProvider, IGameConfigurationExtension> (new GameConfigurationExtensionProvider(ccs)); var game = await gl.CreateGameAsync("NINTENDO_NES"); var profile = await game.WithConfigurations() .CreateNewProfileAsync <ExampleConfigurationCollection>("TestConfiguration", "test"); var profileGuid = profile.CollectionGuid; Assert.NotNull(await game.WithConfigurations() .GetProfileAsync <ExampleConfigurationCollection>("TestConfiguration", profileGuid)); Assert.NotEmpty(game.WithConfigurations().GetProfileNames()); profile.Configuration.ExampleConfiguration.FullscreenResolution = Configuration.FullscreenResolution.Resolution1600X1050; await gl.WithConfigurationLibrary().UpdateProfileAsync(profile); var newProfile = await game.WithConfigurations() .GetProfileAsync <ExampleConfigurationCollection>("TestConfiguration", profileGuid); Assert.Equal(Configuration.FullscreenResolution.Resolution1600X1050, newProfile.Configuration.ExampleConfiguration.FullscreenResolution); await game.WithConfigurations().DeleteProfileAsync("TestConfiguration", profileGuid); Assert.Empty(game.WithConfigurations().GetProfileNames()); }
public async Task GameLibraryIntegrationUpdateAsync_Test() { var path = new DirectoryInfo(Path.GetTempPath()) .CreateSubdirectory(Path.GetFileNameWithoutExtension(Path.GetTempFileName())); var fs = new PhysicalFileSystem(); var gfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(path.FullName)); var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>(); optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}"); var glib = new GameRecordLibrary(optionsBuilder); var flib = new FileRecordLibrary(optionsBuilder); var gl = new GameLibrary(glib); gl.AddExtension <GameFileExtensionProvider, IGameFileExtension >(new GameFileExtensionProvider(flib, gfs)); var game = await gl.CreateGameAsync("NINTENDO_NES"); game.Record.Title = "My Awesome Game"; await gl.UpdateGameRecordAsync(game.Record); var file = game.WithFiles().MiscRoot.OpenFile("Test.txt"); file.OpenStream().Close(); await game.WithFiles().RegisterFileAsync(file, "application/text"); var record = await game.WithFiles().GetFileInfoAsync(file); record.Metadata.Add("file_metadata", "test"); await gl.GetExtension <GameFileExtensionProvider>().UpdateFileAsync(record); var newGame = await gl.GetGameAsync(game.Record.RecordID); Assert.False(await newGame.WithFiles().GetFileRecordsAsync().IsEmptyAsync()); }