File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
src/Files.App/Utils/Storage/StorageItems Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 1
1
// Copyright (c) 2023 Files Community
2
2
// Licensed under the MIT License. See the LICENSE.
3
3
4
+ using Microsoft . Extensions . Logging ;
4
5
using System . Runtime . InteropServices . WindowsRuntime ;
6
+ using Vanara . PInvoke ;
5
7
using Windows . Foundation ;
6
8
using Windows . Foundation . Metadata ;
7
9
using Windows . Storage ;
@@ -27,7 +29,31 @@ public sealed class SystemStorageFolder : BaseStorageFolder
27
29
public SystemStorageFolder ( StorageFolder folder ) => Folder = folder ;
28
30
29
31
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
+ }
31
57
32
58
public override IAsyncOperation < StorageFolder > ToStorageFolderAsync ( ) => Task . FromResult ( Folder ) . AsAsyncOperation ( ) ;
33
59
You can’t perform that action at this time.
0 commit comments