bool BackupDevice::load_raw(const char* filename, u32 force_size) { FILE* inf = fopen(filename,"rb"); if (!inf) return false; fseek(inf, 0, SEEK_END); u32 size = (u32)ftell(inf); u32 left = 0; if (force_size > 0) { if (size > force_size) size = force_size; else if (size < force_size) { left = force_size - size; size = force_size; } } fseek(inf, 0, SEEK_SET); raw_applyUserSettings(size, (force_size > 0)); fread(&data[0],1,size-left,inf); fclose(inf); //dump back out as a dsv, just to keep things sane flush(); return true; }
bool BackupDevice::import_duc(const char* filename, u32 force_size) { size_t elements_read; u32 size; char id[16]; FILE* file = fopen(filename, "rb"); if(!file) return false; fseek(file, 0, SEEK_END); size = (u32)ftell(file) - 500; fseek(file, 0, SEEK_SET); // Make sure we really have the right file elements_read = fread((void *)id, sizeof(char), 16, file); if (elements_read != 16) printf("DUC file should be 16 bytes, not %lu bytes.\n", elements_read); if (memcmp(id, "ARDS000000000001", 16) != 0) { printf("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); u32 left = 0; if (force_size > 0) { if (size > force_size) size = force_size; else if (size < force_size) { left = force_size - size; size = force_size; } } raw_applyUserSettings(size, (force_size > 0)); u8 *data = new u8[size]; u32 sz = (size-left); bool res = (fread(data, 1, sz, file) == sz); fclose(file); if (res) saveBuffer(data, sz, true, true); delete [] data; return res; }
bool BackupDevice::load_no_gba(const char *fname, u32 force_size) { FILE *fsrc = fopen(fname, "rb"); u8 *in_buf = NULL; u8 *out_buf = NULL; if (fsrc) { u32 fsize = 0; fseek(fsrc, 0, SEEK_END); fsize = ftell(fsrc); fseek(fsrc, 0, SEEK_SET); //printf("Open %s file (size %i bytes)\n", fname, fsize); in_buf = new u8 [fsize]; if (fread(in_buf, 1, fsize, fsrc) == fsize) { out_buf = new u8 [8 * 1024 * 1024 / 8]; u32 size = 0; memset(out_buf, 0xFF, 8 * 1024 * 1024 / 8); if (no_gba_unpackSAV(in_buf, fsize, out_buf, size) == 0) { if (force_size > 0) size = force_size; //printf("New size %i byte(s)\n", size); size = no_gba_savTrim(out_buf, size); //printf("--- new size after trim %i byte(s)\n", size); size = no_gba_fillLeft(size); //printf("--- new size after fill %i byte(s)\n", size); raw_applyUserSettings(size, (force_size > 0)); resize(size); for (u32 tt = 0; tt < size; tt++) data[tt] = out_buf[tt]; //dump back out as a dsv, just to keep things sane flush(); printf("---- Loaded no$GBA save\n"); if (in_buf) delete [] in_buf; if (out_buf) delete [] out_buf; fclose(fsrc); return true; } if (out_buf) delete [] out_buf; } if (in_buf) delete [] in_buf; fclose(fsrc); } return false; }
bool BackupDevice::load_duc(const char* filename, u32 force_size) { u32 size; char id[16]; FILE* file = fopen(filename, "rb"); if(!file) return false; fseek(file, 0, SEEK_END); size = (u32)ftell(file) - 500; fseek(file, 0, SEEK_SET); // Make sure we really have the right file fread((void *)id, sizeof(char), 16, file); if (memcmp(id, "ARDS000000000001", 16) != 0) { printf("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); u32 left = 0; if (force_size > 0) { if (size > force_size) size = force_size; else if (size < force_size) { left = force_size - size; size = force_size; } } raw_applyUserSettings(size, (force_size > 0)); ensure((u32)size); fread(&data[0],1,size-left,file); fclose(file); //choose flush(); return true; }
bool BackupDevice::import_no_gba(const char *fname, u32 force_size) { FILE *fsrc = fopen(fname, "rb"); u8 *in_buf = NULL; u8 *out_buf = NULL; if (fsrc) { u32 fsize = 0; fseek(fsrc, 0, SEEK_END); fsize = ftell(fsrc); fseek(fsrc, 0, SEEK_SET); //printf("Open %s file (size %i bytes)\n", fname, fsize); in_buf = new u8 [fsize]; if (fread(in_buf, 1, fsize, fsrc) == fsize) { out_buf = new u8 [8 * 1024 * 1024 / 8]; u32 size = 0; memset(out_buf, 0xFF, 8 * 1024 * 1024 / 8); if (no_gba_unpackSAV(in_buf, fsize, out_buf, size) == 0) { if (force_size > 0) size = force_size; //printf("New size %i byte(s)\n", size); size = trim(out_buf, size); //printf("--- new size after trim %i byte(s)\n", size); size = fillLeft(size); //printf("--- new size after fill %i byte(s)\n", size); raw_applyUserSettings(size, (force_size > 0)); saveBuffer(out_buf, size, true, true); if (in_buf) delete [] in_buf; if (out_buf) delete [] out_buf; fclose(fsrc); return true; } if (out_buf) delete [] out_buf; } if (in_buf) delete [] in_buf; fclose(fsrc); } return false; }
bool BackupDevice::load_raw(const char* filename) { FILE* inf = fopen(filename,"rb"); fseek(inf, 0, SEEK_END); u32 size = (u32)ftell(inf); fseek(inf, 0, SEEK_SET); raw_applyUserSettings(size); data.resize(size); fread(&data[0],1,size,inf); fclose(inf); //dump back out as a dsv, just to keep things sane flush(); return true; }
bool BackupDevice::import_raw(const char* filename, u32 force_size) { FILE* inf = fopen(filename,"rb"); if (!inf) return false; fseek(inf, 0, SEEK_END); u32 size = (u32)ftell(inf); u32 left = 0; if (force_size > 0) { if (size > force_size) size = force_size; else if (size < force_size) { left = force_size - size; size = force_size; } } fseek(inf, 0, SEEK_SET); raw_applyUserSettings(size, (force_size > 0)); u8 *data = new u8[size]; u32 sz = (size-left); bool res = (fread(data, 1, sz, inf) == sz); fclose(inf); if (res) saveBuffer(data, sz, true, true); delete [] data; return true; }