添加默认配置生成功能。

This commit is contained in:
2026-03-15 11:23:17 +08:00
parent c72b16e7fe
commit 7a4036490c

View File

@@ -84,8 +84,9 @@ public:
// 解析命令行参数 // 解析命令行参数
bool parseArguments(int argc, char** argv) bool parseArguments(int argc, char** argv)
{ {
auto msg = fmt::format("fileUpdater - 文件更新工具 \n\n {} on {} at {} {}", VERSION_GIT_COMMIT, VERSION_GIT_BRANCH, auto notice = "使用特殊参数 default 可生成一个默认配置文件模板。";
__DATE__, __TIME__); auto msg = fmt::format("fileUpdater - 文件更新工具 \n\n {} on {} at {} {}\n{}", VERSION_GIT_COMMIT, VERSION_GIT_BRANCH,
__DATE__, __TIME__, notice);
CLI::App app{msg}; CLI::App app{msg};
argv = app.ensure_utf8(argv); argv = app.ensure_utf8(argv);
@@ -479,6 +480,28 @@ int main(int argc, char** argv)
zoostCommon::SetOutputU8(); zoostCommon::SetOutputU8();
zoostCommon::SetStdLibrayU8(); zoostCommon::SetStdLibrayU8();
if (argc > 1) {
std::string specialStr = argv[1];
if (specialStr == "default") {
std::string defaultContent =
R"(<?xml version="1.0" encoding="UTF-8"?>
<AutoUpdate>
<!-- -->
<FileMapping m="a.txt" n="c/d/a.txt" type="file" ext=""/>
<FileMapping m="" n="mm" type="dir" ext="txt|xml"/>
</AutoUpdate>)";
std::ifstream ifs("fileUpdater.xml");
if (!ifs) {
std::ofstream ofs("fileUpdater.xml");
ofs << defaultContent;
ofs.close();
}
ifs.close();
boost::nowide::cout << "已生成默认配置文件: fileUpdater.xml" << std::endl;
return 0;
}
}
AutoUpdateTool tool; AutoUpdateTool tool;
if (tool.parseArguments(argc, argv)) { if (tool.parseArguments(argc, argv)) {