Archive: How to use InstallOptions?


How to use InstallOptions?
Hello,

I tried the last three days to find the solution,
but I couldn't managed it.

I will use a custom finish page for the classic installer.

I have used follow ini file (finish_page.ini):


[Settings]
NumFields=3

[Field 1]
Type=GroupBox
Left=0
Right=-1
Top=0
Bottom=-5
Text=Installation Complete

[Field 2]
Type=checkbox
Text=Create a shortcut on your desktop?
Left=10
Right=-10
Top=17
Bottom=25
State=1
Flags=GROUP

[Field 3]
Type=checkbox
Text=Launch MyApp!
Left=10
Right=-10
Top=43
Bottom=51
State=1
Flags=GROUP


and this working InstallOption page:


!define TEMP1 $R0 ;Temp variable

;The name of the installer
Name "MyApp"

;The file to write
OutFile "MyApp.exe"
InstallDir "$PROGRAMFILES\MyApp"
; Show install details
ShowInstDetails show

;Things that need to be extracted on startup
;Only useful for BZIP2 compression
;Use ReserveFile for your own InstallOptions INI files too!

ReserveFile "${NSISDIR}\Plugins\InstallOptions.dll"
ReserveFile "finish_page.ini"

;Order of pages
;Custom page. InstallOptions gets called in SetCustom.
Page custom SetCustom ValidateCustom ": Finish Page"
Page instfiles

Section "Finish_page"
;Get Install Options dialog user input

ReadINIStr ${TEMP1} "$PLUGINSDIR\finish_page.ini" "Field 2" "State"
DetailPrint "Create Shortcut=${TEMP1}"

ReadINIStr ${TEMP1} "$PLUGINSDIR\finish_page.ini" "Field 3" "State"
DetailPrint "Start Game=${TEMP1}"
SectionEnd

Function .onInit
;Extract InstallOptions files
;$PLUGINSDIR will automatically be removed when the installer closes

InitPluginsDir
File /oname=$PLUGINSDIR\finish_page.ini "finish_page.ini"

FunctionEnd

Function SetCustom
;Display the InstallOptions dialog

Push ${TEMP1}

InstallOptions::dialog "$PLUGINSDIR\finish_page.ini"
Pop ${TEMP1}

Pop ${TEMP1}

FunctionEnd

Function ValidateCustom

ReadINIStr ${TEMP1} "$PLUGINSDIR\finish_page.ini" "Field 2" "State"
StrCmp ${TEMP1} 1 done
ReadINIStr ${TEMP1} "$PLUGINSDIR\finish_page.ini" "Field 3" "State"
StrCmp ${TEMP1} 1 done

done:

FunctionEnd


Please can somebody add the script for the "Creating DesktopShortcut" and "Launching App"?
I doesn't understand the recognition of the used checkbox and the needed function for the checkbox.

I think for a profi it couldn't be difficult and perhaps you take a minute to help me.

Thank you! and best regards.

Rien

You need to compare the ${TEMP1} variable values with 1 (for selected).

E.g.

Function ValidateCustom
Push ${TEMP1}

## Create shortcut
ReadINIStr ${TEMP1} "$PLUGINSDIR\finish_page.ini" "Field 2" "State"
StrCmp ${TEMP1} 1 0 +2
CreateShortcut ...

## Launch program
ReadINIStr ${TEMP1} "$PLUGINSDIR\finish_page.ini" "Field 3" "State"
StrCmp ${TEMP1} 1 0 +2
Exec ...

Pop ${TEMP1}
FunctionEnd


-Stu

I can help you with this...


Hi Afrow UK,

thank you for your help and for the correction of your
script, because first I add your script to this Section:



Section "Finish_page"
;Get Install Options dialog user input

ReadINIStr ${TEMP1} "$PLUGINSDIR\finish_page.ini" "Field 2" "State"
DetailPrint "Create Shortcut=${TEMP1}"
## Create shortcut
StrCmp ${TEMP1} 1 0 +2
CreateShortcut ...
.
.
.


This works, but I have forgot that I would create a finish page with this options.
So I have change the order of the page list.

;Order of pages
Page instfiles
;Custom page. InstallOptions gets called in SetCustom.
Page custom SetCustom ValidateCustom ": Finish Page"
...

-> the result, all files and the options are installed
before I could make a choice!

After your correction I used your script in the "Function ValidateCustom" Section and this is really better.
:)

Now, I have only one question. In the detail list of the installer I always see that the options are choiced before the finishpage.

The reason is this, I think:

Section "Finish_page"
;Get Install Options dialog user input

ReadINIStr ${TEMP1} "$PLUGINSDIR\finish_page.ini" "Field 2" "State"
DetailPrint "Create Shortcut=${TEMP1}"

ReadINIStr ${TEMP1} "$PLUGINSDIR\finish_page.ini" "Field 3" "State"
DetailPrint "Start Game=${TEMP1}"
SectionEnd


Can you tell me how I can correct this?

@Hello Lobo Lunar! Sorry, that I have not the time to
test your script. It is a bittle late, but I will test it tomorrow.

Thanks also for your help.

Good Night!

Sections are executed only on the Instfiles page, before your Custom page. Therefore, how can it see what your user has selected before they have selected it?

Why don't you just delete the whole "Finish_page" Section, as it isn't necessary.

-Stu


Hello Afrow UK and Lobo Lunar,

thanks for your help. The script works now very fine
with all options and the wanted look.


@Lobo Lunar, with your script I have one problem.
If I choice "Launch MyApp! the app will run before it is installed!

io.ini


[Settings]
NumFields=3

[Field 1]
Type=GroupBox
Left=0
Right=-1
Top=0
Bottom=-5
Text=Installation Complete

[Field 2]
Type=checkbox
Text=Create a shortcut on your desktop?
Left=10
Right=-10
Top=17
Bottom=25
State=0

[Field 3]
Type=checkbox
Text=Launch MyApp!
Left=10
Right=-10
Top=43
Bottom=51
State=0


example.nsi

BesterSetCompressor lzma
XPStyle on

Name "MyApp"
OutFile "MyApp.exe"
InstallDir "$PROGRAMFILES\MyApp"
ShowInstDetails show

Page custom "my_own_page" "" ": This is my own page"
Page instfiles "" "inst_show" ""

Var HWND

Function .onInit
InitPluginsDir
File /oname=$PLUGINSDIR\io.ini "io.ini"
FunctionEnd

Function my_own_page
Push $HWND
InstallOptions::dialog "$PLUGINSDIR\io.ini"
Pop $HWND
FunctionEnd

Function inst_show
ReadINIStr $0 "$PLUGINSDIR\io.ini" "Field 2" "State"
StrCmp $0 1 lnk next
next:
ReadINIStr $1 "$PLUGINSDIR\io.ini" "Field 3" "State"
StrCmp $1 1 runme exit

lnk:
DetailPrint "I'm creating a shortcut"
CreateShortCut "$DESKTOP\MyApp.lnk" "$INSTDIR\MyApp.exe"
Goto next

runme:
DetailPrint "I'm running my self"
Exec "$INSTDIR\MyApp.exe"
Goto exit

exit:
FunctionEnd

Section -default
; Set Section properties
SetOverwrite on

; Set Section Files and Shortcuts
SetOutPath "$INSTDIR\"
File "C:\Source\MyApp\MyApp.exe"
SectionEnd


Only for fun I don't need it any more!

Best regards!

Rien

You'd have to put that code to run MyApp in a Section with no name (Section "") after all of your sections.

-Stu