From f8b2a5b8e400d4195d80338d2a01fe9f1f001e50 Mon Sep 17 00:00:00 2001 From: torph <73564623+Torphedo@users.noreply.github.com> Date: Mon, 15 Jan 2024 18:14:27 -0500 Subject: [PATCH] Allow specifying output path --- alr/src/arguments.c | 12 +++++++++++- alr/src/arguments.h | 3 ++- alr/src/main.c | 14 +++++++++----- alr/src/replace.c | 1 - 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/alr/src/arguments.c b/alr/src/arguments.c index 9a62452..01f6c8f 100644 --- a/alr/src/arguments.c +++ b/alr/src/arguments.c @@ -16,7 +16,17 @@ flags parse_arguments(int argc, char** argv) { // Check if first 2 characters are "--" if (argv[i][0] != '-' || argv[i][1] != '-') { // If it's not a flag, it must be a filename - output.filename = argv[i]; + if (output.input_path != NULL) { + if (output.output_path != NULL) { + output.input_path = output.output_path; + } + output.output_path = argv[i]; + } + else { + output.input_path = argv[i]; + } + + continue; } diff --git a/alr/src/arguments.h b/alr/src/arguments.h index f4d5408..1ded180 100644 --- a/alr/src/arguments.h +++ b/alr/src/arguments.h @@ -10,7 +10,8 @@ typedef enum { }program_mode; typedef struct { - char* filename; + char* input_path; + char* output_path; program_mode mode; bool silent; }flags; diff --git a/alr/src/main.c b/alr/src/main.c index c3c131b..4b736d6 100644 --- a/alr/src/main.c +++ b/alr/src/main.c @@ -12,14 +12,14 @@ int main(int argc, char* argv[]) { // Parse command-line arguments. flags options = parse_arguments(argc, argv); - if (options.filename == NULL) { - LOG_MSG(error, "No filenames detected.\n"); + if (options.input_path == NULL) { + LOG_MSG(error, "No ALR to operate on, exiting\n"); return 1; } - if (options.silent) { disable_logging(); } + // Default to dump behaviour if nothing is specified. No arguments probably // means someone drag-and-dropped, which means they probably want textures. alr_interface interface = dump_interface; @@ -39,13 +39,17 @@ int main(int argc, char* argv[]) { LOG_MSG(error, "Unimplemented program mode, exiting.\n"); return 1; case replacetex: - return !(alr_edit(options.filename, "out.alr", options, replace_interface)); + if (options.output_path == NULL) { + LOG_MSG(error, "No output file provided.\n"); + return 1; + } + return !(alr_edit(options.input_path, options.output_path, options, replace_interface)); break; } // Parse ALR with selected interface. // Return value must be inverted because stdbool false == 0, and an exit // code of 0 means success. - return !(alr_parse(options.filename, options, interface)); + return !(alr_parse(options.input_path, options, interface)); } diff --git a/alr/src/replace.c b/alr/src/replace.c index 9b34737..e8e8e66 100644 --- a/alr/src/replace.c +++ b/alr/src/replace.c @@ -6,7 +6,6 @@ #include "int_shorthands.h" #include "filesystem.h" -#include "alr.h" // Size of DDS header and pixel format header #define DDS_HEADER_SIZE (0x7F)