summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/Src/NANDContentLoader.cpp
diff options
context:
space:
mode:
authorcomex <comexk@gmail.com>2013-08-29 18:25:12 -0400
committercomex <comexk@gmail.com>2013-08-31 01:38:52 -0400
commit04c41c1d38261eebb1cdf462a8d836cfc504a9ac (patch)
tree3beaf77f72b93c96de62103c455272c19c41a8e1 /Source/Core/DiscIO/Src/NANDContentLoader.cpp
parent4d6d4a97e4df55ae1f1ec2cb6b7961efd6d35c89 (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/Src/NANDContentLoader.cpp')
-rw-r--r--Source/Core/DiscIO/Src/NANDContentLoader.cpp41
1 files changed, 13 insertions, 28 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);