Implement options flag and help menu
This commit is contained in:
parent
716d7ff496
commit
00be994dd5
@ -11,25 +11,57 @@
|
|||||||
#include "Texture-Extractor.h"
|
#include "Texture-Extractor.h"
|
||||||
|
|
||||||
|
|
||||||
|
int _options = 0x0000; // Global options settings variable
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
// Init buffer vars
|
// Init buffer vars
|
||||||
HMT_FILE *hmt_fdatas = NULL;
|
HMT_FILE *hmt_fdatas = NULL;
|
||||||
|
|
||||||
// Check if filenames arguments exist
|
// Check if filenames arguments exist
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
printf("No input file specified!\nCorrect syntax is:\n HMT-Extractor <texture_file_hmt>\n");
|
printf("\nNo input file/commands specified!\n\nCorrect syntax is:\n$> Texture-Extractor <texture_hmt_file>\n"); //TODO: add help function
|
||||||
return EXCEPTION_NONCONTINUABLE; //TODO: implement own error codes system
|
return EXCEPTION_NONCONTINUABLE; //TODO: implement own error codes system
|
||||||
}
|
}
|
||||||
|
_options = checkArgs(argv, argc); // Analyse program arguments
|
||||||
|
if (_options == -1) return EXIT_SUCCESS;
|
||||||
|
|
||||||
// Do the work
|
// Do the work
|
||||||
hmt_fdatas = extractDatasFromHMT(argv[1]); //TODO: Manage multi inputs files
|
hmt_fdatas = extractDatasFromHMT(argv[(_options >> 8) + 0]); //TODO: Manage multi inputs files
|
||||||
if (hmt_fdatas == NULL) return EXIT_FAILURE;
|
if (hmt_fdatas == NULL) return EXIT_FAILURE;
|
||||||
if (exportTextures(hmt_fdatas, argv[1]) == EXIT_FAILURE) return EXIT_FAILURE;
|
if (exportTextures(hmt_fdatas, argv[(_options >> 8) + 0]) == EXIT_FAILURE) return EXIT_FAILURE;
|
||||||
purgeHMTFromMemory(hmt_fdatas); // Clean up memory (because I'm a good boy)
|
purgeHMTFromMemory(hmt_fdatas); // Clean up memory (because I'm a good boy)
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int checkArgs(char *args[], int arg_nbr) {
|
||||||
|
int _o = 0x0000;
|
||||||
|
char test[256];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (arg_nbr > 1) {
|
||||||
|
for (i=1; i<arg_nbr; i++) {
|
||||||
|
strcpy(test, args[i]);
|
||||||
|
if (args[i][0] != '-') break;
|
||||||
|
if (strcmp(args[i], "-h") == 0) {
|
||||||
|
dispHelp();
|
||||||
|
return -1;
|
||||||
|
} else if (strcmp(args[i], "-v") == 0) {
|
||||||
|
_o |= VERBOSE_ENABLED;
|
||||||
|
printf("[INFO] Verbose enabled.\n");
|
||||||
|
} else if (strcmp(args[i], "-no-subdir") == 0) {
|
||||||
|
_o |= NO_OUTPUT_DIR;
|
||||||
|
printf("[INFO] Extract to current directory.\n");
|
||||||
|
} else {
|
||||||
|
printf("[INFO] Unknow option: %s\n", args[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_o = (i << 8) | (_o & 0x00FF);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _o;
|
||||||
|
}
|
||||||
|
|
||||||
void createSubDir(char *dirName) {
|
void createSubDir(char *dirName) {
|
||||||
if (dirName == NULL) return;
|
if (dirName == NULL) return;
|
||||||
char _dir[50];
|
char _dir[50];
|
||||||
@ -39,7 +71,7 @@ void createSubDir(char *dirName) {
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
CreateDirectory(_dir, NULL);
|
CreateDirectory(_dir, NULL);
|
||||||
#else
|
#else
|
||||||
mkdir(dirName, 755);
|
mkdir(_dir, 755);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +84,7 @@ HMT_FILE *extractDatasFromHMT(char *hmt_filename) {
|
|||||||
hmt_fdatas = parseHMTFile(_hmtFile);
|
hmt_fdatas = parseHMTFile(_hmtFile);
|
||||||
if (hmt_fdatas == NULL) printf("[ERR] Failed to parse datas from %s\n", hmt_filename);
|
if (hmt_fdatas == NULL) printf("[ERR] Failed to parse datas from %s\n", hmt_filename);
|
||||||
} else {
|
} else {
|
||||||
printf("[ERR] Input file not found!\n");
|
printf("[ERR] Input file %s not found!\n", hmt_filename);
|
||||||
}
|
}
|
||||||
fclose(_hmtFile);
|
fclose(_hmtFile);
|
||||||
|
|
||||||
@ -62,6 +94,7 @@ HMT_FILE *extractDatasFromHMT(char *hmt_filename) {
|
|||||||
int exportTextures(HMT_FILE *hmt_f, char *filename) {
|
int exportTextures(HMT_FILE *hmt_f, char *filename) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if(hmt_f->texture_count > 0) {
|
||||||
createSubDir(filename);
|
createSubDir(filename);
|
||||||
for (i=0; i<hmt_f->texture_count; i++) {
|
for (i=0; i<hmt_f->texture_count; i++) {
|
||||||
switch (hmt_f->textures_list[i].image.type_) {
|
switch (hmt_f->textures_list[i].image.type_) {
|
||||||
@ -77,6 +110,17 @@ int exportTextures(HMT_FILE *hmt_f, char *filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dispHelp() {
|
||||||
|
printf("\n");
|
||||||
|
printf("RogueSquadron Data Extractor - TEXTURE module\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("Options:\n -h Print this message\n -v Activate verbose output\n -no-subdir Extract textures directly inside current folder\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("Usage: Texture-Extractor_\"version\" [options] <hmt files...>\n");
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
@ -14,9 +14,14 @@
|
|||||||
#include "RS_images.h"
|
#include "RS_images.h"
|
||||||
#include "Image_Exporter.h"
|
#include "Image_Exporter.h"
|
||||||
|
|
||||||
|
#define VERBOSE_ENABLED 0x0001
|
||||||
|
#define NO_OUTPUT_DIR 0x0002
|
||||||
|
|
||||||
|
|
||||||
void createSubDir(char *dirName);
|
void createSubDir(char *dirName);
|
||||||
|
int checkArgs(char *args[], int arg_nbr);
|
||||||
HMT_FILE *extractDatasFromHMT(char* hmt_filename);
|
HMT_FILE *extractDatasFromHMT(char* hmt_filename);
|
||||||
int exportTextures(HMT_FILE *hmt_f, char *filename);
|
int exportTextures(HMT_FILE *hmt_f, char *filename);
|
||||||
|
void dispHelp();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user