From f5107a3d21d90be03d3c89b07a252408c5e1010b Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Fri, 16 Dec 2022 08:33:09 +0100 Subject: [PATCH] Windream: Fix normalized paths --- Windream/Windream.vb | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Windream/Windream.vb b/Windream/Windream.vb index 7f302e54..ddf8d434 100644 --- a/Windream/Windream.vb +++ b/Windream/Windream.vb @@ -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 + ''' ''' Returns the result of a search file '''