From ceda7715c02c25fd34628e1509e3c24fd3b49f31 Mon Sep 17 00:00:00 2001 From: jakob Date: Sat, 14 Jan 2017 16:49:23 -0500 Subject: Added quiet option. --- TODO.md | 1 - src/cli.c | 16 +++++++++++++--- src/cli.h | 1 + src/write.c | 14 +++++++++++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 4889310..9612929 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,3 @@ TODO ==== * Write a 100% compatible repacker to aid in translation efforts. -* Functionality for just listing the archive's contents. diff --git a/src/cli.c b/src/cli.c index 11638a2..0c8dce8 100644 --- a/src/cli.c +++ b/src/cli.c @@ -37,7 +37,9 @@ " -a, --archive\tAlternate way of specifying archive" \ "to extract.\n" \ " -g, --game\t\tGame the archive is from. Required for " \ - "file decryption" + "file decryption\n" \ + " -q, --quiet\t\tDon't display information about " \ + "extracted files." #define GAME_CONSTANTS "none, nekopara_volume_0, nekopara_volume_0_steam, " \ "nekopara_volume_1, nekopara_volume_1_steam" @@ -47,7 +49,7 @@ struct configuration parse_args(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "Usage: %s [OPTIONS] (ARCHIVE PATH)\n", argv[0]); - exit(1); + exit(EXIT_FAILURE); } /* The struct has to be zeroed out, otherwise argument parsing @@ -62,11 +64,16 @@ struct configuration parse_args(int argc, char *argv[]) { static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, + {"quiet", no_argument, NULL, 'q'}, + {"extract", no_argument, NULL, 'e'}, + {"list", no_argument, NULL, 'l'}, + {"archive", required_argument, NULL, 'a'}, + {"game", required_argument, NULL, 'g'}, {NULL, 0, NULL, 0} }; do { - current = getopt_long(argc, argv, "hvela:g:", long_options, + current = getopt_long(argc, argv, "hvelqa:g:", long_options, &option_index); switch (current) { case 'h': @@ -78,6 +85,9 @@ struct configuration parse_args(int argc, char *argv[]) { printf("Nekopack, version %s\nProgrammed by " "Jakob. \n", VERSION); exit(EXIT_SUCCESS); + case 'q': + parsed.quiet = 1; + break; case 'a': count++; parsed.archive_path = optarg; diff --git a/src/cli.h b/src/cli.h index 2b2d988..5874fb2 100644 --- a/src/cli.h +++ b/src/cli.h @@ -37,6 +37,7 @@ typedef enum mode_type { /* Binary structure for storing command-line options. */ struct configuration { + int quiet; /* Level of output verbosity. */ game_type game; /* Which decryption key to use. */ mode_type mode; /* What to do after initial sanity checks. */ const char *archive_path; /* Path to archive to extract. */ diff --git a/src/write.c b/src/write.c index ebf640c..6aeb629 100644 --- a/src/write.c +++ b/src/write.c @@ -15,6 +15,7 @@ You should have received a copy of the GNU General Public License along with Nekopack. If not, see . */ +#include #include #include #include @@ -62,8 +63,18 @@ void write_files(file_node *file_root, elif_node *elif_root, FILE *archive) { if (file_name == NULL) continue; - /* out_start is kept so out_buffer can be incremented. */ + if (!arguments.quiet) { + printf("Inflating %s (%" PRIu64 " bytes)\n", + file_name, current->file_size); + } + out_buffer = malloc(current->file_size); + if (out_buffer == NULL) { + fprintf(stderr, "Insufficient memory to decompress.\n"); + return; + } + + /* out_start is kept so out_buffer can be incremented. */ out_start = out_buffer; for (uint64_t i = 0; i < current->segment_count; i++) { segment *chunk = current->segments[i]; @@ -96,6 +107,7 @@ void write_files(file_node *file_root, elif_node *elif_root, FILE *archive) { } fwrite(out_start, current->file_size, 1, output); fclose(output); + free(file_name); free(out_start); } } -- cgit v1.3