From 23e454533ced02766ba23c1ce3446f8f025e7af2 Mon Sep 17 00:00:00 2001 From: Asval Date: Mon, 9 Dec 2019 17:36:39 +0100 Subject: [PATCH] auto restart if path changed in settings --- FModel/FModel_Main.xaml.cs | 2 +- FModel/Forms/FModel_Settings.xaml.cs | 8 ++++++-- FModel/Methods/PAKs/RegisterFromPath.cs | 15 ++++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/FModel/FModel_Main.xaml.cs b/FModel/FModel_Main.xaml.cs index 89b8f280..bda08dd4 100644 --- a/FModel/FModel_Main.xaml.cs +++ b/FModel/FModel_Main.xaml.cs @@ -13,7 +13,6 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; -using FProp = FModel.Properties.Settings; namespace FModel { @@ -164,6 +163,7 @@ namespace FModel } private void MI_Settings_Click(object sender, RoutedEventArgs e) { + DebugHelper.WriteLine("FWindow: Settings"); if (!FormsUtility.IsWindowOpen("Settings")) { new FModel_Settings().Show(); diff --git a/FModel/Forms/FModel_Settings.xaml.cs b/FModel/Forms/FModel_Settings.xaml.cs index f9ff1a34..66fec15b 100644 --- a/FModel/Forms/FModel_Settings.xaml.cs +++ b/FModel/Forms/FModel_Settings.xaml.cs @@ -112,7 +112,6 @@ namespace FModel.Forms private void Button_Click(object sender, RoutedEventArgs e) { SetUserSettings(); - DebugHelper.WriteUserSettings(); Close(); } @@ -188,8 +187,13 @@ namespace FModel.Forms if (restart) { - DarkMessageBox.Show("Please, restart FModel to apply your new path(s)", "FModel Path(s) Changed", MessageBoxButton.OK, MessageBoxImage.Information); + DarkMessageBox.Show("FModel is about to restart because you applied your new path(s)", "FModel Path(s) Changed", MessageBoxButton.OK, MessageBoxImage.Information); + DebugHelper.WriteLine("FModel is restarting"); + System.Windows.Forms.Application.Restart(); + Application.Current.Shutdown(); } + else + DebugHelper.WriteUserSettings(); } private async void UpdateImageBox(object sender, RoutedEventArgs e) diff --git a/FModel/Methods/PAKs/RegisterFromPath.cs b/FModel/Methods/PAKs/RegisterFromPath.cs index 1d8ccb65..65bb8e27 100644 --- a/FModel/Methods/PAKs/RegisterFromPath.cs +++ b/FModel/Methods/PAKs/RegisterFromPath.cs @@ -12,6 +12,8 @@ namespace FModel.Methods.PAKs { static class RegisterFromPath { + private static string _ePath = string.Empty; + public static void FilterPAKs() { if (string.IsNullOrEmpty(FProp.Default.FPak_Path)) @@ -87,11 +89,14 @@ namespace FModel.Methods.PAKs private static string GetDatFile() { - string ePath = $"{GetEpicDirectory()}\\UnrealEngineLauncher\\LauncherInstalled.dat"; - if (File.Exists(ePath)) + if (!string.IsNullOrEmpty(_ePath)) + return _ePath; + + _ePath = $"{GetEpicDirectory()}\\UnrealEngineLauncher\\LauncherInstalled.dat"; + if (File.Exists(_ePath)) { - DebugHelper.WriteLine("EPIC .dat file at " + ePath); - return ePath; + DebugHelper.WriteLine("EPIC .dat file at " + _ePath); + return _ePath; } else DebugHelper.WriteLine("EPIC .dat file not found"); @@ -135,7 +140,7 @@ namespace FModel.Methods.PAKs { JToken game = GetGameData(); if (game != null) - DebugHelper.WriteLine("Fortnite version: " + game["AppVersion"] + " found in .dat file"); + DebugHelper.WriteLine(game["AppVersion"] + " found in .dat file"); } } }