From 46a6f8ab567b1d3d2707411236a9f7988e6eba86 Mon Sep 17 00:00:00 2001 From: ZL114514 Date: Sat, 5 Jul 2025 18:48:41 +0800 Subject: [PATCH 1/2] add -m to remove file if done --- src/main.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1c1cf0b..37ba432 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,7 @@ namespace fs = std::filesystem; -void processFile(const fs::path &filePath, const fs::path &outputFolder) +void processFile(const fs::path &filePath, const fs::path &outputFolder, bool isRequiredRemoved) { if (fs::exists(filePath) == false) { @@ -35,7 +35,14 @@ void processFile(const fs::path &filePath, const fs::path &outputFolder) crypt.Dump(outputFolder.u8string()); crypt.FixMetadata(); - std::cout << BOLDGREEN << "[Done] " << RESET << "'" << filePath.u8string() << "' -> '" << crypt.dumpFilepath().u8string() << "'" << std::endl; + std::cout << BOLDGREEN << "[Done] " << RESET << "'" << filePath.u8string() << "' -> '" << crypt.dumpFilepath().u8string() << "'" ; + + if (isRequiredRemoved) + { + fs::remove(filePath); + std::cout << " with removed as required."; + } + std::cout << std::endl; } catch (const std::invalid_argument &e) { @@ -61,6 +68,7 @@ int main(int argc, char **argv) ("r,recursive", "Process files recursively (requires -d option)", cxxopts::value()->default_value("false")) ("o,output", "Output folder (default: original file folder)", cxxopts::value()) ("v,version", "Print version information", cxxopts::value()->default_value("false")) + ("m,remove", "Remove original file if done", cxxopts::value()->default_value("false")) ("filenames", "Input files", cxxopts::value>()); options.positional_help(""); @@ -165,7 +173,7 @@ int main(int argc, char **argv) fs::create_directories(destinationPath.parent_path()); // 处理文件 - processFile(path, destinationPath.parent_path()); + processFile(path, destinationPath.parent_path(), result.count("remove")); } } } @@ -178,11 +186,11 @@ int main(int argc, char **argv) { if (outputDirSpecified) { - processFile(path, outputDir); + processFile(path, outputDir, result.count("remove")); } else { - processFile(path, ""); + processFile(path, "", result.count("remove")); } } } @@ -204,11 +212,11 @@ int main(int argc, char **argv) if (outputDirSpecified) { - processFile(filePathU8, outputDir); + processFile(filePathU8, outputDir, result.count("remove")); } else { - processFile(filePathU8, ""); + processFile(filePathU8, "", result.count("remove")); } } } From 6a0e41c393df96b5945a5a7d845cd5f040d9d640 Mon Sep 17 00:00:00 2001 From: ZL114514 Date: Sun, 6 Jul 2025 16:36:23 +0800 Subject: [PATCH 2/2] add description for -m in README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 6fa29d2..4ceb937 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,12 @@ ncmdump -d source_dir ncmdump -d source_dir -r ``` +使用 `-m` 参数来删除源文件若正确处理 + +```shell +ncmdump -m +``` + 使用 `-o` 参数来指定输出目录,将转换后的文件输出到指定目录,该参数支持与 `-r` 参数一起使用 ```shell