BreezeUADN
3rd May 2012 10:11 UTC
Construct section id name during runtime
Greetings
short version:
Section "sec" Sec1
SectionEnd
MessageBox MB_OK "${Sec1}" works
("Sec1" in $2)
MessageBox MB_OK "${$2}" - want that to work
long version:
Well, I know it's illogical (even silly maybe) to do that sort of thing but maybe there is a workaround, or alternative solution for such a problem:
0) I have several sections with id's like
Section "-Client" SECCLNT_Sec1
Section "-Client" SECCLNT_Sec2
...
Section "-Server" SECSRVR_Sec1
Section "-Server" SECSRVR_Sec2
...
Section "-Common" SECCMN_Sec1
... and so on
so, after setup executable is compiled a section can be found either by it's displayable name (via SectionGetText + iteration through em all) or simply by id.
1) I have an XML like
<root>
<module>Sec1</module>
<module>Sec2</module>
...
</root>
The problem:
When a section is defined I could simply access it via id (int), like
SectionGetText ${Sec1} $R1 (gets displayable section text)
or MessageBox MB_OK ${Sec1} (prints int id)
but
Is there a way to somehow push (read from XML at runtime) "Sec1" name into ${}?
example:
${xml::GetText} $2 $3 ... ("Sec1" in $2)
and then something like (SECCLNT_Sec1 is defined above)
SectionGetText "SECCLNT_$2" $R1 (compiles without warnings/errors but ofc. doesn't work since it requires a variable, not a text...)
p.s. there is a few solutions I can think of but none are pretty, + I can't rely on section names since they all are the same, the only way to solve this is to store section id's inside of XML as an attributes, but then that XML becomes unreliable...
Anders
3rd May 2012 11:13 UTC
You could use names like Section "Client:C1" SECCLNT_Sec1 and parse and store these in a .ini in .onInit so you can get index from name. Then just set the display names to whatever you want before you get to the UI.
BreezeUADN
3rd May 2012 11:42 UTC
Ahhh, really - read a name from an xml, iterate through sections looking for that name, when found - do the work and then just rename... Thanks Anders that's a brilliant idea!
Anders
3rd May 2012 12:29 UTC
Reading from XML was not part of my plan, I would just write to a .ini in .onInit:
[secmappings]
C1=2
C2=3
...
Then read the .ini when you need to know the index of C1...
BreezeUADN
3rd May 2012 14:05 UTC
That would be more convenient yes, but (it's a bit complicated) unfortunately the script is flexible - most of it is generated dynamically: base nsi + generated nsh include with sections part and other stuff - that part changes all the time and could be transferred between PC's (uses sys. env. vars for paths) and because of that I should generate [secmappings] with that nsh part every time section tree changes. Then I'll have 2 files instead of one, and here comes the problem - someone could move only 1 file (i.e. mess up somehow) and my section indexes won't match section names anymore - so in this case indexes are unreliable as I mentioned in p.s. above... On top of that there comes the "license" (sort of) - XML file - that should contain this data anyways. Only "module" names inside, from which section names could be generated...
(err, prob my grammar skills is not good enough to make the phrases look "normal", sorry)