From 01699f6e43c2153ec2bc23db76c0fe56d43845a0 Mon Sep 17 00:00:00 2001 From: PsychoPast <33565739+PsychoPast@users.noreply.github.com> Date: Fri, 1 Nov 2019 19:39:52 +0200 Subject: [PATCH] meh --- FModel/Forms/AESManager.xaml.cs | 28 ++++++++++++++++++++++++- FModel/Forms/FModel_Settings.xaml.cs | 25 +++++++++++++++++++--- FModel/Methods/PAKs/RegisterFromPath.cs | 6 +++--- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/FModel/Forms/AESManager.xaml.cs b/FModel/Forms/AESManager.xaml.cs index 9e650c87..754e2ef6 100644 --- a/FModel/Forms/AESManager.xaml.cs +++ b/FModel/Forms/AESManager.xaml.cs @@ -1,10 +1,14 @@ using FModel.Methods; using FModel.Methods.AESManager; using FModel.Methods.Utilities; +using Newtonsoft.Json; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; +using System.Net.Http; using System.Text.RegularExpressions; +using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; @@ -26,10 +30,30 @@ namespace FModel.Forms this.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Display); } - private void Window_Loaded(object sender, RoutedEventArgs e) + private async void Window_Loaded(object sender, RoutedEventArgs e) { AddLblTxtForDynamicPAKs(); GetUserSettings(); + if (string.IsNullOrEmpty(FProp.Default.FPak_MainAES)) + { + await SetMainKey(); + } + } + + /// + /// Fetch latest version's main aes key. + /// + /// + private async Task SetMainKey() + { + dynamic key = null; + using (HttpClient web = new HttpClient()) + { + //Not using BenBot api since Rate Limit + key = JsonConvert.DeserializeObject(await web.GetStringAsync("https://fnbot.shop/api/aes.json")); + } + MAesTextBox.Text = $"0x{key.aes}"; + FProp.Default.FPak_MainAES = $"{key.aes}"; } private void Button_Click(object sender, RoutedEventArgs e) @@ -128,5 +152,7 @@ namespace FModel.Forms //SAVE FProp.Default.Save(); } + + } } diff --git a/FModel/Forms/FModel_Settings.xaml.cs b/FModel/Forms/FModel_Settings.xaml.cs index 1423c13f..9cc3bc91 100644 --- a/FModel/Forms/FModel_Settings.xaml.cs +++ b/FModel/Forms/FModel_Settings.xaml.cs @@ -19,6 +19,7 @@ using FModel.Methods.Assets.IconCreator; using ColorPickerWPF; using Newtonsoft.Json; using System.Collections.Generic; +using FModel.Methods.PAKs; namespace FModel.Forms { @@ -104,10 +105,20 @@ namespace FModel.Forms SetUserSettings(); Close(); } + /// + /// Get user's Directory Letter. + /// + /// private static string GetEpicDirectory() => Directory.Exists(@"C:\ProgramData\Epic") ? @"C:\ProgramData\Epic" : Directory.Exists(@"D:\ProgramData\Epic") ? @"D:\ProgramData\Epic" : @"E:\ProgramData\Epic"; - + /// + /// Check if the LauncherInstalled.dat exists. + /// + /// private static bool DatFileExists() => File.Exists($@"{GetEpicDirectory()}\UnrealEngineLauncher\LauncherInstalled.dat"); - + /// + /// Fetch automatically user's game file location. + /// + /// private string GetGameFiles() { if (DatFileExists()) @@ -135,7 +146,15 @@ namespace FModel.Forms private async void GetUserSettings() { string AutoPath = GetGameFiles(); - FProp.Default.FPak_Path = string.IsNullOrEmpty(FProp.Default.FPak_Path) && DatFileExists() && AutoPath != null ? AutoPath : FProp.Default.FPak_Path; + if (string.IsNullOrEmpty(FProp.Default.FPak_Path) && DatFileExists() && AutoPath != null) + { + FProp.Default.FPak_Path = AutoPath; + RegisterFromPath.PAK_PATH = AutoPath; + RegisterFromPath.FilterPAKs(); + new UpdateMyProcessEvents("Process events", "State").Update(); + } + + InputTextBox.Text = FProp.Default.FPak_Path; bDiffFileSize.IsChecked = FProp.Default.FDiffFileSize; OutputTextBox.Text = FProp.Default.FOutput_Path; diff --git a/FModel/Methods/PAKs/RegisterFromPath.cs b/FModel/Methods/PAKs/RegisterFromPath.cs index 211d6503..2424b73f 100644 --- a/FModel/Methods/PAKs/RegisterFromPath.cs +++ b/FModel/Methods/PAKs/RegisterFromPath.cs @@ -10,7 +10,7 @@ namespace FModel.Methods.PAKs { static class RegisterFromPath { - private static readonly string PAK_PATH = FProp.Default.FPak_Path; + public static string PAK_PATH = FProp.Default.FPak_Path; public static void FilterPAKs() { @@ -55,7 +55,7 @@ namespace FModel.Methods.PAKs private static IEnumerable GetPAKsFromPath() { - return Directory.GetFiles(PAK_PATH,"*.pak",SearchOption.AllDirectories); + return Directory.GetFiles(PAK_PATH, "*.pak", SearchOption.AllDirectories); } } -} +} \ No newline at end of file