Archive: Checking if a file exists


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?

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


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

Did you check what $INSTDIR actualy is?
Maybe it's pointing to a wrong location.


The $INSTDIR should be correct, it works fine for the rest of the installation. Everything looks like it should work correctly... strange


To be sure, just call MessageBox MB_OK "$INSTDIR\info.ini", and doublecheck if the file really exists.


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...


Hmmm, it just displays a message saying $INSTDIR\info.ini

Should it display the contents of info.ini?


MSG, I just spotted that :)


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?

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


Im still getting nowhere with this issue, do you think it could be that fact that I am setting INSTDIR from a custom page?


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.


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