Im not an expert .. but find NSIS an intriguing language.
I love the simplicity, and small overhead.
I discover new things everyday.
For instance.. today.. i learned:
if used with a wildcard to detect if files exists, will always return true, due to ".", "..".
Example:
Using Logic:
Both examples will execute MessageBox, because it will detect ".", "..".
I have put together a useful script that will allow both above examples to work.
Now you can do this:
im sure the script can be shortened/improved..
But im not an expert..
infact.. i would truly love it if someone could improve the "isEmptyDir" script w/ Logic.
I love the simplicity, and small overhead.
I discover new things everyday.
For instance.. today.. i learned:
PHP Code:
IfFileExists
Example:
PHP Code:
IfFileExists `$INSTDIR\Dir\*.*` 0 skip
MessageBox MB_OK "Did not skip."
skip:
PHP Code:
${If} ${FileExists} `$INSTDIR\Dir\*.*`
MessageBox MB_OK "Did not skip."
${EndIf}
I have put together a useful script that will allow both above examples to work.
PHP Code:
;!include logiclib.nsh
!define IsEmptyDir `"" LL_IsEmptyDir`
!macro _LL_IsEmptyDir _a _b _t _f
!insertmacro _LOGICLIB_TEMP
${EmptyDir} `${_b}` $_LOGICLIB_TEMP
!insertmacro _= $_LOGICLIB_TEMP 1 `${_t}` `${_f}`
!macroend
!macro EmptyDir _DIR _VAR
Push ${_DIR}
Call EmptyDir
Pop ${_VAR}
!macroend
!define EmptyDir `!insertmacro EmptyDir`
Function EmptyDir
; renamed isempty from:
; http://nsis.sourceforge.net/Check_if_dir_is_empty
# Stack -> # Stack: <directory>
Exch $0 # Stack: $0
Push $1 # Stack: $1, $0
FindFirst $0 $1 "$0\*.*"
strcmp $1 "." 0 _notempty
FindNext $0 $1
strcmp $1 ".." 0 _notempty
ClearErrors
FindNext $0 $1
IfErrors 0 _notempty
FindClose $0
Pop $1 # Stack: $0
StrCpy $0 1
Exch $0 # Stack: 1 (true)
goto _end
_notempty:
FindClose $0
ClearErrors
Pop $1 # Stack: $0
StrCpy $0 0
Exch $0 # Stack: 0 (false)
_end:
FunctionEnd
Now you can do this:
PHP Code:
${IfNot} ${IsEmptyDir} `$INSTDIR\Dir`
MessageBox MB_OK "Did not skip."
${EndIf}
im sure the script can be shortened/improved..
But im not an expert..
infact.. i would truly love it if someone could improve the "isEmptyDir" script w/ Logic.
Comment