Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 2nd July 2007, 20:18   #1
madams
Junior Member
 
Join Date: Jun 2007
Posts: 34
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.
madams is offline   Reply With Quote
Old 2nd July 2007, 22:59   #2
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
code:
; ---------------------------------------------------------------
; 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


Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 3rd July 2007, 13:23   #3
madams
Junior Member
 
Join Date: Jun 2007
Posts: 34
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.
madams is offline   Reply With Quote
Old 3rd July 2007, 17:47   #4
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
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

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump