Archive: Alternate install folder after selection


Alternate install folder after selection
Is there a straightforward way to provide a user the ability to select a different installation folder if the one he chooses in the Location page already exists?

It's simple to detect if the folder exists after he clicks Install but I'd like to be able to inform him (with a pop-up?) that the folder exists and give him the option to overwrite its contents, select a new folder or abort. I'd prefer it if selecting a new folder was on a Location page, this time with a blank field instead of the default.

If there isn't a straightforward way, is there any code I can grab to do the job?


you can handle all of this in the leave callback function for the directory page


Sorry to be dense but this is unfamiliar territory for me so a one liner doesn't have enough info.

In System.nsh's !macro MUI_PAGE_DIRECTORY I see a list of PageCallbacks. This included the DirectoryLeave_ I believe you are referring to.

I read the info on nsis.sourceforge.net/Docs/System/System.html#callback but it left me scratching my head. I played with some of the Example code but didn't get any apparent results. I still don't know:
o How to call the DirectoryLeave callback
o How to set up the parameter list
o How to use any return info to cause the directory page to be regenerated.

I'd appreciate any help on this to get me going.


; Select Install Directory Page
!define MUI_PAGE_CUSTOMFUNCTION_PRE preDirectory
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE leaveDirectory
!define MUI_DIRECTORYPAGE_VERIFYONLEAVE
!insertmacro MUI_PAGE_DIRECTORY

Function preDirectory

FunctionEnd

Function leaveDirectory
;This is where you validate if the folder already exists
;If so, present message to user if they want to overwrite
;If yes, do nothing
;If no abort
;the abort command will return the user to the destination selection screen
FunctionEnd


How to change path after failed validation
What I have been unable to figure out is how to change the path presented to the user when returning to the destination selection screen. It returns the user with the field populated with the value that was just rejected. How do we return the value to some type of default

ie:
Default ($INSTDIR) is set to C:\Program Files\Xyz
User fills browses to C:\Recycler, which fails the validation
After notifying the user that C:\Recycler is not an allowable destination, how do we change the path back to C:\Program Files\Xyz?


In the Pre callback function of the directory page, store $INSTDIR in a global variable, like $OriginalINSTDIR.
In the Leave callback function, check if the user gave a valid path, and if not:

FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $R0 $0 1019
SendMessage $R0 ${WM_SETTEXT} 0 "STR:$OriginalINSTDIR"
Abort

Success!!!!
Thanks, this works perfectly and is exactly what I was looking for