Check CDI version to avoid loading any crap as a CDI image and crashing
Less console spam, better error reporting
This commit is contained in:
parent
15fa475f8a
commit
bed7a83b77
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue