NSIS是否具有评估功能?

时间:2016-10-20 00:35:06

标签: scripting nsis

例如,有没有办法沿着这些方向做某事?

Eval "MessageBox MB_OK 'Hello, World!'"

这显然是一个无用的例子,但我觉得这样的功能会很有用。

1 个答案:

答案 0 :(得分:2)

NSIS编译器(MakeNSIS)解析文本文件并将二进制指令写入生成的设置。安装应用程序本身只能执行编译时已知的指令。

大多数指令接受变量作为参数,因此您可以获得不同的行为。这是一个相当无意义的例子:

Page InstFiles

Function MaybeShowMessageBox
    IntCmp $0 0 skip
    MessageBox MB_OK "$1"
skip:
FunctionEnd

Section
StrCpy $0 1 ; Display it
StrCpy $1 "Hello World"
Call MaybeShowMessageBox

StrCpy $1 "Goodbye World"
Call MaybeShowMessageBox

StrCpy $0 0 ; Don't display it
Call MaybeShowMessageBox

StrCpy $0 0
StrCpy $2 "$WinDir" 1 ; Get the first character
StrCmp $2 "C" "" skipWinDirMessage
StrCpy $0 1
skipWinDirMessage:
StrCpy $1 "$WinDir is on drive C"
Call MaybeShowMessageBox
SectionEnd

你通常不会写那样的代码。 IntFmt与您将获得的Eval一样接近,但它仅适用于数字:

ShowInstDetails show
Section
StrCpy $1 42

IntFmt $0 "%d" $1
DetailPrint "$1 as a number: $0"

IntFmt $0 "%#.4x" $1
DetailPrint "$1 as a hex number with a >= 4 width: $0"

IntFmt $0 "%c" $1
DetailPrint "$1 as a character: $0"
SectionEnd