|
| 1 | +using System.Runtime.Versioning; |
| 2 | + |
| 3 | +namespace AssetRipper.NativeDialogs; |
| 4 | + |
| 5 | +public static class OpenFolderDialog |
| 6 | +{ |
| 7 | + public static bool Supported => |
| 8 | + OperatingSystem.IsWindows() || |
| 9 | + OperatingSystem.IsMacOS() || |
| 10 | + (OperatingSystem.IsLinux() && Gtk.Global.IsSupported); |
| 11 | + |
| 12 | + public static Task<string?> OpenFolderAsync(OpenFileDialogOptions? options = null) |
| 13 | + { |
| 14 | + options ??= OpenFileDialogOptions.Default; |
| 15 | + if (OperatingSystem.IsWindows()) |
| 16 | + { |
| 17 | + return OpenFolderAsyncWindows(options); |
| 18 | + } |
| 19 | + else if (OperatingSystem.IsMacOS()) |
| 20 | + { |
| 21 | + return OpenFolderAsyncMacOS(options); |
| 22 | + } |
| 23 | + else if (OperatingSystem.IsLinux()) |
| 24 | + { |
| 25 | + return OpenFolderAsyncLinux(options); |
| 26 | + } |
| 27 | + else |
| 28 | + { |
| 29 | + return Task.FromResult<string?>(null); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + [SupportedOSPlatform("windows")] |
| 34 | + private unsafe static Task<string?> OpenFolderAsyncWindows(OpenFileDialogOptions options) |
| 35 | + { |
| 36 | + return Task.FromResult<string?>(null); |
| 37 | + } |
| 38 | + |
| 39 | + [SupportedOSPlatform("macos")] |
| 40 | + private static Task<string?> OpenFolderAsyncMacOS(OpenFileDialogOptions options) |
| 41 | + { |
| 42 | + return ProcessExecutor.TryRun("osascript", "-e", "POSIX path of (choose folder)"); |
| 43 | + } |
| 44 | + |
| 45 | + [SupportedOSPlatform("linux")] |
| 46 | + private static Task<string?> OpenFolderAsyncLinux(OpenFileDialogOptions options) |
| 47 | + { |
| 48 | + return Task.FromResult<string?>(null); |
| 49 | + } |
| 50 | +} |
0 commit comments