diff --git a/src/Files.App/Services/Storage/StorageNetworkService.cs b/src/Files.App/Services/Storage/StorageNetworkService.cs index a3b000af1e2d..382f914d75c2 100644 --- a/src/Files.App/Services/Storage/StorageNetworkService.cs +++ b/src/Files.App/Services/Storage/StorageNetworkService.cs @@ -208,6 +208,25 @@ public async Task 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); } diff --git a/src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs b/src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs index 1a16a5351ecb..7400bb07abe4 100644 --- a/src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs +++ b/src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs @@ -92,8 +92,11 @@ public static async Task 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 @@ -169,4 +172,4 @@ public static async Task GetThumbnailAsync(StorageFolder f => folder.GetThumbnailAsync(ThumbnailMode.SingleItem, 40, ThumbnailOptions.UseCurrentScale).AsTask() ); } -} \ No newline at end of file +} diff --git a/src/Files.App/ViewModels/ShellViewModel.cs b/src/Files.App/ViewModels/ShellViewModel.cs index a4d1565c34ac..52fad7f7bc55 100644 --- a/src/Files.App/ViewModels/ShellViewModel.cs +++ b/src/Files.App/ViewModels/ShellViewModel.cs @@ -1633,12 +1633,18 @@ private async Task 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) diff --git a/src/Files.Shared/Helpers/PathHelpers.cs b/src/Files.Shared/Helpers/PathHelpers.cs index d359e0ad908d..aac51a157b20 100644 --- a/src/Files.Shared/Helpers/PathHelpers.cs +++ b/src/Files.Shared/Helpers/PathHelpers.cs @@ -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);