Skip to content

Commit

Permalink
Fixed download manager. Was not possible to update your selected syst…
Browse files Browse the repository at this point in the history
…em preset.
  • Loading branch information
josdemmers committed Aug 3, 2023
1 parent d22f526 commit 5ac1fd3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
6 changes: 3 additions & 3 deletions D4Companion.Events/SettingsViewModelEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion D4Companion/Converters/FileNameToImagePathConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
18 changes: 16 additions & 2 deletions D4Companion/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Linq;
using System.Windows;
using System.Threading.Tasks;
using System;

namespace D4Companion.ViewModels
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -208,6 +217,7 @@ public string SelectedSystemPreset
_eventAggregator.GetEvent<ReloadAffixesGuiRequestEvent>().Publish();

DownloadSystemPresetCommand?.RaiseCanExecuteChanged();
RaisePropertyChanged(nameof(PresetDownloadButtonCaption));
}
}
}
Expand All @@ -232,6 +242,7 @@ public SystemPreset SelectedCommunityPreset
_selectedCommunityPreset = value;
RaisePropertyChanged(nameof(SelectedCommunityPreset));
DownloadSystemPresetCommand?.RaiseCanExecuteChanged();
RaisePropertyChanged(nameof(PresetDownloadButtonCaption));
}
}

Expand All @@ -255,6 +266,10 @@ private void HandleSystemPresetExtractedEvent()
DownloadSystemPresetCommand?.RaiseCanExecuteChanged();

InitSystemPresets();

// Reload image data for current system preset.
_eventAggregator.GetEvent<SystemPresetChangedEvent>().Publish();
_eventAggregator.GetEvent<ReloadAffixesGuiRequestEvent>().Publish();
}

private void HandleSystemPresetInfoUpdatedEvent()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion D4Companion/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<mah:MetroHeader Margin="0 10 0 5" Header="Available system presets:" DockPanel.Dock="Top">
<StackPanel Orientation="Horizontal">
<ComboBox Width="175" ItemsSource="{Binding Path=CommunitySystemPresets}" DisplayMemberPath="FileName" SelectedItem="{Binding Path=SelectedCommunityPreset}"/>
<Button Margin="2 0 0 0" Content="Download" Command="{Binding DownloadSystemPresetCommand}"/>
<Button Margin="2 0 0 0" MinWidth="80" Content="{Binding PresetDownloadButtonCaption}" Command="{Binding DownloadSystemPresetCommand}"/>
</StackPanel>
</mah:MetroHeader>

Expand Down
4 changes: 2 additions & 2 deletions D4Companion/common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<FileVersion>1.1.10.0</FileVersion>
<Version>1.1.10.0</Version>
<FileVersion>1.1.11.0</FileVersion>
<Version>1.1.11.0</Version>
<Copyright>Copyright © 2023</Copyright>
<TargetFramework>net6.0-windows</TargetFramework>
</PropertyGroup>
Expand Down

0 comments on commit 5ac1fd3

Please sign in to comment.