DirectoryBlob: Don't keep DOL in memory

This commit is contained in:
JosJuice 2017-06-09 12:45:34 +02:00
parent 4cc8d3091c
commit a6bbf7e21b
3 changed files with 13 additions and 18 deletions

View File

@ -204,7 +204,7 @@ std::unique_ptr<BlobReader> CreateBlobReader(const std::string& filename)
return WbfsFileReader::Create(std::move(file), filename);
default:
if (DirectoryBlobReader::IsValidDirectoryBlob(filename))
return DirectoryBlobReader::Create(std::move(file), filename);
return DirectoryBlobReader::Create(filename);
return PlainFileReader::Create(std::move(file));
}

View File

@ -155,18 +155,16 @@ bool DirectoryBlobReader::IsValidDirectoryBlob(const std::string& dol_path)
return IsValidDirectoryBlob(dol_path, &root_directory);
}
std::unique_ptr<DirectoryBlobReader> DirectoryBlobReader::Create(File::IOFile dol,
const std::string& dol_path)
std::unique_ptr<DirectoryBlobReader> DirectoryBlobReader::Create(const std::string& dol_path)
{
std::string root_directory;
if (!dol || !IsValidDirectoryBlob(dol_path, &root_directory))
if (!IsValidDirectoryBlob(dol_path, &root_directory))
return nullptr;
return std::unique_ptr<DirectoryBlobReader>(
new DirectoryBlobReader(std::move(dol), root_directory));
return std::unique_ptr<DirectoryBlobReader>(new DirectoryBlobReader(root_directory));
}
DirectoryBlobReader::DirectoryBlobReader(File::IOFile dol_file, const std::string& root_directory)
DirectoryBlobReader::DirectoryBlobReader(const std::string& root_directory)
: m_root_directory(root_directory), m_data_start_address(UINT64_MAX),
m_disk_header(DISKHEADERINFO_ADDRESS),
m_disk_header_info(std::make_unique<SDiskHeaderInfo>()), m_fst_address(0), m_dol_address(0)
@ -175,7 +173,7 @@ DirectoryBlobReader::DirectoryBlobReader(File::IOFile dol_file, const std::strin
// Setting the DOL relies on m_dol_address, which is set by SetApploader
if (SetApploader(m_root_directory + "sys/apploader.img"))
SetDOL(std::move(dol_file));
SetDOL();
BuildFST();
@ -183,7 +181,6 @@ DirectoryBlobReader::DirectoryBlobReader(File::IOFile dol_file, const std::strin
m_virtual_disc.emplace(DISKHEADERINFO_ADDRESS, sizeof(m_disk_header_info),
reinterpret_cast<const u8*>(m_disk_header_info.get()));
m_virtual_disc.emplace(APPLOADER_ADDRESS, m_apploader.size(), m_apploader.data());
m_virtual_disc.emplace(m_dol_address, m_dol.size(), m_dol.data());
m_virtual_disc.emplace(m_fst_address, m_fst_data.size(), m_fst_data.data());
if (m_is_wii)
@ -354,16 +351,15 @@ bool DirectoryBlobReader::SetApploader(const std::string& apploader)
}
}
void DirectoryBlobReader::SetDOL(File::IOFile dol_file)
void DirectoryBlobReader::SetDOL()
{
m_dol.resize(dol_file.GetSize());
dol_file.Seek(0, SEEK_SET);
dol_file.ReadBytes(m_dol.data(), m_dol.size());
const DiscContent& dol =
AddFileToContents(&m_virtual_disc, m_root_directory + "sys/main.dol", m_dol_address);
Write32((u32)(m_dol_address >> m_address_shift), 0x0420, &m_disk_header);
// 32byte aligned (plus 0x20 padding)
m_fst_address = Common::AlignUp(m_dol_address + m_dol.size() + 0x20, 0x20ull);
m_fst_address = Common::AlignUp(m_dol_address + dol.GetSize() + 0x20, 0x20ull);
}
void DirectoryBlobReader::BuildFST()

View File

@ -57,7 +57,7 @@ class DirectoryBlobReader : public BlobReader
public:
static bool IsValidDirectoryBlob(const std::string& dol_path, std::string* root_directory);
static bool IsValidDirectoryBlob(const std::string& dol_path);
static std::unique_ptr<DirectoryBlobReader> Create(File::IOFile dol, const std::string& dol_path);
static std::unique_ptr<DirectoryBlobReader> Create(const std::string& dol_path);
// We do not allow copying, because it might mess up the pointers inside DiscContents
DirectoryBlobReader(const DirectoryBlobReader&) = delete;
@ -74,13 +74,13 @@ public:
u64 GetDataSize() const override;
private:
DirectoryBlobReader(File::IOFile dol_file, const std::string& root_directory);
explicit DirectoryBlobReader(const std::string& root_directory);
bool ReadInternal(u64 offset, u64 length, u8* buffer, const std::set<DiscContent>& contents);
void SetDiscHeaderAndDiscType();
bool SetApploader(const std::string& apploader);
void SetDOL(File::IOFile dol_file);
void SetDOL();
void BuildFST();
@ -153,7 +153,6 @@ private:
std::unique_ptr<SDiskHeaderInfo> m_disk_header_info;
std::vector<u8> m_apploader;
std::vector<u8> m_dol;
u64 m_fst_address;
u64 m_dol_address;