Hi!
I'm new to NSIS and try to achieve the following:
I have two sections (s0 and s1) and their state (selection ON|OFF) should be dependend on each other:
When section s0 is deselcted, section s1 should be deselcted.
When section s1 is selected, section s0 should be deselcted.
I have followed the procedure described in previous postings and in
example "one-selection".
I have attached my NSI-file to this posting,
Setting the flags doesn't have an effect and s1 is not interactive in
the installer after its flag has been written.
I'm using NSIS v2.0b0.
Thanks for any hints on how to solve this problem!
Section control using flags
37 posts
Re: Section control using flags
the correction is:
When section s0 is deselcted, section s1 should be deselcted.
When section s1 is selected, section s0 should be selected.
Originally posted by cosmic66Sorry, there was a mistake,
[...]
When section s0 is deselcted, section s1 should be deselcted.
When section s1 is selected, section s0 should be deselcted.
[...]
[/B]
the correction is:
When section s0 is deselcted, section s1 should be deselcted.
When section s1 is selected, section s0 should be selected.
That's where the Edit button is for 🙂.
Have you tried settings the initial value for $R0 and $R1? Set it in .onInit.
Originally posted by kichikThanks for your quick answer.
Have you tried settings the initial value for $R0 and $R1? Set it in .onInit.
Setting the initial value for $R0 and $R1 doesn't make a difference.
But still I was able to solve the problem 😁
I had a mistake in my flow (in which case to jump to which label) and I was using the wrong operation when setting the flag to being deselcted.
In case someone is interested, the working skript is attached to this posting.
I'm looking to do something similar, but not quite.
Here's what I need to do:
There are 4 components.
I need components 1 and 3 to be co-dependent upon one another. So, if a user selects component 1 and component 3 is selected, component 3 becomes unselected. Similarly, if a user selects component 3 and component 1 is selected, component 3 becomes unselected.
I've looked at one-section.nsi and at the script posted on this thread, and I sort of get it, however, it's not the kind of programming logic I'm used to coding in.
Any help is appreciated.
Here's what I need to do:
There are 4 components.
I need components 1 and 3 to be co-dependent upon one another. So, if a user selects component 1 and component 3 is selected, component 3 becomes unselected. Similarly, if a user selects component 3 and component 1 is selected, component 3 becomes unselected.
I've looked at one-section.nsi and at the script posted on this thread, and I sort of get it, however, it's not the kind of programming logic I'm used to coding in.
Any help is appreciated.
I don't understand, if you got it to work what's the problem?
Sorry, I guess I should of explained myself better.
I don't have it working at all. And actually, instead of co-dependent, I should of said mutually exclusive.
one-section.nsi is *almost* what I need. The only thing is, in one-section.nsi, at least one section is required. I need something similar to that, except that no section will be required, the user just can't have component 3 selected if component 1 is selected and visa-versa.
Hopefully that clears things up. 😉
I don't have it working at all. And actually, instead of co-dependent, I should of said mutually exclusive.
one-section.nsi is *almost* what I need. The only thing is, in one-section.nsi, at least one section is required. I need something similar to that, except that no section will be required, the user just can't have component 3 selected if component 1 is selected and visa-versa.
Hopefully that clears things up. 😉
OK, then lets think of a script logic for that.
What you need to do is initially select only one of them to make the initial state valid. Do this in .onInit. Remember what section you initially selected. Then in .onSelChange check to see if the section that wasn't remembered is selected. If it is, remember it and uncheck the one that was remembered earlier. That's all you need to do. It should cover all cases.
What you need to do is initially select only one of them to make the initial state valid. Do this in .onInit. Remember what section you initially selected. Then in .onSelChange check to see if the section that wasn't remembered is selected. If it is, remember it and uncheck the one that was remembered earlier. That's all you need to do. It should cover all cases.
I think he has come up with that idea too, but didn't find the right words for it. What code should he use?
Yeah, virtlink hit the proverbial nail on the head.
I know the logic that's required, it's just that I'm pretty bad with NSIS's programming logic.
I hate being hand-held just as much as the next person, but I've been farting around with this for the past couple of days with no results.
If someone could come up with a small snippet of code, I'd be much appreciative. 😉
Perhaps it could even be included in the examples as mutual-excluseive.nsi or something. I'm sure someone else will want to do something similar to this in the future. 🙂
I know the logic that's required, it's just that I'm pretty bad with NSIS's programming logic.
I hate being hand-held just as much as the next person, but I've been farting around with this for the past couple of days with no results.
If someone could come up with a small snippet of code, I'd be much appreciative. 😉
Perhaps it could even be included in the examples as mutual-excluseive.nsi or something. I'm sure someone else will want to do something similar to this in the future. 🙂
Thanks a lot kichik. 🙂
Hello everyone!
I am trying to create an installer with 2 sections which cannot be both selected at once, exactly as japheth. I saw the example kichik posted, but I would like to ask how I can have the second section selected by default, and not the first one as shown in the example.
Thank you!
I am trying to create an installer with 2 sections which cannot be both selected at once, exactly as japheth. I saw the example kichik posted, but I would like to ask how I can have the second section selected by default, and not the first one as shown in the example.
Thank you!
I didn't see kichik's example but I'll give you my. I hope it is what you need.
name 'example'
outfile 'example.exe'
!include 'sections.nsh'
page components
page instfiles
showinstdetails show
var sec_var
section /o 'first' sec_1
detailprint 'first section'
sectionend
section 'second' sec_2
detailprint 'second section'
sectionend
function .onselchange
!insertmacro startradiobuttons $sec_var
!insertmacro radiobutton ${sec_1}
!insertmacro radiobutton ${sec_2}
!insertmacro endradiobuttons
functionend Thank you pospec for your quick reply. I have already found this way in the web, but it doesn't give me the option to have no section selected as kichik's example does. Thank you anyway!
I see. If you like his example then you can modify it for your purposes. Just change IntOp $0 $0 & ${SECTION_OFF} with IntOp $0 $0 | ${SF_SELECTED} and vice versa in .onInit 😉
I missed one thing - remember ${sec2} in $R9 on init.
Originally posted by pospecThank you very much pospec for your time! It workd! 🙂 🙂
I see. If you like his example then you can modify it for your purposes. Just change IntOp $0 $0 & ${SECTION_OFF} with IntOp $0 $0 | ${SF_SELECTED} and vice versa in .onInit 😉
I need same kind of mutual exclusion wrt " Main " section. I am using Main section of nsi file only to copy few files. i need to achieve to copy few files when some variable set to true.
if i put only File command to copy files when variable set to flase also installer is trying to copy those files and giving me error. If i use /nonfatal with File command then installer gives warning.
what exactly i want achieve is installer should only try to copy if variable set to true. if variable is false then there File command should not get executed.
Any help would be highly appreciated!
if i put only File command to copy files when variable set to flase also installer is trying to copy those files and giving me error. If i use /nonfatal with File command then installer gives warning.
what exactly i want achieve is installer should only try to copy if variable set to true. if variable is false then there File command should not get executed.
Any help would be highly appreciated!
I have the same problem as above,
pospecs solution doesn't give me the option to have no section selected.
I do not understand the explication about on init. I do not have
any code like the following which I could exchange.
IntOp $0 $0 & ${SECTION_OFF} with IntOp $0 $0 | ${SF_SELECTED}.
I only have
SectionSetFlags 1 $sec1_enabled
SectionSetFlags 2 $sec2_enabled
SectionSetFlags 3 $sec3_enabled
SectionSetFlags 4 $sec4_enabled
I had another example that worked - but only for subsequent sections, so it works for sec2 and sec3 mutually exclusive, but not sec2 and sec4 mutually exclusive:
Function .onSelChange
${IfThen} $0 = -1 ${|} Return ${|} ; I don't care about InstType changes
${If} $0 = ${sec2}
${OrIf} $0 = ${sec4}
Return ; I don't care about other sections
${EndIf}
!macro SelectOnlyMe sid
${IfThen} $0 <> ${sid} ${|} v ${sid} ${|}
!macroend
!insertmacro SelectOnlyMe ${sec2}
!insertmacro SelectOnlyMe ${sec4}
FunctionEnd
This code will make the selection mutually exclusive, but sometimes work strangely with sec3 combination.
pospecs solution doesn't give me the option to have no section selected.
I do not understand the explication about on init. I do not have
any code like the following which I could exchange.
IntOp $0 $0 & ${SECTION_OFF} with IntOp $0 $0 | ${SF_SELECTED}.
I only have
SectionSetFlags 1 $sec1_enabled
SectionSetFlags 2 $sec2_enabled
SectionSetFlags 3 $sec3_enabled
SectionSetFlags 4 $sec4_enabled
I had another example that worked - but only for subsequent sections, so it works for sec2 and sec3 mutually exclusive, but not sec2 and sec4 mutually exclusive:
Function .onSelChange
${IfThen} $0 = -1 ${|} Return ${|} ; I don't care about InstType changes
${If} $0 = ${sec2}
${OrIf} $0 = ${sec4}
Return ; I don't care about other sections
${EndIf}
!macro SelectOnlyMe sid
${IfThen} $0 <> ${sid} ${|} v ${sid} ${|}
!macroend
!insertmacro SelectOnlyMe ${sec2}
!insertmacro SelectOnlyMe ${sec4}
FunctionEnd
This code will make the selection mutually exclusive, but sometimes work strangely with sec3 combination.
Don't call SectionSetFlags directly like that. Post more code, it is hard to understand what is going on.
okay - I reworked the whole thing. However no matter if I call SectionSETFlags directly or not - the radio buttons are bugged. They only work correctly if clicking by hand. If I preselect an option - and it is different to sec1 - then I can first select 2 sections - and only the next click will unselect the other options.
Each section if installed will put a String into the HKLM windows registry, then on next install I check for that string to offer the same install options as the user chose the last time. This works fine if sec1 was installed, but if it was sec2 or sec3 then clicking on sec2/sec3 will activate two sections - even though radio buttons are supposed to only allow one out of the three to be selected.
Section /o "Install 1" sec1
SectionIn 1
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_1" $sec1_enabled
SectionEnd
Section /o "Install 2" sec2
SectionIn 2
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_2" $sec2_enabled
SectionEnd
...
Function .onInit
ReadRegStr $1 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_1"
StrCmp $1 "0" 0 Continue11
!insertmacro UnselectSection ${sec1}
Goto Continue111
Continue11:
!insertmacro SelectSection ${sec1}
Continue111:
ReadRegStr $2 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_2"
StrCmp $2 "0" 0 Continue12
!insertmacro UnselectSection ${sec2}
Goto Continue121
Continue12:
!insertmacro SelectSection ${sec2}
Continue121:
ReadRegStr $3 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_3"
StrCmp $3 "0" 0 Continue13
!insertmacro UnselectSection ${sec3}
Goto Continue131
Continue13:
!insertmacro SelectSection ${sec3}
Continue131:
ReadRegStr $4 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_4"
StrCmp $4 "0" 0 Continue14
!insertmacro UnselectSection ${sec4}
Goto Continue141
Continue14:
!insertmacro SelectSection ${sec4}
Continue141:
ReadRegStr $5 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_5"
StrCmp $5 "0" 0 Continue15
!insertmacro UnselectSection ${sec5}
Goto Continue151
Continue15:
!insertmacro SelectSection ${sec5}
Continue151:
StrCpy $6 "$1$2$3$4$5"
StrCmp $6 "00000" 0 Continue20
!insertmacro SelectSection ${sec2}
continue20:
FunctionEnd
; Create a mutually exclusive group of sec1, sec2 and sec3. Only one of them can be and has to be activated.
Function .onSelChange
!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${sec1}
!insertmacro RadioButton ${sec2}
!insertmacro RadioButton ${sec3}
!insertmacro EndRadioButtons
FunctionEnd
Each section if installed will put a String into the HKLM windows registry, then on next install I check for that string to offer the same install options as the user chose the last time. This works fine if sec1 was installed, but if it was sec2 or sec3 then clicking on sec2/sec3 will activate two sections - even though radio buttons are supposed to only allow one out of the three to be selected.
Section /o "Install 1" sec1
SectionIn 1
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_1" $sec1_enabled
SectionEnd
Section /o "Install 2" sec2
SectionIn 2
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_2" $sec2_enabled
SectionEnd
...
Function .onInit
ReadRegStr $1 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_1"
StrCmp $1 "0" 0 Continue11
!insertmacro UnselectSection ${sec1}
Goto Continue111
Continue11:
!insertmacro SelectSection ${sec1}
Continue111:
ReadRegStr $2 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_2"
StrCmp $2 "0" 0 Continue12
!insertmacro UnselectSection ${sec2}
Goto Continue121
Continue12:
!insertmacro SelectSection ${sec2}
Continue121:
ReadRegStr $3 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_3"
StrCmp $3 "0" 0 Continue13
!insertmacro UnselectSection ${sec3}
Goto Continue131
Continue13:
!insertmacro SelectSection ${sec3}
Continue131:
ReadRegStr $4 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_4"
StrCmp $4 "0" 0 Continue14
!insertmacro UnselectSection ${sec4}
Goto Continue141
Continue14:
!insertmacro SelectSection ${sec4}
Continue141:
ReadRegStr $5 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_5"
StrCmp $5 "0" 0 Continue15
!insertmacro UnselectSection ${sec5}
Goto Continue151
Continue15:
!insertmacro SelectSection ${sec5}
Continue151:
StrCpy $6 "$1$2$3$4$5"
StrCmp $6 "00000" 0 Continue20
!insertmacro SelectSection ${sec2}
continue20:
FunctionEnd
; Create a mutually exclusive group of sec1, sec2 and sec3. Only one of them can be and has to be activated.
Function .onSelChange
!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${sec1}
!insertmacro RadioButton ${sec2}
!insertmacro RadioButton ${sec3}
!insertmacro EndRadioButtons
FunctionEnd
And If I use SectionGroup for sec1 sec2 sec3 it goes complete havoc. Depending on what way I achieved the section settings it will be different. In the last example given as soon as I add it to a group - I cannot unselect any section out of that group anymore.
Meaning
SectionGroup /e "group"
Section 1-3
SectionGroupEND
Forgot above - to set those flags I use
SectionGetFlags 1 $sec1_enabled
SectionGetFlags 2 $sec2_enabled
SectionGetFlags 3 $sec3_enabled
SectionGetFlags 4 $sec4_enabled
SectionGetFlags 5 $sec5_enabled
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_1" $sec1_enabled
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_2" $sec2_enabled
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_3" $sec3_enabled
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_4" $sec4_enabled
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_5" $sec5_enabled
Meaning
SectionGroup /e "group"
Section 1-3
SectionGroupEND
Forgot above - to set those flags I use
SectionGetFlags 1 $sec1_enabled
SectionGetFlags 2 $sec2_enabled
SectionGetFlags 3 $sec3_enabled
SectionGetFlags 4 $sec4_enabled
SectionGetFlags 5 $sec5_enabled
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_1" $sec1_enabled
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_2" $sec2_enabled
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_3" $sec3_enabled
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_4" $sec4_enabled
WriteRegDWORD HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_5" $sec5_enabled
oh sorry - my message before is missing- are longer messages not allowed, but shorter are?
My on.init is like this
My on.init is like this
Function .onInit
ReadRegStr $1 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_1"
StrCmp $1 "0" 0 Continue11
!insertmacro UnselectSection ${sec1}
Goto Continue111
Continue11:
!insertmacro SelectSection ${sec1}
Continue111:
ReadRegStr $2 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_2"
StrCmp $2 "0" 0 Continue12
!insertmacro UnselectSection ${sec2}
Goto Continue121
Continue12:
!insertmacro SelectSection ${sec2}
Continue121:
ReadRegStr $3 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_3"
StrCmp $3 "0" 0 Continue13
!insertmacro UnselectSection ${sec3}
Goto Continue131
Continue13:
!insertmacro SelectSection ${sec3}
Continue131:
ReadRegStr $4 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_4"
StrCmp $4 "0" 0 Continue14
!insertmacro UnselectSection ${sec4}
Goto Continue141
Continue14:
!insertmacro SelectSection ${sec4}
Continue141:
ReadRegStr $5 HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "SECTION_5"
StrCmp $5 "0" 0 Continue15
!insertmacro UnselectSection ${sec5}
Goto Continue151
Continue15:
!insertmacro SelectSection ${sec5}
Continue151:
StrCpy $6 "$1$2$3$4$5"
StrCmp $6 "00000" 0 Continue20
!insertmacro SelectSection ${sec2}
continue20:
FunctionEnd
; Create a mutually exclusive group of sec1, sec2 and sec3. Only one of them can be and has to be activated.
Function .onSelChange
!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${sec1}
!insertmacro RadioButton ${sec2}
!insertmacro RadioButton ${sec3}
!insertmacro EndRadioButtons
FunctionEnd
The Following is perfect - but really user unfriendly. Before you can tick another one - you need to untick one (well you can tick 2 or 1 if 3 is ticked - because the if comes later). So I guess the radiobutton macro is simply very buggy...
Function .onSelChange
${If} ${SectionIsSelected} ${sec1}
!insertmacro UnSelectSection ${sec2}
!insertmacro UnSelectSection ${sec3}
${EndIf}
${If} ${SectionIsSelected} ${sec2}
!insertmacro UnSelectSection ${sec1}
!insertmacro UnSelectSection ${sec3}
${EndIf}
${If} ${SectionIsSelected} ${sec3}
!insertmacro UnSelectSection ${sec2}
!insertmacro UnSelectSection ${sec1}
${EndIf}
FunctionEnd
Function .onSelChange
${If} ${SectionIsSelected} ${sec1}
!insertmacro UnSelectSection ${sec2}
!insertmacro UnSelectSection ${sec3}
${EndIf}
${If} ${SectionIsSelected} ${sec2}
!insertmacro UnSelectSection ${sec1}
!insertmacro UnSelectSection ${sec3}
${EndIf}
${If} ${SectionIsSelected} ${sec3}
!insertmacro UnSelectSection ${sec2}
!insertmacro UnSelectSection ${sec1}
${EndIf}
FunctionEnd
Nope , with much that is not clear, your posts need moderation before the can be seen.Originally Posted by extremecarver View Postoh sorry - my message before is missing- are longer messages not allowed, but shorter are?
You post a lot of code and the system this board is using can't detect if that is spam or not.
What is the way to change the section without breaking radiobuttons?
${SectionIsSelected} ${sec3}
breaks radiobutton
was also breaking radiobuttons..
${IfThen} $0 <> ${sid} ${|} v ${sid} ${|}
Is not doing anything at all for me:
Function .onInit
StrCpy $1 ${sec2}
FunctionEnd
Function .onSelChange
!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${sec1}
!insertmacro RadioButton ${sec2}
!insertmacro RadioButton ${sec3}
!insertmacro EndRadioButtons
FunctionEnd
${SectionIsSelected} ${sec3}
breaks radiobutton
was also breaking radiobuttons..
${IfThen} $0 <> ${sid} ${|} v ${sid} ${|}
Is not doing anything at all for me:
Function .onInit
StrCpy $1 ${sec2}
FunctionEnd
Function .onSelChange
!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${sec1}
!insertmacro RadioButton ${sec2}
!insertmacro RadioButton ${sec3}
!insertmacro EndRadioButtons
FunctionEnd
SectionSetFlags ${sec2} 1
Also causes radio button Problems.
What code can I use that is exactly the same as clicking a section. Cause all the code that I find to default preactivate a section - clashes with radiobutton. The radiobutton does not know the box is activated and acts like it is not activated.
Also causes radio button Problems.
What code can I use that is exactly the same as clicking a section. Cause all the code that I find to default preactivate a section - clashes with radiobutton. The radiobutton does not know the box is activated and acts like it is not activated.