如何合并NSIS安装脚本中Win10及X64环境的检测逻辑?
合并NSIS安装脚本中的系统版本与架构检测
问题描述
我在安装脚本中添加了如下.onInit函数:
Function .onInit ${IfNot} ${AtLeastWin10} MessageBox mb_iconStop "Windows 10 x64 is required to install DeepSkyStacker 5.1.0" Abort ${EndIf} ${IfNot} ${RunningX64} MessageBox mb_iconStop "Windows 10 x64 is required to install DeepSkyStacker 5.1.0" Abort ${EndIf} FunctionEnd
当前两个检测逻辑分开编写略显繁琐,请问是否可以将这两项检测合并?
解决方案
可以合并这两项检测,利用NSIS的${Or}逻辑运算符,把两个条件整合到同一个${IfNot}判断中,这样只需要执行一次弹窗和终止操作,简化代码结构:
Function .onInit ${IfNot} ${AtLeastWin10} ${Or} ${Not} ${RunningX64} MessageBox mb_iconStop "Windows 10 x64 is required to install DeepSkyStacker 5.1.0" Abort ${EndIf} FunctionEnd
你也可以用${And}反向表达逻辑,效果完全一致:
Function .onInit ${If} ${AtLeastWin10} ${And} ${RunningX64} ; 满足条件,继续执行安装流程 ${Else} MessageBox mb_iconStop "Windows 10 x64 is required to install DeepSkyStacker 5.1.0" Abort ${EndIf} FunctionEnd
内容的提问来源于stack exchange,提问作者David Partridge
相关产品推荐
相关产品推荐

