55using System . Text ;
66using Vanara . InteropServices ;
77using Vanara . PInvoke ;
8- using Vanara . Windows . Shell ;
98using static Vanara . PInvoke . AdvApi32 ;
109using static Vanara . PInvoke . Mpr ;
1110
1211namespace Files . App . Services
1312{
1413 public sealed class NetworkDrivesService : ObservableObject , INetworkDrivesService
1514 {
15+ private readonly static string guid = "::{f02c1a0d-be21-4350-88b0-7367fc96ef3c}" ;
16+
1617 private ObservableCollection < ILocatableFolder > _Drives ;
1718 /// <inheritdoc/>
1819 public ObservableCollection < ILocatableFolder > Drives
@@ -49,40 +50,16 @@ public NetworkDrivesService()
4950 }
5051
5152 /// <inheritdoc/>
52- public async IAsyncEnumerable < ILocatableFolder > GetDrivesAsync ( )
53+ public async Task < IEnumerable < ILocatableFolder > > GetDrivesAsync ( )
5354 {
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 ) ;
7956
80- foreach ( var item in networkLocations ?? Enumerable . Empty < ShellLinkItem > ( ) )
57+ return result . Enumerate . Where ( item => item . IsFolder ) . Select ( item =>
8158 {
8259 var networkItem = new DriveItem ( )
8360 {
84- Text = SystemIO . Path . GetFileNameWithoutExtension ( item . FileName ) ,
85- Path = item . TargetPath ,
61+ Text = item . FileName ,
62+ Path = item . FilePath ,
8663 DeviceID = item . FilePath ,
8764 Type = DriveType . Network ,
8865 ItemType = NavigationControlItemType . Drive ,
@@ -95,8 +72,9 @@ public async IAsyncEnumerable<ILocatableFolder> GetDrivesAsync()
9572 ShowShellItems = true ,
9673 ShowProperties = true ,
9774 } ;
98- yield return networkItem ;
99- }
75+
76+ return networkItem ;
77+ } ) ;
10078 }
10179
10280 /// <inheritdoc/>
@@ -107,7 +85,7 @@ public async Task UpdateDrivesAsync()
10785 _Drives . Single ( x => x is DriveItem o && o . DeviceID == "network-folder" )
10886 } ;
10987
110- await foreach ( ILocatableFolder item in GetDrivesAsync ( ) )
88+ foreach ( ILocatableFolder item in await GetDrivesAsync ( ) )
11189 unsortedDrives . Add ( item ) ;
11290
11391 var orderedDrives =
0 commit comments