fileUpdater:添加操作历史记录保存。

This commit is contained in:
2026-03-15 10:53:21 +08:00
parent 80edf30ce3
commit c72b16e7fe
5 changed files with 42 additions and 9 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "zoost"]
path = zoost
url = https://www.sinxmiao.cn/taynpg/zoost

View File

@@ -11,5 +11,6 @@ if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif() endif()
add_subdirectory(zoost)
add_subdirectory(strReplace) add_subdirectory(strReplace)
add_subdirectory(fileUpdater) add_subdirectory(fileUpdater)

View File

@@ -41,6 +41,7 @@ target_link_libraries(fileUpdater PRIVATE
CLI11::CLI11 CLI11::CLI11
spdlog::spdlog spdlog::spdlog
tinyxml2::tinyxml2 tinyxml2::tinyxml2
zoost
) )
include(GNUInstallDirs) include(GNUInstallDirs)

View File

@@ -1,25 +1,25 @@
#include <CLI/CLI.hpp> #include <CLI/CLI.hpp>
#include <algorithm> #include <algorithm>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <boost/nowide/filesystem.hpp>
#include <boost/nowide/iostream.hpp> #include <boost/nowide/iostream.hpp>
#include <chrono> #include <chrono>
#include <fileUpdaterVer.h> #include <fileUpdaterVer.h>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h> #include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <tinyxml2.h> #include <tinyxml2.h>
#include <vector> #include <vector>
#include <zoost.h>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#endif #endif
namespace fs = boost::filesystem; namespace fs = std::filesystem;
namespace xml = tinyxml2; namespace xml = tinyxml2;
// 文件映射结构 // 文件映射结构
@@ -52,12 +52,33 @@ private:
std::vector<FileMapping> mappings; std::vector<FileMapping> mappings;
std::shared_ptr<spdlog::logger> logger; std::shared_ptr<spdlog::logger> logger;
std::string markerDir; // 标记目录名 std::string markerDir; // 标记目录名
std::string logPath_;
std::string logName_{"fileUpdater.log"};
public: public:
AutoUpdateTool() AutoUpdateTool()
{ {
logger = spdlog::stdout_color_mt("AutoUpdate"); zoostPath zp;
logger->set_pattern("[%H:%M:%S.%e] %^[%l] %v%$"); 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<spdlog::sinks::rotating_file_sink_mt>(logPath_, 1024 * 1024 * 50, 3);
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
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<spdlog::sink_ptr> sinks{file_sink, console_sink};
logger = std::make_shared<spdlog::logger>(logName_, sinks.begin(), sinks.end());
logger->set_level(spdlog::level::debug);
spdlog::register_logger(logger);
} }
// 解析命令行参数 // 解析命令行参数
@@ -94,6 +115,14 @@ public:
backupDir = fs::absolute(backupDir); 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("工作目录: {}", workDir.string());
logger->info("更新目录: {}", updateDir.string()); logger->info("更新目录: {}", updateDir.string());
logger->info("备份目录: {}", backupDir.string()); logger->info("备份目录: {}", backupDir.string());
@@ -447,11 +476,9 @@ public:
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
#ifdef _WIN32 zoostCommon::SetOutputU8();
SetConsoleOutputCP(CP_UTF8); zoostCommon::SetStdLibrayU8();
#endif
boost::nowide::nowide_filesystem();
AutoUpdateTool tool; AutoUpdateTool tool;
if (tool.parseArguments(argc, argv)) { if (tool.parseArguments(argc, argv)) {

1
zoost Submodule

Submodule zoost added at fd57d590bc