X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=libpcsxcore%2Fcdriso.c;h=09aed17d9c6b1dd345b9fd51eeeb965fc5f1d77c;hp=dde21bcde7314b71b433533642ca827ff0efb1e5;hb=8886a80857ea5329717a54f4deb37d8e974ffc9c;hpb=c0ee7ac6dbe0e4ec289f7cfd2ee1224890751025 diff --git a/libpcsxcore/cdriso.c b/libpcsxcore/cdriso.c index dde21bcd..09aed17d 100644 --- a/libpcsxcore/cdriso.c +++ b/libpcsxcore/cdriso.c @@ -26,14 +26,17 @@ #include "ppf.h" #ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN #include #include #define strcasecmp _stricmp +#define usleep(x) Sleep((x) / 1000) #else #include #include #include #endif +#include #include unsigned int cdrIsoMultidiskCount; @@ -327,6 +330,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(linebuf, " "); + if (token && strncmp(token, "CD", 2) != 0 && strcmp(token, "CATALOG") != 0) { + fclose(fi); + return -1; + } + fseek(fi, 0, SEEK_SET); } memset(&ti, 0, sizeof(ti)); @@ -543,9 +554,9 @@ static int parsecue(const char *isofile) { pregapOffset = -1; // mark to fill track start_offset } else if (!strcmp(token, "FILE")) { - t = sscanf(linebuf, " FILE \"%256[^\"]\"", tmpb); + t = sscanf(linebuf, " FILE \"%255[^\"]\"", tmpb); if (t != 1) - sscanf(linebuf, " FILE %256s", tmpb); + sscanf(linebuf, " FILE %255s", tmpb); // absolute path? ti[numtracks + 1].handle = fopen(tmpb, "rb"); @@ -786,6 +797,8 @@ static int handlepbp(const char *isofile) { if (ext == NULL || (strcmp(ext, ".pbp") != 0 && strcmp(ext, ".PBP") != 0)) return -1; + fseek(cdHandle, 0, SEEK_SET); + numtracks = 0; ret = fread(&pbp_hdr, 1, sizeof(pbp_hdr), cdHandle); @@ -949,6 +962,8 @@ static int handlecbin(const char *isofile) { if (ext == NULL || (strcasecmp(ext + 1, ".cbn") != 0 && strcasecmp(ext, ".cbin") != 0)) return -1; + fseek(cdHandle, 0, SEEK_SET); + ret = fread(&ciso_hdr, 1, sizeof(ciso_hdr), cdHandle); if (ret != sizeof(ciso_hdr)) { SysPrintf("failed to read ciso header\n"); @@ -1205,6 +1220,8 @@ static void PrintTracks(void) { // file for playback static long CALLBACK ISOopen(void) { boolean isMode1ISO = FALSE; + char alt_bin_filename[MAXPATHLEN]; + const char *bin_filename; if (cdHandle != NULL) { return 0; // it's already open @@ -1212,6 +1229,8 @@ static long CALLBACK ISOopen(void) { cdHandle = fopen(GetIsoFile(), "rb"); if (cdHandle == NULL) { + SysPrintf(_("Could't open '%s' for reading: %s\n"), + GetIsoFile(), strerror(errno)); return -1; } @@ -1227,10 +1246,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) { @@ -1239,6 +1255,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; @@ -1257,8 +1276,36 @@ 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 .. + bin_filename = GetIsoFile(); + if (ftell(cdHandle) < 2352 * 0x10) { + static const char *exts[] = { ".bin", ".BIN", ".img", ".IMG" }; + FILE *tmpf = NULL; + size_t i; + char *p; + + strncpy(alt_bin_filename, bin_filename, sizeof(alt_bin_filename)); + alt_bin_filename[MAXPATHLEN - 1] = '\0'; + if (strlen(alt_bin_filename) >= 4) { + p = alt_bin_filename + strlen(alt_bin_filename) - 4; + for (i = 0; i < sizeof(exts) / sizeof(exts[0]); i++) { + strcpy(p, exts[i]); + tmpf = fopen(alt_bin_filename, "rb"); + if (tmpf != NULL) + break; + } + } + if (tmpf != NULL) { + bin_filename = alt_bin_filename; + fclose(cdHandle); + cdHandle = tmpf; + fseek(cdHandle, 0, SEEK_END); + } + } + + // guess whether it is mode1/2048 if (ftell(cdHandle) % 2048 == 0) { unsigned int modeTest = 0; fseek(cdHandle, 0, SEEK_SET); @@ -1281,7 +1328,7 @@ static long CALLBACK ISOopen(void) { // make sure we have another handle open for cdda if (numtracks > 1 && ti[1].handle == NULL) { - ti[1].handle = fopen(GetIsoFile(), "rb"); + ti[1].handle = fopen(bin_filename, "rb"); } cdda_cur_sector = 0; cdda_file_offset = 0;