Windream: Fix normalized paths

This commit is contained in:
Jonathan Jenne 2022-12-16 08:33:09 +01:00
parent 1ea73d9234
commit f5107a3d21

View File

@ -816,22 +816,16 @@ Public Class Windream
End Try
End Function
Public Function GetNormalizedPath(Path As String, pCleanPath As Boolean) As String
_logger.Debug("Normalizing Path: [{0}]", Path)
Dim oNormalizedPath As String = Path
Public Function GetNormalizedPath(pPath As String, pCleanPath As Boolean) As String
_logger.Debug("Normalizing Path: [{0}]", pPath)
Dim oNormalizedPath As String = pPath
If pCleanPath = True Then
oNormalizedPath = Language.Utils.RemoveInvalidCharacters(Path)
oNormalizedPath = Utils.RemoveInvalidCharacters(pPath)
_logger.Debug("Path after RemoveInvalidCharacters: [{0}]", oNormalizedPath)
End If
Try
' Convert any forward slashes / and double slashes \\ into backslashes \
' See: https://stackoverflow.com/questions/3144492/how-do-i-get-nets-path-combine-to-convert-forward-slashes-to-backslashes
If IsPathRooted(oNormalizedPath) Then
oNormalizedPath = GetFullPath(oNormalizedPath)
End If
' Remove Driveletter, eg. W:\
If oNormalizedPath.StartsWith($"{ClientDriveLetter}:\") Then
oNormalizedPath = oNormalizedPath.Substring(ClientDriveLetter.Length + 2)
@ -851,6 +845,18 @@ Public Class Windream
oNormalizedPath = oNormalizedPath.Substring(3)
End If
' Convert any forward slashes / and double slashes \\ into backslashes \
' See: https://stackoverflow.com/questions/3144492/how-do-i-get-nets-path-combine-to-convert-forward-slashes-to-backslashes
If IsPathRooted(oNormalizedPath) Then
' This breaks because it converts the path "\SomeFolder" into "C:\SomeFolder" LOL
'oNormalizedPath = GetFullPath(oNormalizedPath)
' Lets just be pragmatic here
oNormalizedPath = oNormalizedPath.Replace("\\", "\")
oNormalizedPath = oNormalizedPath.Replace("/", "\")
_logger.Debug("Path after converting slashes: [{0}]", oNormalizedPath)
End If
If oNormalizedPath.StartsWith("\") = False Then
oNormalizedPath = $"\{oNormalizedPath}"
End If
@ -864,6 +870,11 @@ Public Class Windream
End Try
End Function
Public Function GetAbsolutePath(pPath As String) As String
Dim oNormalizedPath = GetNormalizedPath(pPath, False)
Return $"\\windream\objects{oNormalizedPath}"
End Function
''' <summary>
''' Returns the result of a search file
''' </summary>