From 655778f7f1e310be3e2a57f25187f11f4666313b Mon Sep 17 00:00:00 2001 From: spycrab Date: Thu, 20 Jul 2017 18:37:11 +0200 Subject: [PATCH] Qt: Implement GetUniqueID() --- Source/Core/DolphinQt2/GameList/GameFile.cpp | 46 ++++++++++++++++++++ Source/Core/DolphinQt2/GameList/GameFile.h | 1 + 2 files changed, 47 insertions(+) diff --git a/Source/Core/DolphinQt2/GameList/GameFile.cpp b/Source/Core/DolphinQt2/GameList/GameFile.cpp index c072b07f44..394b8b81a7 100644 --- a/Source/Core/DolphinQt2/GameList/GameFile.cpp +++ b/Source/Core/DolphinQt2/GameList/GameFile.cpp @@ -11,6 +11,7 @@ #include "Common/Assert.h" #include "Common/FileUtil.h" #include "Common/NandPaths.h" +#include "Common/StringUtil.h" #include "Core/ConfigManager.h" #include "Core/HW/WiiSaveCrypted.h" #include "Core/IOS/ES/ES.h" @@ -305,6 +306,51 @@ QString GameFile::GetLanguage(DiscIO::Language lang) const } } +QString GameFile::GetUniqueID() const +{ + std::vector info; + if (!GetGameID().isEmpty()) + info.push_back(GetGameID().toStdString()); + + if (GetRevision() != 0) + { + info.push_back("Revision " + std::to_string(GetRevision())); + } + + std::string name = m_long_names[DiscIO::Language::LANGUAGE_ENGLISH].toStdString(); + + if (name.empty()) + { + if (!m_long_names.isEmpty()) + name = m_long_names.begin().value().toStdString(); + else + { + std::string filename, extension; + name = SplitPath(m_path.toStdString(), nullptr, &filename, &extension); + name = filename + extension; + } + } + + int disc_number = GetDiscNumber() + 1; + + std::string lower_name = name; + std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower); + if (disc_number > 1 && + lower_name.find(std::string("disc ") + std::to_string(disc_number)) == std::string::npos && + lower_name.find(std::string("disc") + std::to_string(disc_number)) == std::string::npos) + { + info.push_back("Disc " + std::to_string(disc_number)); + } + + if (info.empty()) + return QString::fromStdString(name); + + std::ostringstream ss; + std::copy(info.begin(), info.end() - 1, std::ostream_iterator(ss, ", ")); + ss << info.back(); + return QString::fromStdString(name + " (" + ss.str() + ")"); +} + bool GameFile::IsInstalled() const { _assert_(m_platform == DiscIO::Platform::WII_WAD); diff --git a/Source/Core/DolphinQt2/GameList/GameFile.h b/Source/Core/DolphinQt2/GameList/GameFile.h index 46a45c6674..786274c091 100644 --- a/Source/Core/DolphinQt2/GameList/GameFile.h +++ b/Source/Core/DolphinQt2/GameList/GameFile.h @@ -41,6 +41,7 @@ public: u64 GetTitleID() const { return m_title_id; } u16 GetRevision() const { return m_revision; } QString GetInternalName() const { return m_internal_name; } + QString GetUniqueID() const; u8 GetDiscNumber() const { return m_disc_number; } u64 GetRawSize() const { return m_raw_size; } QPixmap GetBanner() const { return m_banner; }