Skip to content

Commit dbe43ba

Browse files
committed
Initial implementation for opening multiple folders
1 parent d489f1c commit dbe43ba

File tree

4 files changed

+99
-22
lines changed

4 files changed

+99
-22
lines changed

AssetRipper.NativeDialogs.Example/Arguments.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ internal sealed partial class Arguments
99
{
1010
[CommandLineArgument]
1111
[Description("Show the open file dialog.")]
12-
public bool OpenFile { get; set; } = false;
12+
public bool OpenFile { get; set; }
1313

1414
[CommandLineArgument]
15-
[Description("Show the open file dialog and allow multiple files.")]
16-
public bool OpenFiles { get; set; } = false;
15+
[Description("Show the open folder dialog.")]
16+
public bool OpenFolder { get; set; }
1717

1818
[CommandLineArgument]
19-
[Description("Show the open folder dialog.")]
20-
public bool OpenFolder { get; set; } = false;
19+
[Description("If opening files or folders, this allows multiple to be chosen.")]
20+
public bool AllowMultiple { get; set; }
2121

2222
[CommandLineArgument]
2323
[Description("Show the save file dialog.")]
24-
public bool SaveFile { get; set; } = false;
24+
public bool SaveFile { get; set; }
2525

2626
[CommandLineArgument]
2727
[Description("Show the message dialog.")]
28-
public bool Message { get; set; } = false;
28+
public bool Message { get; set; }
2929
}

AssetRipper.NativeDialogs.Example/Program.cs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,49 @@ static async Task Main(string[] args)
1212

1313
if (arguments.OpenFile)
1414
{
15-
string? file = await OpenFileDialog.OpenFileAsync();
16-
Print(file);
17-
}
18-
else if (arguments.OpenFiles)
19-
{
20-
string[]? files = await OpenFileDialog.OpenFilesAsync();
21-
if (files is null || files.Length == 0)
15+
if (arguments.AllowMultiple)
2216
{
23-
Console.WriteLine("No files selected.");
17+
string[]? files = await OpenFileDialog.OpenFilesAsync();
18+
if (files is null || files.Length == 0)
19+
{
20+
Console.WriteLine("No files selected.");
21+
}
22+
else
23+
{
24+
foreach (string file in files)
25+
{
26+
Print(file);
27+
}
28+
}
2429
}
2530
else
2631
{
27-
foreach (string file in files)
28-
{
29-
Print(file);
30-
}
32+
string? file = await OpenFileDialog.OpenFileAsync();
33+
Print(file);
3134
}
3235
}
3336
else if (arguments.OpenFolder)
3437
{
35-
string? folder = await OpenFolderDialog.OpenFolderAsync();
36-
Print(folder);
38+
if (arguments.AllowMultiple)
39+
{
40+
string[]? folders = await OpenFolderDialog.OpenFoldersAsync();
41+
if (folders is null || folders.Length == 0)
42+
{
43+
Console.WriteLine("No folders selected.");
44+
}
45+
else
46+
{
47+
foreach (string file in folders)
48+
{
49+
Print(file);
50+
}
51+
}
52+
}
53+
else
54+
{
55+
string? folder = await OpenFolderDialog.OpenFolderAsync();
56+
Print(folder);
57+
}
3758
}
3859
else if (arguments.SaveFile)
3960
{

AssetRipper.NativeDialogs/OpenFileDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public static class OpenFileDialog
210210
private static async Task<string[]?> OpenFilesAsyncLinux()
211211
{
212212
// Todo: proper Linux implementation
213-
string? path = await OpenFileDialog.OpenFileAsync();
213+
string? path = await OpenFileAsync();
214214
if (string.IsNullOrEmpty(path))
215215
{
216216
return null; // User canceled the dialog

AssetRipper.NativeDialogs/OpenFolderDialog.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,60 @@ public static class OpenFolderDialog
4646
{
4747
return Task.FromResult<string?>(null);
4848
}
49+
50+
public static Task<string[]?> OpenFoldersAsync()
51+
{
52+
if (OperatingSystem.IsWindows())
53+
{
54+
return OpenFoldersAsyncWindows();
55+
}
56+
else if (OperatingSystem.IsMacOS())
57+
{
58+
return OpenFoldersAsyncMacOS();
59+
}
60+
else if (OperatingSystem.IsLinux())
61+
{
62+
return OpenFoldersAsyncLinux();
63+
}
64+
else
65+
{
66+
return Task.FromResult<string[]?>(null);
67+
}
68+
}
69+
70+
[SupportedOSPlatform("windows")]
71+
private static async Task<string[]?> OpenFoldersAsyncWindows()
72+
{
73+
// Todo: proper Windows implementation
74+
string? path = await OpenFolderAsync();
75+
if (string.IsNullOrEmpty(path))
76+
{
77+
return null; // User canceled the dialog
78+
}
79+
return [path];
80+
}
81+
82+
[SupportedOSPlatform("macos")]
83+
private static async Task<string[]?> OpenFoldersAsyncMacOS()
84+
{
85+
// Todo: proper Mac implementation
86+
string? path = await OpenFolderAsync();
87+
if (string.IsNullOrEmpty(path))
88+
{
89+
return null; // User canceled the dialog
90+
}
91+
return [path];
92+
}
93+
94+
[SupportedOSPlatform("linux")]
95+
private static async Task<string[]?> OpenFoldersAsyncLinux()
96+
{
97+
// Todo: proper Linux implementation
98+
string? path = await OpenFolderAsync();
99+
if (string.IsNullOrEmpty(path))
100+
{
101+
return null; // User canceled the dialog
102+
}
103+
return [path];
104+
}
49105
}

0 commit comments

Comments
 (0)