// Load MIN ROM (and others) int PokeMini_LoadROM(const char *filename) { int colorloaded; char tmp[PMTMPV]; // Save Individual EEPROM if (!CommandLine.eeprom_share) { if (PokeMini_EEPROMWritten && StringIsSet(CommandLine.eeprom_file)) { PokeMini_EEPROMWritten = 0; PokeMini_SaveEEPROMFile(CommandLine.eeprom_file); } } #ifndef NO_ZIP if (ExtensionCheck(filename, ".zip")) { // Load new MIN ROM and Color Information inside zip if (!PokeMini_iLoadROMZip(filename, &colorloaded)) return 0; strcpy(CommandLine.min_file, filename); } else #endif { // Setup LCD mode based of color support if (ExtensionCheck(filename, ".minc")) { // Remove c and load new MIN ROM strcpy(tmp, filename); tmp[strlen(filename)-1] = 0; if (!PokeMini_LoadMINFile(tmp)) return 0; strcpy(CommandLine.min_file, tmp); } else { // Load new MIN ROM if (!PokeMini_LoadMINFile(filename)) return 0; strcpy(CommandLine.min_file, filename); } // Load Color Information sprintf(tmp, "%sc", CommandLine.min_file); if (FileExist(tmp) && PokeMini_LoadColorFile(tmp)) { colorloaded = 1; } else colorloaded = 0; } if (!colorloaded) { if (CommandLine.lcdmode == 3) CommandLine.lcdmode = 0; } else CommandLine.lcdmode = 3; // Load Individual EEPROM if (!CommandLine.eeprom_share) { sprintf(CommandLine.eeprom_file, "%s.eep", CommandLine.min_file); MinxIO_FormatEEPROM(); if (FileExist(CommandLine.eeprom_file)) PokeMini_LoadEEPROMFile(CommandLine.eeprom_file); } // Soft reset hardware PokeMini_Reset(0); // Apply changes PokeMini_ApplyChanges(); return 1; }
int SBU::SBU_Extractor(char* inputPath, char* outputPath) { int length=0, capture=0, fileCount=0; long offset=0; int start=-1, end=-1; char* dataPath; //memset(folderPath, 0, 256); FILE* sbufile; MyFile mysbu; // 백업파일 열기 fopen_s(&sbufile, inputPath, "rb"); if( sbufile == NULL ) { puts("ReadFile open Error"); return 0; } // 데이터 저장용 폴더 생성 dataPath = MakeFolder(outputPath, "data"); while(1) { fseek(sbufile, 118+38*capture++, SEEK_SET); fread(Signature, 16, 1, sbufile); if(!strncmp(Signature, SBU_END, 8)) break; // 백업 데이터 출력 StartingOffset = mysbu.readNum(sbufile, ftell(sbufile), 8); fseek(sbufile, StartingOffset+22, SEEK_SET); SizeOfData = mysbu.readNum(sbufile, ftell(sbufile), 8); //cout << " " << endl;for(int i=0;i<16;i++)printf("%02X ", Signature[i] & 0xff); //cout << endl << " Data Area : " << StartingOffset+54 << " ~ " << StartingOffset+54+SizeOfData << endl; fileName = FileNameCheck(Signature); extension = ExtensionCheck(Signature); if(fileName == NULL) continue; mysbu.WriteFile(0, StartingOffset+54, StartingOffset+54+SizeOfData, 0, inputPath, dataPath, fileName, fileCount++, extension); ContentProcess(fileName, outputPath); } return fileCount; }
// Load compressed MIN ROM static int PokeMini_iLoadROMZip(const char *zipfile, int *colorloaded) { unzFile uf = NULL; unz_global_info64 gi; unz_file_info64 file_inf; char filein[PMTMPV]; void *new_data; int i, size, loaded = 0, cloaded = 0; if (colorloaded) *colorloaded = 0; // Open ZIP uf = unzOpen(zipfile); if (!uf) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Opening ZIP error"); return 0; } if (unzGetGlobalInfo64(uf, &gi) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Getting global info"); unzClose(uf); return 0; } // Find and load MIN for (i=0; i<gi.number_entry; i++) { if (unzGetCurrentFileInfo64(uf, &file_inf, filein, PMTMPV, NULL, 0, NULL, 0) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Current file info"); unzClose(uf); return 0; } if (ExtensionCheck(filein, ".min") && (!loaded)) { if (unzLocateFile(uf, filein, 0) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "LocateFile failed"); unzClose(uf); return 0; } if (unzOpenCurrentFile(uf) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Opening file error"); unzClose(uf); return 0; } size = GetMultiple2(file_inf.uncompressed_size); new_data = (void *)malloc(size); memset(new_data, 0xFF, size); if (!new_data) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Not enough memory"); unzCloseCurrentFile(uf); unzClose(uf); return 0; } size = unzReadCurrentFile(uf, new_data, file_inf.uncompressed_size); if (size < 0) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Reading file error"); unzCloseCurrentFile(uf); unzClose(uf); return 0; } PokeMini_FreeColorInfo(); // Free existing color information PokeMini_SetMINMem((uint8_t *)new_data, file_inf.uncompressed_size); PM_ROM_Alloc = 1; if (unzCloseCurrentFile(uf) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Closing file error"); unzClose(uf); return 0; } if (PokeMini_OnAllocMIN) PokeMini_OnAllocMIN(PM_ROM_Size, 1); if (PokeMini_OnLoadMINFile) PokeMini_OnLoadMINFile(zipfile, 1); loaded = 1; break; } if ((i+1) < gi.number_entry) { if (unzGoToNextFile(uf) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "No next file"); unzClose(uf); return 0; } } } // Check if there's color information file strcat(filein, "c"); if (!loaded) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "No ROM in ZIP"); unzClose(uf); return 0; } else { if (unzGoToFirstFile(uf) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "No first file"); unzClose(uf); return 0; } if (unzLocateFile(uf, filein, 0) == UNZ_OK) { if (unzOpenCurrentFile(uf) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Opening file error"); unzClose(uf); return 0; } if (!PokeMini_LoadColorStream(PokeMini_StreamFromZIP, uf)) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Reading file error"); unzCloseCurrentFile(uf); unzClose(uf); return 0; } if (unzCloseCurrentFile(uf) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Closing file error"); unzClose(uf); return 0; } cloaded = 1; if (colorloaded) *colorloaded = 1; if (PokeMini_OnLoadColorFile) PokeMini_OnLoadColorFile(zipfile, 1); } } // Close ZIP unzClose(uf); // Try to load color information from a file outside if wasn't found in the zip if (!cloaded) { // Filename based of the ROM inside the zip RemoveExtension(filein); strcat(filein, ".minc"); if (FileExist(filein)) { if (PokeMini_LoadColorFile(filein)) { if (colorloaded) *colorloaded = 1; if (PokeMini_OnLoadColorFile) PokeMini_OnLoadColorFile(zipfile, 1); return 1; } } // Filename based of the zip strcpy(filein, zipfile); RemoveExtension(filein); strcat(filein, ".minc"); if (FileExist(filein)) { if (PokeMini_LoadColorFile(filein)) { if (colorloaded) *colorloaded = 1; if (PokeMini_OnLoadColorFile) PokeMini_OnLoadColorFile(zipfile, 1); return 1; } } } return 1; }