DiscIO: Fix the wrong NAND root being used

The whole NANDContentLoader stuff is truly awful and will be removed
as soon as possible.

For now, this fixes a bug that was exposed by std::optional::operator*.
This commit is contained in:
Léo Lam
2017-05-26 21:29:15 +02:00
parent 545006f666
commit 62d08e2d17
2 changed files with 15 additions and 9 deletions

View File

@ -94,7 +94,8 @@ bool CNANDContentDataBuffer::GetRange(u32 start, u32 size, u8* buffer)
return true; return true;
} }
CNANDContentLoader::CNANDContentLoader(const std::string& content_name) CNANDContentLoader::CNANDContentLoader(const std::string& content_name, Common::FromWhichRoot from)
: m_root(from)
{ {
m_Valid = Initialize(content_name); m_Valid = Initialize(content_name);
} }
@ -185,7 +186,7 @@ void CNANDContentLoader::InitializeContentEntries(const std::vector<u8>& data_ap
u32 data_app_offset = 0; u32 data_app_offset = 0;
const std::vector<u8> title_key = m_ticket.GetTitleKey(); const std::vector<u8> title_key = m_ticket.GetTitleKey();
IOS::ES::SharedContentMap shared_content{Common::FromWhichRoot::FROM_SESSION_ROOT}; IOS::ES::SharedContentMap shared_content{m_root};
for (size_t i = 0; i < contents.size(); ++i) for (size_t i = 0; i < contents.size(); ++i)
{ {
@ -223,14 +224,15 @@ CNANDContentManager::~CNANDContentManager()
{ {
} }
const CNANDContentLoader& CNANDContentManager::GetNANDLoader(const std::string& content_path) const CNANDContentLoader& CNANDContentManager::GetNANDLoader(const std::string& content_path,
Common::FromWhichRoot from)
{ {
auto it = m_map.find(content_path); auto it = m_map.find(content_path);
if (it != m_map.end()) if (it != m_map.end())
return *it->second; return *it->second;
return *m_map return *m_map
.emplace_hint(it, std::make_pair(content_path, .emplace_hint(it, std::make_pair(content_path, std::make_unique<CNANDContentLoader>(
std::make_unique<CNANDContentLoader>(content_path))) content_path, from)))
->second; ->second;
} }
@ -238,7 +240,7 @@ const CNANDContentLoader& CNANDContentManager::GetNANDLoader(u64 title_id,
Common::FromWhichRoot from) Common::FromWhichRoot from)
{ {
std::string path = Common::GetTitleContentPath(title_id, from); std::string path = Common::GetTitleContentPath(title_id, from);
return GetNANDLoader(path); return GetNANDLoader(path, from);
} }
void CNANDContentManager::ClearCache() void CNANDContentManager::ClearCache()

View File

@ -75,7 +75,7 @@ struct SNANDContent
class CNANDContentLoader final class CNANDContentLoader final
{ {
public: public:
explicit CNANDContentLoader(const std::string& content_name); explicit CNANDContentLoader(const std::string& content_name, Common::FromWhichRoot from);
~CNANDContentLoader(); ~CNANDContentLoader();
bool IsValid() const; bool IsValid() const;
@ -90,6 +90,7 @@ private:
bool m_Valid = false; bool m_Valid = false;
bool m_IsWAD = false; bool m_IsWAD = false;
Common::FromWhichRoot m_root;
std::string m_Path; std::string m_Path;
IOS::ES::TMDReader m_tmd; IOS::ES::TMDReader m_tmd;
IOS::ES::TicketReader m_ticket; IOS::ES::TicketReader m_ticket;
@ -107,8 +108,11 @@ public:
return instance; return instance;
} }
const CNANDContentLoader& GetNANDLoader(const std::string& content_path); const CNANDContentLoader&
const CNANDContentLoader& GetNANDLoader(u64 title_id, Common::FromWhichRoot from); GetNANDLoader(const std::string& content_path,
Common::FromWhichRoot from = Common::FROM_CONFIGURED_ROOT);
const CNANDContentLoader&
GetNANDLoader(u64 title_id, Common::FromWhichRoot from = Common::FROM_CONFIGURED_ROOT);
void ClearCache(); void ClearCache();
private: private: