From b9d2a433bf316d2f471d5d88674f9333411cdc08 Mon Sep 17 00:00:00 2001 From: PancakesWithSyrup <33337475+PancakesWithSyrup@users.noreply.github.com> Date: Wed, 27 May 2020 11:31:25 -0400 Subject: [PATCH] UICommon/GameFile: File name column will show the directory name for extracted games --- Source/Core/UICommon/GameFile.cpp | 20 ++++++++++++++++++-- Source/Core/UICommon/GameFile.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Source/Core/UICommon/GameFile.cpp b/Source/Core/UICommon/GameFile.cpp index d548c55fbb..3198b29e18 100644 --- a/Source/Core/UICommon/GameFile.cpp +++ b/Source/Core/UICommon/GameFile.cpp @@ -103,8 +103,6 @@ GameFile::GameFile() = default; GameFile::GameFile(std::string path) : m_file_path(std::move(path)) { - m_file_name = PathToFileName(m_file_path); - { std::unique_ptr volume(DiscIO::CreateVolume(m_file_path)); if (volume != nullptr) @@ -157,6 +155,13 @@ GameFile::GameFile(std::string path) : m_file_path(std::move(path)) m_blob_type = DiscIO::BlobType::DIRECTORY; } + // If the game is extracted then use the folder name two/three directories up instead + if (m_blob_type == DiscIO::BlobType::DIRECTORY) + m_file_name = FindFolderName(); + + if (m_file_name.empty()) + m_file_name = PathToFileName(m_file_path); + if (!IsValid() && GetExtension() == ".json") { auto descriptor = DiscIO::ParseGameModDescriptorFile(m_file_path); @@ -350,6 +355,17 @@ bool GameFile::IsElfOrDol() const return extension == ".elf" || extension == ".dol"; } +// Function for finding the folder name two (three if a Wii game) directories up for use in the file +// name column for extracted games Returns a blank string if the folder can't be found +std::string GameFile::FindFolderName() const +{ + const std::filesystem::path game_file_path = StringToPath(m_file_path).parent_path().parent_path(); + return PathToString(m_platform == DiscIO::Platform::WiiDisc && + PathToString(game_file_path.filename()) == "DATA" ? + game_file_path.parent_path() : + game_file_path.filename()); +} + bool GameFile::ReadXMLMetadata(const std::string& path) { std::string data; diff --git a/Source/Core/UICommon/GameFile.h b/Source/Core/UICommon/GameFile.h index f015fa9725..adb2258658 100644 --- a/Source/Core/UICommon/GameFile.h +++ b/Source/Core/UICommon/GameFile.h @@ -131,6 +131,7 @@ private: const std::map& strings); const std::string& LookupUsingConfigLanguage(const std::map& strings) const; + std::string FindFolderName() const; std::string GetExtension() const; bool IsElfOrDol() const; bool ReadXMLMetadata(const std::string& path);