Skip to content

Commit d16ae0e

Browse files
authored
Feature: Added support for displaying all network folders on the sidebar (#15388)
1 parent 924d9a0 commit d16ae0e

File tree

3 files changed

+14
-43
lines changed

3 files changed

+14
-43
lines changed

src/Files.App/Data/Contracts/INetworkDrivesService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.Core.Storage.LocatableStorage;
5-
64
namespace Files.App.Data.Contracts
75
{
86
public interface INetworkDrivesService
@@ -16,7 +14,7 @@ public interface INetworkDrivesService
1614
/// Enumerates network storage drives.
1715
/// </summary>
1816
/// <returns>A collection of network storage devices</returns>
19-
IAsyncEnumerable<ILocatableFolder> GetDrivesAsync();
17+
Task<IEnumerable<ILocatableFolder>> GetDrivesAsync();
2018

2119
/// <summary>
2220
/// Updates network storage drives to up-to-date.

src/Files.App/Data/Items/DriveItem.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,9 @@ public DriveType Type
118118
get => type; set
119119
{
120120
type = value;
121-
if (value == DriveType.Network)
122-
{
123-
ToolTip = "Network".GetLocalizedResource();
124-
}
125-
else if (value == DriveType.CloudDrive)
126-
{
121+
122+
if (value is DriveType.Network or DriveType.CloudDrive)
127123
ToolTip = Text;
128-
}
129124
}
130125
}
131126

src/Files.App/Services/NetworkDrivesService.cs

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
using System.Text;
66
using Vanara.InteropServices;
77
using Vanara.PInvoke;
8-
using Vanara.Windows.Shell;
98
using static Vanara.PInvoke.AdvApi32;
109
using static Vanara.PInvoke.Mpr;
1110

1211
namespace 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

Comments
 (0)