re-add duc importing for new savefile system

This commit is contained in:
zeromus 2009-05-20 06:05:39 +00:00
parent c6c2ec7137
commit 47e27cffa5
3 changed files with 39 additions and 1 deletions

View File

@ -1090,7 +1090,7 @@ int NDS_ImportSave(const char *filename)
return 0;
if (memcmp(filename+strlen(filename)-4, ".duc", 4) == 0)
return mc_load_duc(&MMU.bupmem, filename);
return MMU_new.backupDevice.load_duc(filename);
return 0;
}

View File

@ -874,3 +874,39 @@ void BackupDevice::flush()
LOG("Unable to open savefile %s\n",filename.c_str());
}
}
bool BackupDevice::load_duc(const char* filename)
{
long size;
char id[16];
FILE* file = fopen(filename, "rb");
size_t elems_read = 0;
if(file == NULL)
return false;
fseek(file, 0, SEEK_END);
size = ftell(file) - 500;
fseek(file, 0, SEEK_SET);
// Make sure we really have the right file
elems_read += fread((void *)id, sizeof(char), 16, file);
if (memcmp(id, "ARDS000000000001", 16) != 0)
{
LOG("Not recognized as a valid DUC file\n");
fclose(file);
return false;
}
// Skip the rest of the header since we don't need it
fseek(file, 500, SEEK_SET);
ensure((u32)size);
fread(&data[0],1,size,file);
fclose(file);
flush();
return true;
}

View File

@ -88,6 +88,8 @@ public:
static u32 addr_size_for_old_save_size(int bupmem_size);
static u32 addr_size_for_old_save_type(int bupmem_type);
bool load_duc(const char* filename);
private:
BOOL write_enable; //is write enabled?
u32 com; //persistent command actually handled