- NSIS Discussion
- ${__SECTION__} is not defined if section is hidden "-"
Archive: ${__SECTION__} is not defined if section is hidden "-"
dbach
29th March 2010 10:15 UTC
${__SECTION__} is not defined if section is hidden "-"
Hi forum users,
this seems like a bug to me. When I hide a section like this ...
Section "-I am not shown" HIDDENSEC
SectionEnd
the define/var ${__SECTION__} will not be set. This is a bug, right? If not how to get the sectionname?
Kind regards,
dbach
MSG
29th March 2010 17:08 UTC
Hidden sections are nameless, even if you give them a name. I filed a report about this issue ages ago, but it hasn't been fixed yet...
Animaether
30th March 2010 04:32 UTC
I don't think they're nameless - they're just textless. This can almost be explained by ways of the SectionSetText function, which details that setting a section's text to "" (an empty string) will hide it.
So when you specify...
Section "-I am not shown" HIDDENSEC
SectionEnd
You're doing little more than making it easier for yourself, while browsing your source file, to identify sections. The section ID will still be stored in ${HIDDENSEC}, though. So you can do something like this...
!include "MUI2.nsh"
OutFile "test.exe"
setCompress off
!define MUI_PAGE_CUSTOMFUNCTION_PRE Pre
!insertmacro MUI_PAGE_COMPONENTS
Section "I am not shown" HIDDENSEC
SectionEnd
Function Pre
SectionGetText ${HIDDENSEC} $0
MessageBox MB_OK "[$0]"
SectionSetText ${HIDDENSEC} ""
FunctionEnd
!insertmacro MUI_LANGUAGE "English"
Which will pop up the section's text, and then hide it on run-time. Not sure what the point of that (getting the section text of a section that's going to be hidden) would be, though - but if you have a use for it.. go for it.
dbach
30th March 2010 09:06 UTC
I want to use something like this:
Var _day
>Var _month
>Var _year
>Var _dayname
>Var _hour
>Var _minute
>Var _second
>!define SECTIONINFO '!insertmacro SECTIONINFO'
>!macro SECTIONINFO
${GetTime} "" "L" $_day $_month $_year $_dayname $_hour $_minute $_second ; $0=DD, $1=MM, $2=YYYY, $3=dayname, $4=hh, $5=mm, $6=ss
ClearErrors
LogText ""
LogText "------------------------------------------------------------------------------"
LogText "${__SECTION__}"
LogText "($_day.$_month.$_year $_hour:$_minute:$_second)"
Logtext "------------------------------------------------------------------------------"
>!macroend
Section"I am visible" VISIBLESEC
${SECTIONINFO}
>SectionEnd
Section"-I am hidden" HIDDENSEC
${SECTIONINFO}
>SectionEnd
>
The first works, the second not. Is there a simple workaround so that I can contine use my macro without defining a pre?
Animaether
30th March 2010 13:33 UTC
no super-simple transparent work-around that I can think of.
With the Pre function you have to remember to make the appropriate sections invisible - that's some manual editing and tracking.
One alternative would be to add a parameter to your SECTIONINFO macro and supply the information yourself, a la:
SectionEnd
>
But then you have to adjust all of your SECTIONINFO invokes.
dbach
30th March 2010 13:41 UTC
Thanks Animaether,
I guess I will change my SectionInfo Macro. :)
Afrow UK
30th March 2010 14:44 UTC
You could in addition only use __SECTION__ if it is defined:
!ifdef __SECTION__
LogText "${__SECTION__}"
!else
LogText "${MacroParam}"
!endif
Save you repeating section names twice.
Stu
dbach
30th March 2010 14:59 UTC
Originally posted by Afrow UK
You could in addition only use __SECTION__ if it is defined:
!ifdef __SECTION__
LogText "${__SECTION__}"
!else
LogText "${MacroParam}"
!endif
Save you repeating section names twice.
Stu
Its doesn't work that way bcs. __SECTION__ is defined but empty. This works:
${If} "${__SECTION__}" != ""
LogText "${__SECTION__}"
${Else}
LogText "${MacroParam}"
${EndIf}
Animaether
30th March 2010 15:52 UTC
wouldn't you still have to specify -something-, even if an empty string, for the macro, though?
e.g.
"English"
fails with: !insertmacro: macro "SECTIONINFO" requires 1 parameter(s), passed 0!
Afrow UK
30th March 2010 16:36 UTC
Yes of course.
Edit: dbach you could instead do:
!if `${__SECTION__}` != ``
LogText "${__SECTION__}"
!else
LogText "${MacroParam}"
!endif
Stu