Code: Select all
void removeFile(const char *fullpath) {
sceIoRemove(fullpath);
}
long getFileSize(const char * fileName) {
struct stat file;
if(!stat(fileName, &file)) {
return file.st_size;
}
return 0;
}
char *filename[8] = { "PARAM.SFO", "ICON0.PNG", "ICON1.PMF", "UNKNOWN.PNG", "PIC1.PNG", "SND0.AT3", "UNKNOWN.PSP", "UNKNOWN.PSAR" };
Image* processPBP(const char * path) {
Image* imgSource;
Image* imgDefault;
char curPath[512];
getcwd(curPath, 512);
char loadImg[512];
sprintf(loadImg, "%s/icon0.png", curPath);
int theSize = 0;
int loop0, total_size;
FILE *infile, *outfile;
HEADER header;
infile = fopen(path, "rb");
fseek(infile, 0, SEEK_END); total_size = ftell(infile); fseek(infile, 0, SEEK_SET);
if (fread(&header, sizeof(HEADER), 1, infile) < 0) { printf("ERROR: Could not read the input file header. \n"); return NULL; }
if (header.signature[0] != 0x00) { printf("ERROR: Input file is not a PBP file. \n"); return NULL; } else
if (header.signature[1] != 0x50) { printf("ERROR: Input file is not a PBP file. \n"); return NULL; } else
if (header.signature[2] != 0x42) { printf("ERROR: Input file is not a PBP file. \n"); return NULL; } else
if (header.signature[3] != 0x50) { printf("ERROR: Input file is not a PBP file. \n"); return NULL; }
#ifdef __BIG_ENDIAN__
for (loop0=0;loop0<2;loop0++) {
header.offset[loop0] = NXSwapInt(header.offset[loop0]);
}
#endif
// loop0 = 0 is the param.sfo (reads the data then erases, because you have to loop or it ***** up)
// loop0 = 1 is the icon0.png (reads the data, spits out a file; we load, then delete it)
for (loop0=0; loop0<2; loop0++) { void *buffer; int size;
size = header.offset[loop0 + 1] - header.offset[loop0];
buffer = malloc(size);
if (buffer == NULL) { printf("ERROR: Could not allocate the section data buffer. (%d)\n", size); return NULL; }
if (fread(buffer, size, 1, infile) < 0) { printf("ERROR: Could not read in the section data.\n"); return NULL; }
if (loop0==1) {
// WTF (works great until after loading 10 homebrews!?)
// Mess up is happening here
outfile = fopen(filename[loop0], "wb");
if (outfile == NULL) {
printf("ERROR: Could not open the output file. (%s)\n", filename[loop0]);
return NULL;
}
// Mess up is happening here
if (fwrite(buffer, size, 1, outfile) < 0) { printf("ERROR: Could not write out the section data.\n"); return NULL; }
if (fclose(outfile) < 0) { printf("ERROR: Could not close the output file.\n"); return NULL; }
}
free(buffer);
}
theSize = getFileSize(loadImg);
printf("%02d \n", theSize); // Debug
if (theSize > 0) {
imgSource = loadImage(loadImg);
if (!(imgSource)) {
removeFile(loadImg);
imgDefault = loadImage("ms0:/PSPOSX/skins/default/pages/games/default.png");
return (imgDefault);
}
}
else {
removeFile(loadImg);
imgDefault = loadImage("ms0:/PSPOSX/skins/default/pages/games/default.png");
return (imgDefault);
}
removeFile(loadImg);
return (imgSource);
}
Hopefully somebody has some experience with this sort of thing and can lend me a hand.
See any problems with it?
Thanks