使用duilib开发简单的Window安装包
一、具体思路
安装过程:安装包的制作包括资源文件的打包,资源文件打包到安装包exe中,安装的时候需要从exe中提取出对应的资源文件,
然后解压文件安装到指定目录,然后就是对安装的可执行程序进行注册表的注册,以及快捷方式的注册。
卸载过程:安装包安装时,通常会带有一个卸载程序,此程序的功能就是执行对安装程序目录文件的删除和注册表的清除。
二、实现
安装过程分为三部分实现,安装配置,安装过程,安装结束启动程序。
安装配置界面如下:

安装过程实现:
Install类负责对打包文件的释放,注册表的写入,快捷方式的写入,以及回调界面进度的职责:
#pragma once
#include<string>
#include<functional> class Install
{
public:
Install();
virtual ~Install();
static Install& getInstance(){
static Install instance;
return instance;
}
void setStop(){
m_stop = true;
}
bool install(const std::string & install_path, bool is_shortcut);
void setCallBack(const std::function<void(int, const std::string &)> &fun_1,const std::function<void()> &fun_2){
process_fun = fun_1;
process_end = fun_2;
}
private:
bool releaseRes(const std::string & file_name, unsigned short res_id, const std::string & file_type);
bool setShortCutLink(const std::string & path, const std::string & link_name, bool is_desktop);
bool writeToReg();
std::string getDesktopPath();
std::string getStartMenuPath();
private:
std::function<void(int, const std::string &)> process_fun;
std::function<void()> process_end;
std::string m_install_path;
bool m_stop; };
1)导入资源到exe,
.rc文件添加资源,
IDR_en_US APK "res\\bin\\locales\\en-US.pak"
IDR_zh_CN APK "res\\bin\\locales\\zh-CN.pak" /////////////////////////////////////////////////////////////////////////////
//
// EXE
// IDR_YDDemo EXE "res\\bin\\YDDemo.exe"
IDR_Unstall_App EXE "res\\bin\\Unstall_App.exe"
IDR_debug LOG "res\\bin\\debug.log"
IDR_icudtl DAT "res\\bin\\icudtl.dat"
IDR_natives_blob BIN "res\\bin\\natives_blob.bin"
IDR_snapshot_blob BIN "res\\bin\\snapshot_blob.bin"
IDR_cef APK "res\\bin\\cef.pak"
IDR_cef_100_percent APK "res\\bin\\cef_100_percent.pak"
IDR_cef_200_percent APK "res\\bin\\cef_200_percent.pak"
IDR_cef_extensions APK "res\\bin\\cef_extensions.pak"
IDR_devtools_resources APK "res\\bin\\devtools_resources.pak"
/////////////////////////////////////////////////////////////////////////////
//
// DLL
// IDR_d3dcompiler_43 DLL "res\\bin\\d3dcompiler_43.dll"
IDR_d3dcompiler_47 DLL "res\\bin\\d3dcompiler_47.dll"
IDR_DuiLib_u DLL "res\\bin\\DuiLib_u.dll"
IDR_libcef DLL "res\\bin\\libcef.dll"
IDR_libEGL DLL "res\\bin\\libEGL.dll"
IDR_libGLESv2 DLL "res\\bin\\libGLESv2.dll"
IDR_widevinecdmadapter DLL "res\\bin\\widevinecdmadapter.dll"
定义资源ID
#define IDR_en_US 152
#define IDR_zh_CN 153
#define IDR_YDDemo 154
#define IDR_Unstall_App 155
#define IDR_debug 156
#define IDR_icudtl 157
#define IDR_natives_blob 158
#define IDR_snapshot_blob 159
#define IDR_cef 160
#define IDR_cef_100_percent 161
#define IDR_cef_200_percent 162
#define IDR_cef_extensions 163
#define IDR_devtools_resources 164
#define IDR_d3dcompiler_43 165
#define IDR_d3dcompiler_47 166
#define IDR_DuiLib_u 167
#define IDR_libcef 168
#define IDR_libEGL 169
#define IDR_libGLESv2 170
#define IDR_widevinecdmadapter 171
2)释放资源,并且回调安装进度,更新界面的显示
bool releaseRes(const std::string & file_name, unsigned short res_id, const std::string & file_type);
releaseRes负责释放资源
bool Install::releaseRes(const std::string & file_name, unsigned short res_id, const std::string & file_type){
DWORD dwWrite = ;
HANDLE hFile = CreateFile(Ecoder::stringToWstring(file_name).c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE){
return FALSE;
}
HRSRC hrsc = FindResource(NULL, MAKEINTRESOURCE(res_id), Ecoder::stringToWstring(file_type).c_str());
HGLOBAL hG = LoadResource(NULL, hrsc);
DWORD dwSize = SizeofResource(NULL, hrsc);
WriteFile(hFile, hG, dwSize, &dwWrite, NULL);
CloseHandle(hFile);
return true;
}
设置回调函数
std::function<void(int, const std::string &)> process_fun;
std::function<void()> process_end;
Install::getInstance().setCallBack(std::bind(&MainFrame::setProcessCallBack,this,std::placeholders::_1,std::placeholders::_2),
std::bind(&MainFrame::setupEndCallBack,this));
两个回调函数负责更新资源释放的进度,当然也可以用一个回调函数。
3)注册表操作
写入exe到注册表
bool writeToReg();
创建快捷方式
bool setShortCutLink(const std::string & path, const std::string & link_name, bool is_desktop);
结束安装,启动程序。
std::string str_tmp = m_install_path + "\\";
m_install_path += "\\YDDemo.exe";
ShellExecute(NULL, L"open", Ecoder::stringToWstring(m_install_path).c_str(), NULL, Ecoder::stringToWstring(str_tmp).c_str(), SW_SHOWNORMAL);
卸载过程也是分三部分实现:卸载选择,卸载过程,卸载结束,界面操作如下

界面卸载是通过UnInstall类实现,主要负责注册表的清理,目录文件的删除,程序的自删除以及更新界面进度的职责
#pragma once
#include<string>
#include<functional> class UnInstall
{
public:
UnInstall();
virtual ~UnInstall();
static UnInstall& getInstance(){
static UnInstall instance;
return instance;
}
void setCallBack(const std::function<void(int, const std::string &)> &fun_1, const std::function<void()> &fun_2){
process_fun = fun_1;
process_end = fun_2;
}
bool unInstall();
bool deleteRegKey();
bool deleteDirFile(const std::string & path);
bool deleteApplicationSelf();
private:
std::function<void(int, const std::string &)> process_fun;
std::function<void()> process_end;
};
具体代码可以参考https://github.com/karllen/cef3-duilib-YDDemo/tree/master/Setup_App,因为这个是我学习的Demo,
功能还不是特别完善,图片素材取自网络,如有侵权,联系作者删除。此程序适合入门duilib的C++ 程序员来学习,
程序实现用了C++11的std::thread,std::share_ptr,std::bind等。
技术交流QQ群,欢迎大家加入:347769318
使用duilib开发简单的Window安装包的更多相关文章
- 使用Squirrel创建基于Electron开发的Windows 应用安装包
我们把自己开发的Electron应用发布之前,需要把app打包成简单的安装包,这样app更容易被获取,以此来发布我们的应用.我们可以参考Wix或其他的安装程序,但是对于Electron应用更好的打包程 ...
- Ubuntu 18.04安装arm-linux-gcc交叉编译器(超简单,附安装包下载地址)
目前网上搜索发现,最多人安装的是4.4.3版本的: arm-linux-gcc-4.4.3.tar.gz下载地址:https://pan.baidu.com/s/1rAIBASIRZAXl-P1UOW ...
- ANDROID 开发,安装离线安装包的下载地址及安装方法。
前言: 建议采用离线安装的方法安装SDK包,在线的方式实在是.....多了不解释. 下面说一下离线安装的方法: 1.下载地址:http://pan.baidu.com/s/1sjuJwYD#path= ...
- 为自己编写的windows应用程序制作安装包
1 写好了一个windows程序之后如何制作安装包 这个在vs中就可以直接发布了,可以制作msi的安装包和exe的安装包. 2 window应用程序安装包做了哪些事情 rpm安装包的话,只是把相应的文 ...
- Electron实战:创建ELectron开发的window应用安装包
前言:研究electron自动更新的时候,在electron的官方文档auto-updater 中,提到了在几个平台mac,Linux,windows下electron 的自动更新方法,其中winds ...
- iOS开发——程序员必备&iOS安装包的三种格式 deb、ipa 和 pxl的解释和说明
iOS安装包的三种格式 deb.ipa 和 pxl的解释和说明 目前 iOS 平台上常见的安装包有三种,deb.ipa 和 pxl.转自链接:http://fanlb.blogbus.com/logs ...
- WPF开发时光之痕日记本——终于完工了。。晒晒截图(三)(已上传安装包)
由于是业余时间学习的 WPF 的相关开发且不怎么会使用 Blend 软件,所以开发这个客户端着实花费了我很长时间,比如文本编辑器的开发,最初是在 Simple.HtmlEditor 的基础上做的修改, ...
- 在Visual Studio 2013/2015上使用C#开发Android/IOS安装包和操作步骤
Xamarin 配置手册和离线包下载 http://pan.baidu.com/s/1eQ3qw8a 具体操作: 安装前提条件 1. 安装Visual Studio 2013,安装过程省略,我这里安装 ...
- DevExpress控件库 开发使用经验总结3 制作项目安装包
2015-01-27 使用DevExpress控件包开发C/S项目完成后,部署前需要制作本地安装包.本文还是使用“SetupFactory”安装工厂来制作安装包.在以前的系列文章中详细介绍过该工具的使 ...
随机推荐
- HDU1197 Specialized Four-Digit Numbers
进制转化 hdu1197 #include<cstdio> #include<cstdlib> #include<iostream> #include<mem ...
- [解读REST] 1.REST的起源
0. 世界上第一个网站 1990年12月20日,这一天对于现在的互联网来说意义非凡.欧洲核子研究组织(CREN)的科学家Tim Berners-Lee在一台NeXT电脑上启动了世界上的第一个网站(当然 ...
- 深度学习入门篇--手把手教你用 TensorFlow 训练模型
欢迎大家前往腾讯云技术社区,获取更多腾讯海量技术实践干货哦~ 作者:付越 导语 Tensorflow在更新1.0版本之后多了很多新功能,其中放出了很多用tf框架写的深度网络结构(https://git ...
- session多服务器共享的方案
session的存储了解以前是怎么做的,搞清楚了来龙去脉,才会明白进行共享背后的思想和出发点.我喜欢按照这样的方式来问(或者去搞清楚):为什么要session要进行共享,不共享会什么问题呢? php中 ...
- substance在java swing中使用注意事项
package org.dgw.uidemo; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.UI ...
- Linux入门(4)——Ubuntu16.04安装MATLAB2016b
通常有三个安装文件: Matlab 2016b Linux64 Crack.rar R2016b_glnxa64_dvd1.iso R2016b_glnxa64_dvd2.iso sudo apt i ...
- Java 递归调用 recursive 给一个参数 返回一大堆
需求: 需要组装成对象多层嵌套式的 json字符串; 想到使用 递归来完成这个多层嵌套: 憋了四个小时,终于写出来了; 先看效果: 数据库中的数据: 拼装后的效果: [ EmpVO{ ename='孙 ...
- PHP异常处理机制
1. 异常: 异常(Exception)用于在指定的错误发生时改变脚本的正常流程. 当异常被触发时,通常会发生: (1)当前代码状态被保存: (2)代码执行被切换到预定义的异常处理器函数: (3)根据 ...
- Java常用类(四)之数组工具类Arrays
前言 数组的工具类java.util.Arrays 由于数组对象本身并没有什么方法可以供我们调用,但API中提供了一个工具类Arrays供我们使用,从而可以对数据对象进行一些基本的操作. 一.Arra ...
- 基于场景解析RecyclerView的回收复用机制原理
最近在研究 RecyclerView 的回收复用机制,顺便记录一下.我们知道,RecyclerView 在 layout 子 View 时,都通过回收复用机制来管理.网上关于回收复用机制的分析讲解的文 ...