Skip to content

Commit bd8f3b7

Browse files
authored
Fix: Fixed issue where directly opening library would invoke explorer.exe (files-community#14336)
1 parent f21c6f6 commit bd8f3b7

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/Files.App/Utils/Storage/StorageItems/SystemStorageFolder.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4+
using Microsoft.Extensions.Logging;
45
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Vanara.PInvoke;
57
using Windows.Foundation;
68
using Windows.Foundation.Metadata;
79
using Windows.Storage;
@@ -27,7 +29,31 @@ public sealed class SystemStorageFolder : BaseStorageFolder
2729
public SystemStorageFolder(StorageFolder folder) => Folder = folder;
2830

2931
public static IAsyncOperation<BaseStorageFolder> FromPathAsync(string path)
30-
=> AsyncInfo.Run<BaseStorageFolder>(async (cancellationToken) => new SystemStorageFolder(await StorageFolder.GetFolderFromPathAsync(path)));
32+
{
33+
if (path.EndsWith(ShellLibraryItem.EXTENSION))
34+
{
35+
try
36+
{
37+
using var shellItem = new ShellLibraryEx(Shell32.ShellUtil.GetShellItemForPath(path), true);
38+
if (shellItem is ShellLibraryEx library)
39+
{
40+
var libraryItem = ShellFolderExtensions.GetShellLibraryItem(library, path);
41+
var firstFolder = libraryItem?.Folders.FirstOrDefault();
42+
43+
if (firstFolder != null)
44+
{
45+
return AsyncInfo.Run<BaseStorageFolder>(async (cancellationToken) => new SystemStorageFolder(await StorageFolder.GetFolderFromPathAsync(firstFolder)));
46+
}
47+
}
48+
}
49+
catch (Exception e)
50+
{
51+
App.Logger.LogWarning(e, null);
52+
}
53+
}
54+
55+
return AsyncInfo.Run<BaseStorageFolder>(async (cancellationToken) => new SystemStorageFolder(await StorageFolder.GetFolderFromPathAsync(path)));
56+
}
3157

3258
public override IAsyncOperation<StorageFolder> ToStorageFolderAsync() => Task.FromResult(Folder).AsAsyncOperation();
3359

0 commit comments

Comments
 (0)