Skip to content

Commit

Permalink
usable
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Jun 18, 2023
1 parent 25c10e8 commit 2a265ea
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 159 deletions.
13 changes: 13 additions & 0 deletions FModel/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ protected override void OnStartup(StartupEventArgs e)
{
UserSettings.Default = JsonConvert.DeserializeObject<UserSettings>(
File.ReadAllText(UserSettings.FilePath), JsonNetSerializer.SerializerSettings);

/*if (UserSettings.Default.ShowChangelog) */MigrateV1Games();
}
catch
{
Expand Down Expand Up @@ -141,6 +143,17 @@ private void OnUnhandledException(object sender, DispatcherUnhandledExceptionEve
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;
Expand Down
4 changes: 2 additions & 2 deletions FModel/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ private async void OnLoaded(object sender, RoutedEventArgs e)
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;
}
Expand Down
20 changes: 14 additions & 6 deletions FModel/Settings/DirectorySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ 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
{
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)
};
}

Expand Down Expand Up @@ -90,6 +91,13 @@ public AesResponse AesKeys
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;
Expand Down
94 changes: 1 addition & 93 deletions FModel/Settings/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
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;
Expand Down Expand Up @@ -230,109 +228,19 @@ public IDictionary<string, DirectorySettings> PerDirectory
set => SetProperty(ref _perDirectory, value);
}

[JsonIgnore]
public DirectorySettings CurrentDir { get; set; }

/// <summary>
/// TO DELETEEEEEEEEEEEEE
/// </summary>

private IDictionary<FGame, AesResponse> _aesKeys = new Dictionary<FGame, AesResponse>();
public IDictionary<FGame, AesResponse> AesKeys
{
get => _aesKeys;
set => SetProperty(ref _aesKeys, value);
}

// <gameDirectory as string, settings>
// can't refactor to use this data layout for everything
// because it will wipe old user settings that relies on FGame
private IDictionary<string, GameSelectorViewModel.DetectedGame> _manualGames = new Dictionary<string, GameSelectorViewModel.DetectedGame>();
public IDictionary<string, GameSelectorViewModel.DetectedGame> ManualGames
{
get => _manualGames;
set => SetProperty(ref _manualGames, value);
}

private IDictionary<FGame, IList<CustomDirectory>> _customDirectories = new Dictionary<FGame, IList<CustomDirectory>>
{
{FGame.Unknown, new List<CustomDirectory>()},
{
FGame.FortniteGame, new List<CustomDirectory>
{
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<CustomDirectory>
{
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<CustomDirectory>
{
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<CustomDirectory>()},
{
FGame.Dungeons, new List<CustomDirectory>
{
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<CustomDirectory>
{
new("Loot", "WorldExplorers/Content/Loot/"),
new("Strings", "WorldExplorers/Content/Localization/")
}
},
{
FGame.g3, new List<CustomDirectory>
{
new("Cosmetics", "g3/Content/Blueprints/Cosmetics/"),
new("Strings", "g3/Content/Localization/")
}
},
{FGame.StateOfDecay2, new List<CustomDirectory>()},
{FGame.Prospect, new List<CustomDirectory>()},
{FGame.Indiana, new List<CustomDirectory>()},
{FGame.RogueCompany, new List<CustomDirectory>()},
{FGame.SwGame, new List<CustomDirectory>()},
{FGame.Platform, new List<CustomDirectory>()},
{FGame.BendGame, new List<CustomDirectory>()},
{FGame.TslGame, new List<CustomDirectory>()},
{FGame.PortalWars, new List<CustomDirectory>()},
{FGame.Gameface, new List<CustomDirectory>()},
{FGame.Athena, new List<CustomDirectory>()},
{FGame.MultiVersus, new List<CustomDirectory>()},
{FGame.Hotta, new List<CustomDirectory>()},
{FGame.eFootball, new List<CustomDirectory>()}
};

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
{
Expand Down
21 changes: 2 additions & 19 deletions FModel/ViewModels/AesManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,7 @@ public async Task InitAes()
{
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<FileItem>(EnumerateAesKeys());
AesKeys.ItemPropertyChanged += AesKeysOnItemPropertyChanged;
Expand Down Expand Up @@ -105,9 +90,7 @@ private void AesKeysOnItemPropertyChanged(object sender, ItemPropertyChangedEven

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);
}

Expand Down
2 changes: 1 addition & 1 deletion FModel/ViewModels/ApplicationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public DirectorySettings AvoidEmptyGameDirectory(bool bAlreadyLaunched)
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;
}
Expand Down
2 changes: 1 addition & 1 deletion FModel/ViewModels/CUE4ParseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ await _threadWorkerView.Begin(cancellationToken =>
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;
});
}

Expand Down
42 changes: 8 additions & 34 deletions FModel/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -211,20 +205,10 @@ public void Initialize()
_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];
Expand Down Expand Up @@ -300,21 +284,11 @@ public bool Save(out List<SettingsOut> whatShouldIDo)
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<FCustomVersion>) SelectedCustomVersions;
UserSettings.Default.ManualGames[UserSettings.Default.GameDirectory].OverridedOptions = (Dictionary<string, bool>) SelectedOptions;
UserSettings.Default.ManualGames[UserSettings.Default.GameDirectory].OverridedMapStructTypes = (Dictionary<string, KeyValuePair<string, string>>) 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;
Expand Down
2 changes: 1 addition & 1 deletion FModel/Views/Resources/Controls/DictionaryEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</Grid.RowDefinitions>

<avalonEdit:TextEditor x:Name="MyAvalonEditor" Grid.Row="0" Background="{DynamicResource {x:Static adonisUi:Brushes.Layer3BackgroundBrush}}"
FontFamily="Consolas" FontSize="8pt" IsReadOnly="True" ShowLineNumbers="True" Foreground="#DAE5F2" />
FontFamily="Consolas" FontSize="8pt" ShowLineNumbers="True" Foreground="#DAE5F2" />

<Border Grid.Row="1"
Background="{DynamicResource {x:Static adonisUi:Brushes.Layer1BackgroundBrush}}"
Expand Down
3 changes: 1 addition & 2 deletions FModel/Views/Resources/Controls/DictionaryEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using CUE4Parse.UE4.Objects.Core.Misc;
Expand Down Expand Up @@ -104,7 +103,7 @@ private void OnReset(object sender, RoutedEventArgs e)
{
Text = JsonConvert.SerializeObject(_defaultOptions, Formatting.Indented)
},
"MapStructTypes" => new TextDocument
"Versioning Configuration (MapStructTypes)" => new TextDocument
{
Text = JsonConvert.SerializeObject(_defaultMapStructTypes, Formatting.Indented)
},
Expand Down

0 comments on commit 2a265ea

Please sign in to comment.