From 6902bbb696ea7089daded57569cca637a5e69eae Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 2 Nov 2017 17:34:04 +0100 Subject: [PATCH] When NAND is damaged, show title names from save files The earlier code always tried to use TitleDatabase for getting title names, but that didn't work for disc-based games, because there was no way to get the maker ID. --- Source/Core/Common/StringUtil.cpp | 2 +- Source/Core/Core/TitleDatabase.cpp | 4 ++-- Source/Core/Core/TitleDatabase.h | 4 +++- Source/Core/DolphinQt2/MenuBar.cpp | 27 +++++++++++++++++++++++---- Source/Core/DolphinWX/FrameTools.cpp | 27 ++++++++++++++++++++++----- 5 files changed, 51 insertions(+), 13 deletions(-) diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index a368e703fe..c904f150da 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -582,6 +582,6 @@ std::string UTF16BEToUTF8(const char16_t* str, size_t max_size) { const char16_t* str_end = std::find(str, str + max_size, '\0'); std::wstring result(static_cast(str_end - str), '\0'); - std::transform(str, str_end, result.begin(), static_cast(Common::swap16)); + std::transform(str, str_end, result.begin(), static_cast(Common::swap16)); return UTF16ToUTF8(result); } diff --git a/Source/Core/Core/TitleDatabase.cpp b/Source/Core/Core/TitleDatabase.cpp index 29fe07e57b..8ab17c1bf2 100644 --- a/Source/Core/Core/TitleDatabase.cpp +++ b/Source/Core/Core/TitleDatabase.cpp @@ -166,12 +166,12 @@ std::string TitleDatabase::GetTitleName(const std::string& game_id, TitleType ty return iterator != map.end() ? iterator->second : ""; } -std::string TitleDatabase::GetTitleName(u64 title_id) const +std::string TitleDatabase::GetChannelName(u64 title_id) const { const std::string id{ {static_cast((title_id >> 24) & 0xff), static_cast((title_id >> 16) & 0xff), static_cast((title_id >> 8) & 0xff), static_cast(title_id & 0xff)}}; - return GetTitleName(id, IOS::ES::IsChannel(title_id) ? TitleType::Channel : TitleType::Other); + return GetTitleName(id, TitleType::Channel); } std::string TitleDatabase::Describe(const std::string& game_id, TitleType type) const diff --git a/Source/Core/Core/TitleDatabase.h b/Source/Core/Core/TitleDatabase.h index 27793407a3..abc2cd51f1 100644 --- a/Source/Core/Core/TitleDatabase.h +++ b/Source/Core/Core/TitleDatabase.h @@ -27,7 +27,9 @@ public: // Get a user friendly title name for a game ID. // This falls back to returning an empty string if none could be found. std::string GetTitleName(const std::string& game_id, TitleType = TitleType::Other) const; - std::string GetTitleName(u64 title_id) const; + + // Same as above, but takes a title ID instead of a game ID, and can only find names of channels. + std::string GetChannelName(u64 title_id) const; // Get a description for a game ID (title name if available + game ID). std::string Describe(const std::string& game_id, TitleType = TitleType::Other) const; diff --git a/Source/Core/DolphinQt2/MenuBar.cpp b/Source/Core/DolphinQt2/MenuBar.cpp index fbc002457a..98ad117a99 100644 --- a/Source/Core/DolphinQt2/MenuBar.cpp +++ b/Source/Core/DolphinQt2/MenuBar.cpp @@ -16,6 +16,7 @@ #include "Common/CommonPaths.h" #include "Common/FileUtil.h" #include "Common/StringUtil.h" + #include "Core/CommonTitles.h" #include "Core/ConfigManager.h" #include "Core/Core.h" @@ -27,7 +28,10 @@ #include "Core/State.h" #include "Core/TitleDatabase.h" #include "Core/WiiUtils.h" + #include "DiscIO/NANDImporter.h" +#include "DiscIO/WiiSaveBanner.h" + #include "DolphinQt2/AboutDialog.h" #include "DolphinQt2/GameList/GameFile.h" #include "DolphinQt2/QtUtils/ActionHelper.h" @@ -557,10 +561,25 @@ void MenuBar::CheckNAND() Core::TitleDatabase title_db; for (const u64 title_id : result.titles_to_remove) { - const std::string name = title_db.GetTitleName(title_id); - title_listings += !name.empty() ? - StringFromFormat("%s (%016" PRIx64 ")", name.c_str(), title_id) : - StringFromFormat("%016" PRIx64, title_id); + title_listings += StringFromFormat("%016" PRIx64, title_id); + + const std::string database_name = title_db.GetChannelName(title_id); + if (!database_name.empty()) + { + title_listings += " - " + database_name; + } + else + { + DiscIO::WiiSaveBanner banner(title_id); + if (banner.IsValid()) + { + title_listings += " - " + banner.GetName(); + const std::string description = banner.GetDescription(); + if (!StripSpaces(description).empty()) + title_listings += " - " + description; + } + } + title_listings += "\n"; } diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index c714c7f12c..3c6e21386a 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -57,11 +57,13 @@ #include "Core/PowerPC/PPCSymbolDB.h" #include "Core/PowerPC/PowerPC.h" #include "Core/State.h" +#include "Core/TitleDatabase.h" #include "Core/WiiUtils.h" #include "DiscIO/Enums.h" #include "DiscIO/NANDImporter.h" #include "DiscIO/VolumeWad.h" +#include "DiscIO/WiiSaveBanner.h" #include "DolphinWX/AboutDolphin.h" #include "DolphinWX/Cheats/CheatsWindow.h" @@ -1331,10 +1333,25 @@ void CFrame::OnCheckNAND(wxCommandEvent&) Core::TitleDatabase title_db; for (const u64 title_id : result.titles_to_remove) { - const std::string name = title_db.GetTitleName(title_id); - title_listings += !name.empty() ? - StringFromFormat("%s (%016" PRIx64 ")", name.c_str(), title_id) : - StringFromFormat("%016" PRIx64, title_id); + title_listings += StringFromFormat("%016" PRIx64, title_id); + + const std::string database_name = title_db.GetChannelName(title_id); + if (!database_name.empty()) + { + title_listings += " - " + database_name; + } + else + { + DiscIO::WiiSaveBanner banner(title_id); + if (banner.IsValid()) + { + title_listings += " - " + banner.GetName(); + const std::string description = banner.GetDescription(); + if (!StripSpaces(description).empty()) + title_listings += " - " + description; + } + } + title_listings += "\n"; } @@ -1344,7 +1361,7 @@ void CFrame::OnCheckNAND(wxCommandEvent&) "By continuing, the following title(s) will be removed:\n\n" "%s" "\nLaunching these titles may also fix the issues."), - title_listings.c_str()); + StrToWxStr(title_listings)); } if (wxMessageBox(message, _("NAND Check"), wxYES_NO) != wxYES)