CDImageCue: Try for a file based on the cue filename if bin missing

Should work around people who have renamed the files but not updated the
cuesheet.
This commit is contained in:
Connor McLaughlin 2020-12-18 02:09:24 +10:00
parent b3edcc5841
commit 4232ef7bf3
1 changed files with 14 additions and 1 deletions

View File

@ -94,8 +94,21 @@ bool CDImageCueSheet::OpenAndParse(const char* filename)
}
if (track_file_index == m_files.size())
{
std::string track_full_filename = basepath + track_filename;
const std::string track_full_filename(basepath + track_filename);
std::FILE* track_fp = FileSystem::OpenCFile(track_full_filename.c_str(), "rb");
if (!track_fp && track_file_index == 0)
{
// many users have bad cuesheets, or they're renamed the files without updating the cuesheet.
// so, try searching for a bin with the same name as the cue, but only for the first referenced file.
const std::string alternative_filename(FileSystem::ReplaceExtension(filename, "bin"));
track_fp = FileSystem::OpenCFile(alternative_filename.c_str(), "rb");
if (track_fp)
{
Log_WarningPrintf("Your cue sheet references an invalid file '%s', but this was found at '%s' instead.",
track_filename.c_str(), alternative_filename.c_str());
}
}
if (!track_fp)
{
Log_ErrorPrintf("Failed to open track filename '%s' (from '%s' and '%s'): errno %d",