Archive: $INSTDIR removes the colon in path


$INSTDIR removes the colon in path
  Hi,

I retrieve a path from the registry to $INSTDIR. If the path is for example D:\Folder (sans quotes) then no problem. BUT, if the path is contained within quotes as in "C:\Program Files" then NSIS removes the colon!
Retrieving first to a variable (correct path) and then assigning it to $INSTDIR also removes the colon.
The path does exists and there is nothing before the quote. This must be a bug surely.
Please help?
Gerry.
NSIS 2.46


What is the exact string retrieved from registry?
ReadRegStr $0 HKLM foo\bar path
MessageBox mb_ok "$0"


Some of the path variables are special, use a register...


Hi,

Thanks for the replies, but I still can't get it to work.
HKLM "Software\Folder" "Location" contains "D:\Temp" (with quotes)

ReadRegStr $R0 HKLM "Software\Folder" "Location"
$R0 contains D:\Temp

StrCpy $INSTDIR $R0
$INSTDIR contains D\Temp (sans colon)

Any ideas?
Thank you.


Hmm. Could it be that the regstring contains a fullwidth colon, that the $INSTDIR variable sanitization code cannot handle? Try writing a new string D:\Temp to the registry before reading it.


I get it now. Paths with imbedded spaces are never surrounded by quotes in the registry. NSIS sees a colon as an illegal character.

Sorry for wasting your time!
Gerry.


Originally posted by topshoeter
Paths with imbedded spaces are never surrounded by quotes in the registry.
They are sometimes, depends on the key and which program wrote the entry. (Paths that can be executed are often quoted, HKCR\txtfile\shell\open\command etc)

Originally posted by topshoeter
NSIS sees a colon as an illegal character.
It is only legal as the second character when copied into the NSIS $*path variables...

Spaces in file names! Come back DOS, all is forgiven :-)


a rare bug? i never ever had such issue here with : or spaces in path names - even quoted or not.
either your code or your environment is corrupted.


Hi Brummelchen,

I don't think it is a bug, or that my code/installation is corrupt, more ignorance on my part. The situation was this. I was running a test and needed a path in the registry which I entered manually. The path was going to be used in a cmd file to be run subsequently with “ExecWait” so the quotes were necessary. Because there were spaces in the path I (wrongly) entered the path in the registry enclosed in quotes. This resulted in the colon being stripped when reading into $INSTDIR. After removing the quotes in the registry path $INSTDIR contained the correct path including the spaces. I now place the quotes around the path when building my command line.

Regards.


ok, i see. look this works if you dont have it

ExecWait '"$PATH\7zg.exe" x "$otherpath\data.7z" -o"$INSTDIR"' $R9


when i read out unknown path i trim them before working on them, example:
 ${If} $INSTDIR == ""

${registry::Read} "$UNINSTALLREG" "InstallLocation" $R9 $R7
${IfNot} $R7 == ""
${AndIfNot} $R9 == ""
Push $R9
Call Trim
Pop $R9
StrCpy $INSTDIR $R9
${EndIf}
${EndIf}

Trim

; Trim
; Removes leading & trailing whitespace from a string
; Usage:
; Push {var}
; Call Trim
; Pop {var}

Exch $R1 ; Original string
Push $R2
Loop:
StrCpy $R2 "$R1" 1
StrCmp $R2" " TrimLeft
StrCmp $R2"$\"" TrimLeft
StrCmp $R2"$\'" TrimLeft
StrCmp $R2 "\" TrimLeft
StrCmp $R2 "
/" TrimLeft
StrCmp $R2 ";" TrimLeft
StrCmp $R2 "," TrimLeft
StrCmp $R2 "<" TrimLeft
StrCmp $R2 ">" TrimLeft
StrCmp $R2 "$r" TrimLeft
StrCmp $R2 "$n" TrimLeft
StrCmp $R2 " " TrimLeft ; this is a tab.
GoTo Loop2
TrimLeft:
StrCpy $R1 "$R1" "" 1
Goto Loop

Loop2:
StrCpy $R2 "$R1" 1 -1
StrCmp $R2 " " TrimRight
StrCmp $R2 "$"" TrimRight
StrCmp $R2"$\'" TrimRight
StrCmp $R2 "\" TrimRight
StrCmp $R2 "/" TrimRight
StrCmp $R2 ";" TrimRight
StrCmp $R2 "," TrimRight
StrCmp $R2 "<" TrimRight
StrCmp $R2 ">" TrimRight
StrCmp $R2 "$r" TrimRight
StrCmp $R2 "$n" TrimRight
StrCmp $R2 " " TrimRight ; this is a tab
GoTo Done
TrimRight:
StrCpy $R1 "$R1" -1
Goto Loop2

Done:
Pop $R2
Exch $R1
FunctionEnd
>
this blows code a bit but i have several routines like that.

path in registry in quotes are in most cases only needed when a parameter is added, windows itself is capable to handle. if you work in a batch environment (commandline) you need to add always quotes eg. dir /on "c:\program files\" to avoid errors.

@="c:\my.exe"

@="\"c:\my.exe\" \"%1\""

$\" adds a quote within a string (nsis)

if you work with nsis commandline parameters you have to determine wether they are in quotes or not - nsis wiki contains some examples.

HTH