Detect mempak file type by extension

- Also close file after writing
This commit is contained in:
Raphael Assenat 2015-10-31 15:19:57 -04:00
parent 5ff36596bb
commit 11d55b085b
2 changed files with 20 additions and 0 deletions

View File

@ -1,7 +1,9 @@
#define _GNU_SOURCE // for strcasestr
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <libgen.h>
#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;
}

View File

@ -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);