- NSIS Discussion
- SelectSection Circular Reference problem
Archive: SelectSection Circular Reference problem
ogden_ogly
28th November 2006 20:37 UTC
SelectSection Circular Reference problem
Hi, my installer is structured such that:
1. Prerequisites are checked
2. Needed prerequisites are Downloaded
3. Needed prerequisites are Installed
4. Installation of my application.
However, the problem I'm having is this:
I have written various macros to detect these prerequisites, and in these macros I use the SelectSection macros. The *PROBLEM* is that, because my sections appear later in the code, the SelectSection macros give me this error:
unknown variable/constant "{MUI_LANGDLL_PUSHLIST}" detected, ignoring (macro:MUI_LANGDLL_DISPLAY:24)
unknown variable/constant "{sec_i_MSI}" detected, ignoring (macro:UnSelectSection:3)
unknown variable/constant "{sec_i_MSI}" detected, ignoring (macro:UnSelectSection:5)
unknown variable/constant "{sec_i_MSI}" detected, ignoring (macro:SelectSection:3)
unknown variable/constant "{sec_i_MSI}" detected, ignoring (macro:SelectSection:5)
How can I circumvent this error? I feel like I'm missing something fairly obvious.
Thanks,
Ogden
FYI my script looks like this...
...preambles and such
Section "-Windows Installer Check"
!insertmacro CheckWindowsInstaller
(which contains calls like
!insertmacro UnSelectSection ${sec_i_MSI})
SectionEnd
...
;Dialogs and whatnot
...
Section "Windows Installer 3.1" sec_i_MSI
SectionIn RO
DetailPrint "MSI 3.1"
SectionEnd
...rest of the installation
n_baua
29th November 2006 10:04 UTC
hi ogden_ogly,
you may have to do following things
1. write to registry if the macro1, macro2, etc are passed without any error code
2. read this status entry(ies) from registry and
3. use logiclib.nsh
to form code as below
ReadRegStr $0 HKLM "Software\MySoft\Macro1" "Installed"
${If} $0 = "1" ;$0 is satus for macro1 read from registry.
!insertmacro CheckWindowsInstaller
${EndIf}
bholliger
29th November 2006 10:48 UTC
You can use the values of the section indexes only after the Section mySection SEC000 declaration, not before.
ogden_ogly
30th November 2006 18:47 UTC
bholliger:
Thanks for the reply. I tried adding:
Section NoCode SEC000
push $0
pop $0
sectionend
To the top of the script, it didn't seem to help resolve anything. Any thoughts?
kichik
30th November 2006 19:03 UTC
Simply put the code of the first section in a function and call that function from the section. Put that function after the definition of the second section and you're set.
ogden_ogly
30th November 2006 19:03 UTC
n_baua:
While this is certainly possible, I don't think its a real solution. There *HAS* to be a way to set a section on or off *before* you've reached it? Otherwise would be madness.
n_baua
1st December 2006 01:35 UTC
Hi ogden_ogly,
Yes, you are correct, but I also had faught on this for a long time, didn't had much time to research at that time, so adopted the registry logic. It works fine for me.
bholliger
1st December 2006 03:50 UTC
The reason why this has to be done this way is that the compiler creates defines for each section index.
And you can't use a define before it has been created.
Have a look at NSIS Manual, Chapter 4, 4.6.1.2 Section.
ogden_ogly
1st December 2006 18:22 UTC
Looks like it's time for a 2-pass compiler :)
bholliger
2nd December 2006 03:51 UTC
Hi!
I think a solution would be to scan the source file and create the defines on top of the file.
1. Save createsectiondefines.nsi to the folder and compile it.
2. Save this
!macro SECTIONDEFCREATOR FILE
!system "createsectiondefines.exe /file ${FILE}"
!include sectiondefs.nsh
!macroend
to the file sectiondefcreator.nsh to the folder
3. Put this in the project
!include sectiondefcreator.nsh
!insertmacro SECTIONDEFCREATOR ${__FILE__}
This creates a file sectiondefs.nsh that is included into the project with the definitions for every section. Due to the fact that the sections are simply counted from 0 to (SECTIONCOUNT-1) this should work.
A sample:
Section "My Section" SEC01
Creates a definition named CC_SEC01 that can be used before the sections compilation.
Well, it's just an idea. What do you think?
Cheers
Bruno
ogden_ogly
5th December 2006 00:30 UTC
bholliger
This seems to work quite well! I think I owe you a beer :)