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
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