Archive: Check for presence of spaces in the $INSTDIR?


Check for presence of spaces in the $INSTDIR?
I was wondering if its possible to write .onVerifyInstDir in a way that would check the path for the presence of any space characters and only proceed if there aren't any.

Any help is appreciated!


Try this
A function can call another function. Try calling the one below from your .OnVerifyInstDir function. I haven't used .OnVerifyInstDir myself yet, so you'll have to test this, but in general terms try something like this:


;------------------------
Function .OnVerifyInstDir
;------------------------
; whatever

Push "$INSTDIR"
Push " "
Call StrSearch
Exch
Pop $0 ; $0 now = 0 or position in string of remainder
Pop $0 ; $0 now = 0 or position in string of substring
StrCmp $0 "0" DirGood DirBad

DirGood:
; whatever
DirBad:
; whatever
abort

FunctionEnd

;-----------------
Function StrSearch
;-----------------
; Searches string for a substring
; Adapted from Function strstr in NSIS Manual C.4

; Inputs: stack 0 = Substring to search for
; stack 1 = String to search in

; Output: stack 0 = 0 if substring not found, else position in string of substring.
; stack 1 = 0 if substring not found, else position in string of remainder
; (anything following substring). If no remainder, this will be
; len(string) + 1.
; If string is empty, always returns 0,0
; If substring empty, returns 1,1

; Usage:
; Push "string"
; Push "substring"
; Call StrSearch
; Pop $0 ; $0 now = 0 or position in string of substring
; Pop $1 ; $1 now = 0 or position in string of remainder

Exch $3 ; Substring
Exch
Exch $4 ; String
Push $0 ; Temp
Push $1 ; Counter
Push $2 ; Len

StrCmp $4 "" NotFound ; If String empty, we will always return 0,0
StrLen $2 $3 ; Len = len(substring)
StrCpy $1 0 ; initialize counter to 0
Loop:
StrCpy $0 $4 $2 $1 ; Temp = Len chars from String commencing from Counter+1
IntOp $1 $1 + 1
StrCmp $0 $3 Done
StrCmp $0 "" NotFound
Goto Loop
NotFound:
StrCpy $1 0
StrCpy $2 0
Done:
StrCpy $3 $1 ; $3 now = pos of SubString
IntOp $4 $1 + $2 ; $4 now = pos of remainder
Pop $2
Pop $1
Pop $0
Exch $4
Exch
Exch $3
FunctionEnd ; (StrSearch) ====================================