FS: Stream RomFS from file instead of loading all of it to memory
This commit is contained in:
parent
ecdfd0643a
commit
c385b7767d
9 changed files with 48 additions and 33 deletions
|
@ -124,7 +124,7 @@ ResultStatus LoadFile(const std::string& filename) {
|
|||
case FileType::CXI:
|
||||
case FileType::CCI:
|
||||
{
|
||||
AppLoader_NCCH app_loader(std::move(file));
|
||||
AppLoader_NCCH app_loader(std::move(file), filename);
|
||||
|
||||
// Load application and RomFS
|
||||
if (ResultStatus::Success == app_loader.Load()) {
|
||||
|
|
|
@ -99,10 +99,13 @@ public:
|
|||
|
||||
/**
|
||||
* Get the RomFS of the application
|
||||
* @param buffer Reference to buffer to store data
|
||||
* Since the RomFS can be huge, we return a file reference instead of copying to a buffer
|
||||
* @param romfs_file The file containing the RomFS
|
||||
* @param offset The offset the romfs begins on
|
||||
* @param size The size of the romfs
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
virtual ResultStatus ReadRomFS(std::vector<u8>& buffer) const {
|
||||
virtual ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const {
|
||||
return ResultStatus::ErrorNotImplemented;
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -163,7 +163,8 @@ namespace Loader {
|
|||
/// Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI)
|
||||
class AppLoader_NCCH final : public AppLoader {
|
||||
public:
|
||||
AppLoader_NCCH(std::unique_ptr<FileUtil::IOFile>&& file) : AppLoader(std::move(file)) { }
|
||||
AppLoader_NCCH(std::unique_ptr<FileUtil::IOFile>&& file, const std::string& filepath)
|
||||
: AppLoader(std::move(file)), filepath(filepath) { }
|
||||
|
||||
/**
|
||||
* Returns the type of the file
|
||||
|
@ -211,7 +212,7 @@ public:
|
|||
* @param buffer Reference to buffer to store data
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
ResultStatus ReadRomFS(std::vector<u8>& buffer) const override;
|
||||
ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const override;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -244,6 +245,8 @@ private:
|
|||
NCCH_Header ncch_header;
|
||||
ExeFs_Header exefs_header;
|
||||
ExHeader_Header exheader_header;
|
||||
|
||||
std::string filepath;
|
||||
};
|
||||
|
||||
} // namespace Loader
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue