From 4232ef7bf3e0321f373a1fca6a4b3ebb2e0aa862 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 18 Dec 2020 02:09:24 +1000 Subject: [PATCH] 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. --- src/common/cd_image_cue.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/common/cd_image_cue.cpp b/src/common/cd_image_cue.cpp index 876cbaa03..7be980fe5 100644 --- a/src/common/cd_image_cue.cpp +++ b/src/common/cd_image_cue.cpp @@ -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",