Skip to content

Commit

Permalink
Linux: Fixed crash when opening save file dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
SourMesen committed May 28, 2023
1 parent b3fb65b commit 6262048
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions UI/Utilities/FileDialogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public class FileDialogHelper
}
filter.Add(new FilePickerFileType("All files") { Patterns = new List<string>() { "*" } });

IReadOnlyList<IStorageFile> files = await wnd.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions() {
SuggestedStartLocation = initialFolder != null ? await wnd.StorageProvider.TryGetFolderFromPathAsync(initialFolder) : null,
AllowMultiple = false,
FileTypeFilter = filter
});
IReadOnlyList<IStorageFile> files = await wnd.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions() {
SuggestedStartLocation = initialFolder != null ? await wnd.StorageProvider.TryGetFolderFromPathAsync(initialFolder) : null,
AllowMultiple = false,
FileTypeFilter = filter
});

if(files.Count > 0) {
return files[0].Path.LocalPath;
Expand All @@ -91,13 +91,19 @@ public class FileDialogHelper
}
filter.Add(new FilePickerFileType("All files") { Patterns = new List<string>() { "*" } });

IStorageFile? file = await wnd.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions() {
SuggestedStartLocation = initialFolder != null ? await wnd.StorageProvider.TryGetFolderFromPathAsync(initialFolder) : null,
DefaultExtension = extensions[0],
ShowOverwritePrompt = true,
SuggestedFileName = initialFile,
FileTypeChoices = filter
});
IStorageFolder? startLocation = initialFolder != null ? await wnd.StorageProvider.TryGetFolderFromPathAsync(initialFolder) : null;
if(OperatingSystem.IsLinux()) {
//TODOv2 - setting a start location appears to cause crashes on Linux (dbus crash), force it to null for now
startLocation = null;
}

IStorageFile? file = await wnd.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions() {
SuggestedStartLocation = startLocation,
DefaultExtension = extensions[0],
ShowOverwritePrompt = true,
SuggestedFileName = initialFile,
FileTypeChoices = filter
});

if(file != null) {
return file.Path.LocalPath;
Expand Down

0 comments on commit 6262048

Please sign in to comment.