#pragma once #include #include #include #include #include #include namespace frostbite2D { /** * @brief PVF ??????? */ struct PvfFileInfo { size_t offset = 0; ///< ???????????? uint32 crc32 = 0; ///< CRC32 ??? size_t length = 0; ///< ???????? bool decoded = false; ///< ????? }; /** * @brief ????????? */ struct RawData { std::unique_ptr data; ///< ?????????????????? size_t size; ///< ???????? }; /** * @brief PVF ?????? * * ??????? PVF ??????????? * ?????????????????????????? */ class PvfArchive { public: static PvfArchive& get(); PvfArchive(const PvfArchive&) = delete; PvfArchive& operator=(const PvfArchive&) = delete; PvfArchive(PvfArchive&&) = delete; PvfArchive& operator=(PvfArchive&&) = delete; bool open(const std::string& filePath = "Script.pvf"); void close(); bool isOpen() const; void init(); void initHeader(); void initBinStringTable(); void initLoadStrings(); bool hasFile(const std::string& path) const; std::optional getFileInfo(const std::string& path) const; std::vector listFiles() const; std::optional getFileContent(const std::string& path); std::optional> getFileBytes(const std::string& path); std::optional getFileRawData(const std::string& path); std::optional getBinString(int key) const; std::optional getLoadString(const std::string& type, const std::string& key) const; bool hasBinString(int key) const; bool hasLoadString(const std::string& type, const std::string& key) const; std::string normalizePath(const std::string& path) const; std::string resolvePath(const std::string& baseDir, const std::string& path) const; private: PvfArchive() = default; ~PvfArchive() = default; std::vector splitString(const std::string& str, const std::string& delimiter) const; bool decodeFile(const std::string& normalizedPath, PvfFileInfo& info); void clearInitData(); std::optional> readArchiveBytes(size_t absoluteOffset, size_t length); std::optional> readDecodedFileBytes( const PvfFileInfo& info); static void crcDecodeBuffer(std::vector& data, uint32 crc32); BinaryFileStreamReader reader_; size_t dataStartPos_ = 0; std::map fileInfo_; std::map binStringTable_; std::map> loadStrings_; std::map> decodedFileCache_; }; } // namespace frostbite2D