diff options
author | Aki <please@ignore.pl> | 2022-08-20 23:04:27 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-08-20 23:04:27 +0200 |
commit | ac8732867f57f59b8f4aec8d28b8e745046c9ac7 (patch) | |
tree | 68cfa9093dbbb31dc4af3cffd33eb5d0cd178079 /ArchiveEx/dat.cpp | |
parent | bc9502fbc36946f1d96d3f188e18346baddbf1d5 (diff) | |
download | starshatter-ac8732867f57f59b8f4aec8d28b8e745046c9ac7.zip starshatter-ac8732867f57f59b8f4aec8d28b8e745046c9ac7.tar.gz starshatter-ac8732867f57f59b8f4aec8d28b8e745046c9ac7.tar.bz2 |
Added options to inspect archive content in dat utility
Old PrintX methods were replaced by higher order functions ForEachX that are
intended to give slighly more granual control and move the responsibility of
what actually happens to the user without introducing a whole iterator.
Diffstat (limited to 'ArchiveEx/dat.cpp')
-rw-r--r-- | ArchiveEx/dat.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/ArchiveEx/dat.cpp b/ArchiveEx/dat.cpp index ae1304d..06beba1 100644 --- a/ArchiveEx/dat.cpp +++ b/ArchiveEx/dat.cpp @@ -13,6 +13,7 @@ enum class Action { NOTHING, LIST, + BLOCKS, UPDATE, EXTRACT, }; @@ -56,11 +57,15 @@ try { return 0; } ArchiveEx::Archive archive(opts.archive, opts.create); + std::size_t i = 0; switch (opts.action) { case Action::NOTHING: break; case Action::LIST: - archive.PrintNamesOfEntries(); + archive.ForEachEntry([](const char* name){ std::cout << name << std::endl; }); + break; + case Action::BLOCKS: + archive.ForEachBlock([&i](const char* name){ std::cout << i++ << "\t" << name << std::endl; }); break; case Action::UPDATE: for (const auto& file : opts.files) @@ -89,7 +94,7 @@ ParseArgs(int argc, char* argv[]) { int opt; Options opts; - while (-1 != (opt = getopt(argc, argv, ":hluxc"))) { + while (-1 != (opt = getopt(argc, argv, ":hlbuxc"))) { switch (opt) { case 'h': opts.help = true; @@ -97,6 +102,9 @@ ParseArgs(int argc, char* argv[]) case 'l': opts.action = Action::LIST; break; + case 'b': + opts.action = Action::BLOCKS; + break; case 'u': opts.action = Action::UPDATE; break; @@ -124,7 +132,7 @@ ParseArgs(int argc, char* argv[]) void PrintUsage(std::ostream& out) { - out << "Usage: " << program << " [-hluxc] archive [file [files...]]" << std::endl; + out << "Usage: " << program << " [-hlbuxc] archive [file [files...]]" << std::endl; } @@ -134,6 +142,7 @@ PrintHelp(std::ostream& out) out << "Options:" << std::endl; out << " -h\tPrints this help message and exits." << std::endl; out << " -l\tLists files in the archive." << std::endl; + out << " -b\tLists content of each block in archive." << std::endl; out << " -u\tInserts files from file system into archive." << std::endl; out << " -x\tExtracts files from the archive." << std::endl; out << " -c\tCreate the archive if it does not exist." << std::endl; |