From 850802ea887e73e4853e668f939e5f9828ae21ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Fri, 10 Feb 2017 22:46:38 +0100 Subject: [PATCH] Get rid of a singleton for NAND shared contents This also allows shared contents to be installed to the configured root when installing a WAD. --- Source/Core/Core/HW/HW.cpp | 2 -- Source/Core/DiscIO/NANDContentLoader.cpp | 29 +++++++++--------------- Source/Core/DiscIO/NANDContentLoader.h | 18 ++++----------- 3 files changed, 15 insertions(+), 34 deletions(-) diff --git a/Source/Core/Core/HW/HW.cpp b/Source/Core/Core/HW/HW.cpp index 4480d58002..cbb297cf39 100644 --- a/Source/Core/Core/HW/HW.cpp +++ b/Source/Core/Core/HW/HW.cpp @@ -25,7 +25,6 @@ #include "Core/Movie.h" #include "Core/State.h" #include "Core/WiiRoot.h" -#include "DiscIO/NANDContentLoader.h" namespace HW { @@ -52,7 +51,6 @@ void Init() if (SConfig::GetInstance().bWii) { Core::InitializeWiiRoot(Core::g_want_determinism); - DiscIO::CSharedContent::AccessInstance().UpdateLocation(); IOS::Init(); IOS::HLE::Init(); // Depends on Memory } diff --git a/Source/Core/DiscIO/NANDContentLoader.cpp b/Source/Core/DiscIO/NANDContentLoader.cpp index 639891d899..fc1f600aa1 100644 --- a/Source/Core/DiscIO/NANDContentLoader.cpp +++ b/Source/Core/DiscIO/NANDContentLoader.cpp @@ -75,17 +75,11 @@ std::vector AESDecode(const u8* key, u8* iv, const u8* src, u32 size) CNANDContentData::~CNANDContentData() = default; -CSharedContent::CSharedContent() -{ - UpdateLocation(); -} - -void CSharedContent::UpdateLocation() +CSharedContent::CSharedContent(Common::FromWhichRoot root) : m_root(root) { m_Elements.clear(); m_LastID = 0; - m_ContentMap = - StringFromFormat("%s/shared1/content.map", File::GetUserPath(D_WIIROOT_IDX).c_str()); + m_ContentMap = Common::RootUserPath(root) + "/shared1/content.map"; File::IOFile pFile(m_ContentMap, "rb"); SElement Element; @@ -96,18 +90,14 @@ void CSharedContent::UpdateLocation() } } -CSharedContent::~CSharedContent() +std::string CSharedContent::GetFilenameFromSHA1(const u8* hash) const { -} - -std::string CSharedContent::GetFilenameFromSHA1(const u8* hash) -{ - for (auto& Element : m_Elements) + for (const auto& Element : m_Elements) { if (memcmp(hash, Element.SHA1Hash, 20) == 0) { return StringFromFormat( - "%s/shared1/%c%c%c%c%c%c%c%c.app", File::GetUserPath(D_WIIROOT_IDX).c_str(), + "%s/shared1/%c%c%c%c%c%c%c%c.app", Common::RootUserPath(m_root).c_str(), Element.FileName[0], Element.FileName[1], Element.FileName[2], Element.FileName[3], Element.FileName[4], Element.FileName[5], Element.FileName[6], Element.FileName[7]); } @@ -133,7 +123,7 @@ std::string CSharedContent::AddSharedContent(const u8* hash) pFile.WriteArray(&Element, 1); filename = - StringFromFormat("%s/shared1/%s.app", File::GetUserPath(D_WIIROOT_IDX).c_str(), id.c_str()); + StringFromFormat("%s/shared1/%s.app", Common::RootUserPath(m_root).c_str(), id.c_str()); m_LastID++; } @@ -288,6 +278,8 @@ void CNANDContentLoader::InitializeContentEntries(const std::vector& tmd, std::array iv; u32 data_app_offset = 0; + CSharedContent shared_content{Common::FromWhichRoot::FROM_SESSION_ROOT}; + for (u32 i = 0; i < m_NumEntries; i++) { const u32 entry_offset = 0x24 * i; @@ -322,7 +314,7 @@ void CNANDContentLoader::InitializeContentEntries(const std::vector& tmd, std::string filename; if (content.m_Type & 0x8000) // shared app - filename = CSharedContent::AccessInstance().GetFilenameFromSHA1(content.m_SHA1Hash); + filename = shared_content.GetFilenameFromSHA1(content.m_SHA1Hash); else filename = StringFromFormat("%s/%08x.app", m_Path.c_str(), content.m_ContentID); @@ -495,6 +487,7 @@ u64 CNANDContentManager::Install_WiiWAD(const std::string& filename) tmd_file.WriteBytes(content_loader.GetTMDHeader(), CNANDContentLoader::TMD_HEADER_SIZE); + CSharedContent shared_content{Common::FromWhichRoot::FROM_CONFIGURED_ROOT}; for (u32 i = 0; i < content_loader.GetContentSize(); i++) { const SNANDContent& content = content_loader.GetContent()[i]; @@ -503,7 +496,7 @@ u64 CNANDContentManager::Install_WiiWAD(const std::string& filename) std::string app_filename; if (content.m_Type & 0x8000) // shared - app_filename = CSharedContent::AccessInstance().AddSharedContent(content.m_SHA1Hash); + app_filename = shared_content.AddSharedContent(content.m_SHA1Hash); else app_filename = StringFromFormat("%s%08x.app", content_path.c_str(), content.m_ContentID); diff --git a/Source/Core/DiscIO/NANDContentLoader.h b/Source/Core/DiscIO/NANDContentLoader.h index a5c93d7539..632ac0ef3e 100644 --- a/Source/Core/DiscIO/NANDContentLoader.h +++ b/Source/Core/DiscIO/NANDContentLoader.h @@ -155,26 +155,15 @@ private: std::unordered_map> m_map; }; -class CSharedContent +class CSharedContent final { public: - static CSharedContent& AccessInstance() - { - static CSharedContent instance; - return instance; - } + explicit CSharedContent(Common::FromWhichRoot root); - std::string GetFilenameFromSHA1(const u8* hash); + std::string GetFilenameFromSHA1(const u8* hash) const; std::string AddSharedContent(const u8* hash); - void UpdateLocation(); private: - CSharedContent(); - virtual ~CSharedContent(); - - CSharedContent(CSharedContent const&) = delete; - void operator=(CSharedContent const&) = delete; - #pragma pack(push, 1) struct SElement { @@ -183,6 +172,7 @@ private: }; #pragma pack(pop) + Common::FromWhichRoot m_root; u32 m_LastID; std::string m_ContentMap; std::vector m_Elements;