Simple script:section with option: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
No edit summary |
m (A minimal script with a section having an option) |
||
Line 5: | Line 5: | ||
"execwait myprog.exe -myoption" or "execwait myprog" depending if the option is checked or not. | "execwait myprog.exe -myoption" or "execwait myprog" depending if the option is checked or not. | ||
I tried using sections inside sections (does not work), then SectionGroups. But I was not able to to get a consistent checking logic. Many thanks to | I tried using sections inside sections (does not work), then SectionGroups. But I was not able to to get a consistent checking logic. Many thanks to [http://nsis.sourceforge.net/User:Red_Wine Red Wine] for giving me the solution (cf [http://forums.winamp.com/showthread.php?s=&threadid=285136 this] post). | ||
As this seems a fairly common need, here is the complete working script: | As this seems a fairly common need, here is the complete working script: | ||
Line 55: | Line 55: | ||
</highlight-nsis> | </highlight-nsis> | ||
== Credits == | == Credits == | ||
This is not all my code. Most of comes from | This is not all my code. Most of comes from [http://nsis.sourceforge.net/User:Red_Wine Red Wine]. | ||
[[Category:Code Examples]] | [[Category:Code Examples]] |
Latest revision as of 17:53, 17 January 2008
Author: gurzixo (talk, contrib) |
Description
My install script needed an user-selectable section, with an user-selectable option. By default, this option is checked or not depending on the value of a registry key. Obviously, if the section is not selected, the option should be grayed out. The action of this section (if selected) is something like: "execwait myprog.exe -myoption" or "execwait myprog" depending if the option is checked or not.
I tried using sections inside sections (does not work), then SectionGroups. But I was not able to to get a consistent checking logic. Many thanks to Red Wine for giving me the solution (cf this post).
As this seems a fairly common need, here is the complete working script:
The Script
!Include "MUI.nsh" !include "Sections.nsh" !include "logiclib.nsh" !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_LANGUAGE "English" Name "Section with options" OutFile "test.exe" ComponentText "Select the components you want to install." var /GLOBAL WithOption SectionGroup /e "MyProg" Section "" sec1 ${If} $WithOption == ${SF_SELECTED} MessageBox MB_OK "MyProg -MyOption" ${Else} MessageBox MB_OK "MyProg" ${endif} SectionEnd Section /o "MyOption" sec2 # SectionEnd SectionGroupEnd Function .onSelChange SectionGetFlags ${sec1} $R0 IntOp $R0 $R0 & ${SF_SELECTED} ${If} $R0 == ${SF_SELECTED} !insertmacro ClearSectionFlag ${sec2} ${SF_RO} ${ElseIf} $R0 != ${SF_SELECTED} !insertmacro UnSelectSection ${sec2} !insertmacro SetSectionFlag ${sec2} ${SF_RO} ${EndIf} SectionGetFlags ${Sec2} $WithOption FunctionEnd
Credits
This is not all my code. Most of comes from Red Wine.