예제 #1
0
        public async Task AddGamepadAsyncMappings_Test()
        {
            var stoneProvider = new StoneProvider();

            foreach (var testmappings in stoneProvider.Controllers.Values)
            {
                var mapcol = new ControllerElementMappingProfile("Keyboard",
                                                                 "TEST_CONTROLLER",
                                                                 InputDriver.Keyboard,
                                                                 IDeviceEnumerator.VirtualVendorID,
                                                                 new XInputDeviceInstance(0).DefaultLayout);

                var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();
                optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");

                var elementStore = new ControllerElementMappingProfileStore(optionsBuilder);

                await elementStore.AddMappingsAsync(mapcol, "default");

                var retStore = await elementStore.GetMappingsAsync(mapcol.ProfileGuid);

                foreach (var element in retStore)
                {
                    Assert.Contains(element.LayoutElement, mapcol.Select(x => x.LayoutElement));
                    Assert.Equal(element.DeviceCapability,
                                 mapcol.First(x => x.LayoutElement == element.LayoutElement).DeviceCapability);
                }
            }
        }
예제 #2
0
        public void EmulatorPropertiesCreation_Tests()
        {
            var stone       = new StoneProvider();
            var pluginProps = new Mock <IPluginProperties>();

            pluginProps.Setup(p => p.GetEnumerable("capabilities"))
            .Returns(new[] { "testcapability", "testcapability2" });
            pluginProps.Setup(p => p.GetEnumerable("mimetypes"))
            .Returns(new[] { "application/vnd.stone-romfile.nintendo.snes" });
            pluginProps.Setup(p => p.Get("saveformat"))
            .Returns("test-sram");
            pluginProps.Setup(p => p.GetEnumerable("optionalbios"))
            .Returns(new[] { "BS-X.bin" });
            pluginProps.Setup(p => p.GetEnumerable("requiredbios"))
            .Returns(new[] { "cx4.data.rom" });
            var pluginProvision = new Mock <IPluginProvision>();

            pluginProvision.Setup(p => p.Properties)
            .Returns(pluginProps.Object);

            IEmulatorProperties emulatorProps = new EmulatorProperties(pluginProvision.Object, stone);

            Assert.Contains("testcapability", emulatorProps.SpecialCapabilities);
            Assert.Contains("testcapability2", emulatorProps.SpecialCapabilities);
            Assert.Contains("application/vnd.stone-romfile.nintendo.snes", emulatorProps.Mimetypes);
            Assert.Equal("test-sram", emulatorProps.SaveFormat);
            Assert.Equal("fed4d8242cfbed61343d53d48432aced", emulatorProps.OptionalSystemFiles.First().Md5Hash);
            Assert.Equal("037ac4296b6b6a5c47c440188d3c72e3", emulatorProps.RequiredSystemFiles.First().Md5Hash);
        }
예제 #3
0
        public void GetMultipleMappings_Test()
        {
            var stoneProvider = new StoneProvider();

            foreach (var testmappings in stoneProvider.Controllers.Values)
            {
                var mapcol = new ControllerElementMappingProfile("Keyboard",
                                                                 "TEST_CONTROLLER",
                                                                 InputDriver.Keyboard,
                                                                 IDeviceEnumerator.VirtualVendorID,
                                                                 new XInputDeviceInstance(0).DefaultLayout);
                var mapcol2 = new ControllerElementMappingProfile("Keyboard",
                                                                  "TEST_CONTROLLER",
                                                                  InputDriver.Keyboard,
                                                                  IDeviceEnumerator.VirtualVendorID,
                                                                  new XInputDeviceInstance(0).DefaultLayout);

                var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();
                optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
                var elementStore = new ControllerElementMappingProfileStore(optionsBuilder);

                elementStore.AddMappings(mapcol, "default");
                elementStore.AddMappings(mapcol2, "default2");

                Assert.Equal(2, elementStore.GetProfileNames(mapcol.ControllerID, InputDriver.Keyboard, mapcol.DeviceName,
                                                             IDeviceEnumerator.VirtualVendorID)
                             .Count());
                elementStore.DeleteMappings(mapcol.ProfileGuid);
                Assert.Single(elementStore.GetProfileNames(mapcol.ControllerID, InputDriver.Keyboard, mapcol.DeviceName,
                                                           IDeviceEnumerator.VirtualVendorID));
                elementStore.DeleteMappings(mapcol.ControllerID, mapcol.DeviceName, IDeviceEnumerator.VirtualVendorID);
                Assert.Empty(elementStore.GetProfileNames(mapcol.ControllerID, InputDriver.Keyboard, mapcol.DeviceName,
                                                          IDeviceEnumerator.VirtualVendorID));
            }
        }
예제 #4
0
        public void AddGamepadMappings_Test()
        {
            var stoneProvider = new StoneProvider();

            foreach (var testmappings in stoneProvider.Controllers.Values)
            {
                var realmapping =
                    JsonConvert.DeserializeObject <ControllerLayout>(
                        TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
                var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);

                var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();
                optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");

                var elementStore = new ControllerElementMappingsStore(optionsBuilder);

                elementStore.AddMappings(mapcol, "default");

                var retStore = elementStore.GetMappings(mapcol.ControllerId, mapcol.DeviceId, "default");

                foreach (var element in retStore)
                {
                    Assert.Contains(element.LayoutElement, mapcol.Select(x => x.LayoutElement));
                    Assert.Equal(element.DeviceElement,
                                 mapcol.First(x => x.LayoutElement == element.LayoutElement).DeviceElement);
                }
            }
        }
예제 #5
0
        public async Task DeleteMappingsAsync_Test()
        {
            var stoneProvider = new StoneProvider();

            foreach (var testmappings in stoneProvider.Controllers.Values)
            {
                var mapcol = new ControllerElementMappingProfile("Keyboard",
                                                                 "TEST_CONTROLLER",
                                                                 InputDriver.Keyboard,
                                                                 IDeviceEnumerator.VirtualVendorID,
                                                                 new XInputDeviceInstance(0).DefaultLayout);

                var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();
                optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
                var elementStore = new ControllerElementMappingProfileStore(optionsBuilder);

                await elementStore.AddMappingsAsync(mapcol, "default");

                var retStore = await elementStore.GetMappingsAsync(mapcol.ProfileGuid);

                Assert.NotNull(retStore);
                await elementStore.DeleteMappingsAsync(mapcol.ProfileGuid);

                var deletedRetStore = elementStore.GetMappings(mapcol.ProfileGuid);
                Assert.Null(deletedRetStore);
            }
        }
예제 #6
0
        public void GetMultipleMappings_Test()
        {
            var stoneProvider = new StoneProvider();

            foreach (var testmappings in stoneProvider.Controllers.Values)
            {
                var realmapping =
                    JsonConvert.DeserializeObject <ControllerLayout>(
                        TestUtilities.GetStringResource("InputMappings.keyboard_device.json"));
                var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);

                var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();
                optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
                var elementStore = new ControllerElementMappingsStore(optionsBuilder);

                elementStore.AddMappings(mapcol, "default");
                elementStore.AddMappings(mapcol, "default2");

                Assert.Equal(2, elementStore.GetMappings(mapcol.ControllerId, mapcol.DeviceId).Count());
                elementStore.DeleteMappings(mapcol.ControllerId, mapcol.DeviceId, "default");
                Assert.Single(elementStore.GetMappings(mapcol.ControllerId, mapcol.DeviceId));
                elementStore.DeleteMappings(mapcol.ControllerId, mapcol.DeviceId);
                Assert.Empty(elementStore.GetMappings(mapcol.ControllerId, mapcol.DeviceId));
            }
        }
예제 #7
0
        public void InputTemplateToAbstractConfigurationNodeXmlSerializer_Test()
        {
            var testmappings = new StoneProvider().Controllers["XBOX_CONTROLLER"];
            var realmapping  =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
            var           mapcol   = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);
            string        _mapping = TestUtilities.GetStringResource("InputMappings.DirectInput.XINPUT_DEVICE.json");
            IInputMapping mapping  = JsonConvert.DeserializeObject <InputMapping>(_mapping);
            var           input    =
                new InputTemplate <IRetroArchInput>(mapcol).Template;


            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var context = new ConfigurationTraversalContext();

            var list = context.TraverseInputTemplate(input, mapping, 0);

            var xmlSerializer = new SimpleXmlConfigurationSerializer("Config");

            string    outputXml = xmlSerializer.Transform(list);
            XDocument doc       = XDocument.Parse(outputXml);

            Assert.NotEmpty(doc.Nodes());
        }
예제 #8
0
        public void StoneLoad_Test()
        {
            var stone = new StoneProvider();

            Assert.NotEmpty(stone.Controllers);
            Assert.NotEmpty(stone.Platforms);
            Assert.NotNull(stone.StoneVersion);
        }
예제 #9
0
        public void ControllerElementMappingActualLayout_Test()
        {
            var stone  = new StoneProvider();
            var nes    = stone.Controllers["NES_CONTROLLER"];
            var mapcol = new ControllerElementMappingProfile("Keyboard",
                                                             nes,
                                                             InputDriver.Keyboard,
                                                             IDeviceEnumerator.VirtualVendorID,
                                                             new KeyboardDeviceInstance().DefaultLayout);

            Assert.Equal(DeviceCapability.None, mapcol[ControllerElement.Button0]);
            Assert.Equal(nes.Layout.Count(), mapcol.Count());
        }
예제 #10
0
        public void NestedSetter_Test()
        {
            var stoneProvider = new StoneProvider();
            var testmappings  = stoneProvider.Controllers.First().Value;
            var realmapping   =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.keyboard_device.json"));
            var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);
            var x      = new InputTemplate <IRetroArchInput>(mapcol);

            x[ControllerElement.ButtonA] = ControllerElement.DirectionalS;
            Assert.Equal(ControllerElement.DirectionalS, x.Template.Configuration.InputPlayerABtn);
        }
예제 #11
0
        public void DefaultMappedElementCollection_Test()
        {
            var testmappings = new StoneProvider().Controllers.First().Value;
            var realmapping  =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
            var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);

            foreach (var controllerElem in from elem in mapcol
                     where elem.DeviceElement != ControllerElement.NoElement
                     select elem.DeviceElement)
            {
                Assert.NotNull(realmapping.Layout[controllerElem]);
            }
        }
예제 #12
0
        public void GetProfileNames_Test()
        {
            var stoneProvider = new StoneProvider();
            var testmappings  = stoneProvider.Controllers.First().Value;
            var realmapping   =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
            var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);

            var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();

            optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
            var elementStore = new ControllerElementMappingsStore(optionsBuilder);

            elementStore.AddMappings(mapcol, "default");
        }
예제 #13
0
        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());
        }
예제 #14
0
        public void VerifyStoneProvider_Test(Type fileSignature, string filename)
        {
            using var testStream = TestUtilities.GetResource($"TestRoms.{filename}");
            IFileSignature signature = (IFileSignature)Activator.CreateInstance(fileSignature);

            Assert.True(signature.HeaderSignatureMatches(testStream));

            IStoneProvider stone = new StoneProvider();

            testStream.Seek(0, SeekOrigin.Begin);
            string mimetype = stone.GetStoneMimetype(testStream);

            Assert.NotEqual(String.Empty, mimetype);

            var stoneSigs = stone.GetSignatures(mimetype);

            Assert.Contains(stoneSigs, s => s.HeaderSignatureMatches(testStream));
        }
예제 #15
0
        public void IniSerialize_Test()
        {
            var           serializer   = new IniConfigurationSerializer(new BooleanMapping("true", "false"), "nul");
            string        _mapping     = TestUtilities.GetStringResource("InputMappings.DirectInput.XINPUT_DEVICE.json");
            IInputMapping mapping      = JsonConvert.DeserializeObject <InputMapping>(_mapping);
            var           testmappings = new StoneProvider().Controllers.First().Value;
            var           realmapping  =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
            var    mapcol          = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);
            var    template        = new InputTemplate <IRetroArchInput>(mapcol, 0);
            string serializedValue = new InputSerializer(serializer).Serialize(template, mapping)
                                     .Replace(Environment.NewLine, string.Empty);

            Assert.Equal(
                TestUtilities.GetStringResource("Configurations.ExampleInput.ini")
                .Replace(Environment.NewLine, string.Empty),
                serializedValue);
        }
예제 #16
0
        public async Task UpdateMappedInputCollectionGamepadAsync_Test()
        {
            var stoneProvider = new StoneProvider();

            foreach (var testmappings in stoneProvider.Controllers.Values)
            {
                var mapcol = new ControllerElementMappingProfile("Keyboard",
                                                                 "TEST_CONTROLLER",
                                                                 InputDriver.Keyboard,
                                                                 IDeviceEnumerator.VirtualVendorID,
                                                                 new XInputDeviceInstance(0).DefaultLayout);

                var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();
                optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");

                var elementStore = new ControllerElementMappingProfileStore(optionsBuilder);

                await elementStore.AddMappingsAsync(mapcol, "default");

                // map buttonA to buttonB.
                mapcol[ControllerElement.ButtonA] = DeviceCapability.Button1;
                elementStore.UpdateMappings(mapcol);

                mapcol[ControllerElement.ButtonB] = DeviceCapability.Axis0Positive;
                elementStore.UpdateMappings(mapcol);

                var retStore = await elementStore.GetMappingsAsync(mapcol.ProfileGuid);

                foreach (var element in retStore)
                {
                    Assert.Contains(element.LayoutElement, mapcol.Select(x => x.LayoutElement));
                    Assert.Equal(element.DeviceCapability,
                                 mapcol.First(x => x.LayoutElement == element.LayoutElement).DeviceCapability);
                }

                // Switch left joycon has no A button
                if (testmappings.Layout[ControllerElement.ButtonA] != null)
                {
                    Assert.Equal(DeviceCapability.Button1, retStore[ControllerElement.ButtonA]);
                }
            }
        }
예제 #17
0
        public void InputTemplateToAbstractConfigurationNode_Test()
        {
            var testmappings = new StoneProvider().Controllers["XBOX_CONTROLLER"];
            var realmapping  =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
            var           mapcol   = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);
            string        _mapping = TestUtilities.GetStringResource("InputMappings.DirectInput.XINPUT_DEVICE.json");
            IInputMapping mapping  = JsonConvert.DeserializeObject <InputMapping>(_mapping);
            var           input    =
                new InputTemplate <IRetroArchInput>(mapcol).Template;

            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var context = new ConfigurationTraversalContext(("game", dir));
            var node    = context.TraverseInputTemplate(input, mapping, 0);
        }
예제 #18
0
        public void UpdateMappedInputCollectionGamepad_Test()
        {
            var stoneProvider = new StoneProvider();

            foreach (var testmappings in stoneProvider.Controllers.Values)
            {
                var realmapping =
                    JsonConvert.DeserializeObject <ControllerLayout>(
                        TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
                var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);

                var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();
                optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");

                var elementStore = new ControllerElementMappingsStore(optionsBuilder);

                elementStore.AddMappings(mapcol, "default");

                // map buttonA to buttonB.
                mapcol[ControllerElement.ButtonA] = ControllerElement.ButtonB;

                elementStore.UpdateMappings(mapcol, "default");
                var retStore = elementStore.GetMappings(mapcol.ControllerId, mapcol.DeviceId, "default");

                foreach (var element in retStore)
                {
                    Assert.Contains(element.LayoutElement, mapcol.Select(x => x.LayoutElement));
                    Assert.Equal(element.DeviceElement,
                                 mapcol.First(x => x.LayoutElement == element.LayoutElement).DeviceElement);
                }

                // Switch left joycon has no A button
                if (testmappings.Layout[ControllerElement.ButtonA] != null)
                {
                    Assert.Equal(ControllerElement.ButtonB, retStore[ControllerElement.ButtonA]);
                }
            }
        }
예제 #19
0
        static void Main(string[] args)
        {
            var stone = new StoneProvider();

            Console.WriteLine("Using Stone Platforms v" + stone.StoneVersion);

            IEnumerable <RomInfo>    datInfos      = new List <RomInfo>();
            IEnumerable <SerialInfo> serialInfos   = new List <SerialInfo>();
            IEnumerable <string>     mameFilenames = new List <string>();

            if (!Directory.Exists("PlatformDats"))
            {
                Console.WriteLine("PlatformDats folder does not exist.. Creating Directory Structure");
                Directory.CreateDirectory("PlatformDats");
                foreach (var platform in stone.Platforms)
                {
                    Directory.CreateDirectory(Path.Combine("PlatformDats", platform.Key));
                }
            }

            if (File.Exists(Path.Combine("PlatformDats", "openvgdb.sqlite")))
            {
                Console.WriteLine("OpenVGDB Found. Parsing...");
                var openvgdb = new OpenVgdb(Path.Combine("PlatformDats", "openvgdb.sqlite"));
                serialInfos   = serialInfos.Concat(openvgdb.GetSerialInfos().ToList());
                datInfos      = datInfos.Concat(openvgdb.GetDatInfos().ToList());
                mameFilenames = mameFilenames.Concat(openvgdb.GetMameFiles().ToList());
            }

            foreach (string platformId in stone.Platforms.Select(p => p.Key))
            {
                if (!Directory.Exists(Path.Combine("PlatformDats", platformId)))
                {
                    continue;
                }

                foreach (string file in Directory.EnumerateFiles(Path.Combine("PlatformDats", platformId)))
                {
                    Console.Write(platformId + " found: " + Path.GetFileName(file));
                    if (Path.GetExtension(file) == ".idlist")
                    {
                        Console.WriteLine(" is type of ID List");

                        serialInfos = serialInfos.Concat(IdlistParser.ParseSerials(file, platformId));
                        continue;
                    }

                    switch (DatParser.GetParser(File.ReadLines(file).First()))
                    {
                    case ParserClass.Cmp:
                        Console.WriteLine(" is type of ClrMamePro");
                        serialInfos = serialInfos.Concat(CmpParser.ParseSerials(file, platformId));
                        datInfos    = datInfos.Concat(CmpParser.Parse(file, platformId));
                        continue;

                    case ParserClass.Tdb:
                        Console.WriteLine(" is type of GameTDB");
                        serialInfos = serialInfos.Concat(GameTdbParser.ParseSerials(file, platformId));
                        continue;

                    case ParserClass.Xml:
                        Console.WriteLine(" is type of Logiqix XML");
                        datInfos = datInfos.Concat(XmlParser.Parse(file, platformId));
                        continue;

                    default:
                        Console.WriteLine(" is invalid.");
                        continue;
                    }
                }
            }

            Console.WriteLine("Generating shiragame.db ...");
            var memoryDb = new ShiragameDb();

            if (!Directory.Exists("out"))
            {
                Directory.CreateDirectory("out");
            }

            var diskDb = new SqliteDatabase("out\\shiragame.db");

            memoryDb.Commit(datInfos.ToList());
            memoryDb.Commit(serialInfos.DistinctBy(x => new { x.PlatformId, x.Serial }).ToList());
            memoryDb.Commit(mameFilenames.ToList());
            memoryDb.SaveTo(diskDb); // todo fix online backup API
        }