标签:nsis qt windows installer 部署
接上文:http://blog.csdn.net/shallen320/article/details/44915649
上文介绍了如何查找Qt程序依耐性,如何利用NSIS 和 .zip文件制作简单的压缩包。上文所用的方法制作的安装包十分简单,连创建桌面快捷方式都没有。本文介绍如何使用NSIS脚本语言制作一个略微复杂的安装包。
下面是我使用的NSIS脚本语言范例,含有简单全面的功能,包括:
脚本语言如下,程序名为Terminal:
; Terminal.nsi ; ; This script is based on example2.nsi, ; has uninstall support and (optionally) installs start menu shortcuts. ; ; It will install Terminal.nsi into a directory that the user selects, ;-------------------------------- ; The name of the installer Name "Terminal" ; The file to write OutFile "Installer\TerminalInstaller.exe" ; The default installation directory InstallDir C:\Terminal ; Registry key to check for directory (so if you install again, it will ; overwrite the old one automatically) InstallDirRegKey HKLM "Software\NSIS_Terminal" "Install_Dir" ; Request application privileges for Windows Vista RequestExecutionLevel admin LoadLanguageFile "${NSISDIR}\Contrib\Language files\English.nlf" ;-------------------------------- ;Version Information VIProductVersion "0.0.0.1" VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "Terminal" VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "A RS232 Terminal" VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "XXX Company" VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalTrademarks" "YYY is a trademark of XXX Company." VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "2015 (c) XXX company." VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "A RS232 Terminal" VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "0.0.1" ;-------------------------------- ;-------------------------------- ; Pages Page components Page directory Page instfiles UninstPage uninstConfirm UninstPage instfiles ;-------------------------------- ; The stuff to install Section "Terminal (required)" SectionIn RO ; Set output path to the installation directory. SetOutPath $INSTDIR ; root folder ; Put file there File icudt53.dll File icuin53.dll File icuuc53.dll File Terminal.exe File qt_ca.qm File qt_cs.qm File qt_de.qm File qt_fi.qm File qt_hu.qm File qt_it.qm File qt_ja.qm File qt_ru.qm File qt_sk.qm File qt_uk.qm File Qt5Core.dll File Qt5Gui.dll File Qt5SerialPort.dll File Qt5Svg.dll File Qt5Widgets.dll SetOutPath "$INSTDIR\iconengines" File "iconengines\*.*" SetOutPath "$INSTDIR\imageformats" File "imageformats\*.*" SetOutPath "$INSTDIR\platforms" File "platforms\*.*" ; Write the installation path into the registry WriteRegStr HKLM SOFTWARE\NSIS_Terminal "Install_Dir" "$INSTDIR" ; Write the uninstall keys for Windows WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Terminal" "DisplayName" "NSIS_Terminal" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Terminal" "UninstallString" '"$INSTDIR\uninstall.exe"' WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Terminal" "NoModify" 1 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Terminal" "NoRepair" 1 WriteUninstaller "uninstall.exe" SectionEnd ; Optional section (can be disabled by the user) Section "Start Menu Shortcuts" CreateDirectory "$SMPROGRAMS\Terminal" CreateShortcut "$SMPROGRAMS\Terminal\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0 CreateShortcut "$SMPROGRAMS\Terminal\Terminal (MakeNSISW).lnk" "$INSTDIR\Terminal.nsi" "" "$INSTDIR\Terminal.nsi" 0 SectionEnd Section "Desktop Shortcuts" CreateShortCut "$DESKTOP\Terminal.lnk" "$INSTDIR\Terminal.exe" "" SectionEnd ;-------------------------------- ; Uninstaller Section "Uninstall" ; Remove registry keys DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Terminal" DeleteRegKey HKLM SOFTWARE\NSIS_Terminal ; Remove files and uninstaller Delete "$INSTDIR\*.*" Delete "$INSTDIR\scripts\*.*" Delete "$INSTDIR\iconengines\*.*" Delete "$INSTDIR\imageformats\*.*" Delete "$INSTDIR\platforms\*.*" ; Remove shortcuts, if any Delete "$SMPROGRAMS\Terminal\*.*" Delete "$DESKTOP\Terminal.lnk" ; Remove directories used RMDir "$INSTDIR\iconengines" RMDir "$INSTDIR\imageformats" RMDir "$INSTDIR\platforms" RMDir "$SMPROGRAMS\Terminal" RMDir "$INSTDIR\scripts" RMDir "$INSTDIR" SectionEnd
解释:
11行,设定程序名
14行,指定生成的安装程序名和路径
17行,指定安装程序的默认安装路径
30-37行,指定安装程序的版本,公司名称,版权信息
56-102行,主安装选项,括号里的required表示这是必选安装选项。该栏目内指示安装程序安装指定文件,写入指定注册表值
103-109行,第二安装选项,开始菜单快捷方式,可选
111-115行, 第三安装选项,桌面快捷方式,可选
122往后,卸载步骤。注意一般要把一个目录内的文件都删除后才能删除该目录。所以先用delete命令,再用RMDir命令
使用说明:
把脚本文件XXX.nsi放于完整所需拷贝文件的源目录中
运行NSIS,主界面中选择左上角的Compile NSI scripts 。
之后的界面中选择file-load script,或单击左上角的打开按钮。
选择nsis脚本文件,nsis会自动执行该文件,如果没有语法错误,会自动生成TerminalInstaller.exe安装文件到Installer文件夹中。
win7平台下QT软件的打包与发布 (利用NSIS脚本制作安装包)
标签:nsis qt windows installer 部署
原文地址:http://blog.csdn.net/shallen320/article/details/46041155