Example #1
0
        public async Task WatcherRaisesTheChangedEventOnStart()
        {
            using var watcher = new BindingsWatcher(_gif, _gof);
            var evs = new EventCollector <BindingPreset>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(WatcherRaisesTheChangedEventOnStart));

            var binds = await evs.WaitAsync(() =>
            {
                watcher.Start();
                watcher.Stop();
            }).ConfigureAwait(false);

            Assert.Null(binds.PresetName); // "Custom" and "Custom2" get merged to null.
            Assert.Equal(new Version(3, 0), binds.Version);
            Assert.Equal("es-ES", binds.KeyboardLayout);

            var k = binds.Bindings["Supercruise"].Primary;

            Assert.Equal("Keyboard", k.Device);
            Assert.Equal("Key_H", k.Key);
            Assert.Equal(2, k.Modifiers.Count);
            var modifiers = k.Modifiers.OrderBy(x => x.Key).ToList();

            Assert.Equal("Keyboard", modifiers[0].Device);
            Assert.Equal("Key_LeftAlt", modifiers[0].Key);
            Assert.Equal("Keyboard", modifiers[1].Device);
            Assert.Equal("Key_LeftShift", modifiers[1].Key);
        }
Example #2
0
        public void StartAndStopAreNotReentrant()
        {
            using var watcher = new BindingsWatcher(_gif, _gof);

            bool IsRunning() => watcher.GetPrivateField <bool>("_running");

            Assert.False(IsRunning());

            watcher.Start();
            Assert.True(IsRunning());

            watcher.Start();
            Assert.True(IsRunning());

            watcher.Stop();
            Assert.False(IsRunning());

            watcher.Stop();
            Assert.False(IsRunning());
        }
        public void Start()
        {
            if (_running)
            {
                return;
            }

            _running = true;

            _graphicsConfig.Start();
            _bindingsWatcher.Start();
            _statusWatcher.Start();
            _modifierKeysWatcher.Start();
            _journalWatcher.Start();

            if (DetectForegroundProcess)
            {
                _gameProcessWatcher.Start();
            }
        }
Example #4
0
        public async Task WatchesForChangesInTheBidingsFiles()
        {
            using var dirMain = new TestFolder(_gif.FullName);
            using var dirOpts = new TestFolder(_gof.FullName);
            using var watcher = new BindingsWatcher(new GameInstallFolder(dirMain.Name), new GameOptionsFolder(dirOpts.Name));
            watcher.Start();

            var evs = new EventCollector <BindingPreset>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(WatchesForChangesInTheBidingsFiles));

            var bindsCustom = dirOpts.ReadText(_customFile);

            var binds = await evs.WaitAsync(() => dirOpts.WriteText(_customFile, string.Empty), 100).ConfigureAwait(false);

            Assert.Null(binds);

            binds = await evs.WaitAsync(() => dirOpts.WriteText(_customFile, bindsCustom)).ConfigureAwait(false);

            Assert.NotNull(binds);

            binds = await evs.WaitAsync(() => dirOpts.WriteText(_startPresetFile, "Keyboard")).ConfigureAwait(false);

            Assert.NotNull(binds);
        }