From 5ac1fd359a74bd21834d32d2ffb5a503600f52e0 Mon Sep 17 00:00:00 2001 From: Jos Demmers Date: Thu, 3 Aug 2023 15:20:58 +0200 Subject: [PATCH] Fixed download manager. Was not possible to update your selected system preset. --- D4Companion.Events/SettingsViewModelEvents.cs | 6 +++--- .../Converters/FileNameToImagePathConverter.cs | 10 +++++++++- D4Companion/ViewModels/SettingsViewModel.cs | 18 ++++++++++++++++-- D4Companion/Views/SettingsView.xaml | 2 +- D4Companion/common.props | 4 ++-- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/D4Companion.Events/SettingsViewModelEvents.cs b/D4Companion.Events/SettingsViewModelEvents.cs index 1938007b..3d5561bd 100644 --- a/D4Companion.Events/SettingsViewModelEvents.cs +++ b/D4Companion.Events/SettingsViewModelEvents.cs @@ -7,12 +7,12 @@ namespace D4Companion.Events { - public class SystemPresetChangedEvent : PubSubEvent + public class ReloadAffixesGuiRequestEvent : PubSubEvent { } - public class ReloadAffixesGuiRequestEvent : PubSubEvent - { + public class SystemPresetChangedEvent : PubSubEvent + { } public class UpdateHotkeysRequestEvent : PubSubEvent diff --git a/D4Companion/Converters/FileNameToImagePathConverter.cs b/D4Companion/Converters/FileNameToImagePathConverter.cs index 5f4d4261..82ee6e6f 100644 --- a/D4Companion/Converters/FileNameToImagePathConverter.cs +++ b/D4Companion/Converters/FileNameToImagePathConverter.cs @@ -19,7 +19,15 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur string category = (string)values[1]; string systemPreset = (string)values[2]; - return new BitmapImage(new Uri($"{Environment.CurrentDirectory}/Images/{systemPreset}/{category}/{fileName}")); + var uri = new Uri($"{Environment.CurrentDirectory}/Images/{systemPreset}/{category}/{fileName}"); + var bitmap = new BitmapImage(); + bitmap.BeginInit(); + bitmap.CacheOption = BitmapCacheOption.OnLoad; + bitmap.CreateOptions = BitmapCreateOptions.IgnoreImageCache; + bitmap.UriSource = uri; + bitmap.EndInit(); + + return bitmap; } catch (Exception) { diff --git a/D4Companion/ViewModels/SettingsViewModel.cs b/D4Companion/ViewModels/SettingsViewModel.cs index 8c1ab569..6a34f61c 100644 --- a/D4Companion/ViewModels/SettingsViewModel.cs +++ b/D4Companion/ViewModels/SettingsViewModel.cs @@ -13,6 +13,7 @@ using System.Linq; using System.Windows; using System.Threading.Tasks; +using System; namespace D4Companion.ViewModels { @@ -177,6 +178,14 @@ public KeyBindingConfig KeyBindingConfigToggleOverlay } } + public string PresetDownloadButtonCaption + { + get + { + return !string.IsNullOrWhiteSpace(SelectedCommunityPreset.FileName) && SelectedSystemPreset.Equals(Path.GetFileNameWithoutExtension(SelectedCommunityPreset.FileName)) ? "Update" : "Download"; + } + } + public string SelectedOverlayMarkerMode { get => _settingsManager.Settings.SelectedOverlayMarkerMode; @@ -208,6 +217,7 @@ public string SelectedSystemPreset _eventAggregator.GetEvent().Publish(); DownloadSystemPresetCommand?.RaiseCanExecuteChanged(); + RaisePropertyChanged(nameof(PresetDownloadButtonCaption)); } } } @@ -232,6 +242,7 @@ public SystemPreset SelectedCommunityPreset _selectedCommunityPreset = value; RaisePropertyChanged(nameof(SelectedCommunityPreset)); DownloadSystemPresetCommand?.RaiseCanExecuteChanged(); + RaisePropertyChanged(nameof(PresetDownloadButtonCaption)); } } @@ -255,6 +266,10 @@ private void HandleSystemPresetExtractedEvent() DownloadSystemPresetCommand?.RaiseCanExecuteChanged(); InitSystemPresets(); + + // Reload image data for current system preset. + _eventAggregator.GetEvent().Publish(); + _eventAggregator.GetEvent().Publish(); } private void HandleSystemPresetInfoUpdatedEvent() @@ -336,8 +351,7 @@ private void InitSystemPresets() private bool CanDownloadSystemPresetExecute() { - return SystemPresetChangeAllowed && !_downloadInProgress && SelectedCommunityPreset != null && - !string.IsNullOrWhiteSpace(SelectedCommunityPreset.FileName) && !SelectedSystemPreset.Equals(Path.GetFileNameWithoutExtension(SelectedCommunityPreset.FileName)); + return SystemPresetChangeAllowed && !_downloadInProgress && SelectedCommunityPreset != null && !string.IsNullOrWhiteSpace(SelectedCommunityPreset.FileName); } private void DownloadSystemPresetExecute() diff --git a/D4Companion/Views/SettingsView.xaml b/D4Companion/Views/SettingsView.xaml index 8a917ba3..a46a9b44 100644 --- a/D4Companion/Views/SettingsView.xaml +++ b/D4Companion/Views/SettingsView.xaml @@ -111,7 +111,7 @@ -