From 52a45cd6818202aa646782cf9a04ac56193f7595 Mon Sep 17 00:00:00 2001 From: LuChao Date: Sat, 1 Jun 2024 15:01:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/wxhelper/src/wxhelper.cc | 62 ++++++++++++++++++++++++++++-------- app/wxhelper/src/wxhelper.h | 30 +++++++++++++---- 2 files changed, 73 insertions(+), 19 deletions(-) diff --git a/app/wxhelper/src/wxhelper.cc b/app/wxhelper/src/wxhelper.cc index e2cede3..1f9a867 100644 --- a/app/wxhelper/src/wxhelper.cc +++ b/app/wxhelper/src/wxhelper.cc @@ -9,21 +9,57 @@ #include "wechat_db.h" #include "sync_msg_hook.h" #include "wechat_service.h" -namespace wxhelper { + +// 引入其他头文件,这里包含了配置、HTTP服务器、线程池、工具函数等模块 + +namespace wxhelper { // 定义wxhelper命名空间,包含wxhelper相关的函数和类 void WxHelper::init(HMODULE module) { - Config::GetInstance().init(); - if (Config::GetInstance().GetHideDll()) { - base::utils::HideModule(module); + // 打印初始化配置信息 + // wxhelper::wxutils::print_utf8_to_console("Config initialization start"); // 调用wxutils命名空间中的print_utf8_to_console函数,打印配置初始化开始信息 + + Config::GetInstance().init(); // 获取Config类的单例对象并调用其init函数,进行配置初始化 + + // 打印模块隐藏状态 + // wxhelper::wxutils::print_utf8_to_console("Module hiding check"); // 打印模块隐藏检查信息 + + if (Config::GetInstance().GetHideDll()) { // 判断配置中是否需要隐藏模块 + // wxhelper::wxutils::print_utf8_to_console("Hiding module"); // 如果需要隐藏,则打印隐藏模块信息 + base::utils::HideModule(module); // 调用base命名空间中utils的HideModule函数,隐藏模块 } - wechat::WeChatDb::GetInstance().Init(); - wechat::WeChatService::GetInstance().Init(); - SyncMsgHook::GetInstance().Init(); - http::HttpServer::GetInstance().init( - Config::GetInstance().GetHttpServerHost(), - Config::GetInstance().GetHttpServerPort()); - http::HttpServer::GetInstance().Start(); - base::ThreadPool::GetInstance().Create(2, 8); + + // 打印微信数据库初始化信息 + // wxhelper::wxutils::print_utf8_to_console("WeChatDb initialization start"); // 打印微信数据库初始化开始信息 + wechat::WeChatDb::GetInstance().Init(); // 获取WeChatDb类的单例对象并调用其Init函数,进行微信数据库初始化 + + // 打印WeChat服务初始化信息 + // wxhelper::wxutils::print_utf8_to_console("WeChatService initialization start"); // 打印WeChat服务初始化开始信息 + wechat::WeChatService::GetInstance().Init(); // 获取WeChatService类的单例对象并调用其Init函数,进行WeChat服务初始化 + + // 打印消息同步钩子初始化信息 + // wxhelper::wxutils::print_utf8_to_console("SyncMsgHook initialization start"); // 打印消息同步钩子初始化开始信息 + SyncMsgHook::GetInstance().Init(); // 获取SyncMsgHook类的单例对象并调用其Init函数,进行消息同步钩子初始化 + + // 获取HTTP服务器配置并打印 + // wxhelper::wxutils::print_utf8_to_console("HttpServer initialization start"); // 打印HTTP服务器初始化开始信息 + std::string host = Config::GetInstance().GetHttpServerHost(); // 获取配置中的HTTP服务器主机地址 + int port = Config::GetInstance().GetHttpServerPort(); // 获取配置中的HTTP服务器端口 + // wxhelper::wxutils::print_utf8_to_console("HttpServer host: " + host + ", port: " + std::to_string(port)); // 打印HTTP服务器主机和端口信息 + http::HttpServer::GetInstance().init(Config::GetInstance().GetHttpServerHost(), port); // 获取HttpServer类的单例对象并调用其init函数,初始化HTTP服务器 + + // 打印HTTP服务器启动信息 + // wxhelper::wxutils::print_utf8_to_console("HttpServer start"); // 打印HTTP服务器启动信息 + http::HttpServer::GetInstance().Start(); // 调用HttpServer类的Start函数,启动HTTP服务器 + + // 打印线程池创建信息 + wxhelper::wxutils::print_utf8_to_console("Thread pool creation start"); // 打印线程池创建开始信息 + base::ThreadPool::GetInstance().Create(2, 8); // 获取ThreadPool类的单例对象并调用其Create函数,创建线程池,参数为最小线程数和最大线程数 } -void WxHelper::finally() { http::HttpServer::GetInstance().Stop(); } + +void WxHelper::finally() { + // 打印HTTP服务器停止信息 + wxhelper::wxutils::print_utf8_to_console("HttpServer stop"); // 打印HTTP服务器停止信息 + http::HttpServer::GetInstance().Stop(); // 获取HttpServer类的单例对象并调用其Stop函数,停止HTTP服务器 +} + } // namespace wxhelper \ No newline at end of file diff --git a/app/wxhelper/src/wxhelper.h b/app/wxhelper/src/wxhelper.h index 49b80f5..552d554 100644 --- a/app/wxhelper/src/wxhelper.h +++ b/app/wxhelper/src/wxhelper.h @@ -1,14 +1,32 @@ - +// 定义了一个预处理宏,用于防止头文件被重复包含 #ifndef WXHELPER_WXHELPER_H_ #define WXHELPER_WXHELPER_H_ + +// 包含Windows.h头文件,用于Windows应用程序接口 #include +// 引入单例模式的实现,singleton.h文件中定义了如何实现一个单例类 #include "singleton.h" -namespace wxhelper { - class WxHelper : public base::Singleton{ + +// 定义一个名为wxhelper的命名空间,用于组织相关的类和函数 +namespace wxhelper +{ + + // 定义了一个名为WxHelper的类,继承自base::Singleton + // 这意味着WxHelper类将遵循单例模式,即全局只有一个实例 + class WxHelper : public base::Singleton + { public: - void init(HMODULE module); - void finally(); + // WxHelper类的公有成员函数,用于初始化WxHelper实例 + void init(HMODULE module); + // 初始化函数的实现,这里接受一个HMODULE类型的参数module + // 这个参数通常是一个模块的句柄,用于加载或初始化相关资源 + + // WxHelper类的公有成员函数,用于清理或释放WxHelper实例使用的资源 + void finally(); + // 最终化函数的实现,用于在程序结束前清理或释放资源 }; } -#endif \ No newline at end of file + +// 结束命名空间wxhelper +#endif // WXHELPER_WXHELPER_H_ \ No newline at end of file