fix .dnm and .eft loading

This commit is contained in:
tildearrow 2024-03-16 12:16:09 -05:00
parent 92b1c95259
commit 845eb582a6
5 changed files with 24 additions and 6 deletions

View file

@ -19,10 +19,10 @@
#include "fileOpsCommon.h"
bool DivEngine::load(unsigned char* f, size_t slen) {
bool DivEngine::load(unsigned char* f, size_t slen, const char* nameHint) {
unsigned char* file;
size_t len;
if (slen<18) {
if (slen<21) {
logE("too small!");
lastError="file is too small";
delete[] f;
@ -31,6 +31,21 @@ bool DivEngine::load(unsigned char* f, size_t slen) {
if (!systemsRegistered) registerSystems();
// step 0: get extension of file
String extS;
if (nameHint!=NULL) {
const char* ext=strrchr(nameHint,'.');
if (ext!=NULL) {
for (; *ext; ext++) {
char i=*ext;
if (i>='A' && i<='Z') {
i+='a'-'A';
}
extS+=i;
}
}
}
// step 1: try loading as a zlib-compressed file
logD("trying zlib...");
try {
@ -128,7 +143,9 @@ bool DivEngine::load(unsigned char* f, size_t slen) {
if (memcmp(file,DIV_DMF_MAGIC,16)==0) {
return loadDMF(file,len);
} else if (memcmp(file,DIV_FTM_MAGIC,18)==0) {
return loadFTM(file,len,false,false,false);
return loadFTM(file,len,(extS==".dnm"),false,(extS==".eft"));
} else if (memcmp(file,DIV_DNM_MAGIC,21)==0) {
return loadFTM(file,len,true,true,false);
} else if (memcmp(file,DIV_FUR_MAGIC,16)==0) {
return loadFur(file,len);
} else if (memcmp(file,DIV_FUR_MAGIC_DS0,16)==0) {