From f70f4a698b7d236c6294a5584ee922e9a37707e5 Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Sun, 21 Jul 2019 17:20:22 +0200 Subject: [PATCH] Finish add verbose option --- src/HMT_Parser.c | 35 +++++++++++++++++++++-------------- src/HMT_Parser.h | 1 + src/Image_Exporter.c | 2 ++ src/Image_Exporter.h | 1 + src/RS_images.c | 2 ++ src/RS_images.h | 2 ++ src/Texture-Extractor.c | 9 +++++---- src/Texture-Extractor.h | 4 +--- src/options.h | 9 +++++++++ 9 files changed, 44 insertions(+), 21 deletions(-) create mode 100644 src/options.h diff --git a/src/HMT_Parser.c b/src/HMT_Parser.c index 20ad2c8..77297b2 100644 --- a/src/HMT_Parser.c +++ b/src/HMT_Parser.c @@ -1,5 +1,8 @@ #include "HMT_Parser.h" + +extern int _options; // Global options settings variable + HMT_FILE *parseHMTFile(FILE *hmt_src) { int i; HMT_FILE *_buff = NULL; @@ -12,7 +15,7 @@ HMT_FILE *parseHMTFile(FILE *hmt_src) { fread(&(_buff->texture_offset), 4, 1, hmt_src); // Read materials - printf("\n\nMaterials detected: %d\n", _buff->material_count); + printf("[INFO] Materials detected: %d\n", _buff->material_count); _buff->materials_list = calloc(_buff->material_count, sizeof(HMT_MATERIAL)); // Create a big list of materials entries for (i=0; i<_buff->material_count; i++) { // Extract materials datas @@ -25,7 +28,7 @@ HMT_FILE *parseHMTFile(FILE *hmt_src) { // Read textures fseek(hmt_src, _buff->texture_offset, SEEK_SET); fread(&(_buff->texture_count), 4, 1, hmt_src); - printf("\n\nTextures detected: %d\n", _buff->texture_count); + printf("[INFO] Textures detected: %d\n\n", _buff->texture_count); if (_buff->texture_count > 0) { _buff->textures_list = calloc(_buff->texture_count, sizeof(HMT_TEXTURE)); // Create a big list of textures entries for (i=0; i<_buff->texture_count; i++) { @@ -45,8 +48,10 @@ int readMaterial(HMT_MATERIAL *mat, FILE *hmt_src) { fread(mat, sizeof(HMT_MATERIAL), 1, hmt_src); - if (mat->zero != 0 || mat->hex_a != 0x0A) printf("\n Uncommon file detected!\n"); - printf("Material type: %d\nTexture index: %d\n", mat->type_, mat->texture_index); + if (_options & 0x1) { + if (mat->zero != 0 || mat->hex_a != 0x0A) printf("\n Uncommon file detected!\n"); + printf("Material type: %d\nTexture index: %d\n", mat->type_, mat->texture_index); + } return EXIT_SUCCESS; } @@ -83,17 +88,19 @@ int readTexture(HMT_TEXTURE *tex, FILE *hmt_src) { tex->image.width = tex->width; tex->image.height = tex->height; - printf("\n"); - printf("Texture name: %s\n", tex->name); - printf("Size w: %ld h: %ld\n", tex->width, tex->height); - printf("Texture subtype: %d\n", tex->image.type_); - printf("Palette offset: %d\n", tex->palette_offset); - printf("Data offset: %d\n", tex->data_offset); - printf("Transparent color (RGB): %X %X %X\n", tex->image.alpha_color._red, tex->image.alpha_color._green, tex->image.alpha_color._blue); - printf("u0: %d u1: %d\n", u0, u1); + if (_options & VERBOSE_ENABLED) { + printf("\n"); + printf("Texture name: %s\n", tex->name); + printf("Size w: %ld h: %ld\n", tex->width, tex->height); + printf("Texture subtype: %d\n", tex->image.type_); + printf("Palette offset: %d\n", tex->palette_offset); + printf("Data offset: %d\n", tex->data_offset); + printf("Transparent color (RGB): %X %X %X\n", tex->image.alpha_color._red, tex->image.alpha_color._green, tex->image.alpha_color._blue); + printf("u0: %d u1: %d\n", u0, u1); + } if (tex->palette_offset > 0) { - printf("\nPalette entries: %d\n", tex->image.paletteEntries); + if (_options & VERBOSE_ENABLED) printf("\nPalette entries: %d\n", tex->image.paletteEntries); fseek(hmt_src, tex->palette_offset, SEEK_SET); getPaletteFromFile(&(tex->image), hmt_src); } @@ -126,7 +133,7 @@ int getSamplesFromFile(RS_IMAGE *img, FILE *f) { int size = div(img->width*img->height*sample_bits, 8).quot; if (f->_bufsiz >= ftell(f)+size) { - printf("WARNING! Please fix size/sample."); + printf("[ERR] WARNING! Please fix size/sample."); return EXIT_FAILURE; } diff --git a/src/HMT_Parser.h b/src/HMT_Parser.h index 5f2e4fe..50dbd38 100644 --- a/src/HMT_Parser.h +++ b/src/HMT_Parser.h @@ -3,6 +3,7 @@ #include #include +#include "options.h" #include "RS_images.h" ///////////////////////////// diff --git a/src/Image_Exporter.c b/src/Image_Exporter.c index 4264511..c7e7774 100644 --- a/src/Image_Exporter.c +++ b/src/Image_Exporter.c @@ -1,6 +1,8 @@ #include "Image_Exporter.h" +//extern int _options; // Global options settings variable + int saveToPNG(RS_IMAGE *img, char *tex_path, char *hmt_fileName) { if (tex_path == NULL || img == NULL) return EXIT_FAILURE; char export_path[128]; diff --git a/src/Image_Exporter.h b/src/Image_Exporter.h index 8298a25..d4a61e2 100644 --- a/src/Image_Exporter.h +++ b/src/Image_Exporter.h @@ -1,6 +1,7 @@ #ifndef IMAGE_EXPORTER_H_ #define IMAGE_EXPORTER_H_ +//#include "options.h" #include "RS_images.h" #include #include diff --git a/src/RS_images.c b/src/RS_images.c index 998d3af..71305f2 100644 --- a/src/RS_images.c +++ b/src/RS_images.c @@ -1,6 +1,8 @@ #include "RS_images.h" +//extern int _options; // Global options settings variable + void decodePixels(RS_IMAGE *img) { int size; diff --git a/src/RS_images.h b/src/RS_images.h index 4db0f0a..c3ceb60 100644 --- a/src/RS_images.h +++ b/src/RS_images.h @@ -4,6 +4,8 @@ #include #include #include +//#include "options.h" + /** * @brief Constant contain the number of channel inside a PIXEL definition. */ diff --git a/src/Texture-Extractor.c b/src/Texture-Extractor.c index e1d661d..51a3c53 100644 --- a/src/Texture-Extractor.c +++ b/src/Texture-Extractor.c @@ -2,7 +2,7 @@ ================================================================================ Name : Texture-Extractor.c Author : JackCarterSmith - Version : 1.0 + Version : 1.0a License : GPL-v3.0 Description : DAT textures extractor to PNG format with enhanced function in C ================================================================================ @@ -11,7 +11,7 @@ #include "Texture-Extractor.h" -int _options = 0x0000; // Global options settings variable +extern int _options; // Global options settings variable int main(int argc, char *argv[]) { // Init buffer vars @@ -27,7 +27,7 @@ int main(int argc, char *argv[]) { if (_options == -1) return EXIT_SUCCESS; // Do the work - for (file_index=(_options >> 8) & 0xFF; file_index> 8) & 0xFF; file_index #include #endif +#include "options.h" #include "HMT_Parser.h" #include "RS_images.h" #include "Image_Exporter.h" -#define VERBOSE_ENABLED 0x0001 -#define NO_OUTPUT_DIR 0x0002 - void createSubDir(char *dirName); int checkArgs(char *args[], int arg_nbr); diff --git a/src/options.h b/src/options.h new file mode 100644 index 0000000..42635ba --- /dev/null +++ b/src/options.h @@ -0,0 +1,9 @@ +#ifndef OPTIONS_H_ +#define OPTIONS_H_ + +#define VERBOSE_ENABLED 0x0001 +#define NO_OUTPUT_DIR 0x0002 + +int _options; + +#endif