Archive: Mb_okcancel


Mb_okcancel
is there a way to click cancel and go back to the same GUI. I thought it would do that with the code I have but it seems to be going to the next step regardless.

here is my code

MessageBox MB_OKCANCEL "If $0 is the correct IP Address click Ok, if not click Cancel and correct it." IDOK OK IDCANCEL CANCEL
OK:
DetailPrint "$0 is right"

CANCEL:
DetailPrint "$0 needs to be corrected"
Abort


See Page & leave with Abort instruction


Try to rename the labels. Maybe NSIS gets confused by using the words "OK" / "Cancel"

In your code your missing a label after Detailprint "$0 is right". This way the code after the label cancel is executed too.


The name of the lables should have no bearing on the outcome.

From your code, it sounds like you are asking this question after you are already installing files. (I say this because DetailPrint only works during the page instfiles.)

The better approach is to have all the required information BEFORE you start the install.

Take a look at the attached script for an example of one way you might deal with this.

Another option might be to insert a custom "confirmation page" in which you summarize all the user's choices right before they click "next" to start the install.


thanks for the example, it is working for what I want it to do other than going back to my custom page if it is wrong so it is able to be changed to the correct IP address. I'll put in the code for my page so you can see what it is doing exactly.

Function ServerIP

!insertmacro MUI_HEADER_TEXT "Server IP Address Change" "This \
is for Clients only, if this is a server you are \
installing on then place localhost in the text area."

!insertmacro MUI_INSTALLOPTIONS_EXTRACT "ServerIP.ini"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "ServerIP.ini"

ReadINIStr $3 "$PLUGINSDIR\ServerIP.ini" "Field 5" "State"

${If} $3 == 0
ReadINIStr $0 "$PLUGINSDIR\ServerIP.ini" "Field 2" "State"

Push $0
MessageBox MB_OKCANCEL "If $0 is the correct IP address, click 'OK', otherwise, click 'Cancel'" IDOK OK IDCANCEL CANCEL

OK:
MessageBox MB_OK "IP OK!"
pop $0
Return

CANCEL:
MessageBox MB_OK "IP BAADDD!"
pop $0
abort

Push localhost #text to be replaced
Push $0 #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push "$INSTDIR\WARN\Dashboard\dashboard.properties" #file to replace in
Call AdvReplaceInFile

Push localhost #text to be replaced
Push $0 #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push "$INSTDIR\WARN\Dashboard\dashboard.properties_RDR_SIM" #file to replace in
Call AdvReplaceInFile


${EndIf}

FunctionEnd


Couple things:
1) You should do your file extraction outside of your page's show function. (Probably best to do it in .onInit). Otherwise, you could slow down screen refreshes plus each time you extract, you would be replacing the page with a new copy (meaning that anything the user entered would be gone when they return to the page.)

2) Second, the verifications should be done in the page's leave function. If you then want to return back, you simply call the "abort" command in the leave function. Or if you need to go back more than one page, you might check this out:
http://nsis.sourceforge.net/Go_to_a_NSIS_page

My example was written without MUI, but the concepts are the same--you should take a closer look to see how it's done. You might also want to review the InstallOptions documentation and check out the InstallOptions examples in the ${NSISDIR}\Examples\Modern UI


ok all I need to do is use abort. Which I thought I am doing but it dosen't seem to be working. Here is my code

Function ServerIP

!insertmacro MUI_HEADER_TEXT "Server IP Address Change" "This \
is for Clients only, if this is a server you are \
installing on then place localhost in the text area."

!insertmacro MUI_INSTALLOPTIONS_EXTRACT "ServerIP.ini"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "ServerIP.ini"

ReadINIStr $3 "$PLUGINSDIR\ServerIP.ini" "Field 5" "State"

${If} $3 == 0
ReadINIStr $0 "$PLUGINSDIR\ServerIP.ini" "Field 2" "State"

Push $0
MessageBox MB_OKCANCEL "If $0 is the correct IP address, click 'OK', otherwise, click 'Cancel'" IDOK OK IDCANCEL CANCEL

OK:
StrCpy $9 "0"
MessageBox MB_OK "IP OK!"
pop $0
Push localhost #text to be replaced
Push $0 #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push "$INSTDIR\WARN\Dashboard\dashboard.properties" #file to replace in
Call AdvReplaceInFile

Push localhost #text to be replaced
Push $0 #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push "$INSTDIR\WARN\Dashboard\dashboard.properties_RDR_SIM" #file to replace in
Call AdvReplaceInFile
Return

CANCEL:
StrCpy $9 "1"
MessageBox MB_OK "IP BAADDD!"
pop $0
abort

${EndIf}
${if} $9 == "1"

${endif}

FunctionEnd

I changed it to where if they click ok then the text file is changed.


You can't read from the INI file in the Show function.
You must do it in the Leave function.

Page Custom ShowFunc LeaveFunc.

-Stu


Awesome it works now thanks everyone.

here is the working code for those who may be interested.


;show IP address change gui---------------------------
Function ServerIP

!insertmacro MUI_HEADER_TEXT "Server IP Address Change" "This \
is for Clients only, if this is a server you are \
installing on then place localhost in the text area."

!insertmacro MUI_INSTALLOPTIONS_EXTRACT "ServerIP.ini"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "ServerIP.ini"



FunctionEnd
;-----------------------------------------------------

;Change IP address------------------------------------
Function LeaveServerIP

ReadINIStr $3 "$PLUGINSDIR\ServerIP.ini" "Field 5" "State"

${If} $3 == 0
ReadINIStr $0 "$PLUGINSDIR\ServerIP.ini" "Field 2" "State"

Push $0
MessageBox MB_OKCANCEL "If $0 is the correct IP address, click 'OK', otherwise, click 'Cancel'" IDOK OK IDCANCEL CANCEL

OK:
StrCpy $9 "0"
pop $0
Push localhost #text to be replaced
Push $0 #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push "$INSTDIR\WARN\Dashboard\dashboard.properties" #file to replace in
Call AdvReplaceInFile

Push localhost #text to be replaced
Push $0 #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push "$INSTDIR\WARN\Dashboard\dashboard.properties_RDR_SIM" #file to replace in
Call AdvReplaceInFile
Return

CANCEL:
StrCpy $9 "1"
pop $0
abort

${EndIf}

FunctionEnd
;------------------------------------------------------