public void RaisesEventsForEachGameStateChange()
        {
            var expected = new[]
            {
                ChangeType.StatusEntry,
                ChangeType.BindingPreset,
                ChangeType.GraphicsConfig,
                ChangeType.DeviceKeySet,
                ChangeType.GameProcessState,
                ChangeType.JournalEntry,
                ChangeType.JournalEntry,
                ChangeType.JournalEntry,
                ChangeType.JournalDrain,
            };

            using var watcher = new GameStateWatcher(_gameRootFolder, _gameOptionsFolder, _journalFolder)
                  {
                      RaisePreStartupEvents = true,
                  };

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

            var events = evs.Wait(expected.Length, watcher.Start, 5000);

            watcher.Stop();

            var mismatches = expected.Except(events);

            Assert.Empty(mismatches);
        }
        public void WatcherDoesNotThrowWhenDisposingTwice()
        {
            var watcher = new GameStateWatcher(_gameRootFolder, _gameOptionsFolder, _journalFolder);

#pragma warning disable IDISP016, IDISP017
            watcher.Dispose();
            watcher.Dispose();
#pragma warning restore IDISP016, IDISP017
        }
Ejemplo n.º 3
0
        public async Task RaisesEventsForEachGameStateChange()
        {
            using var watcher = new GameStateWatcher(_gameRootFolder, _gameOptionsFolder, _journalFolder);
            var evs = new EventCollector <EventArgs>(h => watcher.Changed += h, h => watcher.Changed -= h);

            await evs.WaitAsync(10, watcher.Start, 5000).ConfigureAwait(false);

            watcher.Stop();
        }
Ejemplo n.º 4
0
        public void RaisesEventsForEachGameStateChange()
        {
            using var watcher = new GameStateWatcher(_gameRootFolder, _gameOptionsFolder, _journalFolder)
                  {
                      RaisePreStartupEvents = true,
                  };

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

            evs.Wait(8, watcher.Start, 5000);
            watcher.Stop();
        }
Ejemplo n.º 5
0
        public void EnUSOverrideIsAppliedInTheGameState()
        {
            using var watcher = new GameStateWatcher(_gameRootFolder, _gameOptionsFolder, _journalFolder);

            Assert.False(watcher.ForceEnUSKeyboardLayout);
            Assert.False(watcher.GetPrivateField <GameState>("_gameState").ForceEnUSKeyboardLayout);
            Assert.False(watcher.GetGameStateSnapshot().ForceEnUSKeyboardLayout);

            watcher.ForceEnUSKeyboardLayout = true;
            Assert.True(watcher.ForceEnUSKeyboardLayout);
            Assert.True(watcher.GetPrivateField <GameState>("_gameState").ForceEnUSKeyboardLayout);
            Assert.True(watcher.GetGameStateSnapshot().ForceEnUSKeyboardLayout);
        }
Ejemplo n.º 6
0
        public ChromaController(string gameInstallFolder, string gameOptionsFolder, string journalFolder)
        {
            _watcher          = new GameStateWatcher(gameInstallFolder, gameOptionsFolder, journalFolder);
            _watcher.Changed += GameState_Changed;

            _animation = new System.Timers.Timer
            {
                AutoReset = true,
                Enabled   = false,
            };
            _animation.Elapsed += Animation_Elapsed;
            AnimationFrameRate  = _defaultFps;

            _effect = InitChromaEffect(_watcher.GameState);
        }
        public void StartAndStopAreNotReentrant()
        {
            using var watcher = new GameStateWatcher(_gameRootFolder, _gameOptionsFolder, _journalFolder);

            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 OnChangedIsNotReentrant()
        {
            using var watcher = new GameStateWatcher(_gameRootFolder, _gameOptionsFolder, _journalFolder)
                  {
                      RaisePreStartupEvents = false,
                  };

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

            evs.Wait(watcher.Start, 5000);

            var nOnChangedCalls = 0;

            using var mre = new ManualResetEventSlim();

            watcher.Changed += (sender, e) =>
            {
                Interlocked.Increment(ref nOnChangedCalls);
                mre.Wait();
            };

            void OnChanged()
            {
                watcher.InvokePrivateMethod <object>("OnChanged", new object[] { null });
                mre.Set();
            }

            Task.WaitAll(new[]
            {
                Task.Run(OnChanged),
                Task.Run(OnChanged),
            });

            watcher.Stop();

            Assert.Equal(1, nOnChangedCalls);
        }