› Foros › PlayStation 2 › Scene
//--------------------------------------------------------------
// getGameTitle below is used to extract the real save title of
// an MC gamesave folder. Normally this is held in the icon.sys
// file of a PS2 game save, but that is not the case for saves
// on a PS1 MC, or similar saves backed up to a PS2 MC. Two new
// methods need to be used to extract such titles correctly, and
// these were added in v3.62, by me (dlanor).
// From v3.91 This routine also extracts titles from PSU files.
//--------------------------------------------------------------
int getGameTitle(const char *path, const FILEINFO *file, char *out)
{
char party[MAX_NAME], dir[MAX_PATH], tmpdir[MAX_PATH];
int fd=-1, size, hddin=FALSE, ret;
psu_header PSU_head;
int i, tst, PSU_content, psu_pad_pos;
char *cp;
out[0] = '\0'; //Start by making an empty result string, for failures
//Avoid title usage in browser root or partition list
if(path[0]==0 || !strcmp(path,"hdd0:/")) return -1;
if(!strncmp(path, "hdd", 3)){
ret = getHddParty(path, file, party, dir);
if((ret = mountParty(party)<0))
return -1;
dir[3]=ret+'0';
hddin=TRUE;
}else{
strcpy(dir, path);
strcat(dir, file->name);
if(file->stats.attrFile & MC_ATTR_SUBDIR) strcat(dir, "/");
}
ret = -1; //Assume that result will be failure, to simplify aborts
if((file->stats.attrFile & MC_ATTR_SUBDIR)==0){
//Here we know that the object needing a title is a file
strcpy(tmpdir, dir); //Copy the pathname for file access
cp = strrchr(tmpdir, '.'); //Find the extension, if any
if((cp==NULL) || stricmp(cp, ".psu") ) //If it's anything other than a PSU file
goto get_PS1_GameTitle; //then it may be a PS1 save
//Here we know that the object needing a title is a PSU file
if((fd=genOpen(tmpdir, O_RDONLY)) < 0) goto finish; //Abort if open fails
tst = genRead(fd, (void *) &PSU_head, sizeof(PSU_head));
if(tst != sizeof(PSU_head)) goto finish; //Abort if read fails
PSU_content = PSU_head.size;
for(i=0; itst = genRead(fd, (void *) &PSU_head, sizeof(PSU_head));
if(tst != sizeof(PSU_head)) goto finish; //Abort if read fails
PSU_head.name[sizeof(PSU_head.name)] = '\0';
if(!strcmp(PSU_head.name, "icon.sys")) {
genLseek(fd, 0xC0, SEEK_CUR);
goto read_title;
}
if(PSU_head.size){
psu_pad_pos = (PSU_head.size + 0x3FF) & -0x400;
genLseek(fd, psu_pad_pos, SEEK_CUR);
}
//Here the PSU file pointer is positioned for reading next header
}//ends for
//Coming here means that the search for icon.sys failed
goto finish; //So go finish off this function
}//ends if clause for files needing a title
//Here we know that the object needing a title is a folder
//First try to find a valid PS2 icon.sys file inside the folder
strcpy(tmpdir, dir);
strcat(tmpdir, "icon.sys");
if((fd=genOpen(tmpdir, O_RDONLY)) >= 0){
if((size=genLseek(fd,0,SEEK_END)) <= 0x100) goto finish;
genLseek(fd,0xC0,SEEK_SET);
goto read_title;
}
//Next try to find a valid PS1 savefile inside the folder instead
strcpy(tmpdir, dir);
strcat(tmpdir, file->name); //PS1 save file should have same name as folder
get_PS1_GameTitle:
if((fd=genOpen(tmpdir, O_RDONLY)) < 0) goto finish; //PS1 gamesave file needed
if((size=genLseek(fd,0,SEEK_END)) < 0x2000) goto finish; //Min size is 8K
if(size & 0x1FFF) goto finish; //Size must be a multiple of 8K
genLseek(fd, 0, SEEK_SET);
genRead(fd, out, 2);
if(strncmp(out, "SC", 2)) goto finish; //PS1 gamesaves always start with "SC"
genLseek(fd, 4, SEEK_SET);
read_title:
genRead(fd, out, 32*2);
out[32*2] = 0;
genClose(fd); fd=-1;
ret=0;
finish:
if(fd>=0)
genClose(fd);
return ret;
}
//--------------------------------------------------------------