NSIS打包QCAD
程序员文章站
2024-02-03 22:05:10
...
QCAD
编译后需要打包的目录:
-
release
文件夹下为生成的动态连接库和可执行程序。 -
font
:字体库 -
plugins
:插件 -
themes
:主题样式 -
ts
:多国语言支持 -
platforms
:window平台支持 -
examples
:示例
将脚本放在上图所示目录下,运行makensis.exe setup_x64.nsi
即可。
;--------------------------------
Unicode true
ShowInstDetails show
; The name of the installer
!define VERSION "3.25"
!define APPNAME "QCAD"
!define BinaryNAME "${APPNAME}.exe"
!define COMPANYNAME "QCAD"
!define DESCRIPTION "${APPNAME}"
!define StartupProgram "$INSTDIR\${APPNAME}.exe"
!define StartMenu_Folder "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}"
!define UserGuide "$INSTDIR\qcad_zh.pdf"
Name "${COMPANYNAME}'s ${APPNAME}64"
;Name and file
OutFile "${APPNAME}64Setup.exe"
;InstallDir "$PROGRAMFILES64\${COMPANYNAME}\${APPNAME}"
InstallDir "$PROGRAMFILES64\${APPNAME}"
; Request application privileges for Windows Vista
; RequestExecutionLevel admin
VIProductVersion ${VERSION}
VIAddVersionKey ProductName "${APPNAME}"
VIAddVersionKey CompanyName "${COMPANYNAME}"
VIAddVersionKey LegalCopyright "http://www.github.com/"
VIAddVersionKey FileVersion ${Version}
VIAddVersionKey FileDescription ""
VIAddVersionKey ProductVersion ${Version}
VIAddVersionKey InternalName "${COMPANYNAME} Launcher"
DirText "This will install QCAD Corp's ${APPNAME} 64Bits software to your computer. Please close ${APPNAME} software and keep default install directory.$\r$\n${VERSION}"
;--------------------------------
; Pages
Page components
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
;--------------------------------
; The stuff to install
; SilentInstall silent
; SilentUninstall silent
Section "${APPNAME}64 (required)"
SectionIn RO
ExecWait "taskkill /f /im ${BinaryNAME}"
; Set output path to the installation directory.
SetOutPath $INSTDIR
WriteUninstaller "uninstall.exe"
; Put file there
File /r /x "*.lib" /x "*.exp" "release\*.*"
File /r /x "*.lib" /x "*.exp" "plugins"
File /r /x src /x support /x scripts "examples"
File /r "fonts"
File /r "libraries"
File /r "patterns"
File /r "platforms"
File /r "themes"
File /r "ts"
File qcad_zh.pdf
;CreateDirectory $INSTDIR\scripts
;SetOutPath $INSTDIR
;File qcad_zh.pdf
; desktop
CreateShortcut "$DESKTOP\${APPNAME}.lnk" "${StartupProgram}"
; shortcuts
CreateDirectory "${StartMenu_Folder}"
CreateShortcut "${StartMenu_Folder}\${APPNAME}_uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortcut "${StartMenu_Folder}\${APPNAME}_startup.lnk" "${StartupProgram}" ""
SetAutoClose True
Exec "${StartupProgram}"
SectionEnd
;--------------------------------
; Uninstaller
Section "Uninstall"
ExecWait "taskkill /f /im ${BinaryNAME}"
; Desktop
Delete "$DESKTOP\${APPNAME}.lnk"
; Remove files and uninstaller
Delete $INSTDIR\*.*
; Remove shortcuts, if any
Delete "${StartMenu_Folder}\*.*"
; Remove directories used
Delete "$INSTDIR\*.*"
RMDir /r "$INSTDIR"
ExecWait '"schtasks.exe" /f /delete /tn ${APPNAME}'
SetAutoClose True
SectionEnd
解析
定义变量
版本,程序名称,二进制文件,…
!define VERSION "3.25"
!define APPNAME "QCAD"
!define BinaryNAME "${APPNAME}.exe"
!define COMPANYNAME "QCAD"
!define DESCRIPTION "${APPNAME}"
!define StartupProgram "$INSTDIR\${APPNAME}.exe"
!define StartMenu_Folder "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}"
!define UserGuide "$INSTDIR\qcad_zh.pdf"
OutFile
:打包文件名称;InstallDir
: 安装目录(这里是C:\Program Files\QCAD
)
;Name and file
OutFile "${APPNAME}64Setup.exe"
;InstallDir "$PROGRAMFILES64\${COMPANYNAME}\${APPNAME}"
InstallDir "$PROGRAMFILES64\${APPNAME}"
; Request application privileges for Windows Vista
; RequestExecutionLevel admin
VIProductVersion ${VERSION}
VIAddVersionKey ProductName "${APPNAME}"
VIAddVersionKey CompanyName "${COMPANYNAME}"
VIAddVersionKey LegalCopyright "http://www.github.com/"
VIAddVersionKey FileVersion ${Version}
VIAddVersionKey FileDescription ""
VIAddVersionKey ProductVersion ${Version}
VIAddVersionKey InternalName "${COMPANYNAME} Launcher"
安装向导和卸载向导
;--------------------------------
; Pages
Page components
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
安装:
-
ExecWait "taskkill /f /im ${BinaryNAME}"
杀死正运行的进程 -
SetOutPath
配置安装的文件路径 -
File /r /x
/r
递归文件夹下的子文件夹和文件,/x
排除文件和文件夹 -
CreateShortcut
创建快捷方式 -
CreateDirectory
创建目录 -
Exec
运行程序 -
WriteUninstaller
创建卸载程序
;--------------------------------
; The stuff to install
; SilentInstall silent
; SilentUninstall silent
Section "${APPNAME}64 (required)"
SectionIn RO
ExecWait "taskkill /f /im ${BinaryNAME}"
; Set output path to the installation directory.
SetOutPath $INSTDIR
WriteUninstaller "uninstall.exe"
; Put file there
File /r /x "*.lib" /x "*.exp" "release\*.*"
File /r /x "*.lib" /x "*.exp" "plugins"
File /r /x src /x support /x scripts "examples"
File /r "fonts"
File /r "libraries"
File /r "patterns"
File /r "platforms"
File /r "themes"
File /r "ts"
File qcad_zh.pdf version taskschd.xml
;CreateDirectory $INSTDIR\scripts
;SetOutPath $INSTDIR
;File qcad_zh.pdf
; desktop
CreateShortcut "$DESKTOP\${APPNAME}.lnk" "${StartupProgram}"
; shortcuts
CreateDirectory "${StartMenu_Folder}"
CreateShortcut "${StartMenu_Folder}\${APPNAME}_uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortcut "${StartMenu_Folder}\${APPNAME}_startup.lnk" "${StartupProgram}" ""
SetAutoClose True
Exec "${StartupProgram}"
SectionEnd
程序卸载
- 删除快捷方式
- 删除安装的所有文件
- 删除启动文件夹下的快捷方式
- 删除目录
;--------------------------------
; Uninstaller
Section "Uninstall"
ExecWait "taskkill /f /im ${BinaryNAME}"
; Desktop
Delete "$DESKTOP\${APPNAME}.lnk"
; Remove files and uninstaller
Delete $INSTDIR\*.*
; Remove shortcuts, if any
Delete "${StartMenu_Folder}\*.*"
; Remove directories used
Delete "$INSTDIR\*.*"
RMDir /r "$INSTDIR"
ExecWait '"schtasks.exe" /f /delete /tn ${APPNAME}'
SetAutoClose True
SectionEnd