NSIS 脚本结构说明

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




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值