Skip to content

Commit

Permalink
NTE support + better directory permission detection
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Nov 29, 2024
1 parent 3edcd31 commit 062d54e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions FModel/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
};

Expand Down

0 comments on commit 062d54e

Please sign in to comment.