NSIS + QT 做安装卸载程序

本文介绍如何结合NSIS(Nullsoft Scriptable Install System)和QT技术,制作具备安装和卸载功能的程序。通过创建两个EXE文件,一个用于部署程序,另一个用于执行安装过程,该过程涉及解压缩发布程序的压缩包。
摘要由CSDN通过智能技术生成
NSIS + QT 做安装卸载程序。
NSIS仅仅用于把所有的东西封装为一个EXE。


NSIS打包
QT做有逼格的可视化界面,并且方便实现。



以下是nSIS源码:


icon ".\xxx.ico" #设置图标
OutFile "setup.exe" #设置生成程序
SilentInstall silent #静默安装不出现任何NSIS自带界面


Function .onInit #NSIS程序安装准备工作
InitPluginsDir #创建临时目录(内存)用于保存一些必要的库
SetOutPath $PLUGINSDIR #将文件保存在临时目录中
  File "Qt5Gui.dll" #我的安装界面必要的库
  File "Qt5Core.dll"
  File "Qt5Widgets.dll"
  File "Qt5Widgets.dll"
  File "qt.conf"
  File /r "plugins\"
  File "UnRAR.exe"
  File "xxx.rar" #rar.exe生成的必要的库和文件。
  File "xxx.exe"
FunctionEnd


Function .onInstSuccess #安装成功后调用
call fun
Functionend


Function fun
   ExecWait $PLUGINSDIR\class8_setup.exe #调用QT安装程序,等待其运行完后运行下一条语句
   RMDir $PLUGINSDIR                #释放临时目录(内存)
FunctionEnd


section
sectionend




出现图标不显示的问题的时候:
在开始里运行tskill ex*




QT做安装程序:
1.必要库的解压。
2.进度条
3.写注册表或配置文件。


这里直接调用第三方的UnRAR.exe程序。QT开一个进程调用它,并且绑定它的标准输出内容到主程序槽,用于设置进度条。
当该程序结束时会返回一个结束信号。


附:
rar unrar命令
rar -help
unrar -help

可以看到详细内容



按照上文的方法,即写两个EXE程序。一个发布的程序,一个是安装程序,安装程序用于解压发布的程序的压缩包。


以下是QT源码:

#ifndef ENV
#define ENV

#include <QDir>
#include <QString>
#include <QStringList>
#include <QDebug>

#include <windows.h>
#include "psapi.h"
#include "stdio.h"
#include <tlhelp32.h>
#include <QStandardPaths>

#include <QByteArray>
#include <QFile>
#include <QCryptographicHash>

namespace ENV{

//define

//创建文件夹
static inline void createFolder(const QString &folderPath);
//查找当前是否有该进程运行
static inline bool findProcess(const QString &proName);
//创建桌面快捷方式
static inline bool createShortCutToDeskTop(const QString &file);
//创建开始菜单快捷方式
static inline bool createShortCutToStartMenue(const QString &file);
//得到文件md5
static inline QByteArray getFileMd5(QFile &file);
static inline QByteArray getFileMd5(const QString &filePath);
//对比文件md5
static inline bool cmpFileMd5(QFile &lhs,QFile &rhs);
static inline bool cmpFileMd5(const QString &lhs,const QString &rhs);



//implementation
void createFolder(const QString &folderPath){
    QDir dir;
    bool exist = dir.exists(folderPath);
    if(!exist){
        QStringList list = folderPath.split('/');
        QString filePath = "";
        int len = 0;
        if(QString(list.at(list.length()-1)).contains('.'))
            len = list.length()-1;
        else
            len = list.length();
        for(int i = 0;i < len;++i){
            filePath = filePath + list[i] + '/';
            exist = dir.exists(filePath);
            if(!exist)
                dir.mkdir(filePath);
        }
    }
}

static inline bool findProcess(const QString &proName)
{
    int count = 0;
    PROCESSENTRY32 pe32;
    pe32.dwSize = sizeof(pe32);
    HANDLE hProcessSnap = ::Cr
  • 7
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值