Archive: The Custom Page Leave Function


The Custom Page Leave Function
Hello,
I have a product key verification in my custom page leave function....which works great....unless the end user tries to exit the installer...it will give an invalid serial key message to the user and not let them exit.

Is there a way to determine if the user pushed the next button, or the Close/Cancel button? If so how?

Thanks
Kyle


Sounds like error leave function, a code snippet would be helpful.


Sure,
This is my page leave function


Function RegLeave
;Grab the Registration ID user entered in textbox
ReadINIStr ${varInput} "$PLUGINSDIR\REG.ini" "Field 2" "State"

;Check the web to see if the code is good
InetLoad::load /post "code=${varInput}" "http://www.metroeguide.net/registration/Registration.aspx" "reg.htm" /slient ""
;load the contents of the downloaded file into the var $3
FileOpen $2 "reg.htm" "r"
FileRead $2 $3
FileClose $2

${If} $3 == 'INVALID'
MessageBox MB_OK|MB_ICONEXCLAMATION "Invalid Product Key"
Abort
${EndIf}

${If} $3 == 'TOOMANY'
MessageBox MB_OK|MB_ICONEXCLAMATION "Product Key used too many times. Please call 800-405-2100"
Abort
${EndIf}

${If} $3 == 'SUCCESS'
goto serialOK
${EndIf}


serialOK:
FunctionEnd

The webpage that is the Registration ID is posted to returns 1 of 3 things....either 'INVALID' if no key is entered, or it's an incorrect registration key...'TOOMANY' if the key has been used more than 3 times, and 'SUCCESS' if the key is good. When the user hits the close button...the function I think is run, and it POSTs to the website, which returns INVALID (no key entered)..and doesn't let the installer exit.

The way I see it is, the installer is actually doing nothing wrong...It sees it's about to leave the page (when the user presses cancel) so it runs the function...the registration page (the asp page) obviously returns INVALID key....I'm not sure how to really get around it, unless somehow I could tell if the user tried to close the application, or press the next button

Next button is 0, e.g. ReadINIStr $0 "$PLUGINSDIR\test.ini" "Settings" "State"
You may want to take a look at included example testnotify.nsi


Thank you very much Red Wine for your quick replys.

It seems...the Back button, the Install button, and the Cancel button....are all 0's...I did a


ReadINIStr $0 "$PLUGINSDIR\REG.ini" "Settings" "State"
MessageBox MB_OK $0

and all the buttons returned 0, I believe they are all 0 because none of them are defined in my REG.ini.

I also tried disabling the Install Button, (infact tried to disable every button) with no luck...
I tried

GetDlgItem $1 $HWNDPARENT 1
EnableWindow $1 0

from ID 1 to about 10, it seems to have no effect.
I am using the ExperienceUI...could this be a problem?

Any other Ideas?

How do you know that they are all 0? The Leave function is only executed when you click Next (unless this is not the case in ExperienceUI)!

Stu


Good to hear from you Stu!

I think I must have another problem them...my Leave Function seems to be executing when I press the Back...The Install...and the Cancel button...

[edit]
I guess that only happens when I have this in my script


!define XPUI_ABORTWARNING

I suppose it will be fine without it, but it is kindof nice to give the user a chance to 'not cancel' the installation...Do you know of a way I can have the Abort Warning enabled, without the leave function executing everytime a button is clicked?
[/edit]

Thanks again for your reply

I suspect this is a specific bug of XPUI,
do you mind give a try to your entire script with MUI?
I guess would be nice for all of us to know about.


I think what makes XPUI a bit unique is the way it handles aborts.

From the XPUI docs, when XPUI_ABORTWARNING should be set with a value of either TRUE or FALSE. (The default is false).

Also if you've defined an abort page, you may find this helpful (also from XPUI docs):

If you have an Abort Page in your installer, you may want to use an automatic abort warning in order to make the Abort page trigger properly. If you aren't using the ExperienceUI's built-in abort warning system, you can insert the following function to properly invoke the Abort page.

Function .onUserAbort
StrCmp $NOABORTWARNING 1 CloseMe
MessageBox MB_YESNO|MB_ICONQUESTION "Are you sure you want to cancel Setup?" IDNO NoAbort
# any custom code you want before the Abort page is called here...
!insertmacro XPUI_USERABORT
NoAbort:
Abort
CloseMe:
# any custom code you want before the installer exits here...
FunctionEnd