From 062d54e3669bbfa5b7728428b1694d319b5d65b5 Mon Sep 17 00:00:00 2001 From: Asval Date: Fri, 29 Nov 2024 11:47:13 +0100 Subject: [PATCH] NTE support + better directory permission detection --- CUE4Parse | 2 +- FModel/App.xaml.cs | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CUE4Parse b/CUE4Parse index 87020fa4..0cd21c2d 160000 --- a/CUE4Parse +++ b/CUE4Parse @@ -1 +1 @@ -Subproject commit 87020fa42ab70bb44a08bcd9f5d742ad70c97373 +Subproject commit 0cd21c2d96068d29b812c9d0538de5654d8fbab5 diff --git a/FModel/App.xaml.cs b/FModel/App.xaml.cs index 4781e951..46602ad0 100644 --- a/FModel/App.xaml.cs +++ b/FModel/App.xaml.cs @@ -51,13 +51,20 @@ protected override void OnStartup(StartupEventArgs e) if (!Directory.Exists(UserSettings.Default.OutputDirectory)) { var currentDir = Directory.GetCurrentDirectory(); - var dirInfo = new DirectoryInfo(currentDir); - if (dirInfo.Attributes.HasFlag(FileAttributes.Archive)) - throw new Exception("FModel cannot be run from an archive file. Please extract it and try again."); - if (dirInfo.Attributes.HasFlag(FileAttributes.ReadOnly)) - throw new Exception("FModel cannot be run from a read-only directory. Please move it to a writable location."); + try + { + var outputDir = Directory.CreateDirectory(Path.Combine(currentDir, "Output")); + using (File.Create(Path.Combine(outputDir.FullName, Path.GetRandomFileName()), 1, FileOptions.DeleteOnClose)) + { + + } - UserSettings.Default.OutputDirectory = Path.Combine(currentDir, "Output"); + UserSettings.Default.OutputDirectory = outputDir.FullName; + } + catch (UnauthorizedAccessException exception) + { + throw new Exception("FModel cannot create the output directory where it is currently located. Please move FModel.exe to a different location.", exception); + } } if (!Directory.Exists(UserSettings.Default.RawDataDirectory)) @@ -126,15 +133,15 @@ private void OnUnhandledException(object sender, DispatcherUnhandledExceptionEve var messageBox = new MessageBoxModel { - Text = $"An unhandled exception occurred: {e.Exception.Message}", + Text = $"An unhandled {e.Exception.GetBaseException().GetType()} occurred: {e.Exception.Message}", Caption = "Fatal Error", Icon = MessageBoxImage.Error, - Buttons = new[] - { + Buttons = + [ MessageBoxButtons.Custom("Reset Settings", EErrorKind.ResetSettings), MessageBoxButtons.Custom("Restart", EErrorKind.Restart), MessageBoxButtons.Custom("OK", EErrorKind.Ignore) - }, + ], IsSoundEnabled = false };