-
逻辑代码结构
1.条件判断
NSIS脚本中可以使用StrCmp、IntCmp、IfErrors、Goto和其他方法有条件地执行代码或在循环中执行代码。
StrCmp $0 'some value' 0 +3
MessageBox MB_OK '$$0 is some value'
Goto done
StrCmp $0 'some other value' 0 +3
MessageBox MB_OK '$$0 is some other value'
Goto done
# else
MessageBox MB_OK '$$0 is "$0"'
done:
不过,有一种更简单的方法[LogicLib],LogicLib提供了一些非常简单的宏,可以轻松地构造复杂的逻辑结构。它的语法,解释于逻辑库.nsh,与其他编程语言类似,对初学者和高级用户来说都更简单。
!include LogicLib.nsh
${If} $0 == 'some value'
MessageBox MB_OK '$$0 is some value'
${ElseIf} $0 == 'some other value'
MessageBox MB_OK '$$0 is some other value'
${Else}
MessageBox MB_OK '$$0 is "$0"'
${EndIf}
LogicLib消除了对标签和相对跳转的需要,从而防止了标签名称冲突,并且消除了每次脚本更改时手动调整相对跳转偏移的需要。
也可以使用switch达到同样的目的