使用duilib开发简单的Window安装包

一、具体思路

安装过程:安装包的制作包括资源文件的打包,资源文件打包到安装包exe中,安装的时候需要从exe中提取出对应的资源文件,

然后解压文件安装到指定目录,然后就是对安装的可执行程序进行注册表的注册,以及快捷方式的注册。

卸载过程:安装包安装时,通常会带有一个卸载程序,此程序的功能就是执行对安装程序目录文件的删除和注册表的清除。

二、实现

安装过程分为三部分实现,安装配置,安装过程,安装结束启动程序。

安装配置界面如下:

安装过程实现:

Install类负责对打包文件的释放,注册表的写入,快捷方式的写入,以及回调界面进度的职责:

 1 #pragma once
 2 #include<string>
 3 #include<functional>
 4
 5 class Install
 6 {
 7 public:
 8     Install();
 9     virtual ~Install();
10     static Install& getInstance(){
11         static Install instance;
12         return instance;
13     }
14     void setStop(){
15         m_stop = true;
16     }
17     bool install(const std::string & install_path, bool is_shortcut);
18     void setCallBack(const std::function<void(int, const std::string &)>  &fun_1,const std::function<void()> &fun_2){
19         process_fun = fun_1;
20         process_end = fun_2;
21     }
22 private:
23     bool releaseRes(const std::string & file_name, unsigned short res_id, const std::string & file_type);
24     bool setShortCutLink(const std::string & path, const std::string & link_name, bool is_desktop);
25     bool writeToReg();
26     std::string getDesktopPath();
27     std::string getStartMenuPath();
28 private:
29     std::function<void(int, const std::string &)> process_fun;
30     std::function<void()> process_end;
31     std::string m_install_path;
32     bool m_stop;
33
34 };

1)导入资源到exe,

.rc文件添加资源,

 1 IDR_en_US              APK                    "res\\bin\\locales\\en-US.pak"
 2 IDR_zh_CN              APK                    "res\\bin\\locales\\zh-CN.pak"
 3
 4 /////////////////////////////////////////////////////////////////////////////
 5 //
 6 // EXE
 7 //
 8
 9 IDR_YDDemo                  EXE                     "res\\bin\\YDDemo.exe"
10 IDR_Unstall_App             EXE                     "res\\bin\\Unstall_App.exe"
11 IDR_debug                   LOG                     "res\\bin\\debug.log"
12 IDR_icudtl                  DAT                     "res\\bin\\icudtl.dat"
13 IDR_natives_blob            BIN                     "res\\bin\\natives_blob.bin"
14 IDR_snapshot_blob           BIN                     "res\\bin\\snapshot_blob.bin"
15 IDR_cef                     APK                     "res\\bin\\cef.pak"
16 IDR_cef_100_percent         APK                     "res\\bin\\cef_100_percent.pak"
17 IDR_cef_200_percent         APK                     "res\\bin\\cef_200_percent.pak"
18 IDR_cef_extensions          APK                     "res\\bin\\cef_extensions.pak"
19 IDR_devtools_resources      APK                     "res\\bin\\devtools_resources.pak"
20 /////////////////////////////////////////////////////////////////////////////
21 //
22 // DLL
23 //
24
25 IDR_d3dcompiler_43          DLL                     "res\\bin\\d3dcompiler_43.dll"
26 IDR_d3dcompiler_47          DLL                     "res\\bin\\d3dcompiler_47.dll"
27 IDR_DuiLib_u                DLL                     "res\\bin\\DuiLib_u.dll"
28 IDR_libcef                  DLL                     "res\\bin\\libcef.dll"
29 IDR_libEGL                  DLL                     "res\\bin\\libEGL.dll"
30 IDR_libGLESv2               DLL                     "res\\bin\\libGLESv2.dll"
31 IDR_widevinecdmadapter      DLL                     "res\\bin\\widevinecdmadapter.dll"

定义资源ID

 1 #define IDR_en_US                       152
 2 #define IDR_zh_CN                       153
 3 #define IDR_YDDemo                      154
 4 #define IDR_Unstall_App                 155
 5 #define IDR_debug                       156
 6 #define IDR_icudtl                      157
 7 #define IDR_natives_blob                158
 8 #define IDR_snapshot_blob               159
 9 #define IDR_cef                         160
10 #define IDR_cef_100_percent             161
11 #define IDR_cef_200_percent             162
12 #define IDR_cef_extensions              163
13 #define IDR_devtools_resources          164
14 #define IDR_d3dcompiler_43              165
15 #define IDR_d3dcompiler_47              166
16 #define IDR_DuiLib_u                    167
17 #define IDR_libcef                      168
18 #define IDR_libEGL                      169
19 #define IDR_libGLESv2                   170
20 #define IDR_widevinecdmadapter          171

2)释放资源,并且回调安装进度,更新界面的显示

1 bool releaseRes(const std::string & file_name, unsigned short res_id, const std::string & file_type);

releaseRes负责释放资源

 1 bool Install::releaseRes(const std::string & file_name, unsigned short res_id, const std::string & file_type){
 2     DWORD   dwWrite = 0;
 3     HANDLE  hFile = CreateFile(Ecoder::stringToWstring(file_name).c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
 4         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 5     if (hFile == INVALID_HANDLE_VALUE){
 6         return FALSE;
 7     }
 8     HRSRC   hrsc = FindResource(NULL, MAKEINTRESOURCE(res_id), Ecoder::stringToWstring(file_type).c_str());
 9     HGLOBAL hG = LoadResource(NULL, hrsc);
10     DWORD   dwSize = SizeofResource(NULL, hrsc);
11     WriteFile(hFile, hG, dwSize, &dwWrite, NULL);
12     CloseHandle(hFile);
13     return true;
14 }

设置回调函数

    std::function<void(int, const std::string &)> process_fun;
    std::function<void()> process_end;
1 Install::getInstance().setCallBack(std::bind(&MainFrame::setProcessCallBack,this,std::placeholders::_1,std::placeholders::_2),
2                                        std::bind(&MainFrame::setupEndCallBack,this));

两个回调函数负责更新资源释放的进度,当然也可以用一个回调函数。

3)注册表操作

写入exe到注册表

1     bool writeToReg();

创建快捷方式

    bool setShortCutLink(const std::string & path, const std::string & link_name, bool is_desktop);

结束安装,启动程序。

1     std::string str_tmp = m_install_path + "\\";
2         m_install_path += "\\YDDemo.exe";
3         ShellExecute(NULL, L"open", Ecoder::stringToWstring(m_install_path).c_str(), NULL, Ecoder::stringToWstring(str_tmp).c_str(), SW_SHOWNORMAL);

卸载过程也是分三部分实现:卸载选择,卸载过程,卸载结束,界面操作如下

界面卸载是通过UnInstall类实现,主要负责注册表的清理,目录文件的删除,程序的自删除以及更新界面进度的职责

 1 #pragma once
 2 #include<string>
 3 #include<functional>
 4
 5 class UnInstall
 6 {
 7 public:
 8     UnInstall();
 9     virtual ~UnInstall();
10     static UnInstall& getInstance(){
11         static UnInstall instance;
12         return instance;
13     }
14     void setCallBack(const std::function<void(int, const std::string &)>  &fun_1, const std::function<void()> &fun_2){
15         process_fun = fun_1;
16         process_end = fun_2;
17     }
18     bool unInstall();
19     bool deleteRegKey();
20     bool deleteDirFile(const std::string & path);
21     bool deleteApplicationSelf();
22 private:
23     std::function<void(int, const std::string &)> process_fun;
24     std::function<void()> process_end;
25 };

具体代码可以参考https://github.com/karllen/cef3-duilib-YDDemo/tree/master/Setup_App,因为这个是我学习的Demo,

功能还不是特别完善,图片素材取自网络,如有侵权,联系作者删除。此程序适合入门duilib的C++ 程序员来学习,

程序实现用了C++11的std::thread,std::share_ptr,std::bind等。

时间: 2024-08-30 12:41:39

使用duilib开发简单的Window安装包的相关文章

duilib开发简单的Window安装包

一.具体思路 安装过程:安装包的制作包括资源文件的打包,资源文件打包到安装包exe中,安装的时候需要从exe中提取出对应的资源文件, 然后解压文件安装到指定目录,然后就是对安装的可执行程序进行注册表的注册,以及快捷方式的注册. 卸载过程:安装包安装时,通常会带有一个卸载程序,此程序的功能就是执行对安 http://p.baidu.com/itopic/main/qlog?qid=58d76162633533366531313500&type=questionloghttp://p.baidu.c

大数据开发环境需要的安装包合集,亲测没问题

大数据环境需要的安装包合集,包括: apache-flume-1.7.0-bin.tar.gz apache-hive-1.2.1-bin.tar.gz hadoop-2.7.2.tar.gz hbase-1.3.1-bin.tar.gz jdk-8u144-linux-x64.tar kafka_2.11-0.11.0.2.tgz mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar scala-2.11.8.tgz spark-2.1.1-bin-hadoop2.

ANDROID 开发,安装离线安装包的下载地址及安装方法。

前言: 建议采用离线安装的方法安装SDK包,在线的方式实在是.....多了不解释. 下面说一下离线安装的方法: 1.下载地址:http://pan.baidu.com/s/1sjuJwYD#path=%252Fandroid%2520SDK%25E7%25A6%25BB%25E7%25BA%25BF%25E5%25AE%2589%25E8%25A3%2585%25E5%258C%2585%25E6%2589%2580%25E6%259C%2589zip.建议全部下载. 2.安装方法: 安装方法(

Unity3D游戏开发之如何减少安装包大小

第一步要做的就是:看看哪些文件是最占空间的,那么它们就是首选优化对象了. 你可以在刚刚完成一次build之后在"Editor Log"中找到这些信息. 如何打开Editor Log: 在Mac上看起来就是这样的了: 可以看出这份log提供了一份资源总括:各种类型资源的总大小,以及所占百分比.同时还降序列出了单个文件的大小. 更多精彩请点击[狗刨学习网] 顺带一提,资源类型中的"File headers"它们并不是资源本身,而是加在原始资源上,用来存储"引用

为自己编写的windows应用程序制作安装包

1 写好了一个windows程序之后如何制作安装包 这个在vs中就可以直接发布了,可以制作msi的安装包和exe的安装包. 2 window应用程序安装包做了哪些事情 rpm安装包的话,只是把相应的文件拷贝到不同的目录.那么window安装包做了什么呢? msi里面有一个table,里面是一条条的指令,windows installer会解释并执行这些指令. 它还是会把安装包里面的文件拷贝到相应的目录.关键是它除了拷贝还做了哪些事情呢? 3 安装包除了把相应的文件放到不同的目录下,还做了哪些事情

Wix 快速开发安装包程序 (四)使用简单的UI

前面总结了一些 wix 制作安装包最基本的一些功能,虽然也可以成功产出安装包. 不过这样的安装包既没有UI设计,也没有任何和用户的任何交互,连安装位置也不能修改. 这一小节,简单的使用 wix 提供的一个内置模板,做一个能看的安装包. 1. 工程添加 wix dll 的引用 2.  使用 WixUI_Mondo <UIRef Id="WixUI_Mondo" /> <UIRef Id="WixUI_ErrorProgressText" />

Electron实战:创建ELectron开发的window应用安装包

前言:研究electron自动更新的时候,在electron的官方文档auto-updater 中,提到了在几个平台mac,Linux,windows下electron 的自动更新方法,其中windsow平台上面,文章中建议先用grunt-electron-installer 模块来创建windows安装包,grunt这个工具是由Squirrel集成的.进而了解下Squirrel这个工具, 一个可以用来给electron应用的安装更新卸载添加快捷方式的工具.本文主要提及如何在windows平台下

DevExpress控件库 开发使用经验总结3 制作项目安装包

2015-01-27 使用DevExpress控件包开发C/S项目完成后,部署前需要制作本地安装包.本文还是使用“SetupFactory”安装工厂来制作安装包.在以前的系列文章中详细介绍过该工具的使用,请参考http://www.cnblogs.com/SavionZhang/p/4106338.html. 实际情景:SetupFactory V9.0.3.DevExpress14.1.8.依赖程序.Net Framework 4.0. 由于项目中引用了很多DevExpress控件库中的DLL

iOS开发——程序员必备&amp;iOS安装包的三种格式 deb、ipa 和 pxl的解释和说明

iOS安装包的三种格式 deb.ipa 和 pxl的解释和说明 目前 iOS 平台上常见的安装包有三种,deb.ipa 和 pxl.转自链接:http://fanlb.blogbus.com/logs/80466716.html  多谢作者分享!其中 deb 格式是 Debian 系统(包含 Debian 和 Ubuntu )专属安装包格式,配合 APT 软件管理系统,成为了当前在 Linux 下非常流行的一种安装包.进入 2.x 时代之后有 Cydia 作者 Jay Freeman(sauri