Skip to content

Commit

Permalink
Do not normalize paths from mapped network drives (#306)
Browse files Browse the repository at this point in the history
On Windows, the GetFinalPathNameByHandle function returns the UNC path if the specified path is from a mapped network drive.  These paths break Visual Studio so they can't be used.  This change detects if the path was normalized and isn't from a network drive, otherwise the original path is used.

Fixes #305
  • Loading branch information
jeffkl authored Nov 16, 2021
1 parent 4858f5a commit 89e5b04
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Shared/ExtensionMethods.Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ public static string ToFullPathInCorrectCase(this string path)

GetFinalPathNameByHandle(stream.SafeFileHandle, stringBuilder, stringBuilder.Capacity, 0);

return stringBuilder.ToString(4, stringBuilder.Capacity - 5);
// The path must begin with \\?\X:in order to be made into a path that Visual Studio can use.
// Mapped network drives return a value like "// \\?\UNC\MachineName\C$" which won't work so the original path must be used
if (stringBuilder.Length > 7 && stringBuilder[0] == '\\' && stringBuilder[1] == '\\' && stringBuilder[2] == '?' && stringBuilder[3] == '\\' && stringBuilder[5] == ':' && stringBuilder[6] == '\\')
{
return stringBuilder.ToString(4, stringBuilder.Capacity - 5);
}
}

return path;
Expand Down

0 comments on commit 89e5b04

Please sign in to comment.