2022-01-16 13:46:16 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using Microsoft.WindowsAPICodePack.Dialogs;
|
|
|
|
|
using Wabbajack.Paths;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.App.Blazor.Utility;
|
|
|
|
|
|
|
|
|
|
public static class Dialog
|
|
|
|
|
{
|
2022-01-17 16:45:52 +00:00
|
|
|
|
/*
|
|
|
|
|
* TODO: [Critical] CommonOpenFileDialog.ShowDialog() causes UI freeze and crash.
|
|
|
|
|
* This method seems to alleviate it, but it still occasionally happens.
|
|
|
|
|
*/
|
2022-01-16 13:46:16 +00:00
|
|
|
|
public static async Task<AbsolutePath?> ShowDialogNonBlocking(bool isFolderPicker = false)
|
|
|
|
|
{
|
|
|
|
|
return await Task.Factory.StartNew(() =>
|
|
|
|
|
{
|
|
|
|
|
Window newWindow = new();
|
|
|
|
|
var dialog = new CommonOpenFileDialog();
|
|
|
|
|
dialog.IsFolderPicker = isFolderPicker;
|
|
|
|
|
dialog.Multiselect = false;
|
2022-01-21 13:41:37 +00:00
|
|
|
|
var result = dialog.ShowDialog(newWindow);
|
2022-01-16 13:46:16 +00:00
|
|
|
|
return result == CommonFileDialogResult.Ok ? dialog.FileName : null;
|
|
|
|
|
}, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext())
|
|
|
|
|
.ContinueWith(result => result.Result?.ToAbsolutePath())
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
}
|
2022-01-17 16:45:52 +00:00
|
|
|
|
}
|