Archive: only one and must one section selected.


only one and must one section selected.
I need help with the Components Page Sections. I have 4 Sections in a subsection and each one is unique, but only and must 1 Section can installed, I don't want two or more Sections are installed.
I made the code reference to "one-section.nsi" an example in the nsis directory. but it doesnot work well, because the user can selected two sections. and there is a small bug with it in the SubSection, if in the installer you click on that sud section(e.g. color) it highlight all the section but one.

If there is and you know it, just let me know.
Thanks.

;"only" and "must" one section is selected.
;----------------------

;--------------------------------
;Include Modern UI
!include "MUI.nsh"
;--------------------------------

; Section define/macro header file
; See this header file for more info

!include "Sections.nsh"

;--------------------------------
;General

;Name and file
!define APPNAME "istest"
!define APPNAMEANDVERSION "v1.0"
Name "${APPNAMEANDVERSION}"
OutFile "istest.exe"

;Default installation folder
InstallDir "$DESKTOP\istest"
InstallDirRegKey HKLM "Software\${APPNAME}" ""
;--------------------------------

;--------------------------------
;Interface Configuration


!define MUI_COMPONENTSPAGE_SMALLDESC
!define MUI_COMPONENTSPAGE_TEXT_COMPLIST ""
!define MUI_COMPONENTSPAGE_TEXT_INSTTYPE ""
;--------------------------------
;Pages

!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
;--------------------------------
;Languages

!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Installer Sections

;Set Section properties
SetOverwrite on

ShowInstDetails "show"
;--------------------------------

Section !Required
SectionIn RO
SectionEnd

SubSection /e "color" "subs"

Section /o "red" sec1
SectionEnd
;--------------------------------
Section /o "blue" sec2
SectionEnd
;--------------------------------
Section /o "green" sec3
SectionEnd
;--------------------------------
Section "gray" sec4
SectionEnd
SubSectionEnd
;-------------------------------------------------------

;Problem!!!!
;the following code from "star" to "end" is to make one section "must" and "only" be selected,but it does not work well.
;--------------------------------start

; Functions

; $1 stores the status

Function .onInit

StrCpy $1 ${sec1}

FunctionEnd
;--------------------------------
Function .onSelChange

!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${sec1}
!insertmacro RadioButton ${sec2}
!insertmacro RadioButton ${sec3}
!insertmacro RadioButton ${sec4}
!insertmacro EndRadioButtons

FunctionEnd
;--------------------------------end


place this in the include folder.And call it in .OnSelChange....

!include "setsections.nsh"


your code here.....


Function .OnSelChange
call setsections
FunctionEnd

try this...


Thanks for your help!
when I try, it seems have some problem. Maybe I don't how to use setsections.nsh and make the code. I hope razor_x can give me a full code base on onlyonesec.nsi.
Thanks again!
the following is the message when MakeNSIS.exe runing
----------
16 warnings:
unknown variable/constant "{SEC1}" detected, ignoring (setsections.nsh:4)
unknown variable/constant "{SEC2}" detected, ignoring (setsections.nsh:6)
unknown variable/constant "{SEC3}" detected, ignoring (setsections.nsh:8)
unknown variable/constant "{SEC4}" detected, ignoring (setsections.nsh:10)
unknown variable/constant "{SEC1}" detected, ignoring (setsections.nsh:14)
unknown variable/constant "{SEC2}" detected, ignoring (setsections.nsh:15)
unknown variable/constant "{SEC3}" detected, ignoring (setsections.nsh:16)
unknown variable/constant "{SEC4}" detected, ignoring (setsections.nsh:17)
unknown variable/constant "{SEC1}" detected, ignoring (macro:RadioButton:2)
unknown variable/constant "{SEC1}" detected, ignoring (macro:RadioButton:5)
unknown variable/constant "{SEC2}" detected, ignoring (macro:RadioButton:2)
unknown variable/constant "{SEC2}" detected, ignoring (macro:RadioButton:5)
unknown variable/constant "{SEC3}" detected, ignoring (macro:RadioButton:2)
unknown variable/constant "{SEC3}" detected, ignoring (macro:RadioButton:5)
unknown variable/constant "{SEC4}" detected, ignoring (macro:RadioButton:2)
unknown variable/constant "{SEC4}" detected, ignoring (macro:RadioButton:5)
------


you need to give each of your sections a section index and modify setsection.nsh accordingly...

the vars are case sensitive...SEC01 is not the same as sec01....I always use capitals for my vars so my example was like that but you may have to adjust them.

change them in the setsection.nsh or the script.


I did the same thing as you say, I modify the scritp base on razor_x's code, I have tried lots of times, but I still could not find the right answer!
Can anyone help me and give me the full Script?


The "!include setsections.nsh" line is in the wrong place.

Put it after the SubSectionEnd line and the script will work.

setsections.nsh uses ${SEC1} to ${SEC4} which are defined in the "Section" lines, so setsections.nsh must appear after all of the "Section" lines (otherwise ${SEC1} to ${SEC4} will be undefined).


OH!GREAT! Thanks to pengyou and razor_x!
I almost succeed! but there is still a small bug.
After compile the script, I run "Test Installer",and click on "green" first, "green" and "gray" are both checked. then click on "blue", "blue" and "green" are both checked,and so on. That is NOT I want. I want "only" and "must" one section is checked. Mybe something worong with setsections.nsh. who can modify it?
thanks!

the follow are the all files.


To get your radiobutton macros to work properly, you need to set $1 to match the section which is initially selected.

In your code, the "gray" section is the default selection so you need to add something like this:


Function .onInit

StrCpy $1 ${SEC4}

FunctionEnd

It is ok!
I don't know how to showe my appreciation of your help, just say Thanks is not enough!
THANKS,THANKS A LOT!