NSIS - switch selection confirmation

I have a really simple NSIS script that allows the user to choose which component they would like to install, but I need a way to say “Please select a component” if they haven’t selected anything.

Here's the script:

# Based on the one-section example # http://nsis.sourceforge.net/Examples/one-section.nsi !include "sections.nsh" Name "Humira & You" OutFile "Humira & You - September 2012.exe" RequestExecutionLevel user Page components Page instfiles Section /o "Rheumatoid Arthritis" P1 File "/oname=$pluginsdir\Setup.msi" "setupfiles\Humira and you - Rheumatoid Arthritis.msi" SectionEnd Section /o "Psoriatic Arthritis" P2 File "/oname=$pluginsdir\Setup.msi" "setupfiles\Humira and you - Psoriatic Arthritis.msi" SectionEnd Section /o "Ankylosing Spondylitis" P3 File "/oname=$pluginsdir\Setup.msi" "setupfiles\Humira and you - Ankylosing Spondylitis.msi" SectionEnd Section /o "Axial Spondyloarthritis" P4 File "/oname=$pluginsdir\Setup.msi" "setupfiles\Humira and you - Axial Spondyloarthritis.msi" SectionEnd Section ; Hidden section that runs the show DetailPrint "Installing selected application..." SetDetailsPrint none ExecWait '"msiexec" /i "$pluginsdir\Setup.msi"' SetDetailsPrint lastused SectionEnd Function .onInit Initpluginsdir ; Make sure $pluginsdir exists StrCpy $1 ${P2} ;The default FunctionEnd Function .onSelChange !insertmacro StartRadioButtons $1 !insertmacro RadioButton ${P1} !insertmacro RadioButton ${P2} !insertmacro RadioButton ${P3} !insertmacro RadioButton ${P4} !insertmacro EndRadioButtons FunctionEnd 

I looked around and came across this example http://nsis.sourceforge.net/Useful_InstallOptions_and_MUI_macros#Macro:_CHECKBOXCHECKER , but it seems too complicated for what I want. Unable to say in NSIS:

 if ($1.selectedIndex > -1) { // continue } else { MessageBox.Show("Please select"); } 

Thanks, Greg.

+4
source share
1 answer

You can use the callback function, leaving the component page to check if it is selected.

Here is the code snippet that I use in the setup. I use a small macro to summarize the selected components in a variable. If not, the variable is null. I use the PageEx block to link the callback functions on the component page (since the callback is the third, I use the dummy function for the first two others)

Replace

 Page components 

by

 PageEx components PageCallbacks DummyFunc DummyFunc componentsLeave PageExEnd 

save the .onSelChange to handle the exclusive selection, then add it to the end of your script:

 !define SECTIONCOUNT 3 ; total -1 ;SaveSections adds one bit to the given variable for each selected component !macro SaveSections VAR StrCpy ${VAR} 0 ${ForEach} $R0 ${SECTIONCOUNT} 0 - 1 IntOp ${VAR} ${VAR} << 1 ${If} ${SectionIsSelected} $R0 ;${DEBUG} "Section $R0 checked" IntOp ${VAR} ${VAR} + 1 ${EndIf} ${Next} !macroend Function DummyFunc FunctionEnd Function componentsLeave !insertmacro SaveSections $2 ${if} $2 = 0 MessageBox MB_OK|MB_ICONEXCLAMATION "Select something !" /sd IDOK Abort ${endif} FunctionEnd 
+3
source

Source: https://habr.com/ru/post/1432458/


All Articles