From 2a265eae60b40a3bf84eae751982dddf1d14bb33 Mon Sep 17 00:00:00 2001 From: 4sval Date: Sun, 18 Jun 2023 03:26:50 +0200 Subject: [PATCH] usable --- FModel/App.xaml.cs | 13 +++ FModel/MainWindow.xaml.cs | 4 +- FModel/Settings/DirectorySettings.cs | 20 ++-- FModel/Settings/UserSettings.cs | 94 +------------------ FModel/ViewModels/AesManagerViewModel.cs | 21 +---- FModel/ViewModels/ApplicationViewModel.cs | 2 +- FModel/ViewModels/CUE4ParseViewModel.cs | 2 +- FModel/ViewModels/SettingsViewModel.cs | 42 ++------- .../Resources/Controls/DictionaryEditor.xaml | 2 +- .../Controls/DictionaryEditor.xaml.cs | 3 +- 10 files changed, 44 insertions(+), 159 deletions(-) diff --git a/FModel/App.xaml.cs b/FModel/App.xaml.cs index f5de48d8..9a07838b 100644 --- a/FModel/App.xaml.cs +++ b/FModel/App.xaml.cs @@ -41,6 +41,8 @@ public partial class App { UserSettings.Default = JsonConvert.DeserializeObject( File.ReadAllText(UserSettings.FilePath), JsonNetSerializer.SerializerSettings); + + /*if (UserSettings.Default.ShowChangelog) */MigrateV1Games(); } catch { @@ -141,6 +143,17 @@ public partial class App e.Handled = true; } + private void MigrateV1Games() + { + foreach ((var gameDir, var setting) in UserSettings.Default.ManualGames) + { + if (!Directory.Exists(gameDir)) continue; + UserSettings.Default.PerDirectory[gameDir] = + DirectorySettings.Default(setting.GameName, setting.GameDirectory, true, setting.OverridedGame); + } + UserSettings.Default.ManualGames.Clear(); + } + private string GetOperatingSystemProductName() { var productName = string.Empty; diff --git a/FModel/MainWindow.xaml.cs b/FModel/MainWindow.xaml.cs index 43bad02d..5adbab52 100644 --- a/FModel/MainWindow.xaml.cs +++ b/FModel/MainWindow.xaml.cs @@ -56,8 +56,8 @@ public partial class MainWindow case EAesReload.Always: await _applicationView.CUE4Parse.RefreshAes(); break; - case EAesReload.OncePerDay when UserSettings.Default.LastAesReload != DateTime.Today: - UserSettings.Default.LastAesReload = DateTime.Today; + case EAesReload.OncePerDay when UserSettings.Default.CurrentDir.LastAesReload != DateTime.Today: + UserSettings.Default.CurrentDir.LastAesReload = DateTime.Today; await _applicationView.CUE4Parse.RefreshAes(); break; } diff --git a/FModel/Settings/DirectorySettings.cs b/FModel/Settings/DirectorySettings.cs index 1fc73451..2a9c0657 100644 --- a/FModel/Settings/DirectorySettings.cs +++ b/FModel/Settings/DirectorySettings.cs @@ -10,8 +10,7 @@ namespace FModel.Settings; public class DirectorySettings : ViewModel { public static DirectorySettings Default( - string gameName, string gameDir, bool manual = false, EGame ue = EGame.GAME_UE4_LATEST, - ETexturePlatform texture = ETexturePlatform.DesktopMobile, VersioningSettings ver = null) + string gameName, string gameDir, bool manual = false, EGame ue = EGame.GAME_UE4_LATEST) { UserSettings.Default.PerDirectory.TryGetValue(gameDir, out var old); return new DirectorySettings @@ -19,11 +18,13 @@ public class DirectorySettings : ViewModel GameName = gameName, GameDirectory = gameDir, IsManual = manual, - UeVersion = ue, - TexturePlatform = texture, - Versioning = ver ?? new VersioningSettings(), + UeVersion = old?.UeVersion ?? ue, + TexturePlatform = old?.TexturePlatform ?? ETexturePlatform.DesktopMobile, + Versioning = old?.Versioning ?? new VersioningSettings(), Endpoints = old?.Endpoints ?? EndpointSettings.Default(gameName), - Directories = old?.Directories ?? CustomDirectory.Default(gameName) + Directories = old?.Directories ?? CustomDirectory.Default(gameName), + AesKeys = old?.AesKeys ?? new AesResponse { MainKey = string.Empty, DynamicKeys = null }, + LastAesReload = old?.LastAesReload ?? DateTime.Today.AddDays(-1) }; } @@ -90,6 +91,13 @@ public class DirectorySettings : ViewModel set => SetProperty(ref _aesKeys, value); } + private DateTime _lastAesReload; + public DateTime LastAesReload + { + get => _lastAesReload; + set => SetProperty(ref _lastAesReload, value); + } + private bool Equals(DirectorySettings other) { return GameDirectory == other.GameDirectory && UeVersion == other.UeVersion; diff --git a/FModel/Settings/UserSettings.cs b/FModel/Settings/UserSettings.cs index 07e16b28..fe4cb7e9 100644 --- a/FModel/Settings/UserSettings.cs +++ b/FModel/Settings/UserSettings.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Windows; using System.Windows.Input; -using CUE4Parse.UE4.Assets.Exports.Texture; -using CUE4Parse.UE4.Objects.Core.Serialization; using CUE4Parse.UE4.Versions; using CUE4Parse_Conversion.Meshes; using CUE4Parse_Conversion.Textures; @@ -230,22 +228,12 @@ namespace FModel.Settings set => SetProperty(ref _perDirectory, value); } + [JsonIgnore] public DirectorySettings CurrentDir { get; set; } /// /// TO DELETEEEEEEEEEEEEE /// - - private IDictionary _aesKeys = new Dictionary(); - public IDictionary AesKeys - { - get => _aesKeys; - set => SetProperty(ref _aesKeys, value); - } - - // - // can't refactor to use this data layout for everything - // because it will wipe old user settings that relies on FGame private IDictionary _manualGames = new Dictionary(); public IDictionary ManualGames { @@ -253,86 +241,6 @@ namespace FModel.Settings set => SetProperty(ref _manualGames, value); } - private IDictionary> _customDirectories = new Dictionary> - { - {FGame.Unknown, new List()}, - { - FGame.FortniteGame, new List - { - new("Cosmetics", "FortniteGame/Content/Athena/Items/Cosmetics/"), - new("Emotes [AUDIO]", "FortniteGame/Content/Athena/Sounds/Emotes/"), - new("Music Packs [AUDIO]", "FortniteGame/Content/Athena/Sounds/MusicPacks/"), - new("Weapons", "FortniteGame/Content/Athena/Items/Weapons/"), - new("Strings", "FortniteGame/Content/Localization/") - } - }, - { - FGame.ShooterGame, new List - { - new("Audio", "ShooterGame/Content/WwiseAudio/Media/"), - new("Characters", "ShooterGame/Content/Characters/"), - new("Gun Buddies", "ShooterGame/Content/Equippables/Buddies/"), - new("Cards and Sprays", "ShooterGame/Content/Personalization/"), - new("Shop Backgrounds", "ShooterGame/Content/UI/OutOfGame/MainMenu/Store/Shared/Textures/"), - new("Weapon Renders", "ShooterGame/Content/UI/Screens/OutOfGame/MainMenu/Collection/Assets/Large/") - } - }, - { - FGame.DeadByDaylight, new List - { - new("Audio", "DeadByDaylight/Content/WwiseAudio/Windows/"), - new("Characters", "DeadByDaylight/Content/Characters/"), - new("Icons", "DeadByDaylight/Content/UI/UMGAssets/Icons/"), - new("Strings", "DeadByDaylight/Content/Localization/") - } - }, - {FGame.OakGame, new List()}, - { - FGame.Dungeons, new List - { - new("Levels", "Dungeons/Content/data/Lovika/Levels"), - new("Friendlies", "Dungeons/Content/Actor/Characters/Friendlies"), - new("Skins", "Dungeons/Content/Actor/Characters/Player/Master/Skins"), - new("Strings", "Dungeons/Content/Localization/") - } - }, - { - FGame.WorldExplorers, new List - { - new("Loot", "WorldExplorers/Content/Loot/"), - new("Strings", "WorldExplorers/Content/Localization/") - } - }, - { - FGame.g3, new List - { - new("Cosmetics", "g3/Content/Blueprints/Cosmetics/"), - new("Strings", "g3/Content/Localization/") - } - }, - {FGame.StateOfDecay2, new List()}, - {FGame.Prospect, new List()}, - {FGame.Indiana, new List()}, - {FGame.RogueCompany, new List()}, - {FGame.SwGame, new List()}, - {FGame.Platform, new List()}, - {FGame.BendGame, new List()}, - {FGame.TslGame, new List()}, - {FGame.PortalWars, new List()}, - {FGame.Gameface, new List()}, - {FGame.Athena, new List()}, - {FGame.MultiVersus, new List()}, - {FGame.Hotta, new List()}, - {FGame.eFootball, new List()} - }; - - private DateTime _lastAesReload = DateTime.Today.AddDays(-1); - public DateTime LastAesReload - { - get => _lastAesReload; - set => SetProperty(ref _lastAesReload, value); - } - private AuthResponse _lastAuthResponse = new() {AccessToken = "", ExpiresAt = DateTime.Now}; public AuthResponse LastAuthResponse { diff --git a/FModel/ViewModels/AesManagerViewModel.cs b/FModel/ViewModels/AesManagerViewModel.cs index c1134cb2..a3fa522d 100644 --- a/FModel/ViewModels/AesManagerViewModel.cs +++ b/FModel/ViewModels/AesManagerViewModel.cs @@ -35,22 +35,7 @@ public class AesManagerViewModel : ViewModel { await _threadWorkerView.Begin(_ => { - if (_cue4Parse.Game == FGame.Unknown && - UserSettings.Default.ManualGames.TryGetValue(UserSettings.Default.GameDirectory, out var settings)) - { - _keysFromSettings = settings.AesKeys; - } - else - { - UserSettings.Default.AesKeys.TryGetValue(_cue4Parse.Game, out _keysFromSettings); - } - - _keysFromSettings ??= new AesResponse - { - MainKey = string.Empty, - DynamicKeys = null - }; - + _keysFromSettings = UserSettings.Default.CurrentDir.AesKeys; _mainKey.Key = Helper.FixKey(_keysFromSettings.MainKey); AesKeys = new FullyObservableCollection(EnumerateAesKeys()); AesKeys.ItemPropertyChanged += AesKeysOnItemPropertyChanged; @@ -105,9 +90,7 @@ public class AesManagerViewModel : ViewModel public void SetAesKeys() { - if (_cue4Parse.Game == FGame.Unknown && UserSettings.Default.ManualGames.ContainsKey(UserSettings.Default.GameDirectory)) - UserSettings.Default.ManualGames[UserSettings.Default.GameDirectory].AesKeys = _keysFromSettings; - else UserSettings.Default.AesKeys[_cue4Parse.Game] = _keysFromSettings; + UserSettings.Default.CurrentDir.AesKeys = _keysFromSettings; // Log.Information("{@Json}", UserSettings.Default); } diff --git a/FModel/ViewModels/ApplicationViewModel.cs b/FModel/ViewModels/ApplicationViewModel.cs index 8c342336..caa8e697 100644 --- a/FModel/ViewModels/ApplicationViewModel.cs +++ b/FModel/ViewModels/ApplicationViewModel.cs @@ -100,10 +100,10 @@ public class ApplicationViewModel : ViewModel if (!result.HasValue || !result.Value) return null; UserSettings.Default.GameDirectory = gameLauncherViewModel.SelectedDirectory.GameDirectory; - UserSettings.Default.PerDirectory[gameDirectory] = gameLauncherViewModel.SelectedDirectory; if (!bAlreadyLaunched || UserSettings.Default.CurrentDir.Equals(gameLauncherViewModel.SelectedDirectory)) return gameLauncherViewModel.SelectedDirectory; + UserSettings.Default.CurrentDir = gameLauncherViewModel.SelectedDirectory; RestartWithWarning(); return null; } diff --git a/FModel/ViewModels/CUE4ParseViewModel.cs b/FModel/ViewModels/CUE4ParseViewModel.cs index 65f6c7fb..c13bf951 100644 --- a/FModel/ViewModels/CUE4ParseViewModel.cs +++ b/FModel/ViewModels/CUE4ParseViewModel.cs @@ -331,7 +331,7 @@ public class CUE4ParseViewModel : ViewModel var aes = _apiEndpointView.DynamicApi.GetAesKeys(cancellationToken, endpoint.Url, endpoint.Path); if (aes is not { IsValid: true }) return; - UserSettings.Default.AesKeys[Game] = aes; + UserSettings.Default.CurrentDir.AesKeys = aes; }); } diff --git a/FModel/ViewModels/SettingsViewModel.cs b/FModel/ViewModels/SettingsViewModel.cs index 9b2b820a..9d3e4f16 100644 --- a/FModel/ViewModels/SettingsViewModel.cs +++ b/FModel/ViewModels/SettingsViewModel.cs @@ -1,26 +1,20 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Threading.Tasks; using CUE4Parse.UE4.Assets.Exports.Texture; -using CUE4Parse.UE4.Objects.Core.Misc; using CUE4Parse.UE4.Objects.Core.Serialization; using CUE4Parse.UE4.Versions; using CUE4Parse_Conversion.Meshes; using CUE4Parse_Conversion.Textures; using CUE4Parse.UE4.Assets.Exports.Material; -using FModel.Extensions; using FModel.Framework; using FModel.Services; using FModel.Settings; -using FModel.ViewModels.ApiEndpoints.Models; namespace FModel.ViewModels; public class SettingsViewModel : ViewModel { - private ThreadWorkerViewModel _threadWorkerView => ApplicationService.ThreadWorkerView; - private ApiEndpointViewModel _apiEndpointView => ApplicationService.ApiEndpointView; private readonly DiscordHandler _discordHandler = DiscordService.DiscordHandler; private bool _useCustomOutputFolders; @@ -211,20 +205,10 @@ public class SettingsViewModel : ViewModel _gameSnapshot = UserSettings.Default.GameDirectory; _updateModeSnapshot = UserSettings.Default.UpdateMode; _uePlatformSnapshot = UserSettings.Default.CurrentDir.TexturePlatform; - if (_game == FGame.Unknown && UserSettings.Default.ManualGames.TryGetValue(_gameSnapshot, out var settings)) - { - _ueGameSnapshot = settings.OverridedGame; - _customVersionsSnapshot = settings.OverridedCustomVersions; - _optionsSnapshot = settings.OverridedOptions; - _mapStructTypesSnapshot = settings.OverridedMapStructTypes; - } - else - { - _ueGameSnapshot = UserSettings.Default.CurrentDir.UeVersion; - _customVersionsSnapshot = UserSettings.Default.CurrentDir.Versioning.CustomVersions; - _optionsSnapshot = UserSettings.Default.CurrentDir.Versioning.Options; - _mapStructTypesSnapshot = UserSettings.Default.CurrentDir.Versioning.MapStructTypes; - } + _ueGameSnapshot = UserSettings.Default.CurrentDir.UeVersion; + _customVersionsSnapshot = UserSettings.Default.CurrentDir.Versioning.CustomVersions; + _optionsSnapshot = UserSettings.Default.CurrentDir.Versioning.Options; + _mapStructTypesSnapshot = UserSettings.Default.CurrentDir.Versioning.MapStructTypes; AesEndpoint = UserSettings.Default.CurrentDir.Endpoints[0]; MappingEndpoint = UserSettings.Default.CurrentDir.Endpoints[1]; @@ -300,21 +284,11 @@ public class SettingsViewModel : ViewModel restart = true; UserSettings.Default.UpdateMode = SelectedUpdateMode; + UserSettings.Default.CurrentDir.UeVersion = SelectedUeGame; UserSettings.Default.CurrentDir.TexturePlatform = SelectedUePlatform; - if (_game == FGame.Unknown && UserSettings.Default.ManualGames.ContainsKey(UserSettings.Default.GameDirectory)) - { - UserSettings.Default.ManualGames[UserSettings.Default.GameDirectory].OverridedGame = SelectedUeGame; - UserSettings.Default.ManualGames[UserSettings.Default.GameDirectory].OverridedCustomVersions = (List) SelectedCustomVersions; - UserSettings.Default.ManualGames[UserSettings.Default.GameDirectory].OverridedOptions = (Dictionary) SelectedOptions; - UserSettings.Default.ManualGames[UserSettings.Default.GameDirectory].OverridedMapStructTypes = (Dictionary>) SelectedMapStructTypes; - } - else - { - UserSettings.Default.CurrentDir.UeVersion = SelectedUeGame; - UserSettings.Default.CurrentDir.Versioning.CustomVersions = SelectedCustomVersions; - UserSettings.Default.CurrentDir.Versioning.Options = SelectedOptions; - UserSettings.Default.CurrentDir.Versioning.MapStructTypes = SelectedMapStructTypes; - } + UserSettings.Default.CurrentDir.Versioning.CustomVersions = SelectedCustomVersions; + UserSettings.Default.CurrentDir.Versioning.Options = SelectedOptions; + UserSettings.Default.CurrentDir.Versioning.MapStructTypes = SelectedMapStructTypes; UserSettings.Default.AssetLanguage = SelectedAssetLanguage; UserSettings.Default.CompressedAudioMode = SelectedCompressedAudio; diff --git a/FModel/Views/Resources/Controls/DictionaryEditor.xaml b/FModel/Views/Resources/Controls/DictionaryEditor.xaml index 6aabf7c6..808745ea 100644 --- a/FModel/Views/Resources/Controls/DictionaryEditor.xaml +++ b/FModel/Views/Resources/Controls/DictionaryEditor.xaml @@ -23,7 +23,7 @@ + FontFamily="Consolas" FontSize="8pt" ShowLineNumbers="True" Foreground="#DAE5F2" /> new TextDocument + "Versioning Configuration (MapStructTypes)" => new TextDocument { Text = JsonConvert.SerializeObject(_defaultMapStructTypes, Formatting.Indented) },