![]() |
#1 |
Junior Member
Join Date: Jan 2003
Posts: 28
|
Section control using flags
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! |
![]() |
![]() |
![]() |
#2 | |
Junior Member
Join Date: Jan 2003
Posts: 28
|
Re: Section control using flags
Quote:
the correction is: When section s0 is deselcted, section s1 should be deselcted. When section s1 is selected, section s0 should be selected. |
|
![]() |
![]() |
![]() |
#3 |
Major Dude
Join Date: Sep 2002
Location: At [4C69:6E6B]
Posts: 561
|
That's where the Edit button is for
![]() - Claudia Pelsmaeker |
![]() |
![]() |
![]() |
#4 |
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
Have you tried settings the initial value for $R0 and $R1? Set it in .onInit.
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
![]() |
![]() |
![]() |
#5 | |
Junior Member
Join Date: Jan 2003
Posts: 28
|
![]() Quote:
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. |
|
![]() |
![]() |
![]() |
#6 |
Junior Member
|
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. |
![]() |
![]() |
![]() |
#7 |
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
I don't understand, if you got it to work what's the problem?
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
![]() |
![]() |
![]() |
#8 |
Junior Member
|
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. ![]() |
![]() |
![]() |
![]() |
#9 |
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
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. NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
![]() |
![]() |
![]() |
#10 |
Major Dude
Join Date: Sep 2002
Location: At [4C69:6E6B]
Posts: 561
|
I think he has come up with that idea too, but didn't find the right words for it. What code should he use?
- Claudia Pelsmaeker |
![]() |
![]() |
![]() |
#11 |
Junior Member
|
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. ![]() |
![]() |
![]() |
![]() |
#12 |
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
![]() |
![]() |
![]() |
#13 |
Junior Member
|
Thanks a lot kichik.
![]() |
![]() |
![]() |
![]() |
#14 |
Junior Member
Join Date: Oct 2007
Posts: 3
|
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! |
![]() |
![]() |
![]() |
#15 |
Senior Member
Join Date: Jun 2007
Location: Otrokovice, Czech Republic
Posts: 308
|
I didn't see kichik's example but I'll give you my. I hope it is what you need.
PHP Code:
|
![]() |
![]() |
![]() |
#16 |
Junior Member
Join Date: Oct 2007
Posts: 3
|
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!
|
![]() |
![]() |
![]() |
#17 |
Senior Member
Join Date: Jun 2007
Location: Otrokovice, Czech Republic
Posts: 308
|
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
![]() |
![]() |
![]() |
![]() |
#18 |
Senior Member
Join Date: Jun 2007
Location: Otrokovice, Czech Republic
Posts: 308
|
I missed one thing - remember ${sec2} in $R9 on init.
|
![]() |
![]() |
![]() |
#19 | |
Junior Member
Join Date: Oct 2007
Posts: 3
|
Quote:
![]() ![]() |
|
![]() |
![]() |
![]() |
#20 |
Junior Member
Join Date: Nov 2011
Posts: 10
|
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! |
![]() |
![]() |
![]() |
#21 |
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
|
![]() |
![]() |
![]() |
#22 |
Junior Member
Join Date: Apr 2013
Posts: 38
|
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. |
![]() |
![]() |
![]() |
#23 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
Don't call SectionSetFlags directly like that. Post more code, it is hard to understand what is going on.
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#24 |
Junior Member
Join Date: Apr 2013
Posts: 38
|
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 |
![]() |
![]() |
![]() |
#25 |
Junior Member
Join Date: Apr 2013
Posts: 38
|
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 |
![]() |
![]() |
![]() |
#26 | |
Junior Member
Join Date: Apr 2013
Posts: 38
|
oh sorry - my message before is missing- are longer messages not allowed, but shorter are?
My on.init is like this Quote:
|
|
![]() |
![]() |
![]() |
#27 |
Junior Member
Join Date: Apr 2013
Posts: 38
|
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 |
![]() |
![]() |
![]() |
#28 | |
FRISIAN
Join Date: Sep 2003
Location: in a house
Posts: 16,459
|
Quote:
You post a lot of code and the system this board is using can't detect if that is spam or not. |
|
![]() |
![]() |
![]() |
#29 |
Junior Member
Join Date: Apr 2013
Posts: 38
|
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 |
![]() |
![]() |
![]() |
#30 |
Junior Member
Join Date: Apr 2013
Posts: 38
|
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. |
![]() |
![]() |
![]() |
#31 |
Junior Member
Join Date: Apr 2013
Posts: 38
|
After searching for a working solution for ages - I am back to this one. Radiobuttons macro Is so inherently bugged that I will not use it anymore.
This works as expected - except you can deselect all options - so I changed the rest of my installer for that ( I will think how I can make sure that if no section is installed, it calls the uninstaller if it exists). Radiobuttons only works if nothing is selected beforehand. code: I do not think this can be adapted well to more than 3 sections. But for 3 sections this works perfectly. |
![]() |
![]() |
![]() |
#32 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
This SelectOnlyMe code is some random code you found on Stackoverflow? I'm pretty sure I wrote it and it is possible the person wanted to be able to unselect the radio.
Try NSIS\Examples\one-section.nsi instead... Or if you must: PHP Code:
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#33 |
Junior Member
Join Date: Apr 2013
Posts: 38
|
NSIS\Examples\one-section.nsi is the one where it went havoc if I preselected an option. Also the radio buttons do not seem to work well with a single section group and many other problems.
Thanks for your code example. I think yes I found that code on stack overflow. I now wrote about 500 lines of nsis code to work around the possibility that someone unselects all of option 1-3... Still tearing my hair out as the logic then becomes very complicated... |
![]() |
![]() |
![]() |
#34 |
Junior Member
Join Date: Apr 2013
Posts: 38
|
I'm having another problem with the predefined selections. The section size is changing depending on which section is selected. That works well as soon as the user actively clicked on a section. However if the section comes preselected due to insertmacro SelectSection it is not enforced.
code: code: So before I actively change section 1-3 (only one can be selected or none which works) - the SectionSetSize will not work correctly or at all. In effect the idea is if section 2 is selected - then sec4 is size 10 (because it's the same files mainly getting installed. If not then it is 10000. If sec3 is selected - then sec5 size is 10, if not then 10000 But this code only works after actually selecting one of sec1 to sec3. Not with the preselection via !insertmacro SelectSection |
![]() |
![]() |
![]() |
#35 |
Junior Member
Join Date: Apr 2013
Posts: 38
|
well - maybe I should have added the code in an attachement, instead inline.
So I will try again. The following section setsize only works if sec1 sec2 or sec3 has been actively selected. Not if it comes preselected via on.init.. Not sure what I'm doing wrong here or if there is a bug... I attached the relevant code... |
![]() |
![]() |
![]() |
#36 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
Ideally example code should be
- Self contained - As minimal as possible - Compile without changes and your attached code is none of those things. Please take my example code above and modify it until it exhibits the problem you are talking about. IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#37 |
Junior Member
Join Date: Apr 2013
Posts: 38
|
After a long time I found the error:
I was missing the line (in this example for Section sec1) which needs to come after: !insertmacro SelectSection ${sec1} StrCpy $0 ${sec1} This needs to be placed after every SelectSection macro else it will not work if set by default reading from registry. Only that way some additional Actions under .onselchange will work if the radio button is ticked from registry/pre definition. Otherwise the following code will only work correctly after a radio button was manually activated/deactivated. code: Or full example: code: |
![]() |
![]() |
![]() |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|