NSIS 脚本结构说明

来源:互联网 发布:淘宝详情页怎么加视频 编辑:程序博客网 时间:2024/05/16 01:58
NSIS脚本(下称nsi脚本)主要包含安装程序属性、页面、区段、函数。

属性

用来定义安装程序的行为和界面风格,这些属性大部分是编译时刻属性,即不能在运行时刻改变。

页面

是指安装程序的向导页面,示例:

Page license
Page components
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles


区段

是对应某种安装/卸载选项的处理逻辑,该段代码仅当用户选择相应的选项才被执行。卸载程序的区段名用"un."作为前缀,示例如下:

Section "Installer Section"
SectionEnd


Section "un.Uninstaller Section"
SectionEnd

在区段中可以使用很多指令用来完成诸如解压缩文件、读写注册表、创建目录、创建快捷方式等任务。最常用的指令是SetOutPath和File。前者用于指定目的位置,后者用于指定文件。示例:

Section "My Program"
      SetOutPath $INSTDIR
      File "My Program.exe"
      File "Readme.txt"
SectionEnd

区段名的修饰符/o表示该区段默认不选上,-表示隐藏区段(匿名区段也是隐藏区段),!表示需要粗体显示的区段。

SectionIn表示该区段和安装类型之间的关系:

SectionIn insttype_index [insttype_index] ... [RO]
;RO修饰符表示不可修改。


子区段用于包含多个区段:

SubSection [/e] Caption [subsection_name index output]

;修饰符/e用于该子区段的所有区段是否默认展开。


函数

包含了模块化的安装逻辑,在nsi脚本中函数分为两种:用户自定义函数和回调函数。

用户自定义函数仅当是Call指令调用时才被执行,如果函数体中没有abort语句,则安装程序执行完了用户自定义函数,继续运行Call语句和指令。

用户自定义函数的语法如下:

Function <函数名>
      # some commands
FunctionEnd

可见无论是函数的定义还是函数的调用都没有参数传递。

通常nsi的参数传递是通过堆栈操作Pop,Push和20个寄存器变量$0~$9, $R0~$R9进行的。也可以通过全局变量完成参数传递。如:

Var input ;
Var output ;

Section bla
      DeteailPrint "input is $input$\n"
      Call square
      DeteailPrint "square of $input is $output$\n"
SectionEnd


Function square
    output = input^2
FunctionEnd


回调函数则是由在特定的时间点触发的程序段。常用的回调函数如.onInit:

Function .onInit
      MessageBox MB_YESNO "This will install My Program. Do you wish to continue?" IDYES gogogo
      Abort
     gogogo:
FunctionEnd


NSIS对于安装逻辑定义以下回调函数:

.onGUIInit、.onInit、.onInstFailed、.onInstSuccess、.onGUIEnd、.onMouseOverSection、.onRebootFailed、
.onSelChange、.onUserAbort、.onVerifyInstDir


NSIS对于卸载逻辑定义以下回调函数:

un.onGUIInit、un.onInit、un.onUninstFailed、un.onUninstSuccess、un.onGUIEnd、un.onRebootFailed、un.onUserAbort




原创粉丝点击