Skip to content

Commit

Permalink
Merge pull request #8890 from drewnoakes/resx-linked-file-path-capita…
Browse files Browse the repository at this point in the history
…lization

Write file reference with correct capitalisation
  • Loading branch information
drewnoakes authored Mar 2, 2023
2 parents 42ce2b8 + 7cb711c commit acda127
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3053,7 +3053,7 @@ Namespace Microsoft.VisualStudio.Editors.ResourceEditor
With Info
.Guid = SplitInfo(0)
.ProjectFile = SplitInfo(1)
.FilePath = SplitInfo(2)
.FilePath = GetExactPath(SplitInfo(2))
End With
Files(i) = Info
Next
Expand All @@ -3069,6 +3069,30 @@ Namespace Microsoft.VisualStudio.Editors.ResourceEditor
Return Files
End Function

' Converts the provided path to use the same capitalization as the file system. Files dragged
' from Solution Explorer produce drop data having a lower-case path, which we then write to
' in the .resx file. Windows has a case-insensitive file system, but users on other operation
' systems (such as Linux) can hit run-time errors when the case doesn't match. This avoids that.
Private Shared Function GetExactPath(path As String) As String
If path Is Nothing OrElse (Not File.Exists(path) AndAlso Not Directory.Exists(path)) Then
Return path
End If

Try
Dim root = System.IO.Path.GetPathRoot(path)
Dim parts = path.Substring(root.Length).Split(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar)

For Each part As String In parts
root = Directory.EnumerateFileSystemEntries(root, part).First()
Next

Return root
Catch
' If we hit any issues, just return the path unchanged
Return path
End Try
End Function

#End Region

#End Region
Expand Down

0 comments on commit acda127

Please sign in to comment.