Update per PR comments.
This commit is contained in:
		@@ -18,13 +18,13 @@ namespace FileSys {
 | 
			
		||||
 | 
			
		||||
ArchiveFactory_RomFS::ArchiveFactory_RomFS(const Loader::AppLoader& app_loader) {
 | 
			
		||||
    // Load the RomFS from the app
 | 
			
		||||
    if (Loader::ResultStatus::Success != app_loader.ReadRomFS(m_romfs_file, m_offset, m_size)) {
 | 
			
		||||
    if (Loader::ResultStatus::Success != app_loader.ReadRomFS(romfs_file, data_offset, data_size)) {
 | 
			
		||||
        LOG_ERROR(Service_FS, "Unable to read RomFS!");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_RomFS::Open(const Path& path) {
 | 
			
		||||
    auto archive = Common::make_unique<IVFCArchive>(m_romfs_file, m_offset, m_size);
 | 
			
		||||
    auto archive = Common::make_unique<IVFCArchive>(romfs_file, data_offset, data_size);
 | 
			
		||||
    return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -27,9 +27,9 @@ public:
 | 
			
		||||
    ResultCode Format(const Path& path) override;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    std::shared_ptr<FileUtil::IOFile> m_romfs_file;
 | 
			
		||||
    u64 m_offset;
 | 
			
		||||
    u64 m_size;
 | 
			
		||||
    std::shared_ptr<FileUtil::IOFile> romfs_file;
 | 
			
		||||
    u64 data_offset;
 | 
			
		||||
    u64 data_size;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace FileSys
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@ std::string IVFCArchive::GetName() const {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::unique_ptr<FileBackend> IVFCArchive::OpenFile(const Path& path, const Mode mode) const {
 | 
			
		||||
    return Common::make_unique<IVFCFile>(m_romfs_file, m_offset, m_size);
 | 
			
		||||
    return Common::make_unique<IVFCFile>(romfs_file, data_offset, data_size);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool IVFCArchive::DeleteFile(const Path& path) const {
 | 
			
		||||
@@ -63,10 +63,10 @@ std::unique_ptr<DirectoryBackend> IVFCArchive::OpenDirectory(const Path& path) c
 | 
			
		||||
 | 
			
		||||
size_t IVFCFile::Read(const u64 offset, const u32 length, u8* buffer) const {
 | 
			
		||||
    LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length);
 | 
			
		||||
    m_romfs_file->Seek(m_offset + offset, SEEK_SET);
 | 
			
		||||
    u32 read_length = (u32) std::min((u64) length, m_size - offset);
 | 
			
		||||
    romfs_file->Seek(data_offset + offset, SEEK_SET);
 | 
			
		||||
    u32 read_length = (u32)std::min((u64)length, data_size - offset);
 | 
			
		||||
 | 
			
		||||
    return m_romfs_file->ReadBytes(buffer, read_length);
 | 
			
		||||
    return romfs_file->ReadBytes(buffer, read_length);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
size_t IVFCFile::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const {
 | 
			
		||||
@@ -75,7 +75,7 @@ size_t IVFCFile::Write(const u64 offset, const u32 length, const u32 flush, cons
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
size_t IVFCFile::GetSize() const {
 | 
			
		||||
    return sizeof(u8) * m_size;
 | 
			
		||||
    return sizeof(u8) * data_size;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool IVFCFile::SetSize(const u64 size) const {
 | 
			
		||||
 
 | 
			
		||||
@@ -26,8 +26,8 @@ namespace FileSys {
 | 
			
		||||
 */
 | 
			
		||||
class IVFCArchive : public ArchiveBackend {
 | 
			
		||||
public:
 | 
			
		||||
    IVFCArchive(std::shared_ptr<FileUtil::IOFile> romfs_file, u64 offset, u64 size)
 | 
			
		||||
        : m_romfs_file(romfs_file), m_offset(offset), m_size(size) {}
 | 
			
		||||
    IVFCArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
 | 
			
		||||
        : romfs_file(file), data_offset(offset), data_size(size) {}
 | 
			
		||||
 | 
			
		||||
    std::string GetName() const override;
 | 
			
		||||
 | 
			
		||||
@@ -41,15 +41,15 @@ public:
 | 
			
		||||
    std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    std::shared_ptr<FileUtil::IOFile> m_romfs_file;
 | 
			
		||||
    u64 m_offset;
 | 
			
		||||
    u64 m_size;
 | 
			
		||||
    std::shared_ptr<FileUtil::IOFile> romfs_file;
 | 
			
		||||
    u64 data_offset;
 | 
			
		||||
    u64 data_size;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class IVFCFile : public FileBackend {
 | 
			
		||||
public:
 | 
			
		||||
    IVFCFile(std::shared_ptr<FileUtil::IOFile> romfs_file, u64 offset, u64 size)
 | 
			
		||||
        : m_romfs_file(romfs_file), m_offset(offset), m_size(size) {}
 | 
			
		||||
    IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
 | 
			
		||||
        : romfs_file(file), data_offset(offset), data_size(size) {}
 | 
			
		||||
 | 
			
		||||
    bool Open() override { return true; }
 | 
			
		||||
    size_t Read(const u64 offset, const u32 length, u8* buffer) const override;
 | 
			
		||||
@@ -60,9 +60,9 @@ public:
 | 
			
		||||
    void Flush() const override { }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    std::shared_ptr<FileUtil::IOFile> m_romfs_file;
 | 
			
		||||
    u64 m_offset;
 | 
			
		||||
    u64 m_size;
 | 
			
		||||
    std::shared_ptr<FileUtil::IOFile> romfs_file;
 | 
			
		||||
    u64 data_offset;
 | 
			
		||||
    u64 data_size;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class IVFCDirectory : public DirectoryBackend {
 | 
			
		||||
 
 | 
			
		||||
@@ -93,7 +93,7 @@ public:
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the RomFS of the application
 | 
			
		||||
     * Since the RomFS is huge, we return a file reference instead of copying to a buffer
 | 
			
		||||
     * 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
 | 
			
		||||
 
 | 
			
		||||
@@ -289,13 +289,14 @@ ResultStatus AppLoader_NCCH::ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_
 | 
			
		||||
        if (file->GetSize () < romfs_offset + romfs_size)
 | 
			
		||||
            return ResultStatus::Error;
 | 
			
		||||
 | 
			
		||||
        // We reopen the file, to avoid reuse of the file offset
 | 
			
		||||
        // We reopen the file, to allow its position to be independent from file's
 | 
			
		||||
        romfs_file.reset(new FileUtil::IOFile(filepath, "rb"));
 | 
			
		||||
        if (!romfs_file->IsOpen())
 | 
			
		||||
            return ResultStatus::Error;
 | 
			
		||||
 | 
			
		||||
        offset = romfs_offset;
 | 
			
		||||
        size = romfs_size;
 | 
			
		||||
 | 
			
		||||
        if (!romfs_file->IsOpen())
 | 
			
		||||
            return ResultStatus::Error;
 | 
			
		||||
        return ResultStatus::Success;
 | 
			
		||||
    }
 | 
			
		||||
    LOG_DEBUG(Loader, "NCCH has no RomFS");
 | 
			
		||||
 
 | 
			
		||||
@@ -163,7 +163,7 @@ 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, std::string filepath)
 | 
			
		||||
    AppLoader_NCCH(std::unique_ptr<FileUtil::IOFile>&& file, const std::string& filepath)
 | 
			
		||||
        : AppLoader(std::move(file)), filepath(filepath) { }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user