mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:34:57 +00:00
unzip: Add option to list files of an archive
This commit is contained in:
parent
a9a62ad8c9
commit
dc65a2f2b8
3 changed files with 28 additions and 3 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <LibArchive/Zip.h>
|
||||
#include <LibCompress/Deflate.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
#include <LibCore/Directory.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/MappedFile.h>
|
||||
|
@ -104,10 +105,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
{
|
||||
StringView zip_file_path;
|
||||
bool quiet { false };
|
||||
bool list_files { false };
|
||||
StringView output_directory_path;
|
||||
Vector<StringView> file_filters;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(list_files, "Only list files in the archive", "list", 'l');
|
||||
args_parser.add_option(output_directory_path, "Directory to receive the archive content", "output-directory", 'd', "path");
|
||||
args_parser.add_option(quiet, "Be less verbose", "quiet", 'q');
|
||||
args_parser.add_positional_argument(zip_file_path, "File to unzip", "path", Core::ArgsParser::Required::Yes);
|
||||
|
@ -140,6 +143,28 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::chdir(output_directory_path));
|
||||
}
|
||||
|
||||
if (list_files) {
|
||||
outln(" Length Date Time Name");
|
||||
outln("--------- ---------- -------- ----");
|
||||
u32 members_count = 0;
|
||||
u64 total_size = 0;
|
||||
TRY(zip_file->for_each_member([&](auto zip_member) -> ErrorOr<IterationDecision> {
|
||||
members_count++;
|
||||
|
||||
auto time = time_from_packed_dos(zip_member.modification_date, zip_member.modification_time);
|
||||
auto time_str = TRY(Core::DateTime::from_timestamp(time.seconds_since_epoch()).to_string());
|
||||
|
||||
total_size += zip_member.uncompressed_size;
|
||||
|
||||
outln("{:>9} {} {}", zip_member.uncompressed_size, time_str, zip_member.name);
|
||||
|
||||
return IterationDecision::Continue;
|
||||
}));
|
||||
outln("--------- ----");
|
||||
outln("{:>9} {} files", total_size, members_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Vector<Archive::ZipMember> zip_directories;
|
||||
|
||||
auto success = TRY(zip_file->for_each_member([&](auto zip_member) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue