diff --git a/src/frontend-common/game_list.cpp b/src/frontend-common/game_list.cpp index a199bded1..a97775b34 100644 --- a/src/frontend-common/game_list.cpp +++ b/src/frontend-common/game_list.cpp @@ -1028,6 +1028,12 @@ void GameList::UpdateGameSettings(const std::string& filename, const std::string } std::string GameList::GetCoverImagePathForEntry(const GameListEntry* entry) const +{ + return GetCoverImagePath(entry->path, entry->code, entry->title); +} + +std::string GameList::GetCoverImagePath(const std::string& path, const std::string& code, + const std::string& title) const { static constexpr auto extensions = make_array("jpg", "jpeg", "png", "webp"); @@ -1035,8 +1041,8 @@ std::string GameList::GetCoverImagePathForEntry(const GameListEntry* entry) cons for (const char* extension : extensions) { // use the file title if it differs (e.g. modded games) - const std::string_view file_title(FileSystem::GetFileTitleFromPath(entry->path)); - if (!file_title.empty() && entry->title != file_title) + const std::string_view file_title(FileSystem::GetFileTitleFromPath(path)); + if (!file_title.empty() && title != file_title) { cover_path.Clear(); cover_path.AppendString(g_host_interface->GetUserDirectory().c_str()); @@ -1051,19 +1057,19 @@ std::string GameList::GetCoverImagePathForEntry(const GameListEntry* entry) cons } // try the title - if (!entry->title.empty()) + if (!title.empty()) { cover_path.Format("%s" FS_OSPATH_SEPARATOR_STR "covers" FS_OSPATH_SEPARATOR_STR "%s.%s", - g_host_interface->GetUserDirectory().c_str(), entry->title.c_str(), extension); + g_host_interface->GetUserDirectory().c_str(), title.c_str(), extension); if (FileSystem::FileExists(cover_path)) return std::string(cover_path.GetCharArray()); } // then the code - if (!entry->code.empty()) + if (!code.empty()) { cover_path.Format("%s" FS_OSPATH_SEPARATOR_STR "covers" FS_OSPATH_SEPARATOR_STR "%s.%s", - g_host_interface->GetUserDirectory().c_str(), entry->code.c_str(), extension); + g_host_interface->GetUserDirectory().c_str(), code.c_str(), extension); if (FileSystem::FileExists(cover_path)) return std::string(cover_path.GetCharArray()); } diff --git a/src/frontend-common/game_list.h b/src/frontend-common/game_list.h index caab3c9de..43a6b592e 100644 --- a/src/frontend-common/game_list.h +++ b/src/frontend-common/game_list.h @@ -123,6 +123,7 @@ public: const GameSettings::Entry& new_entry, bool save_to_list = true); std::string GetCoverImagePathForEntry(const GameListEntry* entry) const; + std::string GetCoverImagePath(const std::string& path, const std::string& code, const std::string& title) const; std::string GetNewCoverImagePathForEntry(const GameListEntry* entry, const char* new_filename) const; private: