GameList: Support getting covers without list entry

This commit is contained in:
Connor McLaughlin 2021-05-02 14:57:52 +10:00
parent 20747d2108
commit 19b84cbe4d
2 changed files with 13 additions and 6 deletions

View File

@ -1028,6 +1028,12 @@ void GameList::UpdateGameSettings(const std::string& filename, const std::string
} }
std::string GameList::GetCoverImagePathForEntry(const GameListEntry* entry) const 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"); 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) for (const char* extension : extensions)
{ {
// use the file title if it differs (e.g. modded games) // use the file title if it differs (e.g. modded games)
const std::string_view file_title(FileSystem::GetFileTitleFromPath(entry->path)); const std::string_view file_title(FileSystem::GetFileTitleFromPath(path));
if (!file_title.empty() && entry->title != file_title) if (!file_title.empty() && title != file_title)
{ {
cover_path.Clear(); cover_path.Clear();
cover_path.AppendString(g_host_interface->GetUserDirectory().c_str()); cover_path.AppendString(g_host_interface->GetUserDirectory().c_str());
@ -1051,19 +1057,19 @@ std::string GameList::GetCoverImagePathForEntry(const GameListEntry* entry) cons
} }
// try the title // 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", 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)) if (FileSystem::FileExists(cover_path))
return std::string(cover_path.GetCharArray()); return std::string(cover_path.GetCharArray());
} }
// then the code // 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", 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)) if (FileSystem::FileExists(cover_path))
return std::string(cover_path.GetCharArray()); return std::string(cover_path.GetCharArray());
} }

View File

@ -123,6 +123,7 @@ public:
const GameSettings::Entry& new_entry, bool save_to_list = true); const GameSettings::Entry& new_entry, bool save_to_list = true);
std::string GetCoverImagePathForEntry(const GameListEntry* entry) const; 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; std::string GetNewCoverImagePathForEntry(const GameListEntry* entry, const char* new_filename) const;
private: private: