diff --git a/core/deps/chdpsr/cdipsr.cpp b/core/deps/chdpsr/cdipsr.cpp index cd250f587..ad8949461 100644 --- a/core/deps/chdpsr/cdipsr.cpp +++ b/core/deps/chdpsr/cdipsr.cpp @@ -115,18 +115,27 @@ void CDI_get_tracks (FILE *fsource, image_s *image) fread(&image->tracks, 2, 1, fsource); } -void CDI_init (FILE *fsource, image_s *image, char *fsourcename) +bool CDI_init (FILE *fsource, image_s *image, const char *fsourcename) { image->length = core_fsize(fsource); - if (image->length < 8) printf( "Image file is too short"); + if (image->length < 8) + { + printf("%s: Image file is too short\n", fsourcename); + return false; + } - fseek(fsource, image->length-8, SEEK_SET); - fread(&image->version, 4, 1, fsource); - fread(&image->header_offset, 4, 1, fsource); + fseek(fsource, image->length-8, SEEK_SET); + fread(&image->version, 4, 1, fsource); + fread(&image->header_offset, 4, 1, fsource); - // if (errno != 0) printf( fsourcename); - if (image->header_offset == 0) printf( "Bad image format"); + if ((image->version != CDI_V2 && image->version != CDI_V3 && image->version != CDI_V35) + || image->header_offset == 0) + { + printf("%s: Bad image format\n", fsourcename); + return false; + } + return true; } void CDI_get_sessions (FILE *fsource, image_s *image) diff --git a/core/deps/chdpsr/cdipsr.h b/core/deps/chdpsr/cdipsr.h index b4bfaa6d7..206fe50b6 100644 --- a/core/deps/chdpsr/cdipsr.h +++ b/core/deps/chdpsr/cdipsr.h @@ -39,7 +39,7 @@ typedef struct track_s #define CDI_V35 0x80000006 unsigned long ask_type(core_file *fsource, long header_position); -void CDI_init(core_file *fsource, image_s *image, char *fsourcename); +bool CDI_init(core_file *fsource, image_s *image, const char *fsourcename); void CDI_get_sessions(core_file *fsource, image_s *image); void CDI_get_tracks(core_file *fsource, image_s *image); void CDI_read_track(core_file *fsource, image_s *image, track_s *track); diff --git a/core/imgread/cdi.cpp b/core/imgread/cdi.cpp index e55266332..a3d375905 100644 --- a/core/imgread/cdi.cpp +++ b/core/imgread/cdi.cpp @@ -13,14 +13,18 @@ Disc* cdi_parse(const wchar* file) if (!fsource) return 0; - Disc* rv= new Disc(); - image_s image = { 0 }; track_s track = { 0 }; - CDI_init(fsource,&image,0); + if (!CDI_init(fsource, &image, file)) + { + core_fclose(fsource); + return NULL; + } CDI_get_sessions(fsource,&image); + Disc* rv= new Disc(); + image.remaining_sessions = image.sessions; /////////////////////////////////////////////////////////////// Loop sessions @@ -36,7 +40,7 @@ Disc* cdi_parse(const wchar* file) image.header_position = core_ftell(fsource); - printf("\nSession %d has %d track(s)\n",image.global_current_session,image.tracks); + //printf("\nSession %d has %d track(s)\n",image.global_current_session,image.tracks); if (image.tracks == 0) printf("Open session\n"); @@ -57,7 +61,7 @@ Disc* cdi_parse(const wchar* file) image.header_position = core_ftell(fsource); // Show info - +#if 0 printf("Saving "); printf("Track: %2d ",track.global_current_track); printf("Type: "); @@ -73,7 +77,7 @@ Disc* cdi_parse(const wchar* file) printf("Pregap: %-3ld ",track.pregap_length); printf("Size: %-6ld ",track.length); printf("LBA: %-6ld ",track.start_lba); - +#endif if (ft) { ft=false; @@ -102,7 +106,7 @@ Disc* cdi_parse(const wchar* file) rv->tracks.push_back(t); - printf("\n"); + //printf("\n"); // if (track.pregap_length != 150) printf("Warning! This track seems to have a non-standard pregap...\n"); @@ -122,7 +126,7 @@ Disc* cdi_parse(const wchar* file) else { - printf("Track position: %lu\n",track.position + track.pregap_length * track.sector_size); + //printf("Track position: %lu\n",track.position + track.pregap_length * track.sector_size); core_fseek(fsource, track.position, SEEK_SET); // fseek(fsource, track->pregap_length * track->sector_size, SEEK_CUR); // fseek(fsource, track->length * track->sector_size, SEEK_CUR);