fistos
16th June 2006 03:51 UTC
NSIS Navigate through functions
Hello,
I am trying to setup an NSIS installer that reboots during the middle of my installation, then when the PC is rebooted the program will automatically continue the installation then when its finished it will pop-up the FINISH page.
I have succesfully managed to write my installer to the registry, with an argument so it could launch on the next reboot with the following code:
Function CPAGEFINISH
IfRebootFlag 0 noreboot
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_TITLE "Installation Half-Done"
!define MUI_FINISHPAGE_TEXT "The installation is not complete but needs to reboot before going \
on. Do you want to reboot now or wait until later to finish this?"
!define MUI_FINISHPAGE_TEXT_REBOOTNOW "Reboot now"
!define MUI_FINISHPAGE_TEXT_REBOOTLATER "I want to manually reboot later"
StrCpy $varRebootNext 1
System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
;$R0 will contain the installer filename
WriteRegStr HKLM Software\Microsoft\Windows\CurrentVersion\Run "SurfsUpDS" "$R0 /STAGE2"
I have no idea how to make my program start from a specific Section after the PC is rebooted. I've tried the GetParameters and goto, but it never worked.
I would like to have something like that:
Function .onInit
Call GetParameters
Pop $R1
${if} $R0 == "STAGE2"
goto SectionAFTERREBOOT
I know this code won't work but I would like to do something similar.
Thanks
CancerFace
16th June 2006 06:52 UTC
I am not sure how to go to a specific section, but if you wanted to run something from your .onInit, I was thinking that this should work: write a flag somewhere on the system registry before rebooting, read this flag during .onInit and if it exists then go to a specific point within your .onInit. The flag could be a number, incremented for every reboot, so you could redirect the installer to a different section every time (if you want say to restart more than once). You could also define some parameter and then setup your sections conditionally so that they would not be executed upon reboot. Something like this:
.onInit
ClearErrors
ReadRegValue $0 HKLM "Software\<YourKey>" "Flag"
IfErrors <label_if_not_reboot>
StrCmp $0 1 <label_if_reboot_1>
StrCmp $0 2 <label_if_reboot_2>
...
<label_if_reboot>
StrCpy $Parameter 1
...
Section <SomeName>
${If} $Parameter 0
<things to do before reboot>
...
${Else}
<things to do after reboot>
...
${EndIf}
Hope this helps
CF
Comperio
17th June 2006 07:10 UTC
Let's say for sake of argument the $Value variable holds the value you pass to it. And using your example, let's say a value of "Stage2" means we want to go to run section.
This might be the code:
InstType "normal"
InstType "Stage2"
Section -Norm
SectionIn 1
### This section would be the start of the install
MessageBox MB_OK "You are in section '-Norm'."
SectionEnd
Section -Stage2
SectionIn 2
### This section would be executed only when stage 2 is done
MessageBox MB_OK "you are in section '-Stage2'."
SectionEnd
Function .onInit
### Determine if this is a normal or Stage2 by looking
### Set the value of $Value
Call GetParameters
Pop $Value
### Then, just compare the value and act accordingly
StrCmp $Value "Stage2" SetStage2 SetNormal
SetStage2:
SetCurInstType 1
Goto end
SetNormal:
SetCurInstType 0
end:
FunctionEnd