public async Task WatchesForChangesInTheGraphicsConfigurationFiles() { using var dirMain = new TestFolder(_gif.FullName); using var dirOpts = new TestFolder(_gof.FullName); using var watcher = new GraphicsConfigWatcher(new GameInstallFolder(dirMain.Name), new GameOptionsFolder(dirOpts.Name)); watcher.Start(); var evs = new EventCollector <GraphicsConfig>(h => watcher.Changed += h, h => watcher.Changed -= h); var xmlMain = dirMain.ReadText(_mainFile); var config = await evs.WaitAsync(() => dirMain.WriteText(_mainFile, string.Empty), 100).ConfigureAwait(false); Assert.Null(config); config = await evs.WaitAsync(() => dirMain.WriteText(_mainFile, xmlMain)).ConfigureAwait(false); Assert.Equal(0, config.GuiColour.Default[0, 0]); config = await evs.WaitAsync(() => dirOpts.WriteText(_overrideFile, string.Empty), 100).ConfigureAwait(false); Assert.Null(config); config = await evs.WaitAsync(() => dirOpts.WriteText(_overrideFile, _minimalConfig)).ConfigureAwait(false); Assert.Equal(1, config.GuiColour.Default[0, 0]); }
internal GameStateWatcher(string gameInstallFolder, string gameOptionsFolder, string journalFolder, INativeMethods nativeMethods) { var gif = new GameInstallFolder(gameInstallFolder); var gof = new GameOptionsFolder(gameOptionsFolder); var jf = new JournalFolder(journalFolder); _journalWatcher = new JournalWatcher(jf); _journalWatcher.Started += JournalWatcher_Started; _journalWatcher.EntryAdded += JournalWatcher_EntryAdded; _statusWatcher = new StatusWatcher(jf); _statusWatcher.Changed += StatusWatcher_Changed; _bindingsWatcher = new BindingsWatcher(gif, gof); _bindingsWatcher.Changed += BindingsWatcher_Changed; _graphicsConfig = new GraphicsConfigWatcher(gif, gof); _graphicsConfig.Changed += GraphicsConfig_Changed; _modifierKeysWatcher = new ModifierKeysWatcher(nativeMethods); _modifierKeysWatcher.Changed += ModifierKeysWatcher_Changed; _gameProcessWatcher = new GameProcessWatcher(gif, nativeMethods); _gameProcessWatcher.Changed += GameProcessWatcher_Changed; _gameState = new GameState(); }
public void WatcherThrowsWhenTheGameOptionsFolderIsNotAValidOptionsFolder() { Assert.Throws <ArgumentNullException>(() => { using var x = new GraphicsConfigWatcher(_gif, null); }); var ex = Assert.Throws <ArgumentException>(() => { using var x = new GraphicsConfigWatcher(_gif, new GameOptionsFolder(@"TestFiles")); }); Assert.Contains("' is not a valid Elite:Dangerous game options folder.", ex.Message, StringComparison.Ordinal); }
public void WatcherDoesNotThrowWhenDisposingTwice() { var watcher = new GraphicsConfigWatcher(_gif, _gof); #pragma warning disable IDISP016, IDISP017 watcher.Dispose(); watcher.Dispose(); #pragma warning restore IDISP016, IDISP017 }
public async Task WatcherRaisesTheChangedEventOnStart() { using var watcher = new GraphicsConfigWatcher(_gif, _gof); var evs = new EventCollector <GraphicsConfig>(h => watcher.Changed += h, h => watcher.Changed -= h); var config = await evs.WaitAsync(() => { watcher.Start(); watcher.Stop(); }).ConfigureAwait(false); Assert.Null(config.GuiColour.Default.LocalisationName); }
public async Task WatcherToleratesEmptyGraphicsConfigurationOverrideFiles() { using var dirOpts = new TestFolder(_gof.FullName); dirOpts.WriteText(_overrideFile, string.Empty); using var watcher = new GraphicsConfigWatcher(_gif, new GameOptionsFolder(dirOpts.Name)); var evs = new EventCollector <GraphicsConfig>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(WatcherRaisesTheChangedEventOnStart)); var config = await evs.WaitAsync(() => { watcher.Start(); watcher.Stop(); }).ConfigureAwait(false); Assert.Equal("Standard", config.GuiColour.Default.LocalisationName); }
public void StartAndStopAreNotReentrant() { using var watcher = new GraphicsConfigWatcher(_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()); }