Archive: Page validation problem


Page validation problem
  If the user enters a directory with 'quake2' in it, and has the 'Use Quake2 directory rename function' CheckBox selected, then it comes up with an error message telling the user that you cnnot have both.
I need it to go back to the custom page after clicking OK.
If I call the custom page function, it instead jumps a page ahead instead of going back to the custom page.

How can I get it to go back a page?


-Stuart


I'm not sure I understand the question.

Do you mean:
You have a custom page which gets some input and if the input is not correct a message box is shown. When the message box is closed you want to go back to the custom page, so the user can enter new data. You have tried to do this by calling the function which creates the custom page again, but the installer shows the next page in the sequence instead?


Yes.

I'm a bit more awake now.


-Stuart


My solution is to do the input validation within the function that creates the custom page. If the input data is ok, you exit from the function. If the input data is not ok, you display a suitable message then re-display the custom page and let the user try again.

The following skeleton code shows this idea:


Function MyCustomPage

; The "ioA.ini" file defines the custom page controls

loop:
!insertmacro MUI_INSTALLOPTIONS_DISPLAY_RETURN "ioA.ini"
Pop $R0

StrCmp $R0 "cancel" exit_from_this_page
StrCmp $R0 "back" exit_from_this_page

; use MUI_INSTALLOPTIONS_READ lines to access and check the user input

; if input Ok, goto exit_from_this_page, if data is not OK goto bad_data

bad_data:
MessageBox MB_OK "Sorry! Input data is not valid. Please enter new data"
Goto loop

exit_from_this_page:
FunctionEnd


Hope this helps,
Brian

The trouble is, I'm not using any of the Modern UI IO commands, just the standard way with Page Custom etc
I shall look in the MUI code for how they have gone back a page.

-Stuart


The one way to go back to a other page is "use two pages in one".

Example:


MyCustomPage


;Code that will execute before the first page show.

;Display first page
InstallOptions
::dialog "inifile.ini"
Pop $R0

StrCmp $R0"success" 0 End

;Code that will execute after the first page, and before the second.

;Display second page
!insertmacro MUI_INSTALLOPTIONS_DISPLAY_RETURN "inifile.ini"
Pop $R0

StrCmp $R0"success" 0 End

;Code that will execute after the second page has showed.

>FunctionEnd
>

I shall try it thanks :)

-Stuart


Have a look at (exactly what pengyou said without the MUI):
http://nsis.sourceforge.net/archive/...instances=0,64


Sorry if I confused you by using MUI code (so far I've only used the MUI stuff). Here is my example, rewritten to use non-MUI code.


Function MyCustomPage

loop:
InstallOptions::dialog "$PLUGINSDIR\demo.ini"
Pop $R0

StrCmp $R0 "cancel" exit_from_this_page
StrCmp $R0 "back" exit_from_this_page

ReadINIStr $R1 "$PLUGINSDIR\demo.ini" "Field 3" "State"
ReadINIStr $R2 "$PLUGINSDIR\demo.ini" "Field 5" "State"
StrCmp $R1 $R2 bad_data exit_from_this_page

bad_data:
MessageBox MB_OK "Sorry! Input data is not valid. Please enter new data"
Goto loop

exit_from_this_page:
FunctionEnd

The function which creates the custom page will repeatedly display the page until the data entered by the user passes the validation test(s).

Final code
  Here is what I now have...


Function SetCustom #Custom Page
Top:
!insertmacro MUI_HEADER_TEXT $(MUI_TEXT_DIRECTORY_TITLE) $(MUI_TEXT_DIRECTORY_SUBTITLE)

InstallOptions::dialog "$9\map-compiler\settings\map-compiler_dir.ini"

Call CustomInstFiles

ReadINIStr $0 "$9\map-compiler\settings\map-compiler.ini" "PageStatus" "Value"
StrCmp $0 "Success" End Top
End:

WriteINIStr "$9\map-compiler\settings\map-compiler.ini" "PageStatus" "Value" "Success"

StrCmp 0 $R7 WthYes WthNo
WthYes:
StrCpy $R7 1
WthNo:
FunctionEnd

And then this for the validation function...

Function CustomInstFiles
WriteINIStr "$9\map-compiler\settings\map-compiler.ini" "PageStatus" "Value" "Success"

ReadINIStr $1 "$9\map-compiler\settings\map-compiler_dir.ini" "Field 4" "State"
IfFileExists "$1\*.*" +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Warning: The main game directory path you have specified ($1) does not exist.$\nPlease validate the path."
WriteINIStr "$9\map-compiler\settings\map-compiler.ini" "PageStatus" "Value" "Failure"

ReadINIStr $1 "$9\map-compiler\settings\map-compiler_dir.ini" "Field 6" "State"
IfFileExists "$1" +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Warning: The map file that you have specified ($1) does not exist.$\nPlease validate the path."
WriteINIStr "$9\map-compiler\settings\map-compiler.ini" "PageStatus" "Value" "Failure"

ReadINIStr $1 "$9\map-compiler\settings\map-compiler_dir.ini" "Field 8" "State"
IfFileExists "$1\*.*" +4
MessageBox MB_OK|MB_ICONEXCLAMATION "Warning: The out directory path you have specified ($1) does not exist.$\nAfrow UK's Map-Compiler will create the directory anyway."
WriteINIStr "$9\map-compiler\settings\map-compiler.ini" "PageStatus" "Value" "Failure"
CreateDirectory "$1"

ReadINIStr $1 "$9\map-compiler\settings\map-compiler_settings.ini" "Field 7" "State"
IfFileExists "$1\*.*" +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Warning: The Quake2 directory path you have specified ($1) does not exist.$\nPlease validate the path."
WriteINIStr "$9\map-compiler\settings\map-compiler.ini" "PageStatus" "Value" "Failure"

ReadINIStr $1 "$9\map-compiler\settings\map-compiler_settings.ini" "Field 10" "State"
IfFileExists "$1\*.*" +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Warning: The Quake2 base directory path you have specified ($1) does not exist.$\nPlease validate the path."
WriteINIStr "$9\map-compiler\settings\map-compiler.ini" "PageStatus" "Value" "Failure"

FindWindow $1 "#32770" "" $HWNDPARENT
GetDlgItem $1 $1 1016
CreateFont $2 "Fixedsys" "6" "40"
SendMessage $1 ${WM_SETFONT} $2 0
FunctionEnd


Works great :)

-Stuart