GameList: Remove exe/psf extensions from titles in game list

This commit is contained in:
Connor McLaughlin 2021-01-24 14:13:08 +10:00
parent 76ec38ee47
commit f61427017d
3 changed files with 34 additions and 14 deletions

View File

@ -287,6 +287,32 @@ std::string GetPathDirectory(const char* path)
return str; return str;
} }
std::string_view GetFileNameFromPath(const char* path)
{
const char* end = path + std::strlen(path);
const char* start = std::max(std::strrchr(path, '/'), std::strrchr(path, '\\'));
if (!start)
return std::string_view(path, end - path);
else
return std::string_view(start + 1, end - start);
}
std::string_view GetFileTitleFromPath(const char* path)
{
const char* end = path + std::strlen(path);
const char* extension = std::strrchr(path, '.');
if (extension && extension > path)
end = extension - 1;
const char* start = std::max(std::strrchr(path, '/'), std::strrchr(path, '\\'));
if (!start)
return std::string_view(path, end - path);
else if (start < end)
return std::string_view(start + 1, end - start);
else
return std::string_view(path);
}
void BuildPathRelativeToFile(char* Destination, u32 cbDestination, const char* CurrentFileName, const char* NewFileName, void BuildPathRelativeToFile(char* Destination, u32 cbDestination, const char* CurrentFileName, const char* NewFileName,
bool OSPath /* = true */, bool Canonicalize /* = true */) bool OSPath /* = true */, bool Canonicalize /* = true */)
{ {

View File

@ -148,6 +148,12 @@ std::string ReplaceExtension(std::string_view path, std::string_view new_extensi
/// Returns the directory component of a filename. /// Returns the directory component of a filename.
std::string GetPathDirectory(const char* path); std::string GetPathDirectory(const char* path);
/// Returns the filename component of a filename.
std::string_view GetFileNameFromPath(const char* path);
/// Returns the file title (less the extension and path) from a filename.
std::string_view GetFileTitleFromPath(const char* path);
// search for files // search for files
bool FindFiles(const char* Path, const char* Pattern, u32 Flags, FindResultsArray* pResults); bool FindFiles(const char* Path, const char* Pattern, u32 Flags, FindResultsArray* pResults);

View File

@ -52,16 +52,6 @@ const char* GameList::GetGameListCompatibilityRatingString(GameListCompatibility
""; "";
} }
static std::string_view GetFileNameFromPath(const char* path)
{
const char* filename_end = path + std::strlen(path);
const char* filename_start = std::max(std::strrchr(path, '/'), std::strrchr(path, '\\'));
if (!filename_start)
return std::string_view(path, filename_end - path);
else
return std::string_view(filename_start + 1, filename_end - filename_start);
}
bool GameList::GetExeListEntry(const char* path, GameListEntry* entry) bool GameList::GetExeListEntry(const char* path, GameListEntry* entry)
{ {
FILESYSTEM_STAT_DATA ffd; FILESYSTEM_STAT_DATA ffd;
@ -96,9 +86,7 @@ bool GameList::GetExeListEntry(const char* path, GameListEntry* entry)
return false; return false;
entry->code.clear(); entry->code.clear();
entry->title = GetFileNameFromPath(path); entry->title = FileSystem::GetFileTitleFromPath(path);
// no way to detect region...
entry->path = path; entry->path = path;
entry->region = BIOS::GetPSExeDiscRegion(header); entry->region = BIOS::GetPSExeDiscRegion(header);
entry->total_size = ZeroExtend64(file_size); entry->total_size = ZeroExtend64(file_size);
@ -143,7 +131,7 @@ bool GameList::GetPsfListEntry(const char* path, GameListEntry* entry)
if (title.has_value()) if (title.has_value())
entry->title += title.value(); entry->title += title.value();
else else
entry->title += GetFileNameFromPath(path); entry->title += FileSystem::GetFileTitleFromPath(path);
return true; return true;
} }