Skip to content

Commit efcfa0c

Browse files
committed
Feature: Add FilePicker winexe type restriction for windows
1 parent a20cbba commit efcfa0c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Avalonia.CpuLimiter/Services/FilesService.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using System.Runtime.InteropServices;
78
using System.Text;
89
using System.Threading.Tasks;
910

@@ -22,14 +23,19 @@ public FilesService(Window target)
2223

2324
public async Task<IStorageFile?> OpenFileAsync()
2425
{
25-
var files = await _target.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
26+
FilePickerOpenOptions options = new()
2627
{
2728
Title = "Select executable file",
28-
AllowMultiple = false
29+
AllowMultiple = false,
30+
};
2931

32+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
33+
{
34+
options.FileTypeFilter = new FilePickerFileType[] { WinexeFileType };
35+
}
3036

31-
});
3237

38+
var files = await _target.StorageProvider.OpenFilePickerAsync(options);
3339
return files.Count >= 1 ? files[0] : null;
3440
}
3541

@@ -40,5 +46,10 @@ public FilesService(Window target)
4046
Title = "Save Text File"
4147
});
4248
}
49+
50+
public static FilePickerFileType WinexeFileType { get; } = new("Windows exe")
51+
{
52+
Patterns = new[] { "*.exe" },
53+
};
4354
}
4455
}

0 commit comments

Comments
 (0)