Support opening multiple folders

* Resolves #1407
* Closes #1411
This commit is contained in:
ds5678 2024-08-11 13:49:27 -07:00
parent 8429911c25
commit f3be12008a
4 changed files with 43 additions and 6 deletions

View File

@ -28,7 +28,7 @@
<ItemGroup>
<PackageReference Include="AssetRipper.Text.Html" Version="1.0.0" />
<PackageReference Include="NativeFileDialogs.Net" Version="1.1.0" />
<PackageReference Include="NativeFileDialogs.Net" Version="1.2.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

View File

@ -61,6 +61,42 @@ internal static class Dialogs
}
}
public static class OpenFolders
{
public static async Task HandleGetRequest(HttpContext context)
{
context.Response.DisableCaching();
string[]? paths = await Task.Run(static () =>
{
if (Supported)
{
GetUserInput(out string[]? paths);
return paths;
}
else
{
return null;
}
});
await Results.Json(paths ?? [], AppJsonSerializerContext.Default.StringArray).ExecuteAsync(context);
}
public static NfdStatus GetUserInput(out string[]? paths, string? defaultPath = null)
{
ThrowIfNotSupported();
lock (lockObject)
{
return Nfd.PickFolderMultiple(out paths, defaultPath);
}
}
public static bool TryGetUserInput([NotNullWhen(true)] out string[]? paths, string? defaultPath = null)
{
NfdStatus status = GetUserInput(out paths, defaultPath);
return status == NfdStatus.Ok && paths is not null;
}
}
public static class OpenFile
{
public static async Task HandleGetRequest(HttpContext context)

View File

@ -42,23 +42,23 @@ public static class Commands
{
IFormCollection form = await request.ReadFormAsync();
string? path;
string[]? paths;
if (form.TryGetValue("Path", out StringValues values))
{
path = values;
paths = values;
}
else if (Dialogs.Supported)
{
Dialogs.OpenFolder.GetUserInput(out path);
Dialogs.OpenFolders.GetUserInput(out paths);
}
else
{
return CommandsPath;
}
if (!string.IsNullOrEmpty(path))
if (paths is { Length: > 0 })
{
GameFileLoader.LoadAndProcess([path]);
GameFileLoader.LoadAndProcess(paths);
}
return null;
}

View File

@ -194,6 +194,7 @@ public static class WebApplicationLauncher
//Dialogs
app.MapGet("/Dialogs/SaveFile", Dialogs.SaveFile.HandleGetRequest);
app.MapGet("/Dialogs/OpenFolder", Dialogs.OpenFolder.HandleGetRequest);
app.MapGet("/Dialogs/OpenFolders", Dialogs.OpenFolders.HandleGetRequest);
app.MapGet("/Dialogs/OpenFile", Dialogs.OpenFile.HandleGetRequest);
app.MapGet("/Dialogs/OpenFiles", Dialogs.OpenFiles.HandleGetRequest);