QT Creator 自定义工程模板+nsis自动更新包

QT Creator新建工程使用自定义创建模板

模板文件夹放置位置:

Tools\QtCreator\share\qtcreator\templates\wizards

例如我这边做的模板protocol

最主要的内容就是上面箭头所指的xml文件,有的好像也有json格式的,但是内容大差不差

下面我把我里面写的xml文件的内容放在下面,大家可以参考

<?xml version="1.0" encoding="utf-8"?>
<wizard version="1" kind="project"
        class="qmakeproject" firstpage="10"
        id="zvit backend business plugin" category="G.Library">
    <icon>logo.ico</icon>
    <description>Creates a C++ plugin to load extensions dynamically into applications using the QDeclarativeEngine class. Requires Qt 4.7.0 or newer.</description>
    <displayname>Zvit Backend Business Plugin</displayname>
    <displaycategory>Library</displaycategory>
    <files>
        <file source="Interface/IApp.h" target="Interface/IApp.h"/>
        <file source="Interface/extend_func_def.h" target="Interface/extend_func_def.h"/>

        <file source="communication/communicationdef.h" target="communication/communicationdef.h"/>
        <file source="communication/communicationglobal.h" target="communication/communicationglobal.h"/>

        <file source="common/common.pri" target="common/common.pri"/>
        <file source="common/DataAreaDeal.cpp" target="common/DataAreaDeal.cpp"/>
        <file source="common/DataAreaDeal.h" target="common/DataAreaDeal.h"/>
        <file source="common/protocol.h" target="common/protocol.h"/>
        <file source="common/protocol_extend.cpp" target="common/protocol_extend.cpp"/>
        <file source="common/protocol_global.h" target="common/protocol_global.h"/>
        <file source="common/protocol_interface.cpp" target="common/protocol_interface.cpp"/>
        <file source="common/protocol_interface.h" target="common/protocol_interface.h"/>
        <file source="common/protocol_type.h" target="common/protocol_type.h"/>
        <file source="common/service.cpp" target="common/service.cpp"/>
        <file source="common/service.h" target="common/service.h"/>
        <file source="common/service_def.h" target="common/service_def.h"/>
        <file source="common/typedefheader.h" target="common/typedefheader.h"/>
        <file source="common/ValueChangeDeal.cpp" target="common/ValueChangeDeal.cpp"/>
        <file source="common/ValueChangeDeal.h" target="common/ValueChangeDeal.h"/>
        
        <file source="protocol/file.h" target="%ProjectName:l%/%ProjectName:l%.%CppHeaderSuffix%"/>
        <file source="protocol/file.cpp" target="%ProjectName:l%/%ProjectName:l%.%CppSourceSuffix%"/>
        <file source="protocol/protocol.cpp" target="%ProjectName:l%/protocol.cpp"/>
        <file source="protocol/protocol.pro" target="%ProjectName:l%/%ProjectName:l%.pro" openproject="true"/>
    </files>
</wizard>

2.使用nsis制作qt creator更新包来更新上面的自定义工程模板

nsis的使用我就不多说了,网上一搜一大把

下面我把我的安装包脚本放出来供大家参考:

!define PRODUCT_NAME "Qt Creator protocol plugin project template"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_EXE_NAME "QtCreatorProtocolTemplate"
!define PRODUCT_TARGET_PATH_NAME "protocol"

!define PRODUCT_INST_PATH_KEY "Applications\QtProject.QtCreator.pro\shell\Open\Command"
!define PRODUCT_INST_PATH_ROOT_KEY "HKCR"

SetCompressor lzma
!include "MUI.nsh"
!include "StrFunc.nsh"
!include "Library.nsh"
!include "WordFunc.nsh"
!include "FileFunc.nsh"
!include "x64.nsh"

!define MUI_ABORTWARING
;!define MUI_ICON "app.ico"
!define MUI_WELCOMEPAGE_TITLE "欢迎使用“${PRODUCT_NAME}”更新向导"
!define MUI_WELCOMEPAGE_TEXT "\r\n点击[安装]开始“${PRODUCT_NAME}”的升级\r\n\r\n\r\n\r\n更新(${PRODUCT_VERSION})"
; 欢迎页面
!insertmacro MUI_PAGE_WELCOME
; 安装目录选择页面
!insertmacro MUI_PAGE_DIRECTORY
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese"


Name "${PRODUCT_NAME}(${PRODUCT_VERSION})(更新)"
OutFile "${PRODUCT_EXE_NAME}_upgrade(${PRODUCT_VERSION}).exe"
ShowInstDetails show
ShowUnInstDetails show
BrandingText $PRODUCT_NAME


Section -Upgrade

    DetailPrint "正在Qt Creator组件..."
    ;SetDetailsPrint none
    SetAutoClose false
    SetOutPath "$INSTDIR\${PRODUCT_TARGET_PATH_NAME}\"
    SetOverwrite on
    File /r "${PRODUCT_TARGET_PATH_NAME}\*.*"

 SectionEnd

 Function .onInit
    ;禁止多个安装程序同时运行
  System::Call 'kernel32::CreateMutexA(i 0, i 0, t "VAUpdate") i .r1 ?e'
  Pop $R0
  StrCmp $R0 0 +3
  MessageBox MB_OK|MB_ICONEXCLAMATION "升级程序已经在运行。"
  Abort

  ClearErrors
  ;获取Qt Creator安装目录
  ReadRegStr $R1 ${PRODUCT_INST_PATH_ROOT_KEY} ${PRODUCT_INST_PATH_KEY} ""
  ${WordFind} $R1 "$\"" +1  $R2
  ;MessageBox MB_OK  $R2
  ${WordFind} $R2 "\bin" "+1{" $R3
  ;MessageBox MB_OK  $R3
  ${WordReplace} $R3 "\\" "\" +1 $R4
  ;MessageBox MB_OK  $R4
  StrCpy $INSTDIR  $R4\share\qtcreator\templates\wizards
  ;MessageBox MB_OK  $INSTDIR

 FunctionEnd
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
检查本地的配置版本与服务器配置的版本, 如果服务器比较新则进行下载并更新文件. 注意: 需要结合NSIS安装进行安装. 升级时采用/S静默安装方式进行安装. 配置中, "name"属性指定的应用程序, 将最后被安装. 程序目前只支持更新一个主程序和一个插件程序, 其他功能自行完善 带源码, 带完整配置文件, 各项主要设置均可通过配置文件修改, 并含程序逻辑简要描述说明文件. 功能不复杂, 主要是不想重复开发. 7. 程序逻辑: a. CommonAutoUpdate启动后, 将检查和加载本地配置文件, 加载成功后, 将判断"run"中指定的程序是否正在运行. 如果在运行, 则给出错误提示后, 退出更新程序; b. 如果"run"中的程序没有在运行, 则根据svrurl + "/commonAutoUpdate.xml" 地址, 加载服务器上的配置文件; c. 在加载配置文件过程中, 任何的异常, 均会提示"检查自动更新失败, 请稍后再试", 并退出; (不会启动"run"中配置的文件) d. 如果加载成功, 则会对比本地"version"中的版本号与服务器"cv"节点中的"v"属性的版本号; e. 如果服务器版本号小于或等于本地版本号, 则不进行更新, 直接运行"run"中指定的程序, 并传递"cau"参数作为标记; f. 如果服务器版本号大于本地版本号, 则会显示提示更新的界面, 在点击确定按钮后, 开始下载服务器"cv"节点中的"p"属性指定的文件; g. 待下载完成, 则会退出, 并运行下载的安装进行安装.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yvonne0627

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值