GameList: Add method to look up a cover image

This commit is contained in:
Connor McLaughlin 2020-09-23 23:43:32 +10:00
parent f1086b18f9
commit b193374dd4
3 changed files with 40 additions and 0 deletions

View file

@ -118,6 +118,7 @@ void CommonHostInterface::InitializeUserDirectory()
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("bios").c_str(), false); result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("bios").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("cache").c_str(), false); result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("cache").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("cheats").c_str(), false); result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("cheats").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("covers").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("dump").c_str(), false); result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("dump").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("dump/audio").c_str(), false); result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("dump/audio").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("inputprofiles").c_str(), false); result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("inputprofiles").c_str(), false);

View file

@ -1109,3 +1109,40 @@ void GameList::UpdateGameSettings(const std::string& filename, const std::string
save_to_user ? m_user_game_settings_filename.c_str() : m_game_settings_filename.c_str()); save_to_user ? m_user_game_settings_filename.c_str() : m_game_settings_filename.c_str());
} }
} }
std::string GameList::GetCoverImagePathForEntry(const GameListEntry* entry)
{
static constexpr std::array<const char*, 2> extensions = {{"jpg", "png"}};
PathString cover_path;
for (const char* extension : extensions)
{
// try the title
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);
if (FileSystem::FileExists(cover_path))
return std::string(cover_path.GetCharArray());
// then the code
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);
if (FileSystem::FileExists(cover_path))
return std::string(cover_path.GetCharArray());
// and the file title if it differs
const std::string_view file_title = GetFileNameFromPath(entry->path.c_str());
if (!file_title.empty() && entry->title != file_title)
{
cover_path.Clear();
cover_path.AppendString(g_host_interface->GetUserDirectory().c_str());
cover_path.AppendCharacter(FS_OSPATH_SEPERATOR_CHARACTER);
cover_path.AppendString(file_title.data(), static_cast<u32>(file_title.size()));
cover_path.AppendCharacter('.');
cover_path.AppendString(extension);
if (FileSystem::FileExists(cover_path))
return std::string(cover_path.GetCharArray());
}
}
return std::string();
}

View file

@ -108,6 +108,8 @@ public:
void UpdateGameSettings(const std::string& filename, const std::string& game_code, const std::string& game_title, void UpdateGameSettings(const std::string& filename, const std::string& game_code, const std::string& game_title,
const GameSettings::Entry& new_entry, bool save_to_list = true, bool save_to_user = true); const GameSettings::Entry& new_entry, bool save_to_list = true, bool save_to_user = true);
std::string GetCoverImagePathForEntry(const GameListEntry* entry);
private: private:
enum : u32 enum : u32
{ {