From d071459a5be38bc88ccb0f5b5219ce51e547fb66 Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Mon, 16 Jun 2025 20:38:10 +0300 Subject: [PATCH] Fix crash when exporting multiple channels to drive root (#1399) --- .../Framework/DialogManager.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/DiscordChatExporter.Gui/Framework/DialogManager.cs b/DiscordChatExporter.Gui/Framework/DialogManager.cs index 930c02c4..0f6a8f86 100644 --- a/DiscordChatExporter.Gui/Framework/DialogManager.cs +++ b/DiscordChatExporter.Gui/Framework/DialogManager.cs @@ -60,7 +60,7 @@ public class DialogManager : IDisposable } ); - return file?.Path.LocalPath; + return file?.TryGetLocalPath() ?? file?.Path.ToString(); } public async Task PromptDirectoryPathAsync(string defaultDirPath = "") @@ -69,19 +69,21 @@ public class DialogManager : IDisposable Application.Current?.ApplicationLifetime?.TryGetTopLevel() ?? throw new ApplicationException("Could not find the top-level visual element."); - var startLocation = await topLevel.StorageProvider.TryGetFolderFromPathAsync( - defaultDirPath - ); - - var folderPickResult = await topLevel.StorageProvider.OpenFolderPickerAsync( + var result = await topLevel.StorageProvider.OpenFolderPickerAsync( new FolderPickerOpenOptions { AllowMultiple = false, - SuggestedStartLocation = startLocation, + SuggestedStartLocation = await topLevel.StorageProvider.TryGetFolderFromPathAsync( + defaultDirPath + ), } ); - return folderPickResult.FirstOrDefault()?.Path.LocalPath; + var directory = result.FirstOrDefault(); + if (directory is null) + return null; + + return directory.TryGetLocalPath() ?? directory.Path.ToString(); } public void Dispose() => _dialogLock.Dispose();