Skip to content

Commit

Permalink
Fix macOS crash when changing parent directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNexusAvenger committed Sep 6, 2021
1 parent 95f2d16 commit c8c5c68
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions NLUL.GUI/Component/Settings/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -87,20 +88,26 @@ public SettingsView()
};
this.Get<RoundedImageButton>("ChangeClientParentDirectory").ButtonPressed += (sender, args) =>
{
// Prompt for the directory.
var dialog = new OpenFolderDialog();
dialog.Directory = this.CurrentParentDirectory;
var newDirectoryTask = dialog.ShowAsync(this.GetWindow());
Task.Run(async () =>
{
// Prompt for the directory.
var dialog = new OpenFolderDialog();
dialog.Directory = this.CurrentParentDirectory;
var newDirectory = await dialog.ShowAsync(this.GetWindow());
if (newDirectory == null) return;
// Get the new directory.
// Can't be awaited directly with ShowAsync because of a multithreading crash on macOS.
var newDirectory = await newDirectoryTask;
if (string.IsNullOrEmpty(newDirectory) || newDirectory == this.CurrentParentDirectory) return;
// Move the clients.
ConfirmPrompt.OpenPrompt("Changing install locations will move any clients you have downloaded to it. Continue?", () =>
{
this.parentDirectoryDisplay.Text = newDirectory.Replace(Path.DirectorySeparatorChar == '/' ? '\\' : '/', Path.DirectorySeparatorChar);
Client.ChangeParentDirectory(newDirectory);
});
ConfirmPrompt.OpenPrompt(
"Changing install locations will move any clients you have downloaded to it. Continue?", () =>
{
this.parentDirectoryDisplay.Text = newDirectory.Replace(
Path.DirectorySeparatorChar == '/' ? '\\' : '/', Path.DirectorySeparatorChar);
Client.ChangeParentDirectory(newDirectory);
});
});
};
}
Expand Down

0 comments on commit c8c5c68

Please sign in to comment.