- NSIS Discussion
- abort in leave function should force to reload the page
Archive: abort in leave function should force to reload the page
vogliadicane
27th February 2010 16:38 UTC
abort in leave function should force to reload the page
I have one page where the user is requested to download some files by links given on the page.
In the leave function of this page I check if all files are present, if not Abort.
What happens (as expected is) that the page is only NOT LEFT, which means stays as it was before.
But I would like to have it reloaded, because some parameters for dinamically creating the page have changed so far, e.g. the user has downloaded some of the files so the links still present on the page are not needed anymore.
So is it possible to force the page to reload when abort is executed in the leave function?
(I´ve tried to call the show function of this page but that makes the installer crash)
pengyou
27th February 2010 20:50 UTC
You don't need to use a leave function to do this. Just use a loop in your custom page function and generate the page again if some files are missing.
vogliadicane
28th February 2010 09:58 UTC
not shure, if I get you right. For the "show" function of this cusom page I HAVE a loop, checking for every file if present, and if not an entry for link and text is generated in the ini fields. This works right.
The thing is, I don´t know how to invoke this show function again, if the user did not download some files, when he wants to leave the page (so the page should be shown again updated to the new situation).
To your post, I don´t know how to generate the page AGAIN.
MSG
28th February 2010 10:59 UTC
I think he means jumping back to the beginning of the page creation function after nsDialogs::Show finishes.
Unrelated question: Why don't you use a download plugin to download the missing files automatically?
vogliadicane
28th February 2010 12:19 UTC
these must be downloaded manually (for legal reasons), ad clicks and so... all others are downloaded automatically :)
btw I´m using InstallOptions..
here´s my code (truncated):
Function ShowCustomMan
StrCpy $MaxField 1
${ForEach} $R1 1 8 + 1
StrCmp $FileXPresent 0 +1 +6
WriteIniStr "$PLUGINSDIR\man.ini" "Field $R1" "State" "${FileX_URL}"
WriteIniStr "$PLUGINSDIR\man.ini" "Field $R1" "Text" "FileX"
StrCpy $FileXPresent 2
IntOp $MaxField $R1 + 1
Goto End
... other file exitence checks and writeinistr...
End:
${Next}
StrCmp $MaxField 9 Skip +1
${ForEach} $R1 $MaxField 8 + 1
WriteIniStr "$PLUGINSDIR\man.ini" "Field $R1" "State" ""
WriteIniStr "$PLUGINSDIR\man.ini" "Field $R1" "Text" ""
${Next}
Skip:
StrCmp $MaxField 1 +1 +2
Abort
InstallOptions::dialog "$PLUGINSDIR\man.ini"
Pop $0
InstallOptions::show
Pop $0
FunctionEnd
edit: for information $FileXPresent is the variable that is updated to 1 in the leave function, if the file now exists.
I don´t get, how to jump back to this function, when leaving the page and some files are still missing, sorry, if I´m repeating myself, but I think there´s something basic I don´t get here...
pengyou
28th February 2010 14:28 UTC
You should have mentioned you were using InstallOptions earlier. Here is a simple example of the idea I suggested you try:
Function ShowFileList
loop:
StrCpy $0 0
IfFileExists "$PLUGINSDIR\file-1.exe" check_2
IntOp $0 $0 + 1
WriteIniStr "$PLUGINSDIR\sfl.ini" "Field $0" "Text" "Download file-1.exe"
check_2:
IfFileExists "$PLUGINSDIR\file-2.exe" check_3
IntOp $0 $0 + 1
WriteIniStr "$PLUGINSDIR\sfl.ini" "Field $0" "Text" "Download file-2.exe"
check_3:
IfFileExists "$PLUGINSDIR\file-3.exe" check_4
IntOp $0 $0 + 1
WriteIniStr "$PLUGINSDIR\sfl.ini" "Field $0" "Text" "Download file-3.exe"
check_4:
IfFileExists "$PLUGINSDIR\file-4.exe" show_page
IntOp $0 $0 + 1
WriteIniStr "$PLUGINSDIR\sfl.ini" "Field $0" "Text" "Download file-4.exe"
show_page:
StrCmp $0 0 all_done
WriteIniStr "$PLUGINSDIR\sfl.ini" "Settings" "NumFields" "$0"
!insertmacro INSTALLOPTIONS_DISPLAY "sfl.ini"
Goto loop
all_done:
FunctionEnd
vogliadicane
28th February 2010 15:49 UTC
hmm more elegant than my way. But isn´t it creating an infinite loop I mean one which hangs up the machine, if some file is missing?
Anyway thanks I´ll give it a try!
edit: No loop! Integrated the "Loop .... Goto Loop" into my script and it works! Seems the INSTALLOPTIONS_DISPLAY macro stops until some notify event happens!
So this was exactly, what I was looking for, Thanks! :D
pengyou
1st March 2010 12:59 UTC
Glad to hear that you have managed to solve your problem.
Sorry my first reply did not go into much detail. INSTALLOPTIONS_DISPLAY and its companion macro INSTALLOPTIONS_DISPLAY_RETURN are documented in the InstallOptions2 Readme installed with NSIS. The Readme is also available online:
http://nsis.sourceforge.net/Docs/Ins...ns/Readme.html
vogliadicane
1st March 2010 21:24 UTC
no prob, actually it´s me who is to blame I have the readme but obviously didn´t read accurately. And I really beleived, a code like that would hang up the machine. next time I´ll just try. (I´m just beginning to script NSIS)
Anyway thanks for help again :)