Skip to content

Commit

Permalink
CDROM: Fix physical disc reading without SubQ on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Dec 9, 2024
1 parent 2e6deca commit 1e83922
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/core/cdrom_subq_replacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ std::unique_ptr<CDROMSubQReplacement> CDROMSubQReplacement::LoadLSD(const std::s
return ret;
}

bool CDROMSubQReplacement::LoadForImage(std::unique_ptr<CDROMSubQReplacement>* ret, CDImage* image, std::string_view serial,
std::string_view title, Error* error)
bool CDROMSubQReplacement::LoadForImage(std::unique_ptr<CDROMSubQReplacement>* ret, CDImage* image,
std::string_view serial, std::string_view title, Error* error)
{
struct FileLoader
{
Expand All @@ -140,13 +140,19 @@ bool CDROMSubQReplacement::LoadForImage(std::unique_ptr<CDROMSubQReplacement>* r
std::string path;

// Try sbi/lsd in the directory first.
for (const FileLoader& loader : loaders)
if (!CDImage::IsDeviceName(image_path.c_str()))
{
path = Path::ReplaceExtension(image_path, loader.extension);
if (FileSystem::FileExists(path.c_str()))
for (const FileLoader& loader : loaders)
{
*ret = loader.func(path, error);
return static_cast<bool>(*ret);
path = Path::ReplaceExtension(image_path, loader.extension);
if (FileSystem::FileExists(path.c_str()))
{
*ret = loader.func(path, error);
if (!static_cast<bool>(*ret))
Error::AddPrefixFmt(error, "Failed to load subchannel data from {}: ", Path::GetFileName(path));

return static_cast<bool>(*ret);
}
}
}

Expand All @@ -161,6 +167,9 @@ bool CDROMSubQReplacement::LoadForImage(std::unique_ptr<CDROMSubQReplacement>* r
if (FileSystem::FileExists(path.c_str()))
{
*ret = loader.func(path, error);
if (!static_cast<bool>(*ret))
Error::AddPrefixFmt(error, "Failed to load subchannel data from {}: ", Path::GetFileName(path));

return static_cast<bool>(*ret);
}
}
Expand All @@ -175,6 +184,9 @@ bool CDROMSubQReplacement::LoadForImage(std::unique_ptr<CDROMSubQReplacement>* r
if (FileSystem::FileExists(path.c_str()))
{
*ret = loader.func(path, error);
if (!static_cast<bool>(*ret))
Error::AddPrefixFmt(error, "Failed to load subchannel data from {}: ", Path::GetFileName(path));

return static_cast<bool>(*ret);
}
}
Expand All @@ -188,6 +200,9 @@ bool CDROMSubQReplacement::LoadForImage(std::unique_ptr<CDROMSubQReplacement>* r
if (FileSystem::FileExists(path.c_str()))
{
*ret = loader.func(path, error);
if (!static_cast<bool>(*ret))
Error::AddPrefixFmt(error, "Failed to load subchannel data from {}: ", Path::GetFileName(path));

return static_cast<bool>(*ret);
}
}
Expand Down

0 comments on commit 1e83922

Please sign in to comment.