Compare commits
5 Commits
80edf30ce3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ecb188a04 | |||
| 8e7c1408f7 | |||
| 5b18af4279 | |||
| 7a4036490c | |||
| c72b16e7fe |
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[submodule "zoost"]
|
||||
path = zoost
|
||||
url = https://www.sinxmiao.cn/taynpg/zoost
|
||||
[submodule "cxxLibrary"]
|
||||
path = cxxLibrary
|
||||
url = https://www.sinxmiao.cn/taynpg/cxxLibrary
|
||||
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"files.autoSave": "onFocusChange",
|
||||
"editor.fontSize": 14,
|
||||
"editor.fontFamily": "'Maple Mono NL NF CN Light', 'Maple Mono NL NF CN Light', 'Maple Mono NL NF CN Light'",
|
||||
"editor.fontFamily": "'Source Code Pro', 'Source Code Pro', 'Source Code Pro'",
|
||||
"editor.wordWrap": "on",
|
||||
"terminal.integrated.fontFamily": "'Maple Mono NL NF CN Light'",
|
||||
"terminal.integrated.fontFamily": "'Source Code Pro'",
|
||||
"cmake.configureOnOpen": true,
|
||||
//"C_Cpp.intelliSenseEngine": "disabled",
|
||||
"cmake.debugConfig": {
|
||||
@@ -25,7 +25,7 @@
|
||||
"-Wno-dev"
|
||||
],
|
||||
"cmake.configureSettings": {
|
||||
"CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake"
|
||||
//"CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake"
|
||||
},
|
||||
"cmake.options.statusBarVisibility": "visible",
|
||||
"cmake.generator": "Ninja",
|
||||
|
||||
@@ -11,5 +11,23 @@ if (MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND git rev-parse --short HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE VERSION_GIT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
execute_process(
|
||||
COMMAND git rev-parse --abbrev-ref HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE VERSION_GIT_BRANCH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
configure_file(Tools.h.in Tools.h)
|
||||
message(STATUS "Version file config to: ${CMAKE_CURRENT_BINARY_DIR}")
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_subdirectory(zoost)
|
||||
add_subdirectory(cxxLibrary)
|
||||
add_subdirectory(strReplace)
|
||||
add_subdirectory(fileUpdater)
|
||||
10
Tools.h.in
Normal file
10
Tools.h.in
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef FILEUPDATER_VERSION_H
|
||||
#define FILEUPDATER_VERSION_H
|
||||
|
||||
#define PROJECT_NAME "@PROJECT_NAME@"
|
||||
#define VERSION_GIT_COMMIT "@VERSION_GIT_HASH@"
|
||||
#define VERSION_GIT_BRANCH "@VERSION_GIT_BRANCH@"
|
||||
#define CMAKE_RUNTIME_OUTPUT_DIRECTORY "@CMAKE_RUNTIME_OUTPUT_DIRECTORY@"
|
||||
#define LIBRARY_OUTPUT_PATH "@LIBRARY_OUTPUT_PATH@"
|
||||
|
||||
#endif // FILEUPDATER_VERSION_H
|
||||
1
cxxLibrary
Submodule
1
cxxLibrary
Submodule
Submodule cxxLibrary added at d1b8734ccc
@@ -10,38 +10,8 @@ if (MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND git rev-parse --short HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE VERSION_GIT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
execute_process(
|
||||
COMMAND git rev-parse --abbrev-ref HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE VERSION_GIT_BRANCH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
configure_file(fileUpdaterVer.h.in fileUpdaterVer.h)
|
||||
message(STATUS "Version file config to: ${CMAKE_CURRENT_BINARY_DIR}")
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
find_package(fmt REQUIRED)
|
||||
find_package(tinyxml2 REQUIRED)
|
||||
find_package(CLI11 REQUIRED)
|
||||
find_package(spdlog REQUIRED)
|
||||
find_package(Boost REQUIRED COMPONENTS locale filesystem nowide)
|
||||
|
||||
add_executable(fileUpdater main.cpp)
|
||||
target_link_libraries(fileUpdater PRIVATE
|
||||
fmt::fmt
|
||||
Boost::locale
|
||||
Boost::filesystem
|
||||
Boost::nowide
|
||||
CLI11::CLI11
|
||||
spdlog::spdlog
|
||||
tinyxml2::tinyxml2
|
||||
)
|
||||
target_link_libraries(fileUpdater PRIVATE cxxLibrary zoost)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS fileUpdater
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#ifndef FILEUPDATER_VERSION_H
|
||||
#define FILEUPDATER_VERSION_H
|
||||
|
||||
#define VERSION_GIT_COMMIT "@VERSION_GIT_HASH@"
|
||||
#define VERSION_GIT_BRANCH "@VERSION_GIT_BRANCH@"
|
||||
|
||||
#endif // FILEUPDATER_VERSION_H
|
||||
@@ -1,25 +1,25 @@
|
||||
#include <CLI/CLI.hpp>
|
||||
#include <CLI11.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 <Tools.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,19 +52,41 @@ 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);
|
||||
}
|
||||
|
||||
// 解析命令行参数
|
||||
bool parseArguments(int argc, char** argv)
|
||||
{
|
||||
auto msg = fmt::format("fileUpdater - 文件更新工具 \n\n {} on {} at {} {}", VERSION_GIT_COMMIT, VERSION_GIT_BRANCH,
|
||||
__DATE__, __TIME__);
|
||||
auto notice = "使用特殊参数 default 可生成一个默认配置文件模板。";
|
||||
auto msg = fmt::format("fileUpdater - 文件更新工具 \n\n {} on {} at {} {}\n{}", VERSION_GIT_COMMIT, VERSION_GIT_BRANCH,
|
||||
__DATE__, __TIME__, notice);
|
||||
CLI::App app{msg};
|
||||
argv = app.ensure_utf8(argv);
|
||||
|
||||
@@ -94,6 +116,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 +477,31 @@ public:
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
#endif
|
||||
zoostCommon::SetOutputU8();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
boost::nowide::nowide_filesystem();
|
||||
AutoUpdateTool tool;
|
||||
|
||||
if (tool.parseArguments(argc, argv)) {
|
||||
|
||||
28
script/AutoPack.bat
Normal file
28
script/AutoPack.bat
Normal file
@@ -0,0 +1,28 @@
|
||||
@echo off
|
||||
|
||||
echo Config CMake...
|
||||
cmake -B..\build -S..\ -DCMAKE_BUILD_TYPE=Release -A x64
|
||||
if errorlevel 1 (
|
||||
echo CMake Failed.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Building...
|
||||
cmake --build ..\build --config Release
|
||||
if errorlevel 1 (
|
||||
echo Build Failed.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Packing...
|
||||
python package.py ..\build\Tools.h
|
||||
if errorlevel 1 (
|
||||
echo Pack Failed.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Done.
|
||||
pause
|
||||
292
script/package.py
Normal file
292
script/package.py
Normal file
@@ -0,0 +1,292 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
解析版本头文件并打包二进制文件的脚本
|
||||
用法: python package_binaries.py <version_header_file>
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import zipfile
|
||||
import tarfile
|
||||
import platform
|
||||
|
||||
def parse_version_header(file_path):
|
||||
"""
|
||||
解析版本头文件,提取路径信息
|
||||
返回字典包含解析结果
|
||||
"""
|
||||
if not os.path.exists(file_path):
|
||||
raise FileNotFoundError(f"文件不存在: {file_path}")
|
||||
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# 使用正则表达式提取信息
|
||||
patterns = {
|
||||
'PROJECT_NAME': r'#define\s+PROJECT_NAME\s+"([^"]+)"',
|
||||
'VERSION_GIT_COMMIT': r'#define\s+VERSION_GIT_COMMIT\s+"([^"]+)"',
|
||||
'VERSION_GIT_BRANCH': r'#define\s+VERSION_GIT_BRANCH\s+"([^"]+)"',
|
||||
'CMAKE_RUNTIME_OUTPUT_DIRECTORY': r'#define\s+CMAKE_RUNTIME_OUTPUT_DIRECTORY\s+"([^"]+)"',
|
||||
'LIBRARY_OUTPUT_PATH': r'#define\s+LIBRARY_OUTPUT_PATH\s+"([^"]+)"',
|
||||
}
|
||||
|
||||
result = {}
|
||||
for key, pattern in patterns.items():
|
||||
match = re.search(pattern, content)
|
||||
if match:
|
||||
result[key] = match.group(1)
|
||||
else:
|
||||
# 尝试无引号的情况
|
||||
pattern_no_quotes = pattern.replace(r'"([^"]+)"', r'(\S+)')
|
||||
match = re.search(pattern_no_quotes, content)
|
||||
if match:
|
||||
result[key] = match.group(1)
|
||||
else:
|
||||
print(f"警告: 未找到 {key} 定义")
|
||||
result[key] = ""
|
||||
|
||||
# 验证必要字段
|
||||
required_fields = ['PROJECT_NAME', 'VERSION_GIT_COMMIT', 'VERSION_GIT_BRANCH']
|
||||
for field in required_fields:
|
||||
if not result.get(field):
|
||||
raise ValueError(f"缺少必要字段: {field}")
|
||||
|
||||
return result
|
||||
|
||||
def normalize_path(path_str):
|
||||
"""标准化路径,处理Windows/Unix路径差异"""
|
||||
if not path_str:
|
||||
return ""
|
||||
|
||||
# 替换反斜杠为正斜杠
|
||||
path_str = path_str.replace('\\', '/')
|
||||
|
||||
# 移除可能的尾部斜杠
|
||||
path_str = path_str.rstrip('/')
|
||||
|
||||
return path_str
|
||||
|
||||
def collect_binary_files(runtime_dir, library_dir):
|
||||
"""
|
||||
收集指定目录下的二进制文件
|
||||
返回文件路径列表
|
||||
"""
|
||||
binary_files = []
|
||||
dirs_to_search = []
|
||||
|
||||
if runtime_dir and os.path.exists(runtime_dir):
|
||||
dirs_to_search.append(runtime_dir)
|
||||
print(f"搜索运行时目录: {runtime_dir}")
|
||||
|
||||
if library_dir and os.path.exists(library_dir):
|
||||
dirs_to_search.append(library_dir)
|
||||
print(f"搜索库目录: {library_dir}")
|
||||
|
||||
# 支持的二进制文件扩展名
|
||||
binary_extensions = {
|
||||
'windows': ['.exe', '.dll', '.pdb', '.lib'],
|
||||
'linux': ['', '.so', '.so.*', '.a'],
|
||||
'darwin': ['', '.dylib', '.a', '.bundle']
|
||||
}
|
||||
|
||||
current_os = platform.system().lower()
|
||||
if 'windows' in current_os:
|
||||
extensions = binary_extensions['windows']
|
||||
elif 'linux' in current_os:
|
||||
extensions = binary_extensions['linux']
|
||||
elif 'darwin' in current_os:
|
||||
extensions = binary_extensions['darwin']
|
||||
else:
|
||||
extensions = binary_extensions['linux'] # 默认
|
||||
|
||||
for search_dir in dirs_to_search:
|
||||
if not os.path.exists(search_dir):
|
||||
print(f"警告: 目录不存在: {search_dir}")
|
||||
continue
|
||||
|
||||
for root, dirs, files in os.walk(search_dir):
|
||||
for file in files:
|
||||
file_path = os.path.join(root, file)
|
||||
|
||||
# 检查文件扩展名
|
||||
should_include = False
|
||||
for ext in extensions:
|
||||
if ext.endswith('*'):
|
||||
# 通配符匹配
|
||||
if file.endswith(ext.rstrip('*')):
|
||||
should_include = True
|
||||
break
|
||||
elif ext == '':
|
||||
# 无扩展名文件(Linux可执行文件)
|
||||
if not os.path.splitext(file)[1]:
|
||||
should_include = True
|
||||
break
|
||||
else:
|
||||
# 普通扩展名匹配
|
||||
if file.lower().endswith(ext.lower()):
|
||||
should_include = True
|
||||
break
|
||||
|
||||
if should_include:
|
||||
binary_files.append(file_path)
|
||||
print(f" 找到: {os.path.relpath(file_path, search_dir)}")
|
||||
|
||||
return binary_files
|
||||
|
||||
def create_zip_package(files, output_filename, base_dirs):
|
||||
"""
|
||||
创建ZIP压缩包
|
||||
"""
|
||||
print(f"创建ZIP包: {output_filename}")
|
||||
|
||||
with zipfile.ZipFile(output_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
||||
for file_path in files:
|
||||
# 确定在ZIP中的相对路径
|
||||
arcname = None
|
||||
|
||||
# 尝试找到最合适的基目录
|
||||
for base_dir in base_dirs:
|
||||
if base_dir and file_path.startswith(base_dir):
|
||||
# 使用相对于基目录的路径
|
||||
rel_path = os.path.relpath(file_path, base_dir)
|
||||
# 保持目录结构
|
||||
arcname = rel_path
|
||||
break
|
||||
|
||||
# 如果没有找到合适的基目录,只使用文件名
|
||||
if not arcname:
|
||||
arcname = os.path.basename(file_path)
|
||||
|
||||
# 确保路径使用正斜杠
|
||||
arcname = arcname.replace('\\', '/')
|
||||
|
||||
zipf.write(file_path, arcname)
|
||||
print(f" 添加: {arcname}")
|
||||
|
||||
print(f"ZIP包创建完成: {output_filename}")
|
||||
print(f"包含文件数: {len(files)}")
|
||||
|
||||
def create_tar_gz_package(files, output_filename, base_dirs):
|
||||
"""
|
||||
创建tar.gz压缩包
|
||||
"""
|
||||
print(f"创建tar.gz包: {output_filename}")
|
||||
|
||||
with tarfile.open(output_filename, "w:gz") as tar:
|
||||
for file_path in files:
|
||||
# 确定在tar中的相对路径
|
||||
arcname = None
|
||||
|
||||
# 尝试找到最合适的基目录
|
||||
for base_dir in base_dirs:
|
||||
if base_dir and file_path.startswith(base_dir):
|
||||
# 使用相对于基目录的路径
|
||||
rel_path = os.path.relpath(file_path, base_dir)
|
||||
# 保持目录结构
|
||||
arcname = rel_path
|
||||
break
|
||||
|
||||
# 如果没有找到合适的基目录,只使用文件名
|
||||
if not arcname:
|
||||
arcname = os.path.basename(file_path)
|
||||
|
||||
tar.add(file_path, arcname=arcname, recursive=False)
|
||||
print(f" 添加: {arcname}")
|
||||
|
||||
print(f"tar.gz包创建完成: {output_filename}")
|
||||
print(f"包含文件数: {len(files)}")
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
if len(sys.argv) != 2:
|
||||
print("用法: python package_binaries.py <version_header_file>")
|
||||
print("示例: python package_binaries.py Tools.h")
|
||||
sys.exit(1)
|
||||
|
||||
header_file = sys.argv[1]
|
||||
|
||||
try:
|
||||
# 1. 解析版本头文件
|
||||
print(f"解析文件: {header_file}")
|
||||
info = parse_version_header(header_file)
|
||||
|
||||
project_name = info['PROJECT_NAME']
|
||||
git_commit = info['VERSION_GIT_COMMIT']
|
||||
git_branch = info['VERSION_GIT_BRANCH']
|
||||
runtime_dir = normalize_path(info.get('CMAKE_RUNTIME_OUTPUT_DIRECTORY', ''))
|
||||
library_dir = normalize_path(info.get('LIBRARY_OUTPUT_PATH', ''))
|
||||
|
||||
print(f"项目: {project_name}")
|
||||
print(f"分支: {git_branch}")
|
||||
print(f"提交: {git_commit}")
|
||||
print(f"运行时目录: {runtime_dir}")
|
||||
print(f"库目录: {library_dir}")
|
||||
|
||||
# 2. 收集二进制文件
|
||||
print("\n收集二进制文件...")
|
||||
binary_files = collect_binary_files(runtime_dir, library_dir)
|
||||
|
||||
if not binary_files:
|
||||
print("错误: 未找到任何二进制文件")
|
||||
print(f"请检查以下目录:")
|
||||
if runtime_dir:
|
||||
print(f" - {runtime_dir}")
|
||||
if library_dir:
|
||||
print(f" - {library_dir}")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"找到 {len(binary_files)} 个二进制文件")
|
||||
|
||||
# 3. 创建输出文件名
|
||||
# 清理分支名(替换特殊字符)
|
||||
safe_branch = re.sub(r'[\\/*?:"<>|]', "_", git_branch)
|
||||
output_basename = f"{project_name}-{safe_branch}-{git_commit}"
|
||||
|
||||
# 4. 根据操作系统选择压缩格式
|
||||
current_os = platform.system().lower()
|
||||
|
||||
# 确定要搜索的基目录(用于保持相对路径)
|
||||
base_dirs = []
|
||||
if runtime_dir:
|
||||
base_dirs.append(runtime_dir)
|
||||
if library_dir:
|
||||
base_dirs.append(library_dir)
|
||||
|
||||
if 'windows' in current_os:
|
||||
output_file = f"{output_basename}.zip"
|
||||
print(f"\n在Windows系统,创建ZIP包...")
|
||||
create_zip_package(binary_files, output_file, base_dirs)
|
||||
else:
|
||||
output_file = f"{output_basename}.tar.gz"
|
||||
print(f"\n在{current_os.capitalize()}系统,创建tar.gz包...")
|
||||
create_tar_gz_package(binary_files, output_file, base_dirs)
|
||||
|
||||
# 5. 输出结果
|
||||
file_size = os.path.getsize(output_file) / (1024 * 1024) # MB
|
||||
print(f"\n✓ 打包完成!")
|
||||
print(f"输出文件: {output_file}")
|
||||
print(f"文件大小: {file_size:.2f} MB")
|
||||
print(f"包含文件: {len(binary_files)} 个")
|
||||
|
||||
# 显示文件列表
|
||||
print("\n文件列表:")
|
||||
for i, file_path in enumerate(binary_files, 1):
|
||||
# 显示相对于工作目录的路径
|
||||
rel_path = os.path.relpath(file_path)
|
||||
print(f" {i:3d}. {rel_path}")
|
||||
|
||||
except FileNotFoundError as e:
|
||||
print(f"错误: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
except ValueError as e:
|
||||
print(f"错误: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"未知错误: {e}", file=sys.stderr)
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -2,7 +2,5 @@ cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(strReplace LANGUAGES CXX)
|
||||
|
||||
find_package(Boost REQUIRED)
|
||||
|
||||
add_executable(strReplace main.cpp)
|
||||
target_link_libraries(strReplace PRIVATE Boost::headers)
|
||||
target_link_libraries(strReplace PRIVATE cxxLibrary zoost)
|
||||
1
zoost
Submodule
1
zoost
Submodule
Submodule zoost added at 78c9c4b887
Reference in New Issue
Block a user