Archive: Restart Section


Restart Section
Hi!

I`ve been looking at some advises here, but they didn`t help me a lot. So maybe somebody else can help me.

My installer checks the installation path, and if it is a forbidden path, it stops the installation. What i`ve been trying to do, is when the installer is stopped, it goes back to the DIRECTORY page and asks the user to select another path. I`m using this code:

Function RelGotoPage
IntCmp $R9 0 0 Move Move
StrCmp $R9 "X" 0 Move
StrCpy $R9 "120"

Move:
SendMessage $HWNDPARENT "0x408" "$R9" ""
FunctionEnd


!macro BadPathsCheck
StrCpy $R0 $INSTDIR "" -2
StrCmp $R0 ":\" bad
StrCpy $R0 $INSTDIR "" -14
StrCmp $R0 "\Program Files" bad
StrCpy $R0 $INSTDIR "" -8
StrCmp $R0 "\Windows" bad
StrCpy $R0 $INSTDIR "" -6
StrCmp $R0 "\WinNT" bad
StrCpy $R0 $INSTDIR "" -9
StrCmp $R0 "\system32" bad
StrCpy $R0 $INSTDIR "" -8
StrCmp $R0 "\Desktop" bad
StrCpy $R0 $INSTDIR "" -22
StrCmp $R0 "\Documents and Settings" bad
StrCpy $R0 $INSTDIR "" -13
StrCmp $R0 "\My Documents" bad good
bad:
MessageBox MB_OK|MB_ICONSTOP "Install path invalid! You should chose another install path."
StrCpy $R9 -1 ;Goto the next page
Call RelGotoPage
good:
!macroend

Section InstallComponents

!insert BadPathsCheck

... Some code here that installs files...

SectionEnd

The point is, that ( maybe i`m mistaken, but i keep getting errors ) Section continues to execute installation of the files, even though it shows the Directory page. Is there a way to make the Section restart, or pause?


It would be a better way to check the path before the user is allowed to leave the DIRECTORY page! You can use the CallbackFunction of the directory page to do this. Just assign a "[leave_function]" function to your directory page. In that function check whether $INSTDIR is valid or not. If it's not valid, then simply call Abort ...


Here is an example:

Name "Path"
OutFile "Path.exe"
InstallDir "C:\Foobar"

page directory "" "" LeaveDir
page instfiles

Section
SetOutPath $INSTDIR
DetailPrint 'Now intsalling stuff to "$INSTDIR"'
SectionEnd

Function LeaveDir
MessageBox MB_TOPMOST|MB_YESNO 'Is "$INSTDIR" a valid directory?' IDYES +2
Abort
FunctionEnd

There is no need for a custom leave function, use the standard .onVerifyInstDir callback function.


You are right. But then you check the directory more often, not only when the user tries to leave the directory page. Depends on what you want to achieve. Try this and compare the result with my first example above:

Name "Path"
OutFile "Path.exe"
InstallDir "C:\Foobar"

page directory
page instfiles

Section
SetOutPath $INSTDIR
DetailPrint 'Now intsalling stuff to "$INSTDIR"'
SectionEnd

Function .onVerifyInstDir
MessageBox MB_TOPMOST|MB_YESNO 'Is "$INSTDIR" a valid directory?' IDYES +2
Abort
FunctionEnd


In case you want to display an error message to the user, when an invalid directory has been selected, I would go with the custom leave function instead of .onVerifyInstDir function. Otherwise you would bomb the user with too many message boxes...

Huge thanx, guys. The installation works fine now.