Archive: Handling a variable number of sections?


Handling a variable number of sections?
The installer I am working on has the primary function of copying over some library files and creating a couple of scripts based on user input during the install.

The installer will:


I have the first couple down. For the second, I understand that I need to use locate in the install directory to find all the versions that are currently installed, and then put those on the components page, and then during the install do an RMDir on the Version (whatever) folder if the user wants to remove the old version.

But I'm not quite sure how to set up displaying a variable number of sections and then handling those sections during install.

Can anyone help walk me through this?

the number of sections is hardcoded at compile time, you could probably add x number of hidden sections and use those, or you could use something other than a components page; a custom page with checkboxes or a listview


Thanks for the quick reply; that seems like it would be fine. So I would have say, 5 hidden sections with a tag for each so I can address it in a function to show it?

I'm not clear on how I would iterate on a list of X old versions to enable these sections, though.

I'll play with it, but some sample code would be great if anyone feels the inclination.


Any thoughts? What I need to do:

Create 5 hidden sections.
Search the directory My App for subdirs starting with "Version"

Populate a components page with each of those found folder names (ie, the hidden sections)

Version 1.3
Version 1.2

etc. where checking the section / component will remove that subdir during the install.

Any pointers, the more specific the better, appreciated.


I guess you mean something like this, change the plugins with a folder name which does not exist and see the difference.

outfile test.exe
showinstdetails show
InstallDir "$PROGRAMFILES\My app"

!include logiclib.nsh

page components func_pre
page directory
page instfiles

section "Main App" sec1

sectionin ro
detailprint "now installing"

sectionend



section /o "" sec2

detailprint "now removing plugins directory"

sectionend



Function .oninit

Readregstr $0 HKLM "Software\NSIS" ""
${Unless} ${Errors}
${If} ${FileExists} "$0\plugins\*.*"
SectionSetText ${sec2} "Remove plugins directory"
SectionGetFlags ${sec2} $0
Intop $0 $0 | 1
SectionSetflags ${sec2} $0
Strcpy $R0 "Showpage"
${Endif}
${Endunless}

FunctionEnd

Function func_pre

${IfThen} $R0 != "Showpage" ${|} Abort ${|}

Functionend