mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
fix: try-catch OpenFolderPickerAsync to avoid crash when select a directory is NOT exist
This commit is contained in:
parent
492f22fcfa
commit
80559ce199
6 changed files with 66 additions and 21 deletions
|
@ -390,11 +390,18 @@ namespace SourceGit.ViewModels
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
||||||
var selected = await storageProvider.OpenFolderPickerAsync(options);
|
try
|
||||||
if (selected.Count == 1)
|
|
||||||
{
|
{
|
||||||
var saveTo = Path.Combine(selected[0].Path.LocalPath, Path.GetFileName(file.Path));
|
var selected = await storageProvider.OpenFolderPickerAsync(options);
|
||||||
Commands.SaveRevisionFile.Run(_repo.FullPath, _commit.SHA, file.Path, saveTo);
|
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;
|
ev.Handled = true;
|
||||||
|
|
|
@ -454,12 +454,19 @@ namespace SourceGit.ViewModels
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
||||||
var selected = await storageProvider.OpenFolderPickerAsync(options);
|
try
|
||||||
if (selected.Count == 1)
|
|
||||||
{
|
{
|
||||||
var succ = new Commands.FormatPatch(_repo.FullPath, commit.SHA, selected[0].Path.LocalPath).Exec();
|
var selected = await storageProvider.OpenFolderPickerAsync(options);
|
||||||
if (succ)
|
if (selected.Count == 1)
|
||||||
App.SendNotification(_repo.FullPath, App.Text("SaveAsPatchSuccess"));
|
{
|
||||||
|
var succ = new Commands.FormatPatch(_repo.FullPath, commit.SHA, selected[0].Path.LocalPath).Exec();
|
||||||
|
if (succ)
|
||||||
|
App.SendNotification(_repo.FullPath, App.Text("SaveAsPatchSuccess"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
App.RaiseException(_repo.FullPath, $"Failed to save as patch: {exception.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
|
@ -18,9 +19,16 @@ namespace SourceGit.Views
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
||||||
var selected = await toplevel.StorageProvider.OpenFolderPickerAsync(options);
|
try
|
||||||
if (selected.Count == 1)
|
{
|
||||||
TxtLocation.Text = selected[0].Path.LocalPath;
|
var selected = await toplevel.StorageProvider.OpenFolderPickerAsync(options);
|
||||||
|
if (selected.Count == 1)
|
||||||
|
TxtLocation.Text = selected[0].Path.LocalPath;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
App.RaiseException(string.Empty, $"Failed to select location: {exception.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
|
@ -18,9 +19,16 @@ namespace SourceGit.Views
|
||||||
if (toplevel == null)
|
if (toplevel == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var selected = await toplevel.StorageProvider.OpenFolderPickerAsync(options);
|
try
|
||||||
if (selected.Count == 1)
|
{
|
||||||
TxtParentFolder.Text = selected[0].Path.LocalPath;
|
var selected = await toplevel.StorageProvider.OpenFolderPickerAsync(options);
|
||||||
|
if (selected.Count == 1)
|
||||||
|
TxtParentFolder.Text = selected[0].Path.LocalPath;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
App.RaiseException(string.Empty, $"Failed to select parent folder: {exception.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,10 +186,17 @@ namespace SourceGit.Views
|
||||||
private async void SelectDefaultCloneDir(object _1, RoutedEventArgs _2)
|
private async void SelectDefaultCloneDir(object _1, RoutedEventArgs _2)
|
||||||
{
|
{
|
||||||
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
||||||
var selected = await StorageProvider.OpenFolderPickerAsync(options);
|
try
|
||||||
if (selected.Count == 1)
|
|
||||||
{
|
{
|
||||||
ViewModels.Preference.Instance.GitDefaultCloneDir = selected[0].Path.LocalPath;
|
var selected = await StorageProvider.OpenFolderPickerAsync(options);
|
||||||
|
if (selected.Count == 1)
|
||||||
|
{
|
||||||
|
ViewModels.Preference.Instance.GitDefaultCloneDir = selected[0].Path.LocalPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
App.RaiseException(string.Empty, $"Failed to select default clone directory: {e.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
@ -30,9 +31,16 @@ namespace SourceGit.Views
|
||||||
options.SuggestedStartLocation = folder;
|
options.SuggestedStartLocation = folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
var selected = await topLevel.StorageProvider.OpenFolderPickerAsync(options);
|
try
|
||||||
if (selected.Count == 1)
|
{
|
||||||
OpenOrInitRepository(selected[0].Path.LocalPath);
|
var selected = await topLevel.StorageProvider.OpenFolderPickerAsync(options);
|
||||||
|
if (selected.Count == 1)
|
||||||
|
OpenOrInitRepository(selected[0].Path.LocalPath);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
App.RaiseException(string.Empty, $"Failed to open repository: {exception.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue