From 83ebcd7de8896d59f02711fe8f3fc43743650c57 Mon Sep 17 00:00:00 2001 From: Drommedhar Date: Thu, 26 Sep 2024 15:34:27 +0200 Subject: [PATCH 1/6] Streamline games ui --- DlssUpdater/Views/Pages/GamesPage.xaml | 4 ++-- DlssUpdater/Views/Pages/GamesPage.xaml.cs | 26 +---------------------- DlssUpdater/changelog.md | 5 ++++- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/DlssUpdater/Views/Pages/GamesPage.xaml b/DlssUpdater/Views/Pages/GamesPage.xaml index f78ca59..ad4397a 100644 --- a/DlssUpdater/Views/Pages/GamesPage.xaml +++ b/DlssUpdater/Views/Pages/GamesPage.xaml @@ -112,9 +112,9 @@ - - diff --git a/DlssUpdater/Views/Pages/GamesPage.xaml.cs b/DlssUpdater/Views/Pages/GamesPage.xaml.cs index fe6c08a..48f887e 100644 --- a/DlssUpdater/Views/Pages/GamesPage.xaml.cs +++ b/DlssUpdater/Views/Pages/GamesPage.xaml.cs @@ -55,7 +55,7 @@ private async void GameButton_MouseLeftButtonDown(object sender, MouseButtonEven { if (sender is GameButton btn && btn.GameInfo is not null) { - if (btn.GameInfo != ViewModel.SelectedGame && !await ensureNewGameData()) return; + if (btn.GameInfo == ViewModel.SelectedGame) return; _newGameInfo = false; await btn.GameInfo.GatherInstalledVersions(); @@ -111,10 +111,6 @@ private async void btnPropsAdd_Click(object sender, RoutedEventArgs e) switch (updateResult) { - case DllUpdater.UpdateResult.NothingDone: - _snackbar.ShowEx("Installation", _newGameInfo ? "Added successfully" : "Nothing done", - ControlAppearance.Dark); - break; case DllUpdater.UpdateResult.Success: _snackbar.ShowEx("Installation", "DLLs were installed successfully!", ControlAppearance.Success); break; @@ -127,26 +123,6 @@ private async void btnPropsAdd_Click(object sender, RoutedEventArgs e) _gameContainer.DoUpdate(); } - private async Task ensureNewGameData() - { - if (gridProps.Visibility == Visibility.Visible) - { - var uiMessageBox = new MessageBox - { - Title = "Warning", - Content = "The currently open game has not been saved and changed data will be lost. Continue?", - SecondaryButtonText = "Yes", - CloseButtonText = "Cancel", - IsPrimaryButtonEnabled = false, - IsSecondaryButtonEnabled = true - }; - - return await uiMessageBox.ShowDialogAsync() == MessageBoxResult.Secondary; - } - - return true; - } - private void ButtonImage_Click(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new(); diff --git a/DlssUpdater/changelog.md b/DlssUpdater/changelog.md index c822493..81c8886 100644 --- a/DlssUpdater/changelog.md +++ b/DlssUpdater/changelog.md @@ -1,4 +1,7 @@ -# 1.0.2.0 +# 1.0.3.0 +* Streamline games ui (no unnecessary popups, easier readable buttons ) + +# 1.0.2.0 * Add notification icon if DLSS updates are available * If a specific type has no version installed, no notification will be shown, as not everyone will use Ray Reconstruction or Frame Gen * Show information if a game has an update available (in Navigation view and game itself) From fb58b70526d461c8d8599bf5673fdcd2803edce6 Mon Sep 17 00:00:00 2001 From: Drommedhar Date: Thu, 26 Sep 2024 17:35:10 +0200 Subject: [PATCH 2/6] Make libraries configurable --- DlssUpdater/Controls/LauncherPanel.xaml | 29 ++++++ DlssUpdater/Controls/LauncherPanel.xaml.cs | 77 ++++++++++++++++ DlssUpdater/Defines/GameInfo.cs | 9 +- DlssUpdater/Defines/LibraryConfig.cs | 91 +++++++++++++++++++ DlssUpdater/GameLibrary/ILibrary.cs | 22 ++++- DlssUpdater/GameLibrary/ManualLibrary.cs | 15 ++- DlssUpdater/GameLibrary/Steam/SteamLibrary.cs | 28 ++++-- .../GameLibrary/UbisoftConnectLibrary.cs | 30 ++++-- DlssUpdater/Settings.cs | 33 ++++++- DlssUpdater/Singletons/GameContainer.cs | 22 ++++- .../ViewModels/Pages/SettingsViewModel.cs | 5 + DlssUpdater/Views/Pages/SettingsPage.xaml | 25 ++++- .../Windows/Splashscreen/Splashscreen.xaml.cs | 1 + DlssUpdater/changelog.md | 3 +- 14 files changed, 351 insertions(+), 39 deletions(-) create mode 100644 DlssUpdater/Controls/LauncherPanel.xaml create mode 100644 DlssUpdater/Controls/LauncherPanel.xaml.cs create mode 100644 DlssUpdater/Defines/LibraryConfig.cs diff --git a/DlssUpdater/Controls/LauncherPanel.xaml b/DlssUpdater/Controls/LauncherPanel.xaml new file mode 100644 index 0000000..e2bd53d --- /dev/null +++ b/DlssUpdater/Controls/LauncherPanel.xaml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/DlssUpdater/Controls/LauncherPanel.xaml.cs b/DlssUpdater/Controls/LauncherPanel.xaml.cs new file mode 100644 index 0000000..5daf110 --- /dev/null +++ b/DlssUpdater/Controls/LauncherPanel.xaml.cs @@ -0,0 +1,77 @@ +using DlssUpdater.Defines; +using DlssUpdater.Singletons; +using DLSSUpdater.Defines; +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DlssUpdater.Controls +{ + /// + /// Interaction logic for LauncherPanel.xaml + /// + public partial class LauncherPanel : UserControl + { + public static readonly DependencyProperty LibraryConfigProperty = + DependencyProperty.Register("LibraryConfig", typeof(LibraryConfig), typeof(LauncherPanel)); + + public LibraryConfig LibraryConfig + { + get => (LibraryConfig)GetValue(LibraryConfigProperty); + set => SetValue(LibraryConfigProperty, value); + } + + private readonly Settings _settings; + private readonly GameContainer _gameContainer; + + public LauncherPanel() + { + InitializeComponent(); + + _settings = App.GetService()!; + _gameContainer = App.GetService()!; + + GridExpand.Visibility = Visibility.Visible; + } + + private async void ToggleSwitch_Click(object sender, RoutedEventArgs e) + { + _settings.Save(); + _gameContainer.UpdateLibraries(); + await _gameContainer.LoadGamesAsync(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + var libRef = _gameContainer.Libraries.FirstOrDefault(l => l.GetLibraryType() == LibraryConfig.LibraryType); + libRef?.GetInstallationDirectory(); + } + + private async void Button_Click_1(object sender, RoutedEventArgs e) + { + OpenFolderDialog dlg = new() + { + Multiselect = false + }; + if (dlg.ShowDialog() == true) + { + LibraryConfig.InstallPath = dlg.FolderName; + _settings.Save(); + _gameContainer.UpdateLibraries(); + await _gameContainer.LoadGamesAsync(); + } + } + } +} diff --git a/DlssUpdater/Defines/GameInfo.cs b/DlssUpdater/Defines/GameInfo.cs index 6ff7761..513b506 100644 --- a/DlssUpdater/Defines/GameInfo.cs +++ b/DlssUpdater/Defines/GameInfo.cs @@ -32,6 +32,7 @@ public partial class GameInfo : ObservableObject [JsonIgnore] public LibraryType LibraryType; [JsonIgnore] public readonly DllUpdater _updater; + [JsonIgnore] public readonly NLog.Logger _logger; public GameInfo(string gameName, string gamePath, LibraryType type) { @@ -45,6 +46,7 @@ public GameInfo(string gameName, string gamePath, LibraryType type) Self = this; HasAntiCheat = App.GetService()!.Check(gamePath); _updater = App.GetService()!; + _logger = App.GetService()!; GatherInstalledVersions().ConfigureAwait(true); } @@ -62,7 +64,12 @@ await Task.Run(() => foreach (var (dll, info) in InstalledDlls) { var allFiles = Directory.GetFiles(GamePath, GetDllName(dll), SearchOption.AllDirectories); - if (allFiles is null || allFiles.Length != 1) continue; + _logger.Debug($"Found '{allFiles?.Length.ToString() ?? "0"} files' for {GetDllName(dll)} in {GameName}"); + if (allFiles is null || allFiles.Length == 0) + { + continue; + } + // TODO: Support for multiple instances of the same dll? // We only should have one entry info.Path = allFiles[0]; diff --git a/DlssUpdater/Defines/LibraryConfig.cs b/DlssUpdater/Defines/LibraryConfig.cs new file mode 100644 index 0000000..cb82e49 --- /dev/null +++ b/DlssUpdater/Defines/LibraryConfig.cs @@ -0,0 +1,91 @@ +using DlssUpdater.Defines; +using DlssUpdater.GameLibrary; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Text.Json; +using System.Threading.Tasks; +using DLSSUpdater.Defines; + +namespace DLSSUpdater.Defines +{ + public partial class LibraryConfig : ObservableObject + { + public LibraryType LibraryType { get; set; } + + [ObservableProperty] + private bool _isChecked; + + [ObservableProperty] + private string _libraryName; + + [ObservableProperty] + private string _installPath; + + [ObservableProperty][JsonIgnore] public LibraryConfig _self; + + public LibraryConfig(LibraryType type, string name) + { + LibraryType = type; + _libraryName = name; + _installPath = string.Empty; + Self = this; + } + } +} + +public class LibraryConvert : JsonConverter +{ + public override LibraryConfig? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + bool isChecked = false; + string libraryName = ""; + string installPath = ""; + LibraryType libraryType = LibraryType.Manual; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + { + var config = new LibraryConfig(libraryType, libraryName) + { + IsChecked = isChecked, + InstallPath = installPath + }; + return config; + } + // TODO: More + var propName = reader.GetString(); + reader.Read(); + if (propName == "IsChecked") + { + isChecked = reader.GetBoolean(); + } + if(propName == "LibraryName") + { + libraryName = reader.GetString()!; + } + if(propName == "LibraryType") + { + libraryType = (LibraryType)Enum.Parse(typeof(LibraryType), reader.GetString()!); + } + if(propName == "InstallPath") + { + installPath = reader.GetString()!; + } + } + + return null; + } + + public override void Write(Utf8JsonWriter writer, LibraryConfig value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + writer.WriteBoolean(nameof(LibraryConfig.IsChecked), value.IsChecked); + writer.WriteString(nameof(LibraryConfig.LibraryName), value.LibraryName); + writer.WriteString(nameof(LibraryConfig.LibraryType), value.LibraryType.ToString()); + writer.WriteString(nameof(LibraryConfig.InstallPath), value.InstallPath); + writer.WriteEndObject(); + } +} diff --git a/DlssUpdater/GameLibrary/ILibrary.cs b/DlssUpdater/GameLibrary/ILibrary.cs index eee613c..59888f5 100644 --- a/DlssUpdater/GameLibrary/ILibrary.cs +++ b/DlssUpdater/GameLibrary/ILibrary.cs @@ -1,5 +1,6 @@ using System.ComponentModel; using DlssUpdater.GameLibrary.Steam; +using DLSSUpdater.Defines; using GameInfo = DlssUpdater.Defines.GameInfo; namespace DlssUpdater.GameLibrary; @@ -15,15 +16,28 @@ public enum LibraryType public interface ILibrary { + public LibraryType GetLibraryType(); + public void GetInstallationDirectory(); public Task> GatherGamesAsync(); - static ILibrary Create(LibraryType type, NLog.Logger logger) + static ILibrary Create(LibraryConfig config, NLog.Logger logger) + { + return config.LibraryType switch + { + LibraryType.Manual => new ManualLibrary(config, logger), + LibraryType.Steam => new SteamLibrary(config, logger), + LibraryType.Ubisoft => new UbisoftConnectLibrary(config, logger), + _ => throw new InvalidEnumArgumentException(nameof(config.LibraryType), (int)config.LibraryType, typeof(LibraryType)) + }; + } + + static string GetName(LibraryType type) { return type switch { - LibraryType.Manual => new ManualLibrary(logger), - LibraryType.Steam => new SteamLibrary(logger), - LibraryType.Ubisoft => new UbisoftConnectLibrary(logger), + LibraryType.Manual => "Manual", + LibraryType.Steam => "Steam", + LibraryType.Ubisoft => "Ubisoft Connect", _ => throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(LibraryType)) }; } diff --git a/DlssUpdater/GameLibrary/ManualLibrary.cs b/DlssUpdater/GameLibrary/ManualLibrary.cs index 7f34869..dcac4a5 100644 --- a/DlssUpdater/GameLibrary/ManualLibrary.cs +++ b/DlssUpdater/GameLibrary/ManualLibrary.cs @@ -1,14 +1,25 @@ -using GameInfo = DlssUpdater.Defines.GameInfo; +using DLSSUpdater.Defines; +using GameInfo = DlssUpdater.Defines.GameInfo; namespace DlssUpdater.GameLibrary; public class ManualLibrary : ILibrary { - public ManualLibrary(NLog.Logger logger) + public ManualLibrary(LibraryConfig config, NLog.Logger logger) { } + public LibraryType GetLibraryType() + { + return LibraryType.Manual; + } + + public void GetInstallationDirectory() + { + + } + public async Task> GatherGamesAsync() { List ret = []; diff --git a/DlssUpdater/GameLibrary/Steam/SteamLibrary.cs b/DlssUpdater/GameLibrary/Steam/SteamLibrary.cs index d40657c..9ed9b17 100644 --- a/DlssUpdater/GameLibrary/Steam/SteamLibrary.cs +++ b/DlssUpdater/GameLibrary/Steam/SteamLibrary.cs @@ -1,5 +1,6 @@ using System.IO; using DlssUpdater.Helpers; +using DLSSUpdater.Defines; using Microsoft.Win32; using GameInfo = DlssUpdater.Defines.GameInfo; @@ -7,19 +8,28 @@ namespace DlssUpdater.GameLibrary.Steam; public class SteamLibrary : ILibrary { - private string? _installPath; private readonly NLog.Logger _logger; + private readonly LibraryConfig _config; - internal SteamLibrary(NLog.Logger logger) + internal SteamLibrary(LibraryConfig config, NLog.Logger logger) { + _config = config; _logger = logger; - getInstallationDirectory(); + if(string.IsNullOrEmpty(config.InstallPath)) + { + GetInstallationDirectory(); + } + } + + public LibraryType GetLibraryType() + { + return _config.LibraryType; } public async Task> GatherGamesAsync() { - if (_installPath is null) return []; + if (string.IsNullOrEmpty(_config.InstallPath)) return []; // We now know steam is installed, so we can carry on by parsing the 'libraryfolder.vdf' var folders = await getLibraryFolders(); @@ -29,7 +39,7 @@ public async Task> GatherGamesAsync() private async Task> getLibraryFolders() { List ret = []; - var vdfPath = Path.Combine(_installPath!, "steamapps", "libraryfolders.vdf"); + var vdfPath = Path.Combine(_config.InstallPath!, "steamapps", "libraryfolders.vdf"); if (!File.Exists(vdfPath)) return ret; VdfParser parser = new(vdfPath); @@ -56,7 +66,7 @@ private async Task> getLibraryFolders() return ret; } - private void getInstallationDirectory() + public void GetInstallationDirectory() { // We are getting the steam installation path from the user registry (if it exists) using var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); @@ -65,7 +75,7 @@ private void getInstallationDirectory() _logger.Debug($"Steam install directory: {installPath ?? "N/A"}"); - if (!string.IsNullOrEmpty(installPath)) _installPath = installPath; + if (!string.IsNullOrEmpty(installPath)) _config.InstallPath = installPath; } private async Task> getGames(List folder) @@ -124,14 +134,14 @@ private async Task> getGames(List folder) await info.GatherInstalledVersions(); if (info.HasInstalledDlls()) return info; - _logger.Debug($"Steam: '{info.GameName}' does not have anny DLSS dll and is ignored."); + _logger.Debug($"Steam: '{info.GameName}' does not have any DLSS dll and is being ignored."); return null; } private string? getGameImage(string appId) { - var cachedImage = Path.Combine(_installPath!, "appcache", "librarycache", $"{appId}_library_600x900.jpg"); + var cachedImage = Path.Combine(_config.InstallPath!, "appcache", "librarycache", $"{appId}_library_600x900.jpg"); if (File.Exists(cachedImage)) return new string(cachedImage); var url = $"https://steamcdn-a.akamaihd.net/steam/apps/{appId}/library_600x900_2x.jpg"; diff --git a/DlssUpdater/GameLibrary/UbisoftConnectLibrary.cs b/DlssUpdater/GameLibrary/UbisoftConnectLibrary.cs index 63650b1..2ea636f 100644 --- a/DlssUpdater/GameLibrary/UbisoftConnectLibrary.cs +++ b/DlssUpdater/GameLibrary/UbisoftConnectLibrary.cs @@ -1,6 +1,7 @@ using System.IO; using DlssUpdater.GameLibrary.Steam; using DlssUpdater.Helpers; +using DLSSUpdater.Defines; using Microsoft.Win32; using GameInfo = DlssUpdater.Defines.GameInfo; @@ -8,24 +9,33 @@ namespace DlssUpdater.GameLibrary; public class UbisoftConnectLibrary : ILibrary { - private string? _installPath; + private readonly LibraryConfig _config; private readonly NLog.Logger _logger; - internal UbisoftConnectLibrary(NLog.Logger logger) + internal UbisoftConnectLibrary(LibraryConfig config, NLog.Logger logger) { + _config = config; _logger = logger; - getInstallationDirectory(); + if(string.IsNullOrEmpty(config.InstallPath) ) + { + GetInstallationDirectory(); + } + } + + public LibraryType GetLibraryType() + { + return _config.LibraryType; } public async Task> GatherGamesAsync() { - if (_installPath is null) return []; + if (string.IsNullOrEmpty(_config.InstallPath)) return []; return await getGames(); } - private void getInstallationDirectory() + public void GetInstallationDirectory() { // We are getting the steam installation path from the user registry (if it exists) using var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); @@ -34,18 +44,18 @@ private void getInstallationDirectory() _logger.Debug($"Ubisoft Connect install directory: {installPath ?? "N/A"}"); - if (!string.IsNullOrEmpty(installPath)) _installPath = installPath; + if (!string.IsNullOrEmpty(installPath)) _config.InstallPath = installPath; } private async Task> getGames() { List ret = []; - if(string.IsNullOrEmpty(_installPath)) + if(string.IsNullOrEmpty(_config.InstallPath)) { return ret; } - var configPath = Path.Combine(_installPath, "cache", "configuration", "configurations"); + var configPath = Path.Combine(_config.InstallPath, "cache", "configuration", "configurations"); if(!File.Exists(configPath)) { _logger.Warn($"Ubisoft connect: Could not find configurations file at {configPath}"); @@ -98,7 +108,7 @@ private async Task> getGames() } else { - _logger.Debug($"Ubisoft connect: '{info.GameName}' does not have any DLSS dll."); + _logger.Debug($"Ubisoft connect: '{info.GameName}' does not have any DLSS dll and is being ignored."); } } @@ -107,7 +117,7 @@ private async Task> getGames() private string? getGameImage(string thumbImage) { - var cachedImage = Path.Combine(_installPath!, "cache", "assets", thumbImage); + var cachedImage = Path.Combine(_config.InstallPath!, "cache", "assets", thumbImage); if (File.Exists(cachedImage)) return new string(cachedImage); var url = $"https://ubistatic3-a.akamaihd.net/orbit/uplay_launcher_3_0/assets/{thumbImage}"; diff --git a/DlssUpdater/Settings.cs b/DlssUpdater/Settings.cs index 9f12ad3..715d863 100644 --- a/DlssUpdater/Settings.cs +++ b/DlssUpdater/Settings.cs @@ -1,16 +1,27 @@ using DlssUpdater.Defines; +using DlssUpdater.GameLibrary; using DlssUpdater.Helpers; using DlssUpdater.Singletons.AntiCheatChecker; +using DLSSUpdater.Defines; using System.Collections.ObjectModel; using System.IO; using System.Runtime; using System.Text.Json; using System.Text.Json.Serialization; +using static DlssUpdater.Defines.DlssTypes; namespace DlssUpdater; public class Settings { + private readonly JsonSerializerOptions _jsonOptions = new() + { + Converters = + { + new LibraryConvert() + } + }; + public static class Constants { public static string GamesFile { get; } = "games.json"; @@ -37,12 +48,26 @@ public class AntiCheat public AntiCheat AntiCheatSettings { get; set; } = new(); public bool ShowChangelogOnStartup { get; set; } = false; public WindowState WindowState { get; set; } = WindowState.Normal; + public SortableObservableCollection Libraries { get; set; } = []; + + public Settings() + { + foreach (LibraryType libType in Enum.GetValues(typeof(LibraryType))) + { + if(libType == LibraryType.Manual) + { + continue; + } + + Libraries.Add(new(libType, ILibrary.GetName(libType))); + } + } public void Save() { DirectoryHelper.EnsureDirectoryExists(Directories.SettingsPath); var settingsPath = Path.Combine(Directories.SettingsPath, Constants.SettingsFile); - var json = JsonSerializer.Serialize(this, new JsonSerializerOptions()); + var json = JsonSerializer.Serialize(this, _jsonOptions); File.WriteAllText(settingsPath, json); } @@ -53,7 +78,7 @@ public void Load() if (File.Exists(settingsPath)) { var jsonData = File.ReadAllText(settingsPath); - var data = JsonSerializer.Deserialize(jsonData, new JsonSerializerOptions())!; + var data = JsonSerializer.Deserialize(jsonData, _jsonOptions)!; copyData(data); } } @@ -64,5 +89,9 @@ private void copyData(Settings other) AntiCheatSettings = other.AntiCheatSettings; ShowChangelogOnStartup = other.ShowChangelogOnStartup; WindowState = other.WindowState; + if(other.Libraries.Count != 0) + { + Libraries = other.Libraries; + } } } \ No newline at end of file diff --git a/DlssUpdater/Singletons/GameContainer.cs b/DlssUpdater/Singletons/GameContainer.cs index a6e5ed6..009429c 100644 --- a/DlssUpdater/Singletons/GameContainer.cs +++ b/DlssUpdater/Singletons/GameContainer.cs @@ -21,7 +21,7 @@ public class GameContainer } }; - private readonly List _libraries = []; + public readonly List Libraries = []; private readonly Settings _settings; private readonly AntiCheatChecker.AntiCheatChecker _antiCheatChecker; @@ -35,9 +35,7 @@ public GameContainer(Settings settings, AntiCheatChecker.AntiCheatChecker antiCh _logger = logger; _watcher = watcher; - // TODO: Add settings for active libraries - _libraries.Add(ILibrary.Create(LibraryType.Steam, _logger)); - _libraries.Add(ILibrary.Create(LibraryType.Ubisoft, _logger)); + UpdateLibraries(); Games.CollectionChanged += Games_CollectionChanged; } @@ -47,6 +45,20 @@ public GameContainer(Settings settings, AntiCheatChecker.AntiCheatChecker antiCh SortingSelector = g => g.GameName }; + public void UpdateLibraries() + { + Libraries.Clear(); + foreach (var library in _settings.Libraries) + { + if (!library.IsChecked) + { + continue; + } + + Libraries.Add(ILibrary.Create(library, _logger)); + } + } + public async Task LoadGamesAsync() { await loadGamesAsync(); @@ -100,7 +112,7 @@ private async Task loadGamesAsync() } } - foreach (var lib in _libraries) + foreach (var lib in Libraries) { var libGames = await lib.GatherGamesAsync(); foreach (var item in libGames) diff --git a/DlssUpdater/ViewModels/Pages/SettingsViewModel.cs b/DlssUpdater/ViewModels/Pages/SettingsViewModel.cs index 9a67759..9817ed0 100644 --- a/DlssUpdater/ViewModels/Pages/SettingsViewModel.cs +++ b/DlssUpdater/ViewModels/Pages/SettingsViewModel.cs @@ -2,7 +2,9 @@ using DlssUpdater.Helpers; using DlssUpdater.Singletons; using DlssUpdater.Singletons.AntiCheatChecker; +using DLSSUpdater.Defines; using Microsoft.VisualBasic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Reflection; using System.Runtime; @@ -21,6 +23,8 @@ public partial class SettingsViewModel : ObservableObject, INavigationAware [ObservableProperty] string? _downloadPath; [ObservableProperty] string? _settingsPath; + [ObservableProperty] private ObservableCollection? _libraries; + private bool _isInitialized = false; private Settings _settings; private GameContainer _gameContainer; @@ -51,6 +55,7 @@ private void InitializeViewModel() UpdateAntiCheat(_settings.AntiCheatSettings.DisclaimerAccepted); AntiCheatEACEnabled = _settings.AntiCheatSettings.ActiveAntiCheatChecks.HasFlag(AntiCheatProvider.EasyAntiCheat); AntiCheatBattlEyeEnabled = _settings.AntiCheatSettings.ActiveAntiCheatChecks.HasFlag(AntiCheatProvider.BattlEye); + Libraries = _settings.Libraries; } public void UpdateAntiCheat(bool enabled) diff --git a/DlssUpdater/Views/Pages/SettingsPage.xaml b/DlssUpdater/Views/Pages/SettingsPage.xaml index 7e18466..3e7743f 100644 --- a/DlssUpdater/Views/Pages/SettingsPage.xaml +++ b/DlssUpdater/Views/Pages/SettingsPage.xaml @@ -7,6 +7,7 @@ xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:helpers="clr-namespace:DlssUpdater.Helpers" xmlns:pages="clr-namespace:DlssUpdater.Views.Pages" + xmlns:controls="clr-namespace:DlssUpdater.Controls" Title="SettingsPage" d:DataContext="{d:DesignInstance pages:SettingsPage, IsDesignTimeCreatable=False}" @@ -16,14 +17,14 @@ ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}" Foreground="{DynamicResource TextFillColorPrimaryBrush}" mc:Ignorable="d"> - + - - - + + + @@ -60,6 +61,20 @@ Foreground="{DynamicResource TextFillColorPrimaryBrush}" Margin="0,0,5,0" /> + + + + + + + + + - + \ No newline at end of file diff --git a/DlssUpdater/Windows/Splashscreen/Splashscreen.xaml.cs b/DlssUpdater/Windows/Splashscreen/Splashscreen.xaml.cs index 17072e5..2bd3733 100644 --- a/DlssUpdater/Windows/Splashscreen/Splashscreen.xaml.cs +++ b/DlssUpdater/Windows/Splashscreen/Splashscreen.xaml.cs @@ -40,6 +40,7 @@ public Splashscreen(MainWindow mainWindow, DllUpdater updater, GameContainer con _logger.Debug("### STARTUP ###"); settings.Load(); + _gameContainer.UpdateLibraries(); _settings = settings; cheatChecker.Init(); diff --git a/DlssUpdater/changelog.md b/DlssUpdater/changelog.md index 81c8886..313b542 100644 --- a/DlssUpdater/changelog.md +++ b/DlssUpdater/changelog.md @@ -1,5 +1,6 @@ # 1.0.3.0 -* Streamline games ui (no unnecessary popups, easier readable buttons ) +* Streamline games ui (no unnecessary popups, easier readable buttons) +* Make libraries configurable and allow manually setting the installation directory # 1.0.2.0 * Add notification icon if DLSS updates are available From 189bc4eadaabc06031590555d6e472fa643d1262 Mon Sep 17 00:00:00 2001 From: Drommedhar Date: Thu, 26 Sep 2024 17:44:54 +0200 Subject: [PATCH 3/6] Multiple dll instances corrected --- DlssUpdater/Defines/GameInfo.cs | 2 +- DlssUpdater/changelog.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DlssUpdater/Defines/GameInfo.cs b/DlssUpdater/Defines/GameInfo.cs index 513b506..2a90e64 100644 --- a/DlssUpdater/Defines/GameInfo.cs +++ b/DlssUpdater/Defines/GameInfo.cs @@ -72,7 +72,7 @@ await Task.Run(() => // TODO: Support for multiple instances of the same dll? // We only should have one entry - info.Path = allFiles[0]; + info.Path = allFiles[^1]; var fileInfo = FileVersionInfo.GetVersionInfo(info.Path); var newVersion = fileInfo.FileVersion?.Replace(',', '.'); if (newVersion is not null && newVersion != info.Version) diff --git a/DlssUpdater/changelog.md b/DlssUpdater/changelog.md index 313b542..5f010f2 100644 --- a/DlssUpdater/changelog.md +++ b/DlssUpdater/changelog.md @@ -1,6 +1,7 @@ # 1.0.3.0 * Streamline games ui (no unnecessary popups, easier readable buttons) * Make libraries configurable and allow manually setting the installation directory +* Change behaviour if more than one instance of the same dll is found in game directory # 1.0.2.0 * Add notification icon if DLSS updates are available From 43ad8c2f82b9a2e0ed5b791937a7bf989968ae02 Mon Sep 17 00:00:00 2001 From: Drommedhar Date: Thu, 26 Sep 2024 17:47:27 +0200 Subject: [PATCH 4/6] Correct readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c77ecdd..61db244 100644 --- a/README.md +++ b/README.md @@ -66,5 +66,5 @@ Dlss Updater is free and open source software licensed under the MIT License. Yo If you have further question feel free to join the official discord [here](https://discord.gg/WShdqSDSvu) # Known issues -* Changes to folders in the [Settings Page](#Settings Page) will not take effect until the application is restarted. +* Changes to folders in the [Settings Page](#settings-page) will not take effect until the application is restarted. * Game auto-detection cannot be turned off at this time. \ No newline at end of file From 7793a166f8519906cde4fd7a32c0911a6d3ba2dc Mon Sep 17 00:00:00 2001 From: Drommedhar Date: Thu, 26 Sep 2024 18:29:45 +0200 Subject: [PATCH 5/6] Fix list update --- DlssUpdater/Controls/LauncherPanel.xaml.cs | 5 ++++- DlssUpdater/Defines/LibraryConfig.cs | 1 + DlssUpdater/Singletons/GameContainer.cs | 23 ++++++++++++++++++++++ DlssUpdater/changelog.md | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/DlssUpdater/Controls/LauncherPanel.xaml.cs b/DlssUpdater/Controls/LauncherPanel.xaml.cs index 5daf110..076e2c4 100644 --- a/DlssUpdater/Controls/LauncherPanel.xaml.cs +++ b/DlssUpdater/Controls/LauncherPanel.xaml.cs @@ -35,6 +35,7 @@ public LibraryConfig LibraryConfig private readonly Settings _settings; private readonly GameContainer _gameContainer; + private readonly NLog.Logger _logger; public LauncherPanel() { @@ -42,6 +43,7 @@ public LauncherPanel() _settings = App.GetService()!; _gameContainer = App.GetService()!; + _logger = App.GetService()!; GridExpand.Visibility = Visibility.Visible; } @@ -49,8 +51,9 @@ public LauncherPanel() private async void ToggleSwitch_Click(object sender, RoutedEventArgs e) { _settings.Save(); + _logger.Debug($"Switched library '{LibraryConfig.LibraryName}' to {LibraryConfig.IsChecked}"); _gameContainer.UpdateLibraries(); - await _gameContainer.LoadGamesAsync(); + await _gameContainer.ReloadLibraryGames(LibraryConfig.LibraryType); } private void Button_Click(object sender, RoutedEventArgs e) diff --git a/DlssUpdater/Defines/LibraryConfig.cs b/DlssUpdater/Defines/LibraryConfig.cs index cb82e49..fa0ba8d 100644 --- a/DlssUpdater/Defines/LibraryConfig.cs +++ b/DlssUpdater/Defines/LibraryConfig.cs @@ -31,6 +31,7 @@ public LibraryConfig(LibraryType type, string name) LibraryType = type; _libraryName = name; _installPath = string.Empty; + _isChecked = true; Self = this; } } diff --git a/DlssUpdater/Singletons/GameContainer.cs b/DlssUpdater/Singletons/GameContainer.cs index 009429c..1d36842 100644 --- a/DlssUpdater/Singletons/GameContainer.cs +++ b/DlssUpdater/Singletons/GameContainer.cs @@ -126,6 +126,29 @@ private async Task loadGamesAsync() } } + public async Task ReloadLibraryGames(LibraryType type) + { + // Create a list of games to remove + var gamesToRemove = Games.Where(game => game.LibraryType == type).ToList(); + + // Remove the games from the ObservableCollection + foreach (var game in gamesToRemove) + { + Games.Remove(game); + } + + // Reload games from libraries of the specified type + foreach (var lib in Libraries.Where(l => l.GetLibraryType() == type)) + { + var libGames = await lib.GatherGamesAsync(); + foreach (var item in libGames.Where(item => !Games.Any(g => g.GamePath == item.GamePath))) + { + Games.Add(item); + _watcher.AddFile(item); + } + } + } + private void Games_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { GamesChanged?.Invoke(this, e); diff --git a/DlssUpdater/changelog.md b/DlssUpdater/changelog.md index 5f010f2..91bad2e 100644 --- a/DlssUpdater/changelog.md +++ b/DlssUpdater/changelog.md @@ -1,7 +1,7 @@ # 1.0.3.0 * Streamline games ui (no unnecessary popups, easier readable buttons) * Make libraries configurable and allow manually setting the installation directory -* Change behaviour if more than one instance of the same dll is found in game directory +* Change behaviour if more than one instance of the same dll is found in game directory. It will selected the last one found. This might result in the wrong one being used, so make sure that not multiple instances are inside a game folder. # 1.0.2.0 * Add notification icon if DLSS updates are available From 89651d1e2b63cf2afb22b43e1c80350838d32da9 Mon Sep 17 00:00:00 2001 From: Drommedhar Date: Thu, 26 Sep 2024 18:39:03 +0200 Subject: [PATCH 6/6] Correct readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 61db244..4911d23 100644 --- a/README.md +++ b/README.md @@ -67,4 +67,4 @@ If you have further question feel free to join the official discord [here](https # Known issues * Changes to folders in the [Settings Page](#settings-page) will not take effect until the application is restarted. -* Game auto-detection cannot be turned off at this time. \ No newline at end of file +* Multiple instances of the the dll in a game folder can lead to strange behaviour. Make sure that there is only 1 instance in a game. \ No newline at end of file