Old 4th July 2008, 13:51   #1
AndyBoy
Junior Member
 
Join Date: Jul 2008
Posts: 3
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?
AndyBoy is offline   Reply With Quote
Old 4th July 2008, 14:46   #2
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
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 ...

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 4th July 2008, 14:54   #3
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Here is an example:

code:
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


My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 4th July 2008, 15:30   #4
Joost Verburg
NSIS MUI Dev
 
Join Date: Nov 2001
Posts: 3,717
There is no need for a custom leave function, use the standard .onVerifyInstDir callback function.
Joost Verburg is offline   Reply With Quote
Old 4th July 2008, 15:33   #5
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
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:

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

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 7th July 2008, 08:21   #6
AndyBoy
Junior Member
 
Join Date: Jul 2008
Posts: 3
Huge thanx, guys. The installation works fine now.
AndyBoy is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump