diff --git a/FModel/Settings/UserSettings.cs b/FModel/Settings/UserSettings.cs index 640dce08..93edc572 100644 --- a/FModel/Settings/UserSettings.cs +++ b/FModel/Settings/UserSettings.cs @@ -39,7 +39,7 @@ namespace FModel.Settings if (File.Exists(FilePath)) File.Delete(FilePath); } - public static bool TryGetGameCustomEndpoint(FGame game, EEndpointType type, out FEndpoint endpoint) + public static bool IsEndpointEnabled(FGame game, EEndpointType type, out FEndpoint endpoint) { endpoint = null; if (!Default.CustomEndpoints.TryGetValue(game, out var endpoints)) diff --git a/FModel/ViewModels/CUE4ParseViewModel.cs b/FModel/ViewModels/CUE4ParseViewModel.cs index 2ba50435..5f2a3e2d 100644 --- a/FModel/ViewModels/CUE4ParseViewModel.cs +++ b/FModel/ViewModels/CUE4ParseViewModel.cs @@ -295,7 +295,7 @@ public class CUE4ParseViewModel : ViewModel { // game directory dependent, we don't have the provider game name yet since we don't have aes keys // except when this comes from the AES Manager - if (!UserSettings.TryGetGameCustomEndpoint(Game, EEndpointType.Aes, out var endpoint)) + if (!UserSettings.IsEndpointEnabled(Game, EEndpointType.Aes, out var endpoint)) return; await _threadWorkerView.Begin(cancellationToken => @@ -323,7 +323,7 @@ public class CUE4ParseViewModel : ViewModel public async Task InitBenMappings() { - if (!UserSettings.TryGetGameCustomEndpoint(Game, EEndpointType.Mapping, out var endpoint)) + if (!UserSettings.IsEndpointEnabled(Game, EEndpointType.Mapping, out var endpoint)) return; await _threadWorkerView.Begin(cancellationToken => diff --git a/FModel/ViewModels/SettingsViewModel.cs b/FModel/ViewModels/SettingsViewModel.cs index 3d12be19..90997f37 100644 --- a/FModel/ViewModels/SettingsViewModel.cs +++ b/FModel/ViewModels/SettingsViewModel.cs @@ -68,6 +68,20 @@ public class SettingsViewModel : ViewModel set => SetProperty(ref _selectedOptions, value); } + private FEndpoint _aesEndpoint; + public FEndpoint AesEndpoint + { + get => _aesEndpoint; + set => SetProperty(ref _aesEndpoint, value); + } + + private FEndpoint _mappingEndpoint; + public FEndpoint MappingEndpoint + { + get => _mappingEndpoint; + set => SetProperty(ref _mappingEndpoint, value); + } + private ELanguage _selectedAssetLanguage; public ELanguage SelectedAssetLanguage { @@ -96,13 +110,6 @@ public class SettingsViewModel : ViewModel set => SetProperty(ref _selectedCompressedAudio, value); } - private string _currentMappingFile; - public string CurrentMappingFile // only used so that it updates the UI - { - get => _currentMappingFile; - set => SetProperty(ref _currentMappingFile, value); - } - private EIconStyle _selectedCosmeticStyle; public EIconStyle SelectedCosmeticStyle { @@ -198,8 +205,11 @@ public class SettingsViewModel : ViewModel _optionsSnapshot = UserSettings.Default.OverridedOptions[_game]; } - if (UserSettings.TryGetGameCustomEndpoint(_game, EEndpointType.Mapping, out var endpoint)) - CurrentMappingFile = endpoint.Path; + if (UserSettings.Default.CustomEndpoints.TryGetValue(_game, out var endpoints)) + { + AesEndpoint = endpoints[0]; + MappingEndpoint = endpoints[1]; + } _assetLanguageSnapshot = UserSettings.Default.AssetLanguage; _compressedAudioSnapshot = UserSettings.Default.CompressedAudioMode; diff --git a/FModel/Views/Resources/Converters/EndpointOverwriteToBoolConverter.cs b/FModel/Views/Resources/Converters/EndpointOverwriteToBoolConverter.cs deleted file mode 100644 index 6fdd553c..00000000 --- a/FModel/Views/Resources/Converters/EndpointOverwriteToBoolConverter.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Globalization; -using System.Windows; -using System.Windows.Data; -using FModel.Framework; -using FModel.Settings; -using FModel.ViewModels; - -namespace FModel.Views.Resources.Converters; - -public class EndpointOverwriteToBoolConverter : IMultiValueConverter -{ - public static readonly EndpointOverwriteToBoolConverter Instance = new(); - - private ApplicationViewModel _vm; - private EEndpointType _type; - private FEndpoint _endpoint; - - public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) - { - _vm = values[0] as ApplicationViewModel; - _type = values[1] as EEndpointType? ?? EEndpointType.Mapping; - if (_vm == null || !UserSettings.TryGetGameCustomEndpoint(_vm.CUE4Parse.Game, _type, out _endpoint)) - return default; - - return targetType switch - { - not null when targetType == typeof(bool?) => _endpoint.Overwrite, // IsChecked - not null when targetType == typeof(string) => _endpoint.Path, - not null when targetType == typeof(Visibility) => _endpoint.Overwrite ? Visibility.Visible : Visibility.Collapsed, - _ => throw new NotImplementedException() - }; - } - - public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture) - { - var t = value.GetType(); - switch (t) - { - case not null when t == typeof(bool): - _endpoint.Overwrite = (bool)value; - break; - case not null when t == typeof(string): - _endpoint.Path = (string)value; - break; - default: - throw new NotImplementedException(); - } - - return new object[] { _vm, _type }; - } -} diff --git a/FModel/Views/Resources/Converters/EndpointToTypeConverter.cs b/FModel/Views/Resources/Converters/EndpointToTypeConverter.cs index 730a8d22..301be6c4 100644 --- a/FModel/Views/Resources/Converters/EndpointToTypeConverter.cs +++ b/FModel/Views/Resources/Converters/EndpointToTypeConverter.cs @@ -17,7 +17,7 @@ public class EndpointToTypeConverter : IMultiValueConverter values[1] is not EEndpointType type) return false; - var isEnabled = UserSettings.TryGetGameCustomEndpoint(viewModel.CUE4Parse.Game, type, out _); + var isEnabled = UserSettings.IsEndpointEnabled(viewModel.CUE4Parse.Game, type, out _); return targetType switch { not null when targetType == typeof(Visibility) => isEnabled ? Visibility.Visible : Visibility.Collapsed, diff --git a/FModel/Views/SettingsView.xaml b/FModel/Views/SettingsView.xaml index 0a9ffa2d..5ec4114b 100644 --- a/FModel/Views/SettingsView.xaml +++ b/FModel/Views/SettingsView.xaml @@ -199,23 +199,13 @@ - - - - - - - - + - - - - - - + ItemsSource="{Binding SettingsView.AesReloads}" SelectedItem="{Binding SettingsView.SelectedAesReload, Mode=TwoWay}" + Visibility="{Binding SettingsView.AesEndpoint.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"> @@ -227,42 +217,25 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + DataContext="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Views.SettingsView}}}" + Visibility="{Binding SettingsView.MappingEndpoint.Overwrite, Converter={StaticResource BoolToVisibilityConverter}}"> - +