RSS
热门关键字:  计算机有关资料  33252  mkv  word  MKV_NT
当前位置 : 主页>vc编程>其它编程知识>列表

NSIS杂记

来源: 作者: 时间:2006-12-01 点击:
nsi脚本的基本语法
注释
单行注释用井号"#"或分号";",跨行注释用可以用c/C++中注释语法。

数据类型
数字
   数字常量可以用十进制、十六进制(0x为前缀)、八进制(0为前缀)表示,颜色用类似html的中RGB表示法,但去井号"#"。
字符串
   字符串常量可以用引号引用,转意字符用"$\"作前缀。美元符号、常用转意字符换行、回车、制表符的nsi语法表示分别为:$$,$\n,$\r,$\t
续行符
    nsi脚本用行尾的反斜杠"\"表示下一行和当前行逻辑上是同一行
默认头文件
    如果在makensis同目录下有nsisconf.nsh文件,该文件会被自动包含,除非编译时指定/NOCONFIG选项

标号
   nsi使用GOTO语句和IfErrors, MessageBox, IfFileExists及StrCmp进行程序控制流表示,标号是这些语句的目标语句。标号定义的语法:
   标号:语句
   标号必须定义在函数和区段中,其作用范围仅限于定义它的区段或函数。以点号"."开头的标号是全局标号。
相对跳转
    nsi脚本常常使用相对跳转表示条件分枝,其语法是[+-][1-9],加号表示从当前位置往前跳转,减号则表示从当前位置往后跳转。数字表示跳转的语句条数。示例:
 Goto +4
 MessageBox MB_OK "The following message will be skipped"
 Goto +3
 MessageBox MB_OK "You will never ever see this message box"
 Goto -3
 MessageBox MB_OK "Done"

页面
向导页面是NSIS安装程序中最重要的界面元素,在nsi脚本中可以使用NSIS内置页面或者定制界面,通过脚本可以指定页面的顺序、显示样子和行为。 Page指令用来定义安装程序中的页面,UninstPage用来定义,此外PageEx指令提供类是功能,但提供更多选项。页面的顺序和它在nsi脚本中出现的次序一致。
示例:
 Page license
 Page components
 Page directory
 Page instfiles
 UninstPage uninstConfirm
 UninstPage instfiles
规定安装程序首先显示license页面,然后显示components选择页面,接着显示安装目录选择页面。

页面选项
不同的页面有不同的选项:
License page有LicenseText,LicenseData,LicenseForceSelection;
Components selection页面有ComponentText;
Directory selection页面有DirText,DirVar(仅能在PageEx中使用),DirVerify;
Un/Installation log页面有DetailsButtonText,CompletedText;
Uninstall confirmation页面有DirVar(仅能在PageEx中使用),UninstallText
对于内置的Page,NSIS支持三个回调函数用于定制界面和验证,对于自定义页面NSIS支持两个回调函数。

Page指令语法
Page license|components|directory|instfiles|uninstConfirm) [pre_function] [show_function] [leave_function]
或者:
Page custom [creator_function] [leave_function] [caption]
示例:
 Page license skipLicense "" stayInLicense
 Page custom customPage "" ": custom page"
 Page instfiles

 Function skipLicense
   MessageBox MB_YESNO "Do you want to skip the license page?" IDNO no
     Abort
   no:
 FunctionEnd

 Function stayInLicense
   MessageBox MB_YESNO "Do you want to stay in the license page?" IDNO no
     Abort
   no:
 FunctionEnd

 Function customPage
   GetTempFileName $R0
   File /oname=$R0 customPage.ini
   InstallOptions::dialog $R0
   Pop $R1
   StrCmp $R1 "cancel" done
   StrCmp $R1 "back" done
   StrCmp $R1 "success" done
   error: MessageBox MB_OK|MB_ICONSTOP "InstallOptions error:$\r$\n$R1"
   done:
 FunctionEnd
 
UninstPage指令语法
UninstPage custom [creator_function] [leave_function] [caption]
  OR
UninstPage (license|components|directory|instfiles|uninstConfirm) [pre_function] [show_function] [leave_function]


PageEx语法
  PageEx使用嵌套结构,比如:
 PageEx license
   LicenseText "Readme"
   LicenseData readme.rtf
   PageCallbacks licensePre licenseShow licenseLeave
 PageExEnd

常用的nsi指令
nsi大致可以分为基本指令、注册表及ini操作指令、通用指令、流程控制指令、文件操作指令、卸载指令、字符串处理指令、多语言支持指令、重启指令。

以下是常用的基本指令:
Delete
Delete [/REBOOTOK] file

Exec
Exec command

ExecShell
ExecShell action command [parameters] [SW_SHOWNORMAL | SW_SHOWMAXIMIZED | SW_SHOWMINIMIZED | SW_HIDE]ExecShell "open" 示例"http://nsis.sf.net/"
ExecWait
ExecWait command [user_var(exit code)]
示例:
ExecWait '"$INSTDIR\someprogram.exe"'
ExecWait '"$INSTDIR\someprogram.exe"' $0
DetailPrint "some program returned $0"


File
File [/nonfatal] [/a] ([/r] [/x file|wildcard [...]] (file|wildcard) [...] | /oname=file.dat infile.dat)
/r选项用作递归模式,/x用于排出文件
示例:
File something.exe
File /a something.exe
File *.exe
File /r *.dat
File /r data
File /oname=$TEMP\temp.dat somefile.ext
File /nonfatal "a file that might not exist"
File /r /x CVS myproject
File /r /x *.res /x *.obj /x *.pch source

Rename
Rename [/REBOOTOK] source_file dest_file

RMDir
RMDir [/r] [/REBOOTOK] directory_name
共2页: 上一页 [1] 2 下一页
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册