SetStatus("Flashing files...");
fd = sceIoOpen("ms0:/500.PBP", PSP_O_RDONLY, 0);
if (fd < 0)
{
InstallError(ofw, "Error opening 500.PBP: 0x%08X", fd);
}
size = sceIoLseek32(fd, 0, PSP_SEEK_END);
sceIoLseek32(fd, 0, PSP_SEEK_SET);
sceIoRead(fd, pbp_header, sizeof(pbp_header));
sceIoLseek32(fd, *(u32 *)&pbp_header[0x24], PSP_SEEK_SET);
size = size - *(u32 *)&pbp_header[0x24];
if (sceIoRead(fd, big_buffer, BIG_BUFFER_SIZE) <= 0)
{
InstallError(ofw, "Error reading 500.PBP");
}
sceKernelDelayThread(10000);
if (pspPSARInit(big_buffer, sm_buffer1, sm_buffer2) < 0)
{
InstallError(ofw, "pspPSARInit failed!");
}
comtable_size = 0;
_1gtable_size = 0;
_2gtable_size = 0;
while (1)
{
char name[128];
int cbExpanded;
int pos;
int signcheck;
int res = pspPSARGetNextFile(big_buffer, size, sm_buffer1, sm_buffer2, name, &cbExpanded, &pos, &signcheck);
if (res < 0)
{
if (error)
InstallError(ofw, "PSAR decode error, pos=0x%08X", pos);
int dpos = pos-psar_pos;
psar_pos = pos;
error = 1;
memmove(big_buffer, big_buffer+dpos, BIG_BUFFER_SIZE-dpos);
if (sceIoRead(fd, big_buffer+(BIG_BUFFER_SIZE-dpos), dpos) <= 0)
{
InstallError(ofw, "Error reading PBP.");
}
pspPSARSetBufferPosition(psar_pos);
continue;
}
else if (res == 0) /* no more files */
{
break;
}
if (cbExpanded > 0)
{
if (!strncmp(name, "com:", 4) && comtable_size > 0)
{
if (!FindTablePath(com_table, comtable_size, name+4, name))
{
InstallError(ofw, "Error: cannot find path of %s.\n", name);
}
}
else if (model == 0 && !strncmp(name, "01g:", 4) && _1gtable_size > 0)
{
if (!FindTablePath(_1g_table, _1gtable_size, name+4, name))
{
InstallError(ofw, "Error: cannot find path of %s.\n", name);
}
}
else if (model == 1 && !strncmp(name, "02g:", 4) && _2gtable_size > 0)
{
if (!FindTablePath(_2g_table, _2gtable_size, name+4, name))
{
InstallError(ofw, "Error: cannot find path of %s.\n", name);
}
}
if (!strncmp(name, "flash0:/", 8))
{
name[3] = 'c';
if (signcheck)
{
pspSignCheck(sm_buffer2);
}
res = WriteFile(name, sm_buffer2, cbExpanded);
if (res <= 0)
{
name[3] = 's';
InstallError(ofw, "Error 0x%08X flashing %s\n", res, name);
}
}