gpt4 book ai didi

NSIS - 验证单选按钮选择

转载 作者:行者123 更新时间:2023-12-02 03:18:52 24 4
gpt4 key购买 nike

我有一个非常简单的 NSIS 脚本,允许用户选择他们想要安装的组件,但如果他们没有选择任何内容,我需要一种方式说“请选择一个组件”。

这是脚本:

# 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

我环顾四周,发现了这个例子,http://nsis.sourceforge.net/Useful_InstallOptions_and_MUI_macros#Macro:_CHECKBOXCHECKER ,但对于我想要的东西来说似乎过于复杂。 NSIS里有没有办法说:

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

谢谢,格雷格。

最佳答案

离开组件页面时,您可以使用回调函数来检查是否选择了某个组件。

这是我在设置中使用的一段代码。我使用一个小宏在变量中总结所选组件。如果没有,则该变量为空。我使用 PageEx block 将回调函数关联到组件页面(因为离开回调是第三个,所以我对前两个函数使用虚拟函数)

替换

Page components

PageEx components
PageCallbacks DummyFunc DummyFunc componentsLeave
PageExEnd

保留 .onSelChange 回调以处理独占选择,然后将其添加到脚本末尾:

!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

关于NSIS - 验证单选按钮选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12279706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com