Archive: Problem with Cancel button


Problem with Cancel button
On the first page of my installer I ask the user to select the installation directory of another piece of dependent software. The installer then checks if a certain file within this directory exists. If it exists the installation will continue. If it doesn't exist an MB_OK message box will be displayed and the user can then re-enter the installation directory.

Here is the code:


Function MainScreen1

try_again:
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "Main_Screen_1.ini"

!insertmacro MUI_INSTALLOPTIONS_READ $var_FL_INSTALL_DIR "Main_Screen_1.ini" "Field 4" "State"

IfFileExists $var_FL_INSTALL_DIR\config\policy finish not_installed

not_installed:
MessageBox MB_OK|MB_ICONSTOP "The software is not installed in the specified directory." IDOK try_again

finish:

FunctionEnd


However, if the user hits Cancel when the incorrect directory is currently selected the "Are you sure you want to quit setup?" message box appears, which is all well and good, but when Yes is clicked the "The software is not installed in the specified directory." message box gets displayed!!

How do I get round this? Is there a best practice way of doing this sort of thing?

you need to set up a validation custom function, you can't use the same IO function as show and leave.
your code is an infinite loop, don't you see it?

you may want to refer to included IO examples.


Originally posted by Red Wine
you need to set up a validation custom function, you can't use the same IO function as show and leave.
your code is an infinite loop, don't you see it?

you may want to refer to included IO examples.
Yeah I see the infinite loop it's just I wanted to know if there was a way around it. I'll have a look at the included IO examples like you suggest.

page custom MainScreen1_show MainScreen1_leave


Function MainScreen1_show

!insertmacro MUI_INSTALLOPTIONS_DISPLAY "Main_Screen_1.ini"

FunctionEnd

Function MainScreen1_leave

!insertmacro MUI_INSTALLOPTIONS_READ $var_FL_INSTALL_DIR "Main_Screen_1.ini" "Field 4" "State"

IfFileExists $var_FL_INSTALL_DIR\config\policy finish not_installed

not_installed:
MessageBox MB_OK|MB_ICONSTOP "The software is not installed in the specified directory." IDOK 0
Abort
finish:

FunctionEnd

This worked a charm, thanks for your help Red Wine. Sorry only getting back to you now!


you welcome, glad if I can help :-)


It might be a good idea to check `$var_FL_INSTALL_DIR\config\policy\*.*`. This will perform a directory check rather than a file check (policy could be a file and therefore the directory path would be invalid).

-Stu