diff options
| author | comex <comexk@gmail.com> | 2013-08-29 18:25:12 -0400 |
|---|---|---|
| committer | comex <comexk@gmail.com> | 2013-08-31 01:38:52 -0400 |
| commit | 04c41c1d38261eebb1cdf462a8d836cfc504a9ac (patch) | |
| tree | 3beaf77f72b93c96de62103c455272c19c41a8e1 /Source/Core/DiscIO | |
| parent | 4d6d4a97e4df55ae1f1ec2cb6b7961efd6d35c89 (diff) | |
Fix loading DLC using IOCTL_ES_OPENTITLECONTENT & /dev/es state save.
(Intertwined enough that's it's easier to do in one patch.)
(1) /dev/es did not support state save, which could cause crashes and
incorrect behavior after loading.
(2) NANDContentLoader tried to read all of a title's contents into
memory when it was first opened. Two issues:
- If any contents were missing, it bailed out. However, with DLC,
only some of the contents may be downloaded, as determined by the
permission bits in the ticket. Instead, return an appropriate error
when a content is accessed that doesn't exist on the filesystem
(don't bother checking the permission bits though).
- Everything was loaded into memory - even if it consisted of 3 GB of
songs, which caused Dolphin to lag out for quite a while (and would
fail on 32-bit). Instead, open content on demand.
Diffstat (limited to 'Source/Core/DiscIO')
| -rw-r--r-- | Source/Core/DiscIO/Src/NANDContentLoader.cpp | 41 | ||||
| -rw-r--r-- | Source/Core/DiscIO/Src/NANDContentLoader.h | 6 |
2 files changed, 17 insertions, 30 deletions
diff --git a/Source/Core/DiscIO/Src/NANDContentLoader.cpp b/Source/Core/DiscIO/Src/NANDContentLoader.cpp index 0cc71bafb8..b0dcd302f7 100644 --- a/Source/Core/DiscIO/Src/NANDContentLoader.cpp +++ b/Source/Core/DiscIO/Src/NANDContentLoader.cpp @@ -5,7 +5,7 @@ #include "NANDContentLoader.h" #include <algorithm> -#include <cctype> +#include <cctype> #include "Crypto/aes.h" #include "MathUtil.h" #include "FileUtil.h" @@ -42,7 +42,7 @@ void CSharedContent::UpdateLocation() CSharedContent::~CSharedContent() {} -std::string CSharedContent::GetFilenameFromSHA1(u8* _pHash) +std::string CSharedContent::GetFilenameFromSHA1(const u8* _pHash) { for (size_t i=0; i<m_Elements.size(); i++) { @@ -58,7 +58,7 @@ std::string CSharedContent::GetFilenameFromSHA1(u8* _pHash) return "unk"; } -std::string CSharedContent::AddSharedContent(u8* _pHash) +std::string CSharedContent::AddSharedContent(const u8* _pHash) { std::string szFilename = GetFilenameFromSHA1(_pHash); if (strcasecmp(szFilename.c_str(), "unk") == 0) @@ -170,8 +170,11 @@ const SNANDContent* CNANDContentLoader::GetContentByIndex(int _Index) const { for (size_t i=0; i<m_Content.size(); i++) { - if (m_Content[i].m_Index == _Index) - return &m_Content[i]; + const SNANDContent* pContent = &m_Content[i]; + if (pContent->m_Index == _Index) + { + return pContent; + } } return NULL; } @@ -262,36 +265,18 @@ bool CNANDContentLoader::Initialize(const std::string& _rName) } rContent.m_pData = NULL; - char szFilename[1024]; if (rContent.m_Type & 0x8000) // shared app { - std::string Filename = CSharedContent::AccessInstance().GetFilenameFromSHA1(rContent.m_SHA1Hash); - strcpy(szFilename, Filename.c_str()); + rContent.m_Filename = CSharedContent::AccessInstance().GetFilenameFromSHA1(rContent.m_SHA1Hash); } else { - sprintf(szFilename, "%s/%08x.app", m_Path.c_str(), rContent.m_ContentID); + rContent.m_Filename = StringFromFormat("%s/%08x.app", m_Path.c_str(), rContent.m_ContentID); } - INFO_LOG(DISCIO, "NANDContentLoader: load %s", szFilename); - - File::IOFile pFile(szFilename, "rb"); - if (pFile) - { - const u64 ContentSize = File::GetSize(szFilename); - rContent.m_pData = new u8[(u32)ContentSize]; - - _dbg_assert_msg_(BOOT, rContent.m_Size==ContentSize, "TMDLoader: Incorrect filesize (%s %i). Your NAND dump may be corrupt.", szFilename, i); - - pFile.ReadBytes(rContent.m_pData, (size_t)ContentSize); - } - else - { - ERROR_LOG(DISCIO, "NANDContentLoader: error opening %s", szFilename); - delete [] pTMD; - return false; - } + // Be graceful about incorrect tmds. + rContent.m_Size = (u32) File::GetSize(rContent.m_Filename); } delete [] pTMD; @@ -493,7 +478,7 @@ u64 CNANDContentManager::Install_WiiWAD(std::string &fileName) for (u32 i = 0; i < ContentLoader.GetContentSize(); i++) { - SNANDContent Content = ContentLoader.GetContent()[i]; + const SNANDContent& Content = ContentLoader.GetContent()[i]; pTMDFile.WriteBytes(Content.m_Header, INANDContentLoader::CONTENT_HEADER_SIZE); diff --git a/Source/Core/DiscIO/Src/NANDContentLoader.h b/Source/Core/DiscIO/Src/NANDContentLoader.h index 66d6a4880c..9172c85338 100644 --- a/Source/Core/DiscIO/Src/NANDContentLoader.h +++ b/Source/Core/DiscIO/Src/NANDContentLoader.h @@ -13,6 +13,7 @@ #include "Blob.h" #include "Volume.h" #include "NandPaths.h" +#include "FileUtil.h" namespace DiscIO { @@ -26,6 +27,7 @@ struct SNANDContent u8 m_SHA1Hash[20]; u8 m_Header[36]; //all of the above + std::string m_Filename; u8* m_pData; }; @@ -95,8 +97,8 @@ public: static CSharedContent& AccessInstance() { return m_Instance; } - std::string GetFilenameFromSHA1(u8* _pHash); - std::string AddSharedContent(u8* _pHash); + std::string GetFilenameFromSHA1(const u8* _pHash); + std::string AddSharedContent(const u8* _pHash); void UpdateLocation(); private: |
