From 11d55b085ba4ba6c25077d264ed514833a6f4b27 Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Sat, 31 Oct 2015 15:19:57 -0400 Subject: [PATCH] Detect mempak file type by extension - Also close file after writing --- tool/mempak.c | 19 +++++++++++++++++++ tool/mempak.h | 1 + 2 files changed, 20 insertions(+) diff --git a/tool/mempak.c b/tool/mempak.c index 1255f68..013e7f6 100644 --- a/tool/mempak.c +++ b/tool/mempak.c @@ -1,7 +1,9 @@ +#define _GNU_SOURCE // for strcasestr #include #include #include #include +#include #include "mempak.h" #define DEXDRIVE_DATA_OFFSET 0x1040 @@ -295,6 +297,7 @@ int mempak_saveToFile(mempak_structure_t *mpk, const char *dst_filename, unsigne break; } + fclose(fptr); return 0; } @@ -413,3 +416,19 @@ int mempak_string2format(const char *str) return MPK_FORMAT_INVALID; } +int mempak_getFilenameFormat(const char *filename) +{ + char *s; + + if ((s = strcasestr(filename, ".N64"))) { + if (s[4] == 0) + return MPK_FORMAT_N64; + } + if ((s = strcasestr(filename, ".MPK"))) { + if (s[4] == 0) + return MPK_FORMAT_MPK4; + } + + return MPK_FORMAT_INVALID; +} + diff --git a/tool/mempak.h b/tool/mempak.h index 8ee8b40..ced0d55 100644 --- a/tool/mempak.h +++ b/tool/mempak.h @@ -26,6 +26,7 @@ int mempak_exportNote(mempak_structure_t *mpk, int note_id, const char *dst_file int mempak_importNote(mempak_structure_t *mpk, const char *notefile, int dst_note_id, int *note_id); void mempak_free(mempak_structure_t *mpk); +int mempak_getFilenameFormat(const char *filename); int mempak_string2format(const char *str); const char *mempak_format2string(int fmt);