Skip to content

Commit beb81e4

Browse files
committed
chd.cpp: More API changes
- Have metadata_find return std::error_condition instead of throwing an exception - Replace the is_XXX predicates with check_is_XXX methods that return a std::error_condition, enabling improved error reporting for cdrom_image_device - Retain read error information in chd_file_compressor - Make a bunch of methods noexcept This mostly restores the changes from cc77207.
1 parent a06ca9e commit beb81e4

File tree

5 files changed

+148
-110
lines changed

5 files changed

+148
-110
lines changed

src/devices/imagedev/cdromimg.cpp

+24-8
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ void cdrom_image_device::setup_current_preset_image()
7979
m_dvdrom_handle.reset();
8080

8181
chd_file *chd = current_preset_image_chd();
82-
if (chd->is_cd() || (m_gd_compat && chd->is_gd()))
82+
if (!chd->check_is_cd() || (m_gd_compat && !chd->check_is_gd()))
8383
m_cdrom_handle = std::make_unique<cdrom_file>(chd);
84-
else if(m_dvd_compat && chd->is_dvd())
84+
else if(m_dvd_compat && !chd->check_is_dvd())
8585
m_dvdrom_handle = std::make_unique<dvdrom_file>(chd);
8686
else
8787
fatalerror("chd for region %s is not compatible with the cdrom image device\n", preset_images_list()[current_preset_image_id()]);
@@ -130,15 +130,31 @@ std::pair<std::error_condition, std::string> cdrom_image_device::call_load()
130130
// open the CHD file
131131
if (chd)
132132
{
133-
if (chd->is_cd() || (m_gd_compat && chd->is_gd()))
134-
m_cdrom_handle.reset(new cdrom_file(chd));
135-
else if (m_dvd_compat && chd->is_dvd())
136-
m_dvdrom_handle.reset(new dvdrom_file(chd));
137-
else
133+
err = chd->check_is_cd();
134+
if (err == chd_file::error::METADATA_NOT_FOUND && m_gd_compat)
135+
err = chd->check_is_gd();
136+
if (!err)
138137
{
139-
err = image_error::INVALIDIMAGE;
138+
m_cdrom_handle.reset(new cdrom_file(chd));
139+
return std::make_pair(std::error_condition(), std::string());
140+
}
141+
if (err != chd_file::error::METADATA_NOT_FOUND)
140142
goto error;
143+
144+
if (m_dvd_compat)
145+
{
146+
err = chd->check_is_dvd();
147+
if (!err)
148+
{
149+
m_dvdrom_handle.reset(new dvdrom_file(chd));
150+
return std::make_pair(std::error_condition(), std::string());
151+
}
152+
if (err != chd_file::error::METADATA_NOT_FOUND)
153+
goto error;
141154
}
155+
156+
err = image_error::INVALIDIMAGE;
157+
goto error;
142158
}
143159
else
144160
{

0 commit comments

Comments
 (0)