fileUpdater:添加操作历史记录保存。
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "zoost"]
|
||||
path = zoost
|
||||
url = https://www.sinxmiao.cn/taynpg/zoost
|
||||
@@ -11,5 +11,6 @@ if (MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
add_subdirectory(zoost)
|
||||
add_subdirectory(strReplace)
|
||||
add_subdirectory(fileUpdater)
|
||||
@@ -41,6 +41,7 @@ target_link_libraries(fileUpdater PRIVATE
|
||||
CLI11::CLI11
|
||||
spdlog::spdlog
|
||||
tinyxml2::tinyxml2
|
||||
zoost
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
#include <CLI/CLI.hpp>
|
||||
#include <algorithm>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/nowide/filesystem.hpp>
|
||||
#include <boost/nowide/iostream.hpp>
|
||||
#include <chrono>
|
||||
#include <fileUpdaterVer.h>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <spdlog/sinks/rotating_file_sink.h>
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <tinyxml2.h>
|
||||
#include <vector>
|
||||
#include <zoost.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
namespace fs = std::filesystem;
|
||||
namespace xml = tinyxml2;
|
||||
|
||||
// 文件映射结构
|
||||
@@ -52,12 +52,33 @@ private:
|
||||
std::vector<FileMapping> mappings;
|
||||
std::shared_ptr<spdlog::logger> 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<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);
|
||||
}
|
||||
|
||||
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)) {
|
||||
|
||||
1
zoost
Submodule
1
zoost
Submodule
Submodule zoost added at fd57d590bc
Reference in New Issue
Block a user