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

打包后安装测试

在这里插入图片描述

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片