NSIS打包QCAD

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

打包后安装测试

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值