Skip to content

Commit

Permalink
more help and better printing
Browse files Browse the repository at this point in the history
  • Loading branch information
moonshadow565 committed Jun 13, 2022
1 parent b13d058 commit ce280d9
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 15 deletions.
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Set of tools to manipulate manifest and bundle files from CLI.

```sh
Usage: rbun-add.exe [options] output input

Expand All @@ -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.
Expand All @@ -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: <not representable>]
-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: <not representable>]
-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
Expand Down Expand Up @@ -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]
Expand Down
12 changes: 9 additions & 3 deletions src/rbun_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
}
Expand Down
37 changes: 29 additions & 8 deletions src/rbun_chk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ using namespace rlib;
struct Main {
struct CLI {
std::vector<std::string> inputs = {};
bool no_hash = {};
bool no_extract = {};
} cli = {};

auto parse_args(int argc, char** argv) -> void {
argparse::ArgumentParser program(fs::path(argv[0]).filename().generic_string());
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<bool>("--no-extract");
cli.no_extract = program.get<bool>("--no-hash");

cli.inputs = program.get<std::vector<std::string>>("input");
}

Expand Down Expand Up @@ -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();
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/rbun_ls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/rbun_usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion src/rman_ls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit ce280d9

Please sign in to comment.