5
5
using System . Text ;
6
6
using Vanara . InteropServices ;
7
7
using Vanara . PInvoke ;
8
- using Vanara . Windows . Shell ;
9
8
using static Vanara . PInvoke . AdvApi32 ;
10
9
using static Vanara . PInvoke . Mpr ;
11
10
12
11
namespace Files . App . Services
13
12
{
14
13
public sealed class NetworkDrivesService : ObservableObject , INetworkDrivesService
15
14
{
15
+ private readonly static string guid = "::{f02c1a0d-be21-4350-88b0-7367fc96ef3c}" ;
16
+
16
17
private ObservableCollection < ILocatableFolder > _Drives ;
17
18
/// <inheritdoc/>
18
19
public ObservableCollection < ILocatableFolder > Drives
@@ -49,40 +50,16 @@ public NetworkDrivesService()
49
50
}
50
51
51
52
/// <inheritdoc/>
52
- public async IAsyncEnumerable < ILocatableFolder > GetDrivesAsync ( )
53
+ public async Task < IEnumerable < ILocatableFolder > > GetDrivesAsync ( )
53
54
{
54
- var networkLocations = await Win32Helper . StartSTATask ( ( ) =>
55
- {
56
- var locations = new List < ShellLinkItem > ( ) ;
57
- using ( var netHood = new ShellFolder ( Shell32 . KNOWNFOLDERID . FOLDERID_NetHood ) )
58
- {
59
- foreach ( var item in netHood )
60
- {
61
- if ( item is ShellLink link )
62
- {
63
- locations . Add ( ShellFolderExtensions . GetShellLinkItem ( link ) ) ;
64
- }
65
- else
66
- {
67
- var linkPath = ( string ? ) item ? . Properties [ "System.Link.TargetParsingPath" ] ;
68
- if ( linkPath is not null )
69
- {
70
- var linkItem = ShellFolderExtensions . GetShellFileItem ( item ) ;
71
- locations . Add ( new ( linkItem ) { TargetPath = linkPath } ) ;
72
- }
73
- }
74
- }
75
- }
76
-
77
- return locations ;
78
- } ) ;
55
+ var result = await Win32Helper . GetShellFolderAsync ( guid , false , true , 0 , int . MaxValue ) ;
79
56
80
- foreach ( var item in networkLocations ?? Enumerable . Empty < ShellLinkItem > ( ) )
57
+ return result . Enumerate . Where ( item => item . IsFolder ) . Select ( item =>
81
58
{
82
59
var networkItem = new DriveItem ( )
83
60
{
84
- Text = SystemIO . Path . GetFileNameWithoutExtension ( item . FileName ) ,
85
- Path = item . TargetPath ,
61
+ Text = item . FileName ,
62
+ Path = item . FilePath ,
86
63
DeviceID = item . FilePath ,
87
64
Type = DriveType . Network ,
88
65
ItemType = NavigationControlItemType . Drive ,
@@ -95,8 +72,9 @@ public async IAsyncEnumerable<ILocatableFolder> GetDrivesAsync()
95
72
ShowShellItems = true ,
96
73
ShowProperties = true ,
97
74
} ;
98
- yield return networkItem ;
99
- }
75
+
76
+ return networkItem ;
77
+ } ) ;
100
78
}
101
79
102
80
/// <inheritdoc/>
@@ -107,7 +85,7 @@ public async Task UpdateDrivesAsync()
107
85
_Drives . Single ( x => x is DriveItem o && o . DeviceID == "network-folder" )
108
86
} ;
109
87
110
- await foreach ( ILocatableFolder item in GetDrivesAsync ( ) )
88
+ foreach ( ILocatableFolder item in await GetDrivesAsync ( ) )
111
89
unsortedDrives . Add ( item ) ;
112
90
113
91
var orderedDrives =
0 commit comments