tags:

views:

376

answers:

2

I have a large number of NSIS install scripts (.nsi files) that simply define a bunch of constants and then the main installer logic resides an include file (.nsh) which is common to each of the installers. One of the include files looks like this:

!ifdef ABC_SUBFOLDER
    RMDir /r "$ABCPath\Data\${ABC_SUBFOLDER}"
    SetOutPath "$ABCPath\Data\${ABC_SUBFOLDER}"
    File /r "${LOCAL_FOLDER}\ABC\${ABC_SUBFOLDER}\*.*"
!endif

!ifdef ABC_SUBFOLDER2
    RMDir /r "$ABCPath\Data\${ABC_SUBFOLDER2}"
    SetOutPath "$ABCPath\Data\${ABC_SUBFOLDER2}"
    File /r "${LOCAL_FOLDER2}\ABC\${ABC_SUBFOLDER2}\*.*"
!endif

!ifdef ABC_SUBFOLDER3
    RMDir /r "$ABCPath\Data\${ABC_SUBFOLDER3}"
    SetOutPath "$ABCPath\Data\${ABC_SUBFOLDER3}"
    File /r "${LOCAL_FOLDER3}\ABC\${ABC_SUBFOLDER3}\*.*"
!endif

... and so on up to 15 subfolders that may or may not be defined in the top level .nsi file. My question is, is there any better syntax in NSIS to achieve this without cut and pasting every time I need to increase the number of subfolders to support?

+2  A: 

You could use ${${VAR}} to access different variables depending on the value of another variable. e.g.

RMDir /r "$ABCPath\Data\${ABC_SUBFOLDER${FOLDERNUMBER}}"
Sam Hasler
Interesting idea. It will need to work on the !ifdef statement too, but if I can put this in a loop with an incrementing S{FOLDERNUMBER} then that may do what I need. Will give it a go and mark as answer if it works
Mark Heath
+1  A: 

Does this help? http://nsis.sourceforge.net/Array_plug-in

Andrew Coleson
looks interesting. I'll try it out if I have to work on these install scripts again
Mark Heath