Skip to content
⌘ NSIS Forum Archive

Checkbox for custom installation

6 posts

Jayme65#

Checkbox for custom installation

Hi,

My application installs a few files in the %APPDATA% folder...but I would like to add a checkbox to give the user the option to install those files in my application folder (for people willing to do a "portable" installation.

How should I please proceed to implement the checkbox and set the conditions (if not checked install data files in appdata. If checked install those files in the app folder)

Thanks very much for your help!
Anders#
You could use a section and let the user toggle it on the components page or you can create a custom page with nsDialogs...
Jayme65#
Thanks for your quick reply!

Well unfortunately I don't know NSIS very well..so I'll take time to understand and implement what you propose me ;-)

How do I then set the files to be installed in a folder or another, based on the checkbox condition? (this being done on the next page)

Thanks!!
Koopa#
You can do a custom page, like Anders said, in a callback function, you can define, what happens if the box is checked or what happens if the box is unchecked.


Page custom MyPage CheckMyPage

Function MyPage

Var /GLOBAL MyDialog
Var /GLOBAL MyCheckbox

nsDialogs::Create 1018
Pop $MyDialog

${If} $MyDialog == error
Abort
${EndIf}

${NSD_CreateGroupBox} 0u 0u 300u 140u "Groupbox"
${NSD_CreateCheckBox} 5u 5u 220u 12u "My Checkbox Name"
Pop $MyCheckbox
SetCtlColors $MyCheckbox "0x000000" "transparent"
${NSD_SetState} $MyCheckbox ${BST_CHECKED}

nsDialogs::Show

FunctionEnd

Function CheckMyPage
Var /GLOBAL MyCheckbox_State

${NSD_GetState} $MyCheckbox $MyCheckbox_State
${If} $MyCheckbox_State = ${BST_CHECKED}
SetOutPath "C:\Blah"
File "text.txt"
${Else}
SetOutPath "$APPDATA\Blah"
File "text.txt"
${EndIf}

FunctionEnd
Note that you must call some specific things, like:
!include "MUI2.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"

As I haven't seen your script, I don't know what you are already calling and what not.
Jayme65#
Koopa,

Thanks so much for taking time to give me code line to study!
That's really appreciated!!
I now go and study that ;-) Thanks
Koopa#
Though, it's nothing more than raw example code. without seeing your script it's hard to help. And even using my code example requires some knowledge. I highly recommend, that you read the NSIS documentation, wiki etc. 🙂