From 00170afd828525ef968d74a9fe0b41a8602e9882 Mon Sep 17 00:00:00 2001 From: Drommedhar Date: Mon, 30 Sep 2024 22:19:43 +0200 Subject: [PATCH] * Fix incorrectly enabled ComboBox for DLL types in configuration view * Fix AsyncFileWatcher not correctly removing removed games --- DlssUpdater/DLSSUpdater.csproj | 4 +- DlssUpdater/Defines/GameInfo.cs | 19 ++++++- DlssUpdater/Singletons/AsyncFileWatcher.cs | 49 +++++++------------ .../ViewModels/Pages/GamesViewModel.cs | 6 +-- .../Windows/Splashscreen/Splashscreen.xaml.cs | 1 + DlssUpdater/changelog.md | 6 ++- DlssUpdater/version.json | 2 +- 7 files changed, 49 insertions(+), 38 deletions(-) diff --git a/DlssUpdater/DLSSUpdater.csproj b/DlssUpdater/DLSSUpdater.csproj index d2d223f..43c2c7d 100644 --- a/DlssUpdater/DLSSUpdater.csproj +++ b/DlssUpdater/DLSSUpdater.csproj @@ -9,11 +9,11 @@ enable enable x64 - 1.0.5.0 + 1.0.5.1 true win-x64 False - 1.0.5.0 + 1.0.5.1 diff --git a/DlssUpdater/Defines/GameInfo.cs b/DlssUpdater/Defines/GameInfo.cs index 16dd690..427046d 100644 --- a/DlssUpdater/Defines/GameInfo.cs +++ b/DlssUpdater/Defines/GameInfo.cs @@ -12,7 +12,7 @@ namespace DlssUpdater.Defines; -public partial class GameInfo : ObservableObject +public partial class GameInfo : ObservableObject, IEquatable { public string UniqueId { get; set; } [ObservableProperty] [JsonIgnore] public ImageSource? _gameImage; @@ -129,6 +129,23 @@ public void SetGameImageUri(string imageUri) TextVisible = Visibility.Visible; } } + + public bool Equals(GameInfo? other) + { + return UniqueId == other?.UniqueId; + } + + public override bool Equals(object? obj) + { + if (obj == null) + return false; + return Equals(obj as GameInfo); + } + + public override int GetHashCode() + { + return HashCode.Combine(UniqueId); + } } public class GameConvert : JsonConverter diff --git a/DlssUpdater/Singletons/AsyncFileWatcher.cs b/DlssUpdater/Singletons/AsyncFileWatcher.cs index de1a69d..9b64714 100644 --- a/DlssUpdater/Singletons/AsyncFileWatcher.cs +++ b/DlssUpdater/Singletons/AsyncFileWatcher.cs @@ -1,6 +1,7 @@  using DlssUpdater.Defines; using DlssUpdater.Singletons; +using System.Collections.Concurrent; namespace DLSSUpdater.Singletons { @@ -11,8 +12,7 @@ public class AsyncFileWatcher { public event EventHandler? FilesChanged; - private Queue _queueFiles = new(); - private object _lock = new(); + private ConcurrentQueue _queueFiles = new(); private Timer? _timer; private readonly DllUpdater _updater; @@ -25,52 +25,41 @@ public AsyncFileWatcher(DllUpdater updater) public void AddFile(GameInfo info) { - lock (_lock) - { - _queueFiles.Enqueue(info); - } + _queueFiles.Enqueue(info); } public void RemoveFile(GameInfo info) { - lock (_lock) - { - var files = _queueFiles.ToList(); - var updated = files.Remove(info); + var files = _queueFiles.ToList(); + var updated = files.Remove(info); - if (updated) + if (updated) + { + _queueFiles.Clear(); + foreach (var file in files) { - _queueFiles.Clear(); - foreach (var file in files) - { - _queueFiles.Enqueue(file); - } + _queueFiles.Enqueue(file); } } } private async void Check(object? state) { - GameInfo? info = null; - lock (_lock) + if(_queueFiles.Count == 0) { - if(_queueFiles.Count == 0) - { - return; - } - info = _queueFiles.Dequeue(); + return; } - - var bChanged = await info.GatherInstalledVersions(); - if (bChanged) + if(_queueFiles.TryDequeue(out var info)) { - FilesChanged?.Invoke(this, EventArgs.Empty); - } + var bChanged = await info.GatherInstalledVersions(); + if (bChanged) + { + FilesChanged?.Invoke(this, EventArgs.Empty); + } - lock (_lock) - { _queueFiles.Enqueue(info); } + } } } diff --git a/DlssUpdater/ViewModels/Pages/GamesViewModel.cs b/DlssUpdater/ViewModels/Pages/GamesViewModel.cs index 3d15d35..5c88c2a 100644 --- a/DlssUpdater/ViewModels/Pages/GamesViewModel.cs +++ b/DlssUpdater/ViewModels/Pages/GamesViewModel.cs @@ -76,9 +76,9 @@ public void Update() } else { - DlssItemInstalled = SelectedGame.InstalledDlls[DlssTypes.DllType.Dlss].Version ?? _notInstalled; - DlssDItemInstalled = SelectedGame.InstalledDlls[DlssTypes.DllType.DlssD].Version ?? _notInstalled; - DlssGItemInstalled = SelectedGame.InstalledDlls[DlssTypes.DllType.DlssG].Version ?? _notInstalled; + DlssItemInstalled = string.IsNullOrEmpty(SelectedGame.InstalledDlls[DlssTypes.DllType.Dlss].Version) ? _notInstalled : SelectedGame.InstalledDlls[DlssTypes.DllType.Dlss].Version; + DlssDItemInstalled = string.IsNullOrEmpty(SelectedGame.InstalledDlls[DlssTypes.DllType.DlssD].Version) ? _notInstalled : SelectedGame.InstalledDlls[DlssTypes.DllType.DlssD].Version; + DlssGItemInstalled = string.IsNullOrEmpty(SelectedGame.InstalledDlls[DlssTypes.DllType.DlssG].Version) ? _notInstalled : SelectedGame.InstalledDlls[DlssTypes.DllType.DlssG].Version; } DlssItemEnabled = DlssItemInstalled != _notInstalled; diff --git a/DlssUpdater/Windows/Splashscreen/Splashscreen.xaml.cs b/DlssUpdater/Windows/Splashscreen/Splashscreen.xaml.cs index 2bd3733..719315a 100644 --- a/DlssUpdater/Windows/Splashscreen/Splashscreen.xaml.cs +++ b/DlssUpdater/Windows/Splashscreen/Splashscreen.xaml.cs @@ -11,6 +11,7 @@ using DlssUpdater.ViewModels.Windows; using DlssUpdater.Views.Windows; using DLSSUpdater.Singletons; +using Wpf.Ui.Appearance; using MessageBox = Wpf.Ui.Controls.MessageBox; using MessageBoxResult = Wpf.Ui.Controls.MessageBoxResult; diff --git a/DlssUpdater/changelog.md b/DlssUpdater/changelog.md index 8be9c27..ea3e56f 100644 --- a/DlssUpdater/changelog.md +++ b/DlssUpdater/changelog.md @@ -1,4 +1,8 @@ -# 1.0.5.0 +# 1.0.5.1 +* Fix incorrectly enabled ComboBox for DLL types in configuration view +* Fix AsyncFileWatcher not correctly removing removed games + +# 1.0.5.0 * Add support for hiding games from main list with right mouse button * Add filter to games page * Validate MD5 hash and signature of downloaded DLL diff --git a/DlssUpdater/version.json b/DlssUpdater/version.json index b90062f..eee430b 100644 --- a/DlssUpdater/version.json +++ b/DlssUpdater/version.json @@ -1,3 +1,3 @@ { - "version": "1.0.5.0" + "version": "1.0.5.1" } \ No newline at end of file