From ce280d976f4fa4ae85370027bf1343011eff5482 Mon Sep 17 00:00:00 2001 From: moonshadow565 Date: Mon, 13 Jun 2022 02:58:52 +0100 Subject: [PATCH] more help and better printing --- README.md | 36 ++++++++++++++++++++++++++++++++++-- src/rbun_add.cpp | 12 +++++++++--- src/rbun_chk.cpp | 37 +++++++++++++++++++++++++++++-------- src/rbun_ls.cpp | 7 ++++++- src/rbun_usage.cpp | 1 + src/rman_ls.cpp | 6 +++++- 6 files changed, 84 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 392f153..bea7b18 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -Set of tools to manipulate manifest and bundle files from CLI. - ```sh Usage: rbun-add.exe [options] output input @@ -26,12 +24,16 @@ input Bundle file or folder to read from. Optional arguments: -h --help shows help message and exits [default: false] -v --version prints version information and exits [default: false] +--no-extract Do not even attempt to extract chunk. [default: false] +--no-hash Do not verify hash. [default: false] ``` ```sh Usage: rbun-ls.exe [options] input Lists contents of one or more bundles. +Output is in CSV format as follows: +BundlID,ChunkID,SizeCompressed,SizeUncompressed Positional arguments: input Bundle file or folder to read from. @@ -54,6 +56,34 @@ Optional arguments: -v --version prints version information and exits [default: false] ``` +```sh +Usage: rman [options] action manifest + +Positional arguments: +action action: list, bundles, chunks, download [required] +manifest .manifest or .json [required] + +Optional arguments: +-h --help shows help message and exits [default: false] +-v --version prints version information and exits [default: false] +-v --verify Skip: verified chunks. [default: false] +-e --exist Skip: existing files. [default: false] +-n --nowrite Skip: writing files to disk. [default: false] +-l --lang Filter: language(none for international files). [default: ""] +-p --path Filter: path with regex match. [default: ] +-o --output Directory: to store and verify files from. [default: "."] +-d --download Url: to download from. [default: "http://lol.secure.dyn.riotcdn.net/channels/public"] +-a --archive Directory: to use as cache archive for bundles. [default: ""] +-m --mode Mode: of range downloading: full, one, multi. [default: ] +-r --retry Number: of retrys for failed bundles. [default: 0] +-c --connections Number: of connections per downloaded file. [default: 64] +--curl-verbose Curl: verbose logging. [default: false] +--curl-buffer Curl: buffer size in bytes [1024, 524288]. [default: 0] +--curl-proxy Curl: proxy. [default: ""] +--curl-useragent Curl: user agent string. [default: ""] +--curl-cookiefile Curl: cookie file or '-' to disable cookie engine. [default: ""] +--curl-cookielist Curl: cookie list string. [default: ""] +``` ```sh Usage: rman-bl.exe [options] manifest @@ -103,6 +133,8 @@ Optional arguments: Usage: rman-ls.exe [options] manifest Lists files in manifest. +Output is in CSV format as follows: +Path,Size,ID,Lang1;Lang2;Lang3... Positional arguments: manifest Manifest file to read from. [required] diff --git a/src/rbun_add.cpp b/src/rbun_add.cpp index 45ecd1a..2fc0885 100644 --- a/src/rbun_add.cpp +++ b/src/rbun_add.cpp @@ -63,9 +63,11 @@ struct Main { auto add_bundle(fs::path const& path, RCache& output) -> void { try { + rlib_trace("path: %s\n", path.generic_string().c_str()); + printf("Start %s\n", path.filename().generic_string().c_str()); auto infile = IOFile(path, false); auto bundle = RBUN::read(infile, true); - printf("Start(%s)\n", path.filename().generic_string().c_str()); + printf(" ... "); for (std::uint64_t offset = 0; auto const& chunk : bundle.chunks) { rlib_assert(in_range(offset, chunk.compressed_size, bundle.toc_offset)); auto src = infile.copy(offset, chunk.compressed_size); @@ -76,9 +78,13 @@ struct Main { offset += chunk.compressed_size; output.add(chunk, src); } - printf("Ok(%s)\n", path.filename().generic_string().c_str()); + printf("Ok!\n"); } catch (std::exception const& e) { - printf("Failed(%s): %s\n", path.filename().generic_string().c_str(), e.what()); + printf("Failed!\n"); + std::cerr << e.what() << std::endl; + for (auto const& error : error_stack()) { + std::cerr << error << std::endl; + } error_stack().clear(); } } diff --git a/src/rbun_chk.cpp b/src/rbun_chk.cpp index e52faec..a755521 100644 --- a/src/rbun_chk.cpp +++ b/src/rbun_chk.cpp @@ -10,6 +10,8 @@ using namespace rlib; struct Main { struct CLI { std::vector inputs = {}; + bool no_hash = {}; + bool no_extract = {}; } cli = {}; auto parse_args(int argc, char** argv) -> void { @@ -17,8 +19,17 @@ struct Main { program.add_description("Checks one or more bundles for errors."); program.add_argument("input").help("Bundle file or folder to read from.").remaining(); + program.add_argument("--no-extract") + .help("Do not even attempt to extract chunk.") + .default_value(false) + .implicit_value(true); + program.add_argument("--no-hash").help("Do not verify hash.").default_value(false).implicit_value(true); + program.parse_args(argc, argv); + cli.no_hash = program.get("--no-extract"); + cli.no_extract = program.get("--no-hash"); + cli.inputs = program.get>("input"); } @@ -47,21 +58,31 @@ struct Main { auto verify_bundle(fs::path const& path) -> void { try { + rlib_trace("path: %s\n", path.generic_string().c_str()); + printf("Start %s\n", path.filename().generic_string().c_str()); auto infile = IOFile(path, false); auto bundle = RBUN::read(infile, true); - printf("Start(%s)\n", path.filename().generic_string().c_str()); + printf(" ... "); for (std::uint64_t offset = 0; auto const& chunk : bundle.chunks) { rlib_assert(in_range(offset, chunk.compressed_size, bundle.toc_offset)); - auto src = infile.copy(offset, chunk.compressed_size); - auto dst = try_zstd_decompress(src, chunk.uncompressed_size); - rlib_assert(dst.size() == chunk.uncompressed_size); - auto hash_type = RBUN::Chunk::hash_type(dst, chunk.chunkId); - rlib_assert(hash_type != HashType::None); + if (!cli.no_extract) { + auto src = infile.copy(offset, chunk.compressed_size); + auto dst = try_zstd_decompress(src, chunk.uncompressed_size); + rlib_assert(dst.size() == chunk.uncompressed_size); + if (!cli.no_hash) { + auto hash_type = RBUN::Chunk::hash_type(dst, chunk.chunkId); + rlib_assert(hash_type != HashType::None); + } + } offset += chunk.compressed_size; } - printf("Ok(%s)\n", path.filename().generic_string().c_str()); + printf("Ok!\n"); } catch (std::exception const& e) { - printf("Failed(%s): %s\n", path.filename().generic_string().c_str(), e.what()); + printf("Failed!\n"); + std::cerr << e.what() << std::endl; + for (auto const& error : error_stack()) { + std::cerr << error << std::endl; + } error_stack().clear(); } } diff --git a/src/rbun_ls.cpp b/src/rbun_ls.cpp index c579e99..a582e81 100644 --- a/src/rbun_ls.cpp +++ b/src/rbun_ls.cpp @@ -14,7 +14,11 @@ struct Main { auto parse_args(int argc, char** argv) -> void { argparse::ArgumentParser program(fs::path(argv[0]).filename().generic_string()); - program.add_description("Lists contents of one or more bundles."); + program.add_description( + "Lists contents of one or more bundles." + "\n" + "Output is in CSV format as follows:\n" + "BundlID,ChunkID,SizeCompressed,SizeUncompressed"); program.add_argument("input").help("Bundle file or folder to read from.").remaining(); program.parse_args(argc, argv); @@ -47,6 +51,7 @@ struct Main { auto list_bundle(fs::path const& path) noexcept -> void { try { + rlib_trace("path: %s\n", path.generic_string().c_str()); auto infile = IOFile(path, true); auto bundle = RBUN::read(infile); for (std::uint64_t offset = 0; auto const& chunk : bundle.chunks) { diff --git a/src/rbun_usage.cpp b/src/rbun_usage.cpp index 9648ee8..a0d1166 100644 --- a/src/rbun_usage.cpp +++ b/src/rbun_usage.cpp @@ -105,6 +105,7 @@ struct Main { auto process_bundle(fs::path const& path) noexcept -> void { try { + rlib_trace("path: %s\n", path.generic_string().c_str()); auto infile = IOFile(path, false); auto bundle = RBUN::read(infile, true); for (std::uint64_t offset = 0; auto const& chunk : bundle.chunks) { diff --git a/src/rman_ls.cpp b/src/rman_ls.cpp index b048125..6c973aa 100644 --- a/src/rman_ls.cpp +++ b/src/rman_ls.cpp @@ -15,7 +15,11 @@ struct Main { auto parse_args(int argc, char** argv) -> void { argparse::ArgumentParser program(fs::path(argv[0]).filename().generic_string()); - program.add_description("Lists files in manifest."); + program.add_description( + "Lists files in manifest." + "\n" + "Output is in CSV format as follows:\n" + "Path,Size,ID,Lang1;Lang2;Lang3..."); program.add_argument("manifest").help("Manifest file to read from.").required(); program.add_argument("-l", "--filter-lang")