mirror of https://github.com/PCSX2/pcsx2.git
GameList: Sanitize all cover paths
This commit is contained in:
parent
367f839934
commit
8f991c311f
|
@ -1166,8 +1166,8 @@ std::string GameList::GetCoverImagePathForEntry(const Entry* entry)
|
||||||
const std::string_view file_title(Path::GetFileTitle(entry->path));
|
const std::string_view file_title(Path::GetFileTitle(entry->path));
|
||||||
if (!file_title.empty() && entry->title != file_title)
|
if (!file_title.empty() && entry->title != file_title)
|
||||||
{
|
{
|
||||||
std::string cover_filename(file_title);
|
std::string cover_filename = fmt::format("{}{}", file_title, extension);
|
||||||
cover_filename += extension;
|
Path::SanitizeFileName(&cover_filename);
|
||||||
|
|
||||||
cover_path = Path::Combine(EmuFolders::Covers, cover_filename);
|
cover_path = Path::Combine(EmuFolders::Covers, cover_filename);
|
||||||
if (FileSystem::FileExists(cover_path.c_str()))
|
if (FileSystem::FileExists(cover_path.c_str()))
|
||||||
|
@ -1177,8 +1177,9 @@ std::string GameList::GetCoverImagePathForEntry(const Entry* entry)
|
||||||
// Last resort, check the game title
|
// Last resort, check the game title
|
||||||
if (!entry->title.empty())
|
if (!entry->title.empty())
|
||||||
{
|
{
|
||||||
std::string cover_filename(entry->title + extension);
|
std::string cover_filename = fmt::format("{}{}", entry->title, extension);
|
||||||
Path::SanitizeFileName(&cover_filename);
|
Path::SanitizeFileName(&cover_filename);
|
||||||
|
|
||||||
cover_path = Path::Combine(EmuFolders::Covers, cover_filename);
|
cover_path = Path::Combine(EmuFolders::Covers, cover_filename);
|
||||||
if (FileSystem::FileExists(cover_path.c_str()))
|
if (FileSystem::FileExists(cover_path.c_str()))
|
||||||
return cover_path;
|
return cover_path;
|
||||||
|
@ -1186,8 +1187,9 @@ std::string GameList::GetCoverImagePathForEntry(const Entry* entry)
|
||||||
// EN title too
|
// EN title too
|
||||||
if (!entry->title_en.empty())
|
if (!entry->title_en.empty())
|
||||||
{
|
{
|
||||||
std::string cover_filename(entry->title_en + extension);
|
std::string cover_filename = fmt::format("{}{}", entry->title_en, extension);
|
||||||
Path::SanitizeFileName(&cover_filename);
|
Path::SanitizeFileName(&cover_filename);
|
||||||
|
|
||||||
cover_path = Path::Combine(EmuFolders::Covers, cover_filename);
|
cover_path = Path::Combine(EmuFolders::Covers, cover_filename);
|
||||||
if (FileSystem::FileExists(cover_path.c_str()))
|
if (FileSystem::FileExists(cover_path.c_str()))
|
||||||
return cover_path;
|
return cover_path;
|
||||||
|
@ -1200,19 +1202,19 @@ std::string GameList::GetCoverImagePathForEntry(const Entry* entry)
|
||||||
|
|
||||||
std::string GameList::GetNewCoverImagePathForEntry(const Entry* entry, const char* new_filename, bool use_serial)
|
std::string GameList::GetNewCoverImagePathForEntry(const Entry* entry, const char* new_filename, bool use_serial)
|
||||||
{
|
{
|
||||||
const char* extension = std::strrchr(new_filename, '.');
|
const std::string_view extension = Path::GetExtension(new_filename);
|
||||||
if (!extension)
|
if (extension.empty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
std::string existing_filename = GetCoverImagePathForEntry(entry);
|
const std::string existing_filename = GetCoverImagePathForEntry(entry);
|
||||||
if (!existing_filename.empty())
|
if (!existing_filename.empty())
|
||||||
{
|
{
|
||||||
std::string::size_type pos = existing_filename.rfind('.');
|
const std::string_view existing_extension = Path::GetExtension(existing_filename);
|
||||||
if (pos != std::string::npos && existing_filename.compare(pos, std::strlen(extension), extension) == 0)
|
if (!existing_extension.empty() && existing_extension == extension)
|
||||||
return existing_filename;
|
return existing_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cover_filename(use_serial ? (entry->serial + extension) : (entry->title + extension));
|
std::string cover_filename = fmt::format("{}.{}", use_serial ? entry->serial : entry->title, extension);
|
||||||
Path::SanitizeFileName(&cover_filename);
|
Path::SanitizeFileName(&cover_filename);
|
||||||
return Path::Combine(EmuFolders::Covers, cover_filename);
|
return Path::Combine(EmuFolders::Covers, cover_filename);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue