diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cli.c | 16 | ||||
| -rw-r--r-- | src/cli.h | 1 | ||||
| -rw-r--r-- | src/write.c | 14 |
3 files changed, 27 insertions, 4 deletions
@@ -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. <http://tsar-fox.com/>\n", VERSION); exit(EXIT_SUCCESS); + case 'q': + parsed.quiet = 1; + break; case 'a': count++; parsed.archive_path = optarg; @@ -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 <http://www.gnu.org/licenses/>. */ +#include <inttypes.h> #include <stdint.h> #include <stdlib.h> #include <string.h> @@ -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); } } |