mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
Try to detect if someone tries to open a PSX ISO
This commit is contained in:
parent
ad74a80bb7
commit
33be3da057
@ -35,9 +35,35 @@ IdentifiedFileType Identify_File(std::string &filename)
|
||||
return FILETYPE_ERROR;
|
||||
}
|
||||
|
||||
FileInfo info;
|
||||
if (!getFileInfo(filename.c_str(), &info)) {
|
||||
return FILETYPE_ERROR;
|
||||
}
|
||||
|
||||
std::string extension = filename.size() >= 5 ? filename.substr(filename.size() - 4) : "";
|
||||
if (!strcasecmp(extension.c_str(),".iso"))
|
||||
{
|
||||
// may be a psx iso, they have 2352 byte sectors. You never know what some people try to open
|
||||
if ((info.size % 2352) == 0)
|
||||
{
|
||||
FILE *f = File::OpenCFile(filename.c_str(), "rb");
|
||||
if (!f) {
|
||||
// File does not exists
|
||||
return FILETYPE_ERROR;
|
||||
}
|
||||
|
||||
unsigned char sync[12];
|
||||
fread(sync,1,12,f);
|
||||
fclose(f);
|
||||
|
||||
// each sector in a mode2 image starts with these 12 bytes
|
||||
if (memcmp(sync,"\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00",12) == 0)
|
||||
{
|
||||
return FILETYPE_ISO_MODE2;
|
||||
}
|
||||
|
||||
// maybe it also just happened to have that size,
|
||||
}
|
||||
return FILETYPE_PSP_ISO;
|
||||
}
|
||||
else if (!strcasecmp(extension.c_str(),".cso"))
|
||||
@ -45,13 +71,8 @@ IdentifiedFileType Identify_File(std::string &filename)
|
||||
return FILETYPE_PSP_ISO;
|
||||
}
|
||||
|
||||
// First, check if it's a directory with an EBOOT.PBP in it.
|
||||
FileInfo info;
|
||||
if (!getFileInfo(filename.c_str(), &info)) {
|
||||
return FILETYPE_ERROR;
|
||||
}
|
||||
|
||||
if (info.isDirectory) {
|
||||
// First, check if it's a directory with an EBOOT.PBP in it. if (info.isDirectory) {
|
||||
if (filename.size() > 4) {
|
||||
FileInfo ebootInfo;
|
||||
// Check for existence of EBOOT.PBP, as required for "Directory games".
|
||||
@ -218,6 +239,10 @@ bool LoadFile(std::string &filename, std::string *error_string) {
|
||||
#endif
|
||||
break;
|
||||
|
||||
case FILETYPE_ISO_MODE2:
|
||||
*error_string = "File is a MODE2 image. Are you trying to open a PSX game?";
|
||||
break;
|
||||
|
||||
case FILETYPE_NORMAL_DIRECTORY:
|
||||
ERROR_LOG(LOADER, "Just a directory.");
|
||||
*error_string = "Just a directory.";
|
||||
|
@ -36,6 +36,7 @@ enum IdentifiedFileType {
|
||||
FILETYPE_ARCHIVE_RAR,
|
||||
FILETYPE_ARCHIVE_ZIP,
|
||||
FILETYPE_PSP_PS1_PBP,
|
||||
FILETYPE_ISO_MODE2,
|
||||
|
||||
FILETYPE_NORMAL_DIRECTORY,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user