Fixed error handling now

This commit is contained in:
twinaphex 2016-07-20 05:52:35 +02:00
parent 1b9ca42ec9
commit d57df932ae
11 changed files with 128 additions and 124 deletions

View File

@ -2344,23 +2344,21 @@ static bool disk_replace_image_index(unsigned index, const struct retro_game_inf
return true;
}
try
{
CDIF *iface = CDIF_Open(info->path, false, false);
delete cdifs->at(index);
cdifs->at(index) = iface;
CalcDiscSCEx();
bool success = true;
CDIF *iface = CDIF_Open(&success, info->path, false, false);
/* If we replace, we want the "swap disk manually effect". */
extract_basename(retro_cd_base_name, info->path, sizeof(retro_cd_base_name));
/* Ugly, but needed to get proper disk swapping effect. */
update_md5_checksum(iface);
return true;
}
catch (const std::exception &e)
{
if (!success)
return false;
}
delete cdifs->at(index);
cdifs->at(index) = iface;
CalcDiscSCEx();
/* If we replace, we want the "swap disk manually effect". */
extract_basename(retro_cd_base_name, info->path, sizeof(retro_cd_base_name));
/* Ugly, but needed to get proper disk swapping effect. */
update_md5_checksum(iface);
return true;
}
static bool disk_add_image_index(void)
@ -2880,112 +2878,115 @@ static std::vector<CDIF *> CDInterfaces; // FIXME: Cleanup on error out.
MDFNGI *MDFNI_LoadCD(const char *force_module, const char *devicename)
{
uint8 LayoutMD5[16];
uint8 LayoutMD5[16];
log_cb(RETRO_LOG_INFO, "Loading %s...\n", devicename ? devicename : "PHYSICAL CD");
log_cb(RETRO_LOG_INFO, "Loading %s...\n", devicename ? devicename : "PHYSICAL CD");
try
{
if(devicename && strlen(devicename) > 4 && !strcasecmp(devicename + strlen(devicename) - 4, ".m3u"))
{
std::vector<std::string> file_list;
ReadM3U(file_list, devicename);
for(unsigned i = 0; i < file_list.size(); i++)
try
{
CDInterfaces.push_back(CDIF_Open(file_list[i].c_str(), false, old_cdimagecache));
if(devicename && strlen(devicename) > 4 && !strcasecmp(devicename + strlen(devicename) - 4, ".m3u"))
{
std::vector<std::string> file_list;
ReadM3U(file_list, devicename);
for(unsigned i = 0; i < file_list.size(); i++)
{
bool success = true;
CDInterfaces.push_back(CDIF_Open(&success, file_list[i].c_str(), false, old_cdimagecache));
}
}
else if(devicename && strlen(devicename) > 4 && !strcasecmp(devicename + strlen(devicename) - 4, ".pbp"))
{
bool success = true;
CD_IsPBP = true;
CDInterfaces.push_back(CDIF_Open(&success, devicename, false, old_cdimagecache));
}
else
{
bool success = true;
CDInterfaces.push_back(CDIF_Open(&success, devicename, false, old_cdimagecache));
}
}
}
else if(devicename && strlen(devicename) > 4 && !strcasecmp(devicename + strlen(devicename) - 4, ".pbp"))
{
CD_IsPBP = true;
CDInterfaces.push_back(CDIF_Open(devicename, false, old_cdimagecache));
}
else
{
CDInterfaces.push_back(CDIF_Open(devicename, false, old_cdimagecache));
}
}
catch(std::exception &e)
{
log_cb(RETRO_LOG_ERROR, "Error opening CD.\n");
return(0);
}
//
// Print out a track list for all discs. //
for(unsigned i = 0; i < CDInterfaces.size(); i++)
{
TOC toc;
TOC_Clear(&toc);
CDInterfaces[i]->ReadTOC(&toc);
log_cb(RETRO_LOG_DEBUG, "CD %d Layout:\n", i + 1);
for(int32 track = toc.first_track; track <= toc.last_track; track++)
{
log_cb(RETRO_LOG_DEBUG, "Track %2d, LBA: %6d %s\n", track, toc.tracks[track].lba, (toc.tracks[track].control & 0x4) ? "DATA" : "AUDIO");
}
log_cb(RETRO_LOG_DEBUG, "Leadout: %6d\n", toc.tracks[100].lba);
}
// Calculate layout MD5. The system emulation LoadCD() code is free to ignore this value and calculate
// its own, or to use it to look up a game in its database.
{
md5_context layout_md5;
md5_starts(&layout_md5);
for(unsigned i = 0; i < CDInterfaces.size(); i++)
{
CD_TOC toc;
TOC_Clear(&toc);
CDInterfaces[i]->ReadTOC(&toc);
md5_update_u32_as_lsb(&layout_md5, toc.first_track);
md5_update_u32_as_lsb(&layout_md5, toc.last_track);
md5_update_u32_as_lsb(&layout_md5, toc.tracks[100].lba);
for(uint32 track = toc.first_track; track <= toc.last_track; track++)
catch(std::exception &e)
{
md5_update_u32_as_lsb(&layout_md5, toc.tracks[track].lba);
md5_update_u32_as_lsb(&layout_md5, toc.tracks[track].control & 0x4);
log_cb(RETRO_LOG_ERROR, "Error opening CD.\n");
return(0);
}
}
md5_finish(&layout_md5, LayoutMD5);
}
//
// Print out a track list for all discs. //
for(unsigned i = 0; i < CDInterfaces.size(); i++)
{
TOC toc;
TOC_Clear(&toc);
// This if statement will be true if force_module references a system without CDROM support.
if(!MDFNGameInfo->LoadCD)
{
log_cb(RETRO_LOG_ERROR, "Specified system \"%s\" doesn't support CDs!", force_module);
return 0;
}
CDInterfaces[i]->ReadTOC(&toc);
// TODO: include module name in hash
memcpy(MDFNGameInfo->MD5, LayoutMD5, 16);
log_cb(RETRO_LOG_DEBUG, "CD %d Layout:\n", i + 1);
if(!(MDFNGameInfo->LoadCD(&CDInterfaces)))
{
for(unsigned i = 0; i < CDInterfaces.size(); i++)
delete CDInterfaces[i];
CDInterfaces.clear();
for(int32 track = toc.first_track; track <= toc.last_track; track++)
{
log_cb(RETRO_LOG_DEBUG, "Track %2d, LBA: %6d %s\n", track, toc.tracks[track].lba, (toc.tracks[track].control & 0x4) ? "DATA" : "AUDIO");
}
MDFNGameInfo = NULL;
return(0);
}
log_cb(RETRO_LOG_DEBUG, "Leadout: %6d\n", toc.tracks[100].lba);
}
//MDFNI_SetLayerEnableMask(~0ULL);
// Calculate layout MD5. The system emulation LoadCD() code is free to ignore this value and calculate
// its own, or to use it to look up a game in its database.
{
md5_context layout_md5;
MDFN_LoadGameCheats(NULL);
MDFNMP_InstallReadPatches();
md5_starts(&layout_md5);
return(MDFNGameInfo);
for(unsigned i = 0; i < CDInterfaces.size(); i++)
{
CD_TOC toc;
TOC_Clear(&toc);
CDInterfaces[i]->ReadTOC(&toc);
md5_update_u32_as_lsb(&layout_md5, toc.first_track);
md5_update_u32_as_lsb(&layout_md5, toc.last_track);
md5_update_u32_as_lsb(&layout_md5, toc.tracks[100].lba);
for(uint32 track = toc.first_track; track <= toc.last_track; track++)
{
md5_update_u32_as_lsb(&layout_md5, toc.tracks[track].lba);
md5_update_u32_as_lsb(&layout_md5, toc.tracks[track].control & 0x4);
}
}
md5_finish(&layout_md5, LayoutMD5);
}
// This if statement will be true if force_module references a system without CDROM support.
if(!MDFNGameInfo->LoadCD)
{
log_cb(RETRO_LOG_ERROR, "Specified system \"%s\" doesn't support CDs!", force_module);
return 0;
}
// TODO: include module name in hash
memcpy(MDFNGameInfo->MD5, LayoutMD5, 16);
if(!(MDFNGameInfo->LoadCD(&CDInterfaces)))
{
for(unsigned i = 0; i < CDInterfaces.size(); i++)
delete CDInterfaces[i];
CDInterfaces.clear();
MDFNGameInfo = NULL;
return(0);
}
//MDFNI_SetLayerEnableMask(~0ULL);
MDFN_LoadGameCheats(NULL);
MDFNMP_InstallReadPatches();
return(MDFNGameInfo);
}
#endif

View File

@ -40,14 +40,14 @@ CDAccess::~CDAccess()
}
CDAccess *cdaccess_open_image(const char *path, bool image_memcache)
CDAccess *cdaccess_open_image(bool *success, const char *path, bool image_memcache)
{
if(strlen(path) >= 4 && !strcasecmp(path + strlen(path) - 4, ".ccd"))
return new CDAccess_CCD(path, image_memcache);
return new CDAccess_CCD(success, path, image_memcache);
else if(strlen(path) >= 4 && !strcasecmp(path + strlen(path) - 4, ".pbp"))
return new CDAccess_PBP(path, image_memcache);
return new CDAccess_PBP(success, path, image_memcache);
else
return new CDAccess_Image(path, image_memcache);
return new CDAccess_Image(success, path, image_memcache);
return NULL;
}

View File

@ -27,6 +27,6 @@ class CDAccess
CDAccess& operator=(const CDAccess&); // No assignment operator.
};
CDAccess *cdaccess_open_image(const char *path, bool image_memcache);
CDAccess *cdaccess_open_image(bool *success, const char *path, bool image_memcache);
#endif

View File

@ -66,10 +66,11 @@ static T CCD_ReadInt(CCD_Section &s, const std::string &propname, const bool hav
}
CDAccess_CCD::CDAccess_CCD(const char *path, bool image_memcache) : img_stream(NULL), sub_stream(NULL), img_numsectors(0)
CDAccess_CCD::CDAccess_CCD(bool *success, const char *path, bool image_memcache) : img_stream(NULL), sub_stream(NULL), img_numsectors(0)
{
TOC_Clear(&tocd);
Load(path, image_memcache);
if (!Load(path, image_memcache))
*success = false;
}
bool CDAccess_CCD::Load(const char *path, bool image_memcache)

View File

@ -28,7 +28,7 @@ class CDAccess_CCD : public CDAccess
{
public:
CDAccess_CCD(const char *path, bool image_memcache);
CDAccess_CCD(bool *success, const char *path, bool image_memcache);
virtual ~CDAccess_CCD();
virtual bool Read_Raw_Sector(uint8_t *buf, int32_t lba);

View File

@ -916,12 +916,13 @@ void CDAccess_Image::Cleanup(void)
}
}
CDAccess_Image::CDAccess_Image(const char *path, bool image_memcache) :
CDAccess_Image::CDAccess_Image(bool *success, const char *path, bool image_memcache) :
NumTracks(0), FirstTrack(0), LastTrack(0), total_sectors(0)
{
memset(Tracks, 0, sizeof(Tracks));
ImageOpen(path, image_memcache);
if (!ImageOpen(path, image_memcache))
*success = false;
}
CDAccess_Image::~CDAccess_Image()

View File

@ -36,7 +36,7 @@ class CDAccess_Image : public CDAccess
{
public:
CDAccess_Image(const char *path, bool image_memcache);
CDAccess_Image(bool *success, const char *path, bool image_memcache);
virtual ~CDAccess_Image();
virtual bool Read_Raw_Sector(uint8_t *buf, int32_t lba);

View File

@ -219,13 +219,14 @@ void CDAccess_PBP::Cleanup(void)
free(index_table);
}
CDAccess_PBP::CDAccess_PBP(const char *path, bool image_memcache) : NumTracks(0), FirstTrack(0), LastTrack(0), total_sectors(0)
CDAccess_PBP::CDAccess_PBP(bool *success, const char *path, bool image_memcache) : NumTracks(0), FirstTrack(0), LastTrack(0), total_sectors(0)
{
is_official = false;
index_table = NULL;
fp = NULL;
kirk_init();
ImageOpen(path, image_memcache);
if (!ImageOpen(path, image_memcache))
*success = false;
}
CDAccess_PBP::~CDAccess_PBP()

View File

@ -12,7 +12,7 @@ class CDAccess_PBP : public CDAccess
{
public:
CDAccess_PBP(const char *path, bool image_memcache);
CDAccess_PBP(bool *success, const char *path, bool image_memcache);
virtual ~CDAccess_PBP();
virtual bool Read_Raw_Sector(uint8_t *buf, int32_t lba);

View File

@ -807,9 +807,9 @@ Stream *CDIF::MakeStream(uint32 lba, uint32 sector_count)
}
CDIF *CDIF_Open(const char *path, const bool is_device, bool image_memcache)
CDIF *CDIF_Open(bool *success, const char *path, const bool is_device, bool image_memcache)
{
CDAccess *cda = cdaccess_open_image(path, image_memcache);
CDAccess *cda = cdaccess_open_image(success, path, image_memcache);
if(!image_memcache)
return new CDIF_MT(cda);

View File

@ -63,6 +63,6 @@ class CDIF
bool DiscEjected;
};
CDIF *CDIF_Open(const char *path, const bool is_device, bool image_memcache);
CDIF *CDIF_Open(bool *success, const char *path, const bool is_device, bool image_memcache);
#endif