naomi: fix gdrom searching in rom parent path

OpenDisc() now throws so exceptions must be caught
Never return null from OpenDisc
This commit is contained in:
Flyinghead 2023-10-05 11:43:22 +02:00
parent d4a02e3c2b
commit 56517b027a
2 changed files with 26 additions and 12 deletions

View File

@ -495,18 +495,32 @@ void GDCartridge::device_start(LoadProgress *progress, std::vector<u8> *digest)
std::string parent = hostfs::storage().getParentPath(settings.content.path); std::string parent = hostfs::storage().getParentPath(settings.content.path);
std::string gdrom_path = get_file_basename(settings.content.fileName) + "/" + gdrom_name; std::string gdrom_path = get_file_basename(settings.content.fileName) + "/" + gdrom_name;
gdrom_path = hostfs::storage().getSubPath(parent, gdrom_path); gdrom_path = hostfs::storage().getSubPath(parent, gdrom_path);
std::unique_ptr<Disc> gdrom = std::unique_ptr<Disc>(OpenDisc(gdrom_path + ".chd", digest)); std::unique_ptr<Disc> gdrom;
if (gdrom == nullptr) try {
gdrom = std::unique_ptr<Disc>(OpenDisc(gdrom_path + ".chd", digest));
}
catch (const FlycastException& e)
{
try {
gdrom = std::unique_ptr<Disc>(OpenDisc(gdrom_path + ".gdi", digest)); gdrom = std::unique_ptr<Disc>(OpenDisc(gdrom_path + ".gdi", digest));
if (gdrom_parent_name != nullptr && gdrom == nullptr) }
catch (const FlycastException& e)
{
if (gdrom_parent_name != nullptr)
{ {
std::string gdrom_parent_path = hostfs::storage().getSubPath(parent, std::string(gdrom_parent_name) + "/" + gdrom_name); std::string gdrom_parent_path = hostfs::storage().getSubPath(parent, std::string(gdrom_parent_name) + "/" + gdrom_name);
try {
gdrom = std::unique_ptr<Disc>(OpenDisc(gdrom_parent_path + ".chd", digest)); gdrom = std::unique_ptr<Disc>(OpenDisc(gdrom_parent_path + ".chd", digest));
if (gdrom == nullptr) } catch (const FlycastException& e) {
try {
gdrom = std::unique_ptr<Disc>(OpenDisc(gdrom_parent_path + ".gdi", digest)); gdrom = std::unique_ptr<Disc>(OpenDisc(gdrom_parent_path + ".gdi", digest));
} catch (const FlycastException& e) {}
}
} }
if (gdrom == nullptr) if (gdrom == nullptr)
throw NaomiCartException("Naomi GDROM: Cannot open " + gdrom_path + ".chd or " + gdrom_path + ".gdi"); throw NaomiCartException("Naomi GDROM: Cannot open " + gdrom_path + ".chd or " + gdrom_path + ".gdi");
}
}
// primary volume descriptor // primary volume descriptor
// read frame 0xb06e (frame=sector+150) // read frame 0xb06e (frame=sector+150)

View File

@ -90,7 +90,7 @@ Disc* OpenDisc(const std::string& path, std::vector<u8> *digest)
return disc; return disc;
} }
return nullptr; throw FlycastException("Unknown disk format");
} }
static bool loadDisk(const std::string& path) static bool loadDisk(const std::string& path)