Skip to content

Feature: Added support for displaying all network folders on the sidebar #15388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Files.App/Data/Contracts/INetworkDrivesService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.Core.Storage.LocatableStorage;

namespace Files.App.Data.Contracts
{
public interface INetworkDrivesService
Expand All @@ -16,7 +14,7 @@ public interface INetworkDrivesService
/// Enumerates network storage drives.
/// </summary>
/// <returns>A collection of network storage devices</returns>
IAsyncEnumerable<ILocatableFolder> GetDrivesAsync();
Task<IEnumerable<ILocatableFolder>> GetDrivesAsync();

/// <summary>
/// Updates network storage drives to up-to-date.
Expand Down
9 changes: 2 additions & 7 deletions src/Files.App/Data/Items/DriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,9 @@ public DriveType Type
get => type; set
{
type = value;
if (value == DriveType.Network)
{
ToolTip = "Network".GetLocalizedResource();
}
else if (value == DriveType.CloudDrive)
{

if (value is DriveType.Network or DriveType.CloudDrive)
ToolTip = Text;
}
}
}

Expand Down
44 changes: 11 additions & 33 deletions src/Files.App/Services/NetworkDrivesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
using System.Text;
using Vanara.InteropServices;
using Vanara.PInvoke;
using Vanara.Windows.Shell;
using static Vanara.PInvoke.AdvApi32;
using static Vanara.PInvoke.Mpr;

namespace Files.App.Services
{
public sealed class NetworkDrivesService : ObservableObject, INetworkDrivesService
{
private readonly static string guid = "::{f02c1a0d-be21-4350-88b0-7367fc96ef3c}";

private ObservableCollection<ILocatableFolder> _Drives;
/// <inheritdoc/>
public ObservableCollection<ILocatableFolder> Drives
Expand Down Expand Up @@ -49,40 +50,16 @@ public NetworkDrivesService()
}

/// <inheritdoc/>
public async IAsyncEnumerable<ILocatableFolder> GetDrivesAsync()
public async Task<IEnumerable<ILocatableFolder>> GetDrivesAsync()
{
var networkLocations = await Win32Helper.StartSTATask(() =>
{
var locations = new List<ShellLinkItem>();
using (var netHood = new ShellFolder(Shell32.KNOWNFOLDERID.FOLDERID_NetHood))
{
foreach (var item in netHood)
{
if (item is ShellLink link)
{
locations.Add(ShellFolderExtensions.GetShellLinkItem(link));
}
else
{
var linkPath = (string?)item?.Properties["System.Link.TargetParsingPath"];
if (linkPath is not null)
{
var linkItem = ShellFolderExtensions.GetShellFileItem(item);
locations.Add(new(linkItem) { TargetPath = linkPath });
}
}
}
}

return locations;
});
var result = await Win32Helper.GetShellFolderAsync(guid, false, true, 0, int.MaxValue);

foreach (var item in networkLocations ?? Enumerable.Empty<ShellLinkItem>())
return result.Enumerate.Where(item => item.IsFolder).Select(item =>
{
var networkItem = new DriveItem()
{
Text = SystemIO.Path.GetFileNameWithoutExtension(item.FileName),
Path = item.TargetPath,
Text = item.FileName,
Path = item.FilePath,
DeviceID = item.FilePath,
Type = DriveType.Network,
ItemType = NavigationControlItemType.Drive,
Expand All @@ -95,8 +72,9 @@ public async IAsyncEnumerable<ILocatableFolder> GetDrivesAsync()
ShowShellItems = true,
ShowProperties = true,
};
yield return networkItem;
}

return networkItem;
});
}

/// <inheritdoc/>
Expand All @@ -107,7 +85,7 @@ public async Task UpdateDrivesAsync()
_Drives.Single(x => x is DriveItem o && o.DeviceID == "network-folder")
};

await foreach (ILocatableFolder item in GetDrivesAsync())
foreach (ILocatableFolder item in await GetDrivesAsync())
unsortedDrives.Add(item);

var orderedDrives =
Expand Down
Loading