diff options
author | Aki <please@ignore.pl> | 2022-09-11 00:45:57 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-09-11 00:45:57 +0200 |
commit | b00704ef37155c17daff1986cda3274d95560bad (patch) | |
tree | c2d4601c2dc68098f4d4d7ac1e124fd798985f63 /ArchiveEx | |
parent | ac8732867f57f59b8f4aec8d28b8e745046c9ac7 (diff) | |
download | starshatter-b00704ef37155c17daff1986cda3274d95560bad.zip starshatter-b00704ef37155c17daff1986cda3274d95560bad.tar.gz starshatter-b00704ef37155c17daff1986cda3274d95560bad.tar.bz2 |
Extended dat update action with recursive behaviour
Diffstat (limited to 'ArchiveEx')
-rw-r--r-- | ArchiveEx/dat.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/ArchiveEx/dat.cpp b/ArchiveEx/dat.cpp index 06beba1..a8f112d 100644 --- a/ArchiveEx/dat.cpp +++ b/ArchiveEx/dat.cpp @@ -1,6 +1,7 @@ #include <unistd.h> #include <exception> +#include <filesystem> #include <iostream> #include <ostream> #include <string> @@ -9,6 +10,9 @@ #include <Archive.h> +namespace fs = std::filesystem; + + enum class Action { NOTHING, @@ -41,6 +45,7 @@ public: static Options ParseArgs(int argc, char* argv[]); static void PrintUsage(std::ostream& out=std::cerr); static void PrintHelp(std::ostream& out=std::cout); +static void UpdateFile(ArchiveEx::Archive& archive, const std::string& path, bool warn=true); static const char* program {"dat"}; @@ -69,7 +74,7 @@ try { break; case Action::UPDATE: for (const auto& file : opts.files) - archive.Insert(file.c_str()); // Support recursive directories tar-like + UpdateFile(archive, file); break; case Action::EXTRACT: break; // Not implemented @@ -147,3 +152,23 @@ PrintHelp(std::ostream& out) out << " -x\tExtracts files from the archive." << std::endl; out << " -c\tCreate the archive if it does not exist." << std::endl; } + + +void +UpdateFile(ArchiveEx::Archive& archive, const std::string& path, bool warn) +{ + const auto status = fs::status(path); + switch (status.type()) { + case fs::file_type::regular: + archive.Insert(path.c_str()); + break; + case fs::file_type::directory: + for (const auto& entry : fs::directory_iterator{path}) + UpdateFile(archive, entry.path(), false); + break; + default: + if (warn) + std::cerr << "unsupported file type: " << path << std::endl; + break; + } +} |