FS: Stream RomFS from file instead of loading all of it to memory

This commit is contained in:
condut 2015-07-10 00:55:23 +03:00 committed by Yuri Kunde Schlesner
parent ecdfd0643a
commit c385b7767d
9 changed files with 48 additions and 33 deletions

View file

@ -299,7 +299,7 @@ ResultStatus AppLoader_NCCH::ReadLogo(std::vector<u8>& buffer) const {
return LoadSectionExeFS("logo", buffer);
}
ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const {
ResultStatus AppLoader_NCCH::ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const {
if (!file->IsOpen())
return ResultStatus::Error;
@ -311,12 +311,17 @@ ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const {
LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset);
LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size);
buffer.resize(romfs_size);
file->Seek(romfs_offset, SEEK_SET);
if (file->ReadBytes(&buffer[0], romfs_size) != romfs_size)
if (file->GetSize () < romfs_offset + romfs_size)
return ResultStatus::Error;
// We reopen the file, to allow its position to be independent from file's
romfs_file = std::make_shared<FileUtil::IOFile>(filepath, "rb");
if (!romfs_file->IsOpen())
return ResultStatus::Error;
offset = romfs_offset;
size = romfs_size;
return ResultStatus::Success;
}
LOG_DEBUG(Loader, "NCCH has no RomFS");