From 482e5495f044daaf3b73a315de07e3e6c644aaa6 Mon Sep 17 00:00:00 2001 From: amass <168062547@qq.com> Date: Mon, 10 Nov 2025 19:29:40 +0800 Subject: [PATCH] add info checker. --- .clangd | 2 +- CMakeLists.txt | 4 ++ Infoer.cpp | 124 +++++++++++++++++++++++++++++++++++++++++++++ resources/build.sh | 12 ++--- 4 files changed, 132 insertions(+), 10 deletions(-) create mode 100644 Infoer.cpp diff --git a/.clangd b/.clangd index 7762c3c..9b5fca2 100644 --- a/.clangd +++ b/.clangd @@ -1,5 +1,5 @@ CompileFlags: CompilationDatabase: build Add: [ - "-I/opt/Libraries/boost_1_89_0/include", + "-I/opt/3rdparty/boost_1_89_0/include", ] \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index eb0df74..bf9086b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,4 +18,8 @@ add_executable(shifter target_link_libraries(shifter PRIVATE Boost::program_options +) + +add_executable(infoer + Infoer.cpp ) \ No newline at end of file diff --git a/Infoer.cpp b/Infoer.cpp new file mode 100644 index 0000000..659f6cc --- /dev/null +++ b/Infoer.cpp @@ -0,0 +1,124 @@ +#include +#include +#include +#include +#include +#include + +namespace fs = std::filesystem; + +class AdvancedNfoFileChecker { +private: + std::vector videoExtensions = {".avi", ".m2ts", ".mkv", ".mp4", ".ts"}; + std::map checkResults; + +public: + bool isVideoFile(const fs::path &filePath) { + std::string extension = filePath.extension().string(); + std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); + return std::find(videoExtensions.begin(), videoExtensions.end(), extension) != videoExtensions.end(); + } + + bool hasNfoFile(const fs::path &videoPath) { + fs::path nfoPath = videoPath; + nfoPath.replace_extension(".nfo"); + return fs::exists(nfoPath); + } + + void checkFolderRecursive(const std::string &folderPath, bool recursive = false) { + checkResults.clear(); + int totalVideoFiles = 0; + int missingNfoCount = 0; + + try { + auto iterator = fs::directory_iterator(folderPath); + for (const auto &entry : iterator) { + if (entry.is_regular_file()) { + fs::path filePath = entry.path(); + + if (isVideoFile(filePath)) { + totalVideoFiles++; + bool hasNfo = hasNfoFile(filePath); + checkResults[filePath.string()] = hasNfo; + + if (!hasNfo) { + missingNfoCount++; + } + } + } + } + + printResults(totalVideoFiles, missingNfoCount); + + } catch (const fs::filesystem_error &ex) { + std::cerr << "错误:无法访问文件夹 '" << folderPath << "'" << std::endl; + std::cerr << "详细信息: " << ex.what() << std::endl; + } + } + +private: + void printResults(int totalVideoFiles, int missingNfoCount) { + std::cout << "检查结果:" << std::endl; + std::cout << "==========================================" << std::endl; + std::cout << "总视频文件数: " << totalVideoFiles << std::endl; + std::cout << "缺少.nfo的文件数: " << missingNfoCount << std::endl; + std::cout << "完整率: " << (totalVideoFiles - missingNfoCount) * 100 / std::max(1, totalVideoFiles) << "%" + << std::endl; + std::cout << "==========================================" << std::endl; + + if (missingNfoCount > 0) { + std::cout << "缺少.nfo文件的视频文件:" << std::endl; + for (const auto &[filepath, hasNfo] : checkResults) { + if (!hasNfo) { + std::cout << " ✗ " << fs::path(filepath).filename().string() << std::endl; + } + } + } else if (totalVideoFiles > 0) { + std::cout << "✓ 所有视频文件都有对应的.nfo文件" << std::endl; + } else { + std::cout << "! 在指定文件夹中未找到视频文件" << std::endl; + } + } +}; + +int main(int argc, char *argv[]) { + AdvancedNfoFileChecker checker; + + std::string folderPath; + bool recursive = false; + + // 解析命令行参数 + for (int i = 1; i < argc; ++i) { + std::string arg = argv[i]; + if (arg == "-r" || arg == "--recursive") { + recursive = true; + } else if (arg == "-h" || arg == "--help") { + std::cout << "用法: " << argv[0] << " [文件夹路径] [-r]" << std::endl; + std::cout << "选项:" << std::endl; + std::cout << " -r, --recursive 递归检查子文件夹" << std::endl; + std::cout << " -h, --help 显示帮助信息" << std::endl; + return 0; + } else { + folderPath = arg; + } + } + + if (folderPath.empty()) { + std::cout << "请输入要检查的文件夹路径(留空使用当前目录): "; + std::getline(std::cin, folderPath); + if (folderPath.empty()) { + folderPath = "."; + } + } + + std::cout << "正在检查文件夹: " << fs::absolute(folderPath) << std::endl; + if (recursive) { + std::cout << "模式: 递归检查(包含子文件夹)" << std::endl; + } + std::cout << "支持的视频格式: .avi, .m2ts, .mkv, .mp4, .ts" << std::endl; + std::cout << "==========================================" << std::endl; + + checker.checkFolderRecursive(folderPath, recursive); + + return 0; +} \ No newline at end of file diff --git a/resources/build.sh b/resources/build.sh index e1c48df..e5283a4 100755 --- a/resources/build.sh +++ b/resources/build.sh @@ -2,13 +2,7 @@ base_path=$(pwd) build_path=${base_path}/build -libraries_root="/opt/Libraries" - -if command -v cmake >/dev/null 2>&1; then - cmake_exe=cmake -else - cmake_exe=/opt/Qt/Tools/CMake/bin/cmake -fi +libraries_root="/opt/3rdparty" function cmake_scan() { echo "scanning the project..." @@ -16,7 +10,7 @@ function cmake_scan() { mkdir -p ${build_path} fi cd ${build_path} - ${cmake_exe} -G Ninja -S ${base_path} -B ${build_path} \ + cmake -G Ninja -S ${base_path} -B ${build_path} \ -DCMAKE_BUILD_TYPE=Debug \ -DMbedTLS_DIR=${libraries_root}/mbedtls-3.6.5/lib/cmake/MbedTLS \ -Dnng_DIR=${libraries_root}/nng-1.11/lib/cmake/nng \ @@ -31,7 +25,7 @@ function build() { if [ $? -ne 0 ]; then exit 1 fi - ${cmake_exe} --build ${build_path} --target all + cmake --build ${build_path} --target all if [ $? -ne 0 ]; then exit 1 fi