aviadlich
23rd April 2007 09:26 UTC
validate directory is empty
I am also new with NSIS
i am trying to do the following:
After the user picked the installation directory i want to warn (message box) him in case the directory is not empty and go back to the directory page if he wishes to.
I am using the
!insertmacro MUI_PAGE_DIRECTORY
for the directory page chooser.
How do i do it?
kichik
23rd April 2007 13:31 UTC
The directory page won't let the user input an empty directory as it's invalid. Just try and see.
Please don't add your question to another thread unless it concerns the exact same topic.
aviadlich
23rd April 2007 14:45 UTC
I am not trying to insert an empty string
i want to check that the user didnt pick a directory tat exists and has data in it.
kichik
23rd April 2007 14:51 UTC
Oh, right. Of course that's what you'd want... :) Check if the directory has any files in it in the leave function of the page. To check that, use isEmptyDir.
aviadlich
23rd April 2007 14:57 UTC
Thanks for the quick reply
And how do i get to the leave function of the page
I couldnt find it using the MUI_PAGE_DIRECTORY
Afrow UK
23rd April 2007 16:30 UTC
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE DirectoryLeave
!insertmacro MUI_PAGE_DIRECTORY
Stu
aviadlich
23rd April 2007 16:40 UTC
Thanks
timberman
28th August 2008 15:13 UTC
Originally posted by kichik
Oh, right. Of course that's what you'd want... :) Check if the directory has any files in it in the leave function of the page. To check that, use isEmptyDir.
There is also the ${DirState} macro from FileFunc.nsh
example:
target dir validation
!insertmacro "DirState"
>.
.
.
!
define MUI_PAGE_CUSTOMFUNCTION_LEAVE "ValidateInstallationDir"
>!insertmacro MUI_PAGE_DIRECTORY
>.
.
.
.
Function ValidateInstallationDir
;make sure $INSTDIR path is either empty or does not exist.
Push $0
${DirState} "$INSTDIR" $0
${If} $0 == 1 ;folder is full. (other values: 0: empty, -1: not found)
;refuse selection
MessageBox MB_OK|MB_ICONSTOP "$(msgDirectoryNotEmpty)"
Abort
${EndIf}
Pop $0
FunctionEnd
>