Archive: Installation Directory Restrictions


Installation Directory Restrictions
Hello,

What I am trying to do is check the installation directory chosen by the user, and if it contains any spaces (ex: Program Files) disable the "next" button and show a message box informing the user that the installation directory may not contain spaces. I know how to disable the "next" button and create a message box, but I can't figure out how to check for spaces in the $INSTDIR variable.

If anyone knows how to do this, please let me know.

Thanks.


; ---------------------------------------------------------------
; Function StrOutOfStr
/*
Usage:

!insertmacro StrOutOfStr ; for installer
!insertmacro un.StrOutOfStr ; for uninstaller


Whithin installer section/function use:

${StrOutOfStr} "Input_String" "String_To_Get" "$var"
$var = String_To_Get if found
if not found/error then $var = error


Whithin uninstaller section/function use:

${un.StrOutOfStr} "Input_String" "String_To_Get" "$var"
$var = String_To_Get if found
if not found/error then $var = error
*/

!macro StrOutOfStrFunc UN
Function ${UN}StrOutOfStr
Exch $0 ;str to get
Exch
Exch $1 ;input str
Push $2
Push $3
Push $4
Push $5

StrCpy $3 "0"
StrLen $4 "$0"
StrLen $5 "$1"
IntCmp $4 $5 0 0 _err
Intop $5 $5 - $4

_start:
StrCpy $2 "$1" $4 $3
StrCmp "$2" "$0" _done
IntCmp "$3" "$5" _err
Intop $3 $3 + 1
Goto _start

_err:
StrCpy $2 "error"

_done:
StrCpy $0 "$2"

Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Exch $0
FunctionEnd
!macroend

!macro StrOutOfStrCall _UN _INPUT _FIND _RESULT
Push "${_INPUT}"
Push "${_FIND}"
Call ${_UN}StrOutOfStr
Pop "${_RESULT}"
!macroend

!macro StrOutOfStr
!define StrOutOfStr `!insertmacro StrOutOfStrCall ""`
!insertmacro StrOutOfStrFunc ""
!macroend

!macro un.StrOutOfStr
!define un.StrOutOfStr `!insertmacro StrOutOfStrCall "un."`
!insertmacro StrOutOfStrFunc "un."
!macroend


;----------------------------------------
; Example of usage

outfile 'test.exe'
ShowInstDetails show

!define STRING_TO_GET " "

!insertmacro StrOutOfStr
;!insertmacro un.StrOutOfStr

Section -
${StrOutOfStr} "$PROGRAMFILES" "${STRING_TO_GET}" "$R0"
DetailPrint "Search result: [$R0]"
SectionEnd

Thanks for the code Red Wine. I'm pretty new to NSIS though, and I'm not totally sure how I'm supposed to use it. If you could give me little bit more usage information, that would be great.

Thanks.


Don't know what else should I add, it is a function that you can use to find a specific string within a given sting, so it finds the space for your case.
There is a small example of usage as well, just copy/paste and compile the code to see the action.
Furthermore, you said that you know all the rest ;)