From c72b16e7fe421b5241a342419959a9e600cdbf1b Mon Sep 17 00:00:00 2001 From: taynpg Date: Sun, 15 Mar 2026 10:53:21 +0800 Subject: [PATCH] =?UTF-8?q?fileUpdater=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitmodules | 3 +++ CMakeLists.txt | 1 + fileUpdater/CMakeLists.txt | 1 + fileUpdater/main.cpp | 45 ++++++++++++++++++++++++++++++-------- zoost | 1 + 5 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 .gitmodules create mode 160000 zoost diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b275c48 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "zoost"] + path = zoost + url = https://www.sinxmiao.cn/taynpg/zoost diff --git a/CMakeLists.txt b/CMakeLists.txt index 41a2d12..a5f2690 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,5 +11,6 @@ if (MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() +add_subdirectory(zoost) add_subdirectory(strReplace) add_subdirectory(fileUpdater) \ No newline at end of file diff --git a/fileUpdater/CMakeLists.txt b/fileUpdater/CMakeLists.txt index 330ce4d..769b632 100644 --- a/fileUpdater/CMakeLists.txt +++ b/fileUpdater/CMakeLists.txt @@ -41,6 +41,7 @@ target_link_libraries(fileUpdater PRIVATE CLI11::CLI11 spdlog::spdlog tinyxml2::tinyxml2 + zoost ) include(GNUInstallDirs) diff --git a/fileUpdater/main.cpp b/fileUpdater/main.cpp index 3cbe05e..28cd9a0 100644 --- a/fileUpdater/main.cpp +++ b/fileUpdater/main.cpp @@ -1,25 +1,25 @@ #include #include #include -#include -#include #include #include #include #include #include +#include #include #include #include #include #include #include +#include #ifdef _WIN32 #include #endif -namespace fs = boost::filesystem; +namespace fs = std::filesystem; namespace xml = tinyxml2; // 文件映射结构 @@ -52,12 +52,33 @@ private: std::vector mappings; std::shared_ptr logger; std::string markerDir; // 标记目录名 + std::string logPath_; + std::string logName_{"fileUpdater.log"}; public: AutoUpdateTool() { - logger = spdlog::stdout_color_mt("AutoUpdate"); - logger->set_pattern("[%H:%M:%S.%e] %^[%l] %v%$"); + zoostPath zp; + if (!zp.GetConfigFile("fileUpdater", logName_, logPath_)) { + boost::nowide::cerr << "获取日志文件路径失败。" << std::endl; + exit(1); + } + if (!zoostFs::exists((zp.GetParentPath(logPath_)))) { + if (!zp.CreateConfigDir("fileUpdater")) { + boost::nowide::cerr << "创建配置目录失败。" << std::endl; + exit(1); + } + } + + auto file_sink = std::make_shared(logPath_, 1024 * 1024 * 50, 3); + auto console_sink = std::make_shared(); + file_sink->set_pattern("[%Y-%m-%d %H:%M:%S.%e][%l]: %v"); + console_sink->set_pattern("[%H:%M:%S.%e] %^[%l] %v%$"); + + std::vector sinks{file_sink, console_sink}; + logger = std::make_shared(logName_, sinks.begin(), sinks.end()); + logger->set_level(spdlog::level::debug); + spdlog::register_logger(logger); } // 解析命令行参数 @@ -94,6 +115,14 @@ public: backupDir = fs::absolute(backupDir); } + std::string rec; + for (int i = 1; i < argc; i++) { + rec += argv[i]; + rec += " "; + } + + logger->debug("原始参数: {}", rec); + logger->debug("CMD目录: {}", zoostFs::current_path().string()); logger->info("工作目录: {}", workDir.string()); logger->info("更新目录: {}", updateDir.string()); logger->info("备份目录: {}", backupDir.string()); @@ -447,11 +476,9 @@ public: int main(int argc, char** argv) { -#ifdef _WIN32 - SetConsoleOutputCP(CP_UTF8); -#endif + zoostCommon::SetOutputU8(); + zoostCommon::SetStdLibrayU8(); - boost::nowide::nowide_filesystem(); AutoUpdateTool tool; if (tool.parseArguments(argc, argv)) { diff --git a/zoost b/zoost new file mode 160000 index 0000000..fd57d59 --- /dev/null +++ b/zoost @@ -0,0 +1 @@ +Subproject commit fd57d590bc2e3776704fbb942f429dcae7ada833