X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=libpcsxcore%2Fcdriso.c;h=d6672f98cb557a3c078173e68ca777eddc0841aa;hp=36ff40556db2c35562b6bf76781169ed96da627c;hb=291224374dd130c5cbee87ccce40a1cd0d9eb968;hpb=92f43ab07c8daf13c89a96f61e0c8a2ccce8f32a diff --git a/libpcsxcore/cdriso.c b/libpcsxcore/cdriso.c index 36ff4055..d6672f98 100644 --- a/libpcsxcore/cdriso.c +++ b/libpcsxcore/cdriso.c @@ -34,6 +34,7 @@ #include #include #endif +#include #include unsigned int cdrIsoMultidiskCount; @@ -329,8 +330,8 @@ static int parsetoc(const char *isofile) { } // 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) { + token = strtok(linebuf, " "); + if (token && strncmp(token, "CD", 2) != 0 && strcmp(token, "CATALOG") != 0) { fclose(fi); return -1; } @@ -1213,6 +1214,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 @@ -1220,6 +1223,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; } @@ -1265,8 +1270,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); @@ -1289,7 +1322,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;