From 663c2ad16708053e86a02833fcbae44ce7e0d2ab Mon Sep 17 00:00:00 2001 From: Paul De Smul Date: Sat, 23 Nov 2024 12:06:40 +0100 Subject: [PATCH] Fix crash when browsing a file on disk that doesn't exist --- src/ViewModels/CodexEditViewModel.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ViewModels/CodexEditViewModel.cs b/src/ViewModels/CodexEditViewModel.cs index 04a3310..1ca451d 100644 --- a/src/ViewModels/CodexEditViewModel.cs +++ b/src/ViewModels/CodexEditViewModel.cs @@ -71,10 +71,16 @@ public bool ShowLoading public RelayCommand BrowsePathCommand => _browsePathCommand ??= new(BrowsePath); private void BrowsePath() { + string? initialDir = Path.GetDirectoryName(TempCodex.Sources.Path); + if (!Path.Exists(initialDir)) + { + initialDir = string.Empty; + } + OpenFileDialog openFileDialog = new() { AddExtension = false, - InitialDirectory = Path.GetDirectoryName(TempCodex.Sources.Path) ?? String.Empty + InitialDirectory = initialDir }; if (openFileDialog.ShowDialog() == true) {