Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 3rd May 2012, 09:11   #1
BreezeUADN
Junior Member
 
Join Date: Dec 2011
Posts: 13
Question 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...

Last edited by BreezeUADN; 3rd May 2012 at 10:12. Reason: p.s.
BreezeUADN is offline   Reply With Quote
Old 3rd May 2012, 10:13   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 2,781
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 3rd May 2012, 10:42   #3
BreezeUADN
Junior Member
 
Join Date: Dec 2011
Posts: 13
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!
BreezeUADN is offline   Reply With Quote
Old 3rd May 2012, 11:29   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 2,781
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...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 3rd May 2012, 13:05   #5
BreezeUADN
Junior Member
 
Join Date: Dec 2011
Posts: 13
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)
BreezeUADN is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump