From 23662de8dc1ac6890a367e1a1bf1061b6f0a985b Mon Sep 17 00:00:00 2001 From: lzwdgc Date: Tue, 6 Feb 2024 06:42:54 +0300 Subject: [PATCH] [unpaker] Allow to unpak specific files. --- src/unpaker/unpaker.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/unpaker/unpaker.cpp b/src/unpaker/unpaker.cpp index 2e6bb6c..78f2758 100644 --- a/src/unpaker/unpaker.cpp +++ b/src/unpaker/unpaker.cpp @@ -40,7 +40,7 @@ using namespace std; -void unpack_file(path fn) { +void unpack_file(path fn, const Files &files_to_extract) { primitives::templates2::mmap_file f{fn}; stream s{f}; pak p = s; @@ -167,6 +167,9 @@ void unpack_file(path fn) { auto dir = fn += ".dir"; fs::create_directories(dir); for (auto &&d : descs) { + if (!files_to_extract.empty() && !files_to_extract.contains(d.name)) { + continue; + } auto fn = dir / d.name; fs::create_directories(fn.parent_path()); std::cout << "unpacking " << fn << "\n"; @@ -178,17 +181,23 @@ void unpack_file(path fn) { int main(int argc, char *argv[]) { cl::opt p(cl::Positional, cl::desc(""), cl::Required); + cl::opt cl_files_to_extract(cl::Positional, cl::desc(""), cl::ZeroOrMore); cl::ParseCommandLineOptions(argc, argv); + Files files_to_extract; + for (auto &&f : cl_files_to_extract) { + files_to_extract.insert(f); + } + if (fs::is_regular_file(p)) { - unpack_file(p); + unpack_file(p, files_to_extract); } else if (fs::is_directory(p)) { auto files = enumerate_files_like(p, ".*\\.pak", false); for (auto &f : files) { std::cout << "processing: " << f << "\n"; try { - unpack_file(f); + unpack_file(f, files_to_extract); } catch (std::exception &e) { std::cerr << e.what() << "\n"; }