From 2a91d87efaa340eb23ab24d461a84afb9d6335ac Mon Sep 17 00:00:00 2001 From: KFlab Date: Sat, 15 Feb 2025 08:43:46 +0800 Subject: [PATCH 1/5] Update StorageNetworkService.cs Signed-off-by: KFlab --- .../Services/Storage/StorageNetworkService.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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); } From 2b262f486b02bc800984113857e0394dcc82fba2 Mon Sep 17 00:00:00 2001 From: KFlab Date: Sat, 15 Feb 2025 08:47:33 +0800 Subject: [PATCH 2/5] Update DriveHelpers.cs Signed-off-by: KFlab --- src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs b/src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs index 1a16a5351ecb..bf99fa024e90 100644 --- a/src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs +++ b/src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs @@ -92,8 +92,12 @@ 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) && + !devicePath.StartsWith(@"\\SHELL\", StringComparison.Ordinal) + ) || + GetDriveType(new SystemIO.DriveInfo(devicePath)) is DriveType.Network + ) { int lastSepIndex = rootPath.LastIndexOf(@"\", StringComparison.Ordinal); rootPath = lastSepIndex > 1 ? rootPath.Substring(0, lastSepIndex) : rootPath; // Remove share name @@ -169,4 +173,4 @@ public static async Task GetThumbnailAsync(StorageFolder f => folder.GetThumbnailAsync(ThumbnailMode.SingleItem, 40, ThumbnailOptions.UseCurrentScale).AsTask() ); } -} \ No newline at end of file +} From 6dd571b4813a62c4d5b330e14abdb35c543b6843 Mon Sep 17 00:00:00 2001 From: KFlab Date: Sat, 15 Feb 2025 08:49:52 +0800 Subject: [PATCH 3/5] Update ShellViewModel.cs Signed-off-by: KFlab --- src/Files.App/ViewModels/ShellViewModel.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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) From a38a613c3d1cd41909751156115ce6a30f043fe7 Mon Sep 17 00:00:00 2001 From: KFlab Date: Sat, 15 Feb 2025 08:52:22 +0800 Subject: [PATCH 4/5] Update PathHelpers.cs Signed-off-by: KFlab --- src/Files.Shared/Helpers/PathHelpers.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); From 43cc10524897547a051fd45e9ce12636b2e1e440 Mon Sep 17 00:00:00 2001 From: KFlab Date: Sat, 15 Feb 2025 09:26:41 +0800 Subject: [PATCH 5/5] Update DriveHelpers.cs Signed-off-by: KFlab --- src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs b/src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs index bf99fa024e90..7400bb07abe4 100644 --- a/src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs +++ b/src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs @@ -93,10 +93,9 @@ public static async Task GetRootFromPathAsync(string devi } // Network share else if ( - ( devicePath.StartsWith(@"\\", StringComparison.Ordinal) && + ( devicePath.StartsWith(@"\\", StringComparison.Ordinal) || + GetDriveType(new SystemIO.DriveInfo(devicePath)) is DriveType.Network ) && !devicePath.StartsWith(@"\\SHELL\", StringComparison.Ordinal) - ) || - GetDriveType(new SystemIO.DriveInfo(devicePath)) is DriveType.Network ) { int lastSepIndex = rootPath.LastIndexOf(@"\", StringComparison.Ordinal);