X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=libpcsxcore%2Fcdriso.c;h=9ca41726572711a38b4f65582c24207d78c09ba0;hp=90c9d856fc3f2c067b8035b866616b4e5d68df48;hb=c9e5423e97341d1c10c2bc2c5f770cdf2dbd58b4;hpb=deebc67fc5c5027248842562e02d71d5f683a1e2 diff --git a/libpcsxcore/cdriso.c b/libpcsxcore/cdriso.c index 90c9d856..9ca41726 100644 --- a/libpcsxcore/cdriso.c +++ b/libpcsxcore/cdriso.c @@ -327,6 +327,14 @@ static int parsetoc(const char *isofile) { return -1; } } + // check if it's really a TOC named as a .cue + fgets(linebuf, sizeof(linebuf), fi); + token = strtok(tmp, " "); + if (strncmp(token, "CD", 2) != 0 && strcmp(token, "CATALOG") != 0) { + fclose(fi); + return -1; + } + fseek(fi, 0, SEEK_SET); } memset(&ti, 0, sizeof(ti)); @@ -470,10 +478,12 @@ static int parsecue(const char *isofile) { // build a path for files referenced in .cue strncpy(filepath, cuename, sizeof(filepath)); - tmp = strrchr(filepath, '/') + 1; - if (tmp == NULL) - tmp = strrchr(filepath, '\\') + 1; + tmp = strrchr(filepath, '/'); if (tmp == NULL) + tmp = strrchr(filepath, '\\'); + if (tmp != NULL) + tmp++; + else tmp = filepath; *tmp = 0; filepath[sizeof(filepath) - 1] = 0; @@ -1225,10 +1235,7 @@ static long CALLBACK ISOopen(void) { CDR_getBuffer = ISOgetBuffer; cdimg_read_func = cdread_normal; - if (parsecue(GetIsoFile()) == 0) { - SysPrintf("[+cue]"); - } - else if (parsetoc(GetIsoFile()) == 0) { + if (parsetoc(GetIsoFile()) == 0) { SysPrintf("[+toc]"); } else if (parseccd(GetIsoFile()) == 0) { @@ -1237,6 +1244,9 @@ static long CALLBACK ISOopen(void) { else if (parsemds(GetIsoFile()) == 0) { SysPrintf("[+mds]"); } + else if (parsecue(GetIsoFile()) == 0) { + SysPrintf("[+cue]"); + } if (handlepbp(GetIsoFile()) == 0) { SysPrintf("[pbp]"); CDR_getBuffer = ISOgetBuffer_compr; @@ -1255,8 +1265,33 @@ static long CALLBACK ISOopen(void) { SysPrintf("[+sbi]"); } - // guess whether it is mode1/2048 fseek(cdHandle, 0, SEEK_END); + + // maybe user selected metadata file instead of main .bin .. + if (ftell(cdHandle) < 2352 * 0x10) { + static const char *exts[] = { ".bin", ".BIN", ".img", ".IMG" }; + char tmp[MAXPATHLEN], *p; + FILE *tmpf; + size_t i; + + strncpy(tmp, GetIsoFile(), sizeof(tmp)); + tmp[MAXPATHLEN - 1] = '\0'; + if (strlen(tmp) >= 4) { + p = tmp + strlen(tmp) - 4; + for (i = 0; i < sizeof(exts) / sizeof(exts[0]); i++) { + strcpy(p, exts[i]); + tmpf = fopen(tmp, "rb"); + if (tmpf != NULL) { + fclose(cdHandle); + cdHandle = tmpf; + fseek(cdHandle, 0, SEEK_END); + break; + } + } + } + } + + // guess whether it is mode1/2048 if (ftell(cdHandle) % 2048 == 0) { unsigned int modeTest = 0; fseek(cdHandle, 0, SEEK_SET); @@ -1314,8 +1349,12 @@ static long CALLBACK ISOclose(void) { } } numtracks = 0; + ti[1].type = 0; UnloadSBI(); + memset(cdbuffer, 0, sizeof(cdbuffer)); + CDR_getBuffer = ISOgetBuffer; + return 0; } @@ -1398,6 +1437,7 @@ static void DecodeRawSubData(void) { // uses bcd format static long CALLBACK ISOreadTrack(unsigned char *time) { int sector = MSF2SECT(btoi(time[0]), btoi(time[1]), btoi(time[2])); + long ret; if (cdHandle == NULL) { return -1; @@ -1412,7 +1452,9 @@ static long CALLBACK ISOreadTrack(unsigned char *time) { } } - cdimg_read_func(cdHandle, 0, cdbuffer, sector); + ret = cdimg_read_func(cdHandle, 0, cdbuffer, sector); + if (ret < 0) + return -1; if (subHandle != NULL) { fseek(subHandle, sector * SUB_FRAMESIZE, SEEK_SET);