Skip to content

Commit bc5deac

Browse files
committed
fix: OpenFolderPickerAsync raise exception when selected a drive root such as E:\
Signed-off-by: leo <[email protected]>
1 parent 1bd2044 commit bc5deac

File tree

8 files changed

+32
-9
lines changed

8 files changed

+32
-9
lines changed

src/Commands/FormatPatch.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public FormatPatch(string repo, string commit, string saveTo)
66
{
77
WorkingDirectory = repo;
88
Context = repo;
9+
Editor = EditorType.None;
910
Args = $"format-patch {commit} -1 --output=\"{saveTo}\"";
1011
}
1112
}

src/ViewModels/CommitDetail.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,9 @@ public ContextMenu CreateRevisionFileContextMenu(Models.Object file)
452452
var selected = await storageProvider.OpenFolderPickerAsync(options);
453453
if (selected.Count == 1)
454454
{
455-
var saveTo = Path.Combine(selected[0].Path.LocalPath, Path.GetFileName(file.Path));
455+
var folder = selected[0];
456+
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder?.Path.ToString();
457+
var saveTo = Path.Combine(folderPath, Path.GetFileName(file.Path));
456458
Commands.SaveRevisionFile.Run(_repo.FullPath, _commit.SHA, file.Path, saveTo);
457459
}
458460
}

src/ViewModels/Histories.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,12 @@ public ContextMenu MakeContextMenu(ListBox list)
333333
{
334334
log = _repo.CreateLog("Save as Patch");
335335

336+
var folder = picker[0];
337+
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder?.Path.ToString();
336338
var succ = false;
337339
for (var i = 0; i < selected.Count; i++)
338340
{
339-
var saveTo = GetPatchFileName(picker[0].Path.LocalPath, selected[i], i);
341+
var saveTo = GetPatchFileName(folderPath, selected[i], i);
340342
succ = await Task.Run(() => new Commands.FormatPatch(_repo.FullPath, selected[i].SHA, saveTo).Use(log).Exec());
341343
if (!succ)
342344
break;
@@ -691,8 +693,10 @@ public ContextMenu MakeContextMenu(ListBox list)
691693
{
692694
log = _repo.CreateLog("Save as Patch");
693695

694-
var saveTo = GetPatchFileName(selected[0].Path.LocalPath, commit);
695-
var succ = new Commands.FormatPatch(_repo.FullPath, commit.SHA, saveTo).Use(log).Exec();
696+
var folder = selected[0];
697+
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder?.Path.ToString();
698+
var saveTo = GetPatchFileName(folderPath, commit);
699+
var succ = await Task.Run(() => new Commands.FormatPatch(_repo.FullPath, commit.SHA, saveTo).Use(log).Exec());
696700
if (succ)
697701
App.SendNotification(_repo.FullPath, App.Text("SaveAsPatchSuccess"));
698702
}

src/Views/AddWorktree.axaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ private async void SelectLocation(object _, RoutedEventArgs e)
2323
{
2424
var selected = await toplevel.StorageProvider.OpenFolderPickerAsync(options);
2525
if (selected.Count == 1)
26-
TxtLocation.Text = selected[0].Path.LocalPath;
26+
{
27+
var folder = selected[0];
28+
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder?.Path.ToString();
29+
TxtLocation.Text = folderPath;
30+
}
2731
}
2832
catch (Exception exception)
2933
{

src/Views/Clone.axaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ private async void SelectParentFolder(object _, RoutedEventArgs e)
2323
{
2424
var selected = await toplevel.StorageProvider.OpenFolderPickerAsync(options);
2525
if (selected.Count == 1)
26-
TxtParentFolder.Text = selected[0].Path.LocalPath;
26+
{
27+
var folder = selected[0];
28+
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder?.Path.ToString();
29+
TxtParentFolder.Text = folderPath;
30+
}
2731
}
2832
catch (Exception exception)
2933
{

src/Views/ConfigureWorkspace.axaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ private async void SelectDefaultCloneDir(object _, RoutedEventArgs e)
3232
var selected = await StorageProvider.OpenFolderPickerAsync(options);
3333
if (selected.Count == 1)
3434
{
35-
workspace.Selected.DefaultCloneDir = selected[0].Path.LocalPath;
35+
var folder = selected[0];
36+
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder?.Path.ToString();
37+
workspace.Selected.DefaultCloneDir = folderPath;
3638
}
3739
}
3840
catch (Exception ex)

src/Views/Preferences.axaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ private async void SelectDefaultCloneDir(object _, RoutedEventArgs e)
250250
var selected = await StorageProvider.OpenFolderPickerAsync(options);
251251
if (selected.Count == 1)
252252
{
253-
ViewModels.Preferences.Instance.GitDefaultCloneDir = selected[0].Path.LocalPath;
253+
var folder = selected[0];
254+
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder?.Path.ToString();
255+
ViewModels.Preferences.Instance.GitDefaultCloneDir = folderPath;
254256
}
255257
}
256258
catch (Exception ex)

src/Views/WelcomeToolbar.axaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ private async void OpenLocalRepository(object _1, RoutedEventArgs e)
3535
{
3636
var selected = await topLevel.StorageProvider.OpenFolderPickerAsync(options);
3737
if (selected.Count == 1)
38-
ViewModels.Welcome.Instance.OpenOrInitRepository(selected[0].Path.LocalPath, null, false);
38+
{
39+
var folder = selected[0];
40+
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder?.Path.ToString();
41+
ViewModels.Welcome.Instance.OpenOrInitRepository(folderPath, null, false);
42+
}
3943
}
4044
catch (Exception exception)
4145
{

0 commit comments

Comments
 (0)