Archive: Unselect RO Section?


Unselect RO Section?
I have an installer which hides the sections that the user installs, as he/she installs them. So when the person re-opens the installer, the sections that are already installed will have disappeared from the list of options to install. They are then found in the uninstaller.

This all works as intended.

However - I have a section now, that I need to be RO.

Only problem is - that RO section won't hide once it's installed, like the others still do.

So how can I hide an RO section after it's installed?

The way I do it for the other sections, is(in .onInit):


ReadRegStr $0 HKCU "Software\${VER_NAME}\Sections" "01"
${if} $0 == 1
!insertmacro UnselectSection ${Sec01}
SectionSetText ${Sec01} ""
${endif}


This works for all sections, but not for the RO section. It still shows up after it's installed, with description and everything, and I don't want that, because it could confuse the user into thinking he/she didn't install it afterall.

How do I fix this?

Thanks. :)

SectionSetText doesn't care if the section is RO or not. There must be an error somewhere else. Please attach a minimal example reproducing the problem.


Hmm, using...
SectionSetText ${Index} ""
...hides Read-Only sections here.

Are you using latest NSIS version?
If you are then it must be something in the code not working right...

-Stu


OK I'll look through it again.

However - it works if I remove the "SectionIn RO" from the section, making it selectable again. Should I not use "SectionIn RO" below the Section name? Isn't that the only way?
All the other selectable sections are hidden when they are installed, using the code I have now.

I'm using the latest build.

[edit]I tried it now - the only change I made to the script now was to remove SectionIn RO from the section, then I saved it and compiled it. Once installed, the option then doesn't appear in the installer when it's reopened. So the only difference is the SectionIn RO thing.[/edit]


Could you attach your script please.

Edit: Or make a cut-down script which produces the same problem.

-Stu


Well - I've tried to cut it down to it's bare essentials, but it's a big script, and there's a whole lot of stuff that depends on other stuff so it's hard to cut things out without getting errors.

So I'll try to post the most essential parts that has to do with this problem instead.

First, one of the sections(the one I'm having problems with):

Section "Testing testing." Sec01
SectionIn RO
SetDetailsPrint textonly
DetailPrint "Extracting And Installing Files... Please Wait."
SetDetailsPrint none
ReadRegStr $0 HKCU "Software\${VER_NAME}\Sections" "01"
${if} $0 == 1
Goto AlreadyInstalled
${endif}
LOTS OF STUFF DOWN HERE, BUT NOT IMPORTANT, JUST FILES TO EXTRACT ETC.


then on to .onInit:


ReadRegStr $0 HKCU "Software\${VER_NAME}\Sections" "01"
${if} $0 == 1
!insertmacro UnselectSection ${Sec01}
SectionSetText ${Sec01} ""
${endif}

(one of those for each section)


Then there's -post:


Section -post
ReadRegStr $0 HKCU "Software\${VER_NAME}\Sections" "01"
${if} $0 == 1
Goto +4
${else}
SectionGetFlags ${Sec01} $0
WriteRegStr HKCU "Software\${VER_NAME}\Sections" "01" $0
${endif}


(one of those for each section)

And I have some similar ones in the un.onInit and un.post parts of the script.


And in each of the uninstall sections, there's one of these:


WriteRegStr HKCU "Software\${VER_NAME}\Sections" "01" "0"




That's all I can see that can play any part in the problem.

Again - what I want is for the installed sections to disappear from the components page when the installer is reopened. This works already, for all sections, even the one I'm having problems with. The ONLY thing that mucks things up, is if I add the SectionIn RO to the section. Then, when it's installed and I reopen the installer, it's still there. If I REMOVE only the SectionIn RO line, save and compile, ALL sections are gone from the installer when reopened (as I want them to be), if all the components were installed.

Did you make sure the registry value is set right after the first installation? Add a message box just above the SectionSetText instruction to make sure it's really executed.


Couldn't find any errors there, except you could change the -post Section code to make it a little cleaner:


Section -post
ReadRegStr $0 HKCU "Software\${VER_NAME}\Sections" "01"
${if} $0 != 1
SectionGetFlags ${Sec01} $0
WriteRegStr HKCU "Software\${VER_NAME}\Sections" "01" $0
${endif}

However, that shouldn't fix anything.

Please attach your whole script (as file attachment).

-Stu

Originally posted by kichik
Did you make sure the registry value is set right after the first installation? Add a message box just above the SectionSetText instruction to make sure it's really executed.
OK - I think I've found the problem. I opened the registry, and for some strange reason, the first entry says 17, when it's supposed to say 1. So there's obviously something in the script I have overlooked. It should say either 1 or 0 (installed or not installed), so I don't know where 17 comes from...

But I think I'll be able to solve it now anyway.

Thanks for the tips and help, both of you.

Actually I still don't get it.

When the ONLY thing I do to the script is to remove the line SectionIn RO from the first section, then save and compile, and run the installer, then suddenly the registry entry says 1 for that section, which it's supposed to do.

-How can the registry setting go from 17 to 1 just because I remove one unrelated line from the script??

I'm sorry, but I won't put the script up here(could e-mail or PM it to someone though). If it's impossible to solve then, I'll just have to do it some other way. After all, it does work as long as I don't make a section Read Only...


You probably write exactly what you get from SectionGetFlags into the registry. SF_RO is 16. SF_RO | SF_SELECTED is 17.


Originally posted by kichik
You probably write exactly what you get from SectionGetFlags into the registry. SF_RO is 16. SF_RO | SF_SELECTED is 17.
Ah! I didn't know that (how many people do?). Thanks!

John, use:

 ${if} ${SectionIsSelected} ${Sec01}
WriteRegStr HKCU "Software\${VER_NAME}\Sections" "01" "1"
${Else}
WriteRegStr HKCU "Software\${VER_NAME}\Sections" "01" "0"
${endif}


-Stu