Skip to content

Commit

Permalink
windows上测试通过
Browse files Browse the repository at this point in the history
  • Loading branch information
da1234cao committed Mar 25, 2023
1 parent c27e4ca commit cf923b2
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 36 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" /MT)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_RELEASE}" /MTd)
endif()
add_subdirectory(UI/domain_block_client)
add_subdirectory(windows/WFP)
else()
add_subdirectory(UI/domain_block_client)
Expand Down
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@



```json
{
"name": "dacao",
Expand All @@ -17,4 +18,41 @@
}
```

```shell
## 编译与打包

### linux平台

```shell
mkdir build && cd build
cmake ..
make package
```

### windwos平台

windows下面的打包有点麻烦。

* qt程序没有打包成安装包,通过脚本执行windeployqt,生成一个免安装版本。

* 驱动程序,没有接入cmake管理,得使用vs打开进行编译。

* 上面程序编译通过后,使用inno setup进行打包

```shell
mkdir build && cd build
cmake -G "Visual Studio 16 2019" -A x64 ..
cmake --build . --config Release

# 生成windows的qt免安装包
## 进入项目的\package\windows目录,运行
### 输出qt程序在ui-output目录
python .\ui.py

# 生成驱动
## 进入项目的windows\WFP\block目录,使用visiual studio打开项目
### 进行编译

## 当上面编译完成后
### 使用inno setup,打开\package\windows\service.iss
### 输出安装包在service-output目录
```
6 changes: 6 additions & 0 deletions UI/domain_block_client/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QPushButton>
#include <QString>
#include <QTcpSocket>
#include <QTextStream>
#include <QtNetwork/QHostInfo>

void rules::set_default_info_path() {
Expand Down Expand Up @@ -155,7 +156,12 @@ void rules::save_info_to_file() {
QTextStream stream(&rules_file);
for (auto &info : m_rules_info) {
// 获取tuple的最后一个元素有点麻烦,这里直接使用数字
#ifdef _WIN32
stream << std::get<0>(info) << m_separator << std::get<1>(info)
<< Qt::endl;
#else
stream << std::get<0>(info) << m_separator << std::get<1>(info) << endl;
#endif
}
rules_file.close();
}
Expand Down
11 changes: 0 additions & 11 deletions bin/config.toml

This file was deleted.

Binary file removed bin/domain_block_client
Binary file not shown.
Binary file removed bin/domain_block_service
Binary file not shown.
Binary file removed bin/libspdlog.a
Binary file not shown.
6 changes: 3 additions & 3 deletions package/windows/service.iss
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.i
; 安装服务程序
; flag的参数分别是:
; ignoreversion指定在替换同版本的应用程序文件时不弹出提示
Source: "..\..\bin\Debug\domain_block_service.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\..\bin\Debug\block.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\..\bin\Debug\config.toml"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\..\bin\Release\domain_block_service.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\..\bin\Release\block.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\..\windows\WFP\service\domain_block_service.toml"; DestDir: "{app}"; Flags: ignoreversion

; 安装驱动程序
Source: "..\..\windows\WFP\block\x64\Debug\block.sys"; DestDir: "{app}"; Flags: restartreplace ignoreversion
Expand Down
6 changes: 3 additions & 3 deletions package/windows/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def copy_files_and_dirs(src_dir, dst_dir, items):

if __name__ == '__main__':
# 拷贝需要的二进制文件
bin_dir = "../../UI/build-domain_block_client-Desktop_Qt_6_4_2_MSVC2019_64bit-Release"
bin_dir = "../../bin/Release"
dst_dir = "ui-output"
items = [
'domain_block_client.exe'
Expand All @@ -45,11 +45,11 @@ def copy_files_and_dirs(src_dir, dst_dir, items):
# 拷贝需要的资源文件
res_dir = "../../UI/domain_block_client"
items = [
'domain_block.ini'
'domain_block_client.ini'
]
copy_files_and_dirs(res_dir, dst_dir, items)

# 进入output目录
# 进入ui-output目录
os.chdir(dst_dir)
result = subprocess.run(
["windeployqt", "domain_block_client.exe"], capture_output=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 日志文件
[log]
path = 'C:\domain_block_services.log'
path = 'C:\ProgramData\domain_block_service\log.txt'
level = 'trace'
max_file_size = '1' # MB单位
max_files = '3'
Expand Down
36 changes: 19 additions & 17 deletions windows/WFP/service/main.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#include "service.hpp"

int main(int argc, char* argv[]) {
boost::filesystem::path cur_path = boost::dll::program_location().parent_path();
boost::filesystem::path cfg_path = cur_path / "config.toml";
std::cout << cfg_path.string() << std::endl;
// 解析配置文件
config::instance().parse_toml(cfg_path);
int main(int argc, char *argv[]) {
boost::filesystem::path cur_path =
boost::dll::program_location().parent_path();
boost::filesystem::path cfg_path = cur_path / "domain_block_service.toml";
std::cout << cfg_path.string() << std::endl;
// 解析配置文件
config::instance().parse_toml(cfg_path);

// 初始化日志配置
std::string log_file_path = config::instance().get_str("log_file_path");
std::string log_level = config::instance().get_str("log_level");
int max_log_files = config::instance().get_int("max_log_files");
int max_log_file_size = config::instance().get_int("max_log_file_size");
Log::SPDLOG::getInstance().init(log_file_path, "default_logger", log_level,
max_log_file_size * 1024 * 1024, max_log_files, false);
LOG_DEBUG("log has inited.");
service::start();
LOG_DEBUG("process end.");
return 0;
// 初始化日志配置
std::string log_file_path = config::instance().get_str("log_file_path");
std::string log_level = config::instance().get_str("log_level");
int max_log_files = config::instance().get_int("max_log_files");
int max_log_file_size = config::instance().get_int("max_log_file_size");
Log::SPDLOG::getInstance().init(log_file_path, "default_logger", log_level,
max_log_file_size * 1024 * 1024,
max_log_files, false);
LOG_DEBUG("log has inited.");
service::start();
LOG_DEBUG("process end.");
return 0;
}

0 comments on commit cf923b2

Please sign in to comment.