- NSIS Discussion
- Checking if a file exists
Archive: Checking if a file exists
starfighter5
17th December 2010 11:04 UTC
Checking if a file exists
The installer I am creating patches some already installed software, as such I want it to check that a certain file exists before allowing it to continue, I have the following.....
Page custom instcheckleave
Function instcheckleave
IfFileExists $INSTDIR\info.ini PathGood
Abort ; if $INSTDIR is not a valid program, don't let us run the patch
PathGood:
FunctionEnd
This code doesn't seem to let the user go any further, regardless of the file existing or not. Where am I going wrong?
Anders
17th December 2010 11:17 UTC
Calling abort in the pre callback will skip the page, so I don't see how the user can be stuck there no matter what
starfighter5
17th December 2010 11:35 UTC
Do you think it may be where I am calling it? Here is the page before......
Page custom page4 page4leave
Function page4
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "page4"
!insertmacro MUI_INSTALLOPTIONS_READ $INSTDIR "page4" "Field 1" "State"
FunctionEnd
Page custom page4leave
Function page4leave
IfFileExists $INSTDIR\info.ini PathGood
MessageBox MB_ICONEXCLAMATION|MB_OK "File does not exist"
Abort ;
PathGood:
FunctionEnd
It just gives me the 'File Does not exist' message, even though it does
jpderuiter
17th December 2010 12:25 UTC
Did you check what $INSTDIR actualy is?
Maybe it's pointing to a wrong location.
starfighter5
17th December 2010 13:41 UTC
The $INSTDIR should be correct, it works fine for the rest of the installation. Everything looks like it should work correctly... strange
jpderuiter
17th December 2010 13:48 UTC
To be sure, just call MessageBox MB_OK "$INSTDIR\info.ini", and doublecheck if the file really exists.
MSG
17th December 2010 14:26 UTC
First you do
Page custom page4 page4leave
And then you do
Page custom page4leave
This is not correct. Page4leave is a leave function, not a page function. You call it first as a leave function, but then tell NSIS to create a second page, with the same function...
starfighter5
17th December 2010 14:47 UTC
Hmmm, it just displays a message saying $INSTDIR\info.ini
Should it display the contents of info.ini?
starfighter5
17th December 2010 15:03 UTC
MSG, I just spotted that :)
MSG
17th December 2010 15:13 UTC
Originally posted by starfighter5
Hmmm, it just displays a message saying $INSTDIR\info.ini
Should it display the contents of info.ini?
No, it should display the contents of the $INSTDIR variable. So it should look like "C:\Program Files\YourApp\info.ini". $INSTDIR is a built-in variable, you cannot disable it (as far as I know). Are you sure you typed it correctly?
starfighter5
17th December 2010 15:20 UTC
This is what I have after the changes and corrections I made, could the problem be that I am bypassing the normal installation directory and setting $INSTDIR from a custom page?
Page custom page4 page4leave
Function page4
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "page4"
!insertmacro MUI_INSTALLOPTIONS_READ $INSTDIR "page4" "Field 1" "State"
FunctionEnd
Function page4leave
IfFileExists "$INSTDIR\info.ini" PathGood
MessageBox MB_OK "$INSTDIR\info.ini"
Abort ; if $INSTDIR is not a valid program, don't let us run the patch
PathGood:
FunctionEnd
starfighter5
4th January 2011 14:52 UTC
Im still getting nowhere with this issue, do you think it could be that fact that I am setting INSTDIR from a custom page?
starfighter5
4th January 2011 14:58 UTC
I have just put the following into the function
MessageBox MB_OK "$INSTDIR"
And it displays nothing, but if I put the same into the function below then it displays the installation directory.
starfighter5
4th January 2011 15:02 UTC
Managed to resolve it, I changed where it reads $INSTDIR to the leave function and things have started working....
Page custom page4 page4leave
Function page4
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "page4"
FunctionEnd
Page custom page4leave
!insertmacro MUI_INSTALLOPTIONS_READ $INSTDIR "page4" "Field 1" "State"
Function page4leave
IfFileExists $INSTDIR\info.ini PathGood
MessageBox MB_ICONEXCLAMATION|MB_OK "File does not exist"
Abort
PathGood:
FunctionEnd