#pragma once #include #include #include #include #include #include namespace fnd { class LayeredIntegrityWrappedIFile : public fnd::IFile { public: LayeredIntegrityWrappedIFile(const fnd::SharedPtr& file, const LayeredIntegrityMetadata& hdr); size_t size(); void seek(size_t offset); void read(byte_t* out, size_t len); void read(byte_t* out, size_t offset, size_t len); void write(const byte_t* out, size_t len); void write(const byte_t* out, size_t offset, size_t len); private: const std::string kModuleName = "LayeredIntegrityWrappedIFile"; static const size_t kDefaultCacheSize = 0x10000; std::stringstream mErrorSs; fnd::SharedPtr mFile; // data file fnd::SharedPtr mData; size_t mDataOffset; size_t mDataBlockSize; fnd::List mDataHashLayer; bool mAlignHashCalcToBlock; fnd::Vec mCache; size_t mCacheBlockNum; inline size_t getOffsetBlock(size_t offset) const { return offset / mDataBlockSize; } inline size_t getOffsetInBlock(size_t offset) const { return offset % mDataBlockSize; } inline size_t getRemanderBlockReadSize(size_t total_size) const { return total_size % mDataBlockSize; } inline size_t getBlockNum(size_t total_size) const { return (total_size / mDataBlockSize) + (getRemanderBlockReadSize(total_size) > 0); } void initialiseDataLayer(const LayeredIntegrityMetadata& hdr); void readData(size_t block_offset, size_t block_num); }; }