From 9714ed8cd753288b835f93e1b656dc962bf33eef Mon Sep 17 00:00:00 2001 From: Speykious Date: Sun, 27 Mar 2022 17:40:08 +0200 Subject: [PATCH] Implement `OpenDialogMultiple` --- NativeFileDialogs.Net/Nfd.cs | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/NativeFileDialogs.Net/Nfd.cs b/NativeFileDialogs.Net/Nfd.cs index c72f42c..76c9162 100644 --- a/NativeFileDialogs.Net/Nfd.cs +++ b/NativeFileDialogs.Net/Nfd.cs @@ -11,6 +11,7 @@ namespace NativeFileDialogs.Net; public static class Nfd { private static readonly NfdManager manager = new NfdManager(); + public static NfdStatus OpenDialog(out string outPath, IDictionary? filters = null, string? defaultPath = null) { manager.PushDialog(); @@ -28,6 +29,42 @@ public static class Nfd return status; } + public static NfdStatus OpenDialogMultiple(out string[] outPaths, IDictionary? filters = null, string? defaultPath = null) + { + manager.PushDialog(); + NfdnfilteritemT[] filterItems = ToFilterItems(filters); + NfdStatus status; + + unsafe + { + IntPtr pathSet; + status = nfd.NFD_OpenDialogMultipleN(&pathSet, filterItems, (uint)filterItems.Length, defaultPath).ToNfdStatus(); + + if (status == NfdStatus.Ok) + { + uint count = 0; + nfd.NFD_PathSetGetCount(pathSet, ref count).ToNfdStatus(); + outPaths = new string[count]; + + for (uint i = 0; i < count; i++) + { + sbyte* pathPtr; + nfd.NFD_PathSetGetPathN(pathSet, i, &pathPtr); + outPaths[i] = new string(pathPtr); + } + + nfd.NFD_PathSetFree(pathSet); + } + else + { + outPaths = Array.Empty(); + } + } + + manager.PullDialog(); + return status; + } + internal static NfdnfilteritemT[] ToFilterItems(IDictionary? filters) { if (filters == null)