Detect mempak file type by extension
- Also close file after writing
This commit is contained in:
parent
5ff36596bb
commit
11d55b085b
|
@ -1,7 +1,9 @@
|
||||||
|
#define _GNU_SOURCE // for strcasestr
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
#include <libgen.h>
|
||||||
#include "mempak.h"
|
#include "mempak.h"
|
||||||
|
|
||||||
#define DEXDRIVE_DATA_OFFSET 0x1040
|
#define DEXDRIVE_DATA_OFFSET 0x1040
|
||||||
|
@ -295,6 +297,7 @@ int mempak_saveToFile(mempak_structure_t *mpk, const char *dst_filename, unsigne
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(fptr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,3 +416,19 @@ int mempak_string2format(const char *str)
|
||||||
return MPK_FORMAT_INVALID;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
int mempak_importNote(mempak_structure_t *mpk, const char *notefile, int dst_note_id, int *note_id);
|
||||||
void mempak_free(mempak_structure_t *mpk);
|
void mempak_free(mempak_structure_t *mpk);
|
||||||
|
|
||||||
|
int mempak_getFilenameFormat(const char *filename);
|
||||||
int mempak_string2format(const char *str);
|
int mempak_string2format(const char *str);
|
||||||
const char *mempak_format2string(int fmt);
|
const char *mempak_format2string(int fmt);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue