Keep Windows variables untouched on Linux
This commit is contained in:
+23
-17
@@ -335,16 +335,19 @@ Public Class mgrPath
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Shared Function ProcessEnvironmentVariables(ByVal sValue As String) As String
|
Private Shared Function ProcessEnvironmentVariables(ByVal sValue As String) As String
|
||||||
Dim sAppDataLocalLinux As String = "${XDG_DATA_HOME:-~/.local/share}"
|
Dim sXdgData As String = "${XDG_DATA_HOME:-~/.local/share}"
|
||||||
Dim sEnvAppDataLocal As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
Dim sEnvAppDataLocal As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
||||||
Dim sAppDataRoamingLinux As String = "${XDG_CONFIG_HOME:-~/.config}"
|
Dim sXdgConfig As String = "${XDG_CONFIG_HOME:-~/.config}"
|
||||||
Dim sEnvAppDataRoaming As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
|
Dim sEnvAppDataRoaming As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
|
||||||
Dim sCurrentUserLinux As String = "${HOME}"
|
Dim sHomeDir As String = "${HOME}"
|
||||||
Dim sEnvCurrentUser As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
|
Dim sEnvCurrentUser As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
|
||||||
|
|
||||||
If mgrCommon.IsUnix Then
|
If mgrCommon.IsUnix Then
|
||||||
|
'$VAR_iable
|
||||||
Dim oParse As new Regex("\$([a-zA-Z0-9_]+)")
|
Dim oParse As new Regex("\$([a-zA-Z0-9_]+)")
|
||||||
|
'${VAR_iable} but not advanced syntax like ${VAR:-iable}
|
||||||
Dim oParseBracketed As new Regex("\$\{([a-zA-Z0-9_]+?)\}")
|
Dim oParseBracketed As new Regex("\$\{([a-zA-Z0-9_]+?)\}")
|
||||||
|
'~ not inside ${...}
|
||||||
Dim oParseTilde As new Regex("~(?![^\$\{]*\})")
|
Dim oParseTilde As new Regex("~(?![^\$\{]*\})")
|
||||||
If sEnvCurrentUser = String.Empty Then
|
If sEnvCurrentUser = String.Empty Then
|
||||||
'Fall back
|
'Fall back
|
||||||
@@ -358,28 +361,31 @@ Public Class mgrPath
|
|||||||
'$HOME to ${HOME}
|
'$HOME to ${HOME}
|
||||||
sValue = oParse.Replace(sValue, "${$1}")
|
sValue = oParse.Replace(sValue, "${$1}")
|
||||||
'Special notations for home directory
|
'Special notations for home directory
|
||||||
'Don't replace inside variables
|
|
||||||
sValue = oParseTilde.Replace(sValue,"${HOME}")
|
sValue = oParseTilde.Replace(sValue,"${HOME}")
|
||||||
'XDG Base Directory Specification has default values
|
'XDG Base Directory Specification has default values
|
||||||
sValue = sValue.Replace("${XDG_DATA_HOME}", "${XDG_DATA_HOME:-~/.local/share}")
|
sValue = sValue.Replace("${XDG_DATA_HOME}", sXdgData)
|
||||||
sValue = sValue.Replace("${XDG_CONFIG_HOME}", "${XDG_CONFIG_HOME:-~/.config}")
|
sValue = sValue.Replace("${XDG_CONFIG_HOME}", sXdgConfig)
|
||||||
|
|
||||||
'Replace with paths
|
'Replace with paths
|
||||||
sValue = sValue.Replace(sAppDataLocalLinux, sEnvAppDataLocal)
|
sValue = sValue.Replace(sXdgData, sEnvAppDataLocal)
|
||||||
sValue = sValue.Replace(sAppDataRoamingLinux, sEnvAppDataRoaming)
|
sValue = sValue.Replace(sXdgConfig, sEnvAppDataRoaming)
|
||||||
sValue = sValue.Replace(sCurrentUserLinux, sEnvCurrentUser)
|
sValue = sValue.Replace(sHomeDir, sEnvCurrentUser)
|
||||||
|
|
||||||
|
'Escape real Windows variables
|
||||||
|
sValue = sValue.Replace("%", "\%")
|
||||||
'Transform Linux variables to Windows variables
|
'Transform Linux variables to Windows variables
|
||||||
'More complex syntax couldn't be converted back
|
|
||||||
sValue = oParseBracketed.Replace(sValue, "%$1%")
|
sValue = oParseBracketed.Replace(sValue, "%$1%")
|
||||||
End If
|
End If
|
||||||
|
|
||||||
'On Linux real Linux environmental variables are used
|
'On Linux real Linux environmental variables are used
|
||||||
sValue = Environment.ExpandEnvironmentVariables(sValue)
|
sValue = Environment.ExpandEnvironmentVariables(sValue)
|
||||||
|
|
||||||
If mgrCommon.IsUnix Then
|
If mgrCommon.IsUnix Then
|
||||||
'TODO: breaks support of Windows variables on Linux
|
'Transform missing variables back
|
||||||
Dim oParse As new Regex("%([a-zA-Z0-9_]+?)%")
|
Dim oParse As new Regex("%([a-zA-Z0-9_]+?)%")
|
||||||
sValue = oParse.Replace(sValue, "${$1}")
|
sValue = oParse.Replace(sValue, "${$1}")
|
||||||
|
'Unscape real Windows variables
|
||||||
|
sValue = sValue.Replace("\%", "%")
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Return sValue
|
Return sValue
|
||||||
@@ -391,13 +397,13 @@ Public Class mgrPath
|
|||||||
Dim sPublicDocs As String = "%COMMONDOCUMENTS%"
|
Dim sPublicDocs As String = "%COMMONDOCUMENTS%"
|
||||||
Dim sEnvPublicDocs As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)
|
Dim sEnvPublicDocs As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)
|
||||||
Dim sAppDataLocal As String = "%LOCALAPPDATA%"
|
Dim sAppDataLocal As String = "%LOCALAPPDATA%"
|
||||||
Dim sAppDataLocalLinux As String = "${XDG_DATA_HOME:-~/.local/share}"
|
Dim sXdgData As String = "${XDG_DATA_HOME:-~/.local/share}"
|
||||||
Dim sEnvAppDataLocal As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
Dim sEnvAppDataLocal As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
||||||
Dim sAppDataRoaming As String = "%APPDATA%"
|
Dim sAppDataRoaming As String = "%APPDATA%"
|
||||||
Dim sAppDataRoamingLinux As String = "${XDG_CONFIG_HOME:-~/.config}"
|
Dim sXdgConfig As String = "${XDG_CONFIG_HOME:-~/.config}"
|
||||||
Dim sEnvAppDataRoaming As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
|
Dim sEnvAppDataRoaming As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
|
||||||
Dim sCurrentUser As String = "%USERPROFILE%"
|
Dim sCurrentUser As String = "%USERPROFILE%"
|
||||||
Dim sCurrentUserLinux As String = "~"
|
Dim sHomeDir As String = "~"
|
||||||
Dim sEnvCurrentUser As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
|
Dim sEnvCurrentUser As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
|
||||||
Dim oCustomVariable As clsPathVariable
|
Dim oCustomVariable As clsPathVariable
|
||||||
|
|
||||||
@@ -435,11 +441,11 @@ Public Class mgrPath
|
|||||||
Else
|
Else
|
||||||
'Use different paths on Linux
|
'Use different paths on Linux
|
||||||
If sValue.Contains(sEnvAppDataRoaming) Then
|
If sValue.Contains(sEnvAppDataRoaming) Then
|
||||||
Return sValue.Replace(sEnvAppDataRoaming, sAppDataRoamingLinux)
|
Return sValue.Replace(sEnvAppDataRoaming, sXdgConfig)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If sValue.Contains(sEnvAppDataLocal) Then
|
If sValue.Contains(sEnvAppDataLocal) Then
|
||||||
Return sValue.Replace(sEnvAppDataLocal, sAppDataLocalLinux)
|
Return sValue.Replace(sEnvAppDataLocal, sXdgData)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
'Must be last
|
'Must be last
|
||||||
@@ -452,7 +458,7 @@ Public Class mgrPath
|
|||||||
'Fall back
|
'Fall back
|
||||||
sEnvCurrentUser = sMyDocs
|
sEnvCurrentUser = sMyDocs
|
||||||
End If
|
End If
|
||||||
Return sValue.Replace(sEnvCurrentUser, sCurrentUserLinux)
|
Return sValue.Replace(sEnvCurrentUser, sHomeDir)
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user