From d73d698fd5802d95658a6fa9d2429a5a690eb54a Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 22 Dec 2023 19:16:04 +1000 Subject: [PATCH] FileSystem: Purge GetDisplayNameFromPath() Redundant function. --- common/FileSystem.cpp | 5 ----- common/FileSystem.h | 3 --- pcsx2/CDVD/CDVDcommon.cpp | 2 +- pcsx2/GameList.cpp | 10 ++++------ pcsx2/ImGui/FullscreenUI.cpp | 2 +- pcsx2/VMManager.cpp | 15 +++++++-------- 6 files changed, 13 insertions(+), 24 deletions(-) diff --git a/common/FileSystem.cpp b/common/FileSystem.cpp index 2a5c2a9811..06cd49d222 100644 --- a/common/FileSystem.cpp +++ b/common/FileSystem.cpp @@ -531,11 +531,6 @@ static std::string_view::size_type GetLastSeperatorPosition(const std::string_vi return last_separator; } -std::string FileSystem::GetDisplayNameFromPath(const std::string_view& path) -{ - return std::string(Path::GetFileName(path)); -} - std::string_view Path::GetDirectory(const std::string_view& path) { const std::string::size_type pos = GetLastSeperatorPosition(path, false); diff --git a/common/FileSystem.h b/common/FileSystem.h index 13d0cb4b37..df98abd7ad 100644 --- a/common/FileSystem.h +++ b/common/FileSystem.h @@ -71,9 +71,6 @@ namespace FileSystem { using FindResultsArray = std::vector; - /// Returns the display name of a filename. Usually this is the same as the path. - std::string GetDisplayNameFromPath(const std::string_view& path); - /// Returns a list of "root directories" (i.e. root/home directories on Linux, drive letters on Windows). std::vector GetRootDirectoryList(); diff --git a/pcsx2/CDVD/CDVDcommon.cpp b/pcsx2/CDVD/CDVDcommon.cpp index d9a51d712d..ee4889690d 100644 --- a/pcsx2/CDVD/CDVDcommon.cpp +++ b/pcsx2/CDVD/CDVDcommon.cpp @@ -366,7 +366,7 @@ bool DoCDVDopen(Error* error) return true; } - std::string dump_name(Path::StripExtension(FileSystem::GetDisplayNameFromPath(m_SourceFilename[CurrentSourceType]))); + std::string dump_name(Path::StripExtension(m_SourceFilename[CurrentSourceType])); if (dump_name.empty()) dump_name = "Untitled"; diff --git a/pcsx2/GameList.cpp b/pcsx2/GameList.cpp index 809821d9b3..8afb454697 100644 --- a/pcsx2/GameList.cpp +++ b/pcsx2/GameList.cpp @@ -200,7 +200,7 @@ bool GameList::GetElfListEntry(const std::string& path, GameList::Entry* entry) entry->path = path; entry->serial.clear(); - entry->title = Path::GetFileTitle(FileSystem::GetDisplayNameFromPath(path)); + entry->title = Path::GetFileTitle(path); entry->region = Region::Other; entry->type = EntryType::ELF; entry->compatibility_rating = CompatibilityRating::Unknown; @@ -632,7 +632,8 @@ void GameList::ScanDirectory(const char* path, bool recursive, bool only_cache, continue; } - progress->SetFormattedStatusText("Scanning '%s'...", FileSystem::GetDisplayNameFromPath(ffd.FileName).c_str()); + const std::string_view filename = Path::GetFileName(ffd.FileName); + progress->SetFormattedStatusText("Scanning '%.*s'...", static_cast(filename.size()), filename.data()); ScanFile(std::move(ffd.FileName), ffd.ModificationTime, lock, played_time_map, custom_attributes_ini); progress->SetProgressValue(files_scanned); } @@ -1269,10 +1270,7 @@ bool GameList::DownloadCovers(const std::vector& url_templates, boo if (has_title) StringUtil::ReplaceAll(&url, "${title}", HTTPDownloader::URLEncode(entry.title)); if (has_file_title) - { - std::string display_name(FileSystem::GetDisplayNameFromPath(entry.path)); - StringUtil::ReplaceAll(&url, "${filetitle}", HTTPDownloader::URLEncode(Path::GetFileTitle(display_name))); - } + StringUtil::ReplaceAll(&url, "${filetitle}", HTTPDownloader::URLEncode(Path::GetFileTitle(entry.path))); if (has_serial) StringUtil::ReplaceAll(&url, "${serial}", HTTPDownloader::URLEncode(entry.serial)); diff --git a/pcsx2/ImGui/FullscreenUI.cpp b/pcsx2/ImGui/FullscreenUI.cpp index a9774d326a..746e8bf7b9 100644 --- a/pcsx2/ImGui/FullscreenUI.cpp +++ b/pcsx2/ImGui/FullscreenUI.cpp @@ -1004,7 +1004,7 @@ void FullscreenUI::DoChangeDiscFromFile() { if (!VMManager::IsDiscFileName(path)) { - ShowToast({}, fmt::format(FSUI_FSTR("{} is not a valid disc image."), FileSystem::GetDisplayNameFromPath(path))); + ShowToast({}, fmt::format(FSUI_FSTR("{} is not a valid disc image."), Path::GetFileName(path))); } else { diff --git a/pcsx2/VMManager.cpp b/pcsx2/VMManager.cpp index 404d40e596..7fc45e7ef9 100644 --- a/pcsx2/VMManager.cpp +++ b/pcsx2/VMManager.cpp @@ -841,7 +841,7 @@ void VMManager::UpdateDiscDetails(bool booting) } else if (!s_elf_override.empty()) { - s_disc_serial = Path::GetFileTitle(FileSystem::GetDisplayNameFromPath(s_elf_override)); + s_disc_serial = Path::GetFileTitle(s_elf_override); s_disc_version = {}; s_disc_crc = 0; // set below } @@ -884,7 +884,7 @@ void VMManager::UpdateDiscDetails(bool booting) if (!s_elf_override.empty()) { title = fmt::format( - "{} [{}]", game_title, Path::GetFileTitle(FileSystem::GetDisplayNameFromPath(s_elf_override))); + "{} [{}]", game_title, Path::GetFileTitle(s_elf_override)); } else { @@ -1025,13 +1025,12 @@ bool VMManager::AutoDetectSource(const std::string& filename) return false; } - const std::string display_name(FileSystem::GetDisplayNameFromPath(filename)); - if (IsGSDumpFileName(display_name)) + if (IsGSDumpFileName(filename)) { CDVDsys_ChangeSource(CDVD_SourceType::NoDisc); return GSDumpReplayer::Initialize(filename.c_str()); } - else if (IsElfFileName(display_name)) + else if (IsElfFileName(filename)) { // alternative way of booting an elf, change the elf override, and (optionally) use the disc // specified in the game settings. @@ -2015,7 +2014,6 @@ bool VMManager::ChangeDisc(CDVD_SourceType source, std::string path) const CDVD_SourceType old_type = CDVDsys_GetSourceType(); const std::string old_path(CDVDsys_GetFile(old_type)); - const std::string display_name((source != CDVD_SourceType::Iso) ? path : FileSystem::GetDisplayNameFromPath(path)); CDVDsys_ChangeSource(source); if (!path.empty()) CDVDsys_SetFile(source, std::move(path)); @@ -2032,7 +2030,8 @@ bool VMManager::ChangeDisc(CDVD_SourceType source, std::string path) else { Host::AddIconOSDMessage("ChangeDisc", ICON_FA_COMPACT_DISC, - fmt::format(TRANSLATE_FS("VMManager", "Disc changed to '{}'."), display_name), Host::OSD_INFO_DURATION); + fmt::format(TRANSLATE_FS("VMManager", "Disc changed to '{}'."), Path::GetFileName(path)), + Host::OSD_INFO_DURATION); } } else @@ -2040,7 +2039,7 @@ bool VMManager::ChangeDisc(CDVD_SourceType source, std::string path) Host::AddIconOSDMessage("ChangeDisc", ICON_FA_COMPACT_DISC, fmt::format( TRANSLATE_FS("VMManager", "Failed to open new disc image '{}'. Reverting to old image.\nError was: {}"), - display_name, error.GetDescription()), + Path::GetFileName(path), error.GetDescription()), Host::OSD_ERROR_DURATION); CDVDsys_ChangeSource(old_type); if (!old_path.empty())