From 9c60080d3edaec63e0237fda836b7813e3c7da0e Mon Sep 17 00:00:00 2001 From: LongerWarrior Date: Mon, 23 Mar 2026 17:50:31 +0200 Subject: [PATCH] Add folder drag&drop for configuring game directory --- FModel/Enums.cs | 1 + FModel/Helper.cs | 23 ++- FModel/MainWindow.xaml | 8 +- FModel/ViewModels/ApplicationViewModel.cs | 31 ++++ FModel/Views/DirectorySelector.xaml | 17 +- FModel/Views/DirectorySelector.xaml.cs | 34 +--- ...UsmapDropOverlay.xaml => DropOverlay.xaml} | 8 +- .../Resources/Controls/DropOverlay.xaml.cs | 169 ++++++++++++++++++ .../Controls/UsmapDropOverlay.xaml.cs | 106 ----------- FModel/Views/SettingsView.xaml | 6 +- FModel/Views/SettingsView.xaml.cs | 20 +++ 11 files changed, 276 insertions(+), 147 deletions(-) rename FModel/Views/Resources/Controls/{UsmapDropOverlay.xaml => DropOverlay.xaml} (90%) create mode 100644 FModel/Views/Resources/Controls/DropOverlay.xaml.cs delete mode 100644 FModel/Views/Resources/Controls/UsmapDropOverlay.xaml.cs diff --git a/FModel/Enums.cs b/FModel/Enums.cs index 2bb4c25d..9f435a10 100644 --- a/FModel/Enums.cs +++ b/FModel/Enums.cs @@ -27,6 +27,7 @@ public enum SettingsOut public enum EStatusKind { Ready, // ready + Configuring, // waiting for user input Loading, // doing stuff Stopping, // trying to stop Stopped, // stopped diff --git a/FModel/Helper.cs b/FModel/Helper.cs index 58d51545..05f1530b 100644 --- a/FModel/Helper.cs +++ b/FModel/Helper.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Windows; @@ -62,7 +63,7 @@ public static class Helper GetOpenedWindow(windowName).Close(); } - private static bool IsWindowOpen(string name = "") where T : Window + public static bool IsWindowOpen(string name = "") where T : Window { return string.IsNullOrEmpty(name) ? Application.Current.Windows.OfType().Any() @@ -111,4 +112,24 @@ public static class Helper const float ratio = 180f / MathF.PI; return radians * ratio; } + + public static string GetGameName(string path) + { + // install_folder/ + // ├─ Engine/ + // ├─ GameName/ + // │ ├─ Binaries/ + // │ ├─ Content/ + // │ │ ├─ Paks/ + // our goal is to get the GameName folder + var dir = new DirectoryInfo(path); + if (dir.Name.Equals("Paks", StringComparison.InvariantCulture) && dir.Parent is { Parent: not null } && + dir.Parent.Name.Equals("Content", StringComparison.InvariantCulture) && + dir.Parent.Parent.GetDirectories().Any(x => x.Name == "Binaries")) + { + return dir.Parent.Parent.Name; + } + + return dir.Name; + } } diff --git a/FModel/MainWindow.xaml b/FModel/MainWindow.xaml index abf9e32a..46d2ddb5 100644 --- a/FModel/MainWindow.xaml +++ b/FModel/MainWindow.xaml @@ -629,6 +629,10 @@ + + + + @@ -710,7 +714,7 @@ - + diff --git a/FModel/ViewModels/ApplicationViewModel.cs b/FModel/ViewModels/ApplicationViewModel.cs index b49b2dd9..51aa8bfe 100644 --- a/FModel/ViewModels/ApplicationViewModel.cs +++ b/FModel/ViewModels/ApplicationViewModel.cs @@ -141,8 +141,10 @@ public class ApplicationViewModel : ViewModel if (!bAlreadyLaunched && UserSettings.Default.PerDirectory.TryGetValue(gameDirectory, out var currentDir)) return currentDir; + Status.SetStatus(EStatusKind.Configuring); var gameLauncherViewModel = new GameSelectorViewModel(gameDirectory); var result = new DirectorySelector(gameLauncherViewModel).ShowDialog(); + Status.SetStatus(EStatusKind.Ready); if (!result.HasValue || !result.Value) return null; UserSettings.Default.GameDirectory = gameLauncherViewModel.SelectedDirectory.GameDirectory; @@ -155,6 +157,35 @@ public class ApplicationViewModel : ViewModel return null; } + public DirectorySettings AddGameDirectory(string directory) + { + if (Status.Kind is EStatusKind.Configuring) + { + var directorySelector = Helper.GetWindow("Directory Selector", null); + directorySelector.AddManualGame(directory); + return null; + } + else + { + Status.SetStatus(EStatusKind.Configuring); + var gameLauncherViewModel = new GameSelectorViewModel(UserSettings.Default.GameDirectory); + var directorySelector = new DirectorySelector(gameLauncherViewModel); + directorySelector.AddManualGame(directory); + var result = directorySelector.ShowDialog(); + Status.SetStatus(EStatusKind.Ready); + if (!result.HasValue || !result.Value) + return null; + + UserSettings.Default.GameDirectory = gameLauncherViewModel.SelectedDirectory.GameDirectory; + if (UserSettings.Default.CurrentDir.Equals(gameLauncherViewModel.SelectedDirectory)) + return gameLauncherViewModel.SelectedDirectory; + + UserSettings.Default.CurrentDir = gameLauncherViewModel.SelectedDirectory; + RestartWithWarning(); + return null; + } + } + public void RestartWithWarning() { MessageBox.Show("It looks like you just changed something.\nFModel will restart to apply your changes.", "Uh oh, a restart is needed", MessageBoxButton.OK, MessageBoxImage.Warning); diff --git a/FModel/Views/DirectorySelector.xaml b/FModel/Views/DirectorySelector.xaml index 22f27a2a..3bc8b1de 100644 --- a/FModel/Views/DirectorySelector.xaml +++ b/FModel/Views/DirectorySelector.xaml @@ -1,4 +1,4 @@ - + Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.25'}" + AllowDrop="True">