Skip to content
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

Fix: Fixed performance issue with SMB shares #16812

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions src/Files.App/Services/Storage/StorageNetworkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,25 @@ public async Task<bool> AuthenticateNetworkShare(string path)

unsafe
{

if (!path.StartsWith(@"\\", StringComparison.Ordinal))
{
// Special handling for network drives
// This part will change path from "y:\Download" to "\\192.168.0.1\nfs\Download"
[DllImport("mpr.dll", CharSet = CharSet.Auto)]
static extern int WNetGetConnection(string lpLocalName, StringBuilder lpRemoteName, ref int lpnLength);

StringBuilder remoteName = new StringBuilder(300);
int length = remoteName.Capacity;
string lpLocalName = path.Substring(0, 2);

int ret = WNetGetConnection(lpLocalName, remoteName, ref length);

if ( ret == 0 )
path = path.Replace(lpLocalName, remoteName.ToString());

}

fixed (char* lpcPath = path)
netRes.lpRemoteName = new PWSTR(lpcPath);
}
Expand Down
9 changes: 6 additions & 3 deletions src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ public static async Task<StorageFolderWithPath> GetRootFromPathAsync(string devi
}
}
// Network share
else if (devicePath.StartsWith(@"\\", StringComparison.Ordinal) &&
!devicePath.StartsWith(@"\\SHELL\", StringComparison.Ordinal))
else if (
( devicePath.StartsWith(@"\\", StringComparison.Ordinal) ||
GetDriveType(new SystemIO.DriveInfo(devicePath)) is DriveType.Network ) &&
!devicePath.StartsWith(@"\\SHELL\", StringComparison.Ordinal)
)
{
int lastSepIndex = rootPath.LastIndexOf(@"\", StringComparison.Ordinal);
rootPath = lastSepIndex > 1 ? rootPath.Substring(0, lastSepIndex) : rootPath; // Remove share name
Expand Down Expand Up @@ -169,4 +172,4 @@ public static async Task<StorageItemThumbnail> GetThumbnailAsync(StorageFolder f
=> folder.GetThumbnailAsync(ThumbnailMode.SingleItem, 40, ThumbnailOptions.UseCurrentScale).AsTask()
);
}
}
}
8 changes: 7 additions & 1 deletion src/Files.App/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,12 +1633,18 @@ private async Task<int> EnumerateItemsFromStandardFolderAsync(string path, Cance
!isMtp &&
!isShellFolder &&
!isWslDistro;

// Special handling for network drives
bool isNetdisk = false;
if (!isNetwork)
isNetdisk = (new DriveInfo(path).DriveType == System.IO.DriveType.Network);

bool isFtp = FtpHelpers.IsFtpPath(path);
bool enumFromStorageFolder = isBoxFolder || isFtp;

BaseStorageFolder? rootFolder = null;

if (isNetwork)
if (isNetwork || isNetdisk)
{
var auth = await NetworkService.AuthenticateNetworkShare(path);
if (!auth)
Expand Down
6 changes: 5 additions & 1 deletion src/Files.Shared/Helpers/PathHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public static string FormatName(string path)
string fileName;
string rootPath = Path.GetPathRoot(path) ?? string.Empty;

if (rootPath == path && path.StartsWith(@"\\"))
if (rootPath == path &&
( path.StartsWith(@"\\") ||
(new DriveInfo(path).DriveType == System.IO.DriveType.Network)
)
)
{
// Network Share path
fileName = path.Substring(path.LastIndexOf(@"\", StringComparison.Ordinal) + 1);
Expand Down
Loading