fix: try-catch OpenFolderPickerAsync to avoid crash when select a directory is NOT exist

This commit is contained in:
Gadfly 2024-08-27 10:40:49 +08:00
parent 492f22fcfa
commit 80559ce199
No known key found for this signature in database
6 changed files with 66 additions and 21 deletions

View file

@ -390,11 +390,18 @@ namespace SourceGit.ViewModels
return;
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
var selected = await storageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
try
{
var saveTo = Path.Combine(selected[0].Path.LocalPath, Path.GetFileName(file.Path));
Commands.SaveRevisionFile.Run(_repo.FullPath, _commit.SHA, file.Path, saveTo);
var selected = await storageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
{
var saveTo = Path.Combine(selected[0].Path.LocalPath, Path.GetFileName(file.Path));
Commands.SaveRevisionFile.Run(_repo.FullPath, _commit.SHA, file.Path, saveTo);
}
}
catch (Exception e)
{
App.RaiseException(_repo.FullPath, $"Failed to save file: {e.Message}");
}
ev.Handled = true;