| 1 | #ifndef SEAD_ARCHIVE_RES_H_ |
| 2 | #define SEAD_ARCHIVE_RES_H_ |
| 3 | |
| 4 | #include <basis/seadRawPrint.h> |
| 5 | #include <basis/seadTypes.h> |
| 6 | #include <container/seadSafeArray.h> |
| 7 | #include <filedevice/seadFileDevice.h> |
| 8 | #include <heap/seadHeap.h> |
| 9 | #include <prim/seadSafeString.h> |
| 10 | #include <resource/seadResource.h> |
| 11 | |
| 12 | namespace sead |
| 13 | { |
| 14 | class ArchiveRes : public DirectResource |
| 15 | { |
| 16 | SEAD_RTTI_OVERRIDE(ArchiveRes, DirectResource) |
| 17 | |
| 18 | public: |
| 19 | struct FileInfo |
| 20 | { |
| 21 | u32 mStartOffset; |
| 22 | u32 mLength; |
| 23 | }; |
| 24 | |
| 25 | public: |
| 26 | ArchiveRes() : DirectResource(), mEnable(false) {} |
| 27 | ~ArchiveRes() override = default; |
| 28 | |
| 29 | s32 getLoadDataAlignment() const override; |
| 30 | void doCreate_(u8* buf, u32, Heap*) override; |
| 31 | |
| 32 | const void* getFile(const SafeString& file_path, FileInfo* info = nullptr) const |
| 33 | { |
| 34 | SEAD_ASSERT(mEnable); |
| 35 | return getFileImpl_(file_path, file_info: info); |
| 36 | } |
| 37 | |
| 38 | const void* getFileFast(const s32 entry_id, FileInfo* info) const |
| 39 | { |
| 40 | SEAD_ASSERT(mEnable); |
| 41 | return getFileFastImpl_(entry_id, file_info: info); |
| 42 | } |
| 43 | |
| 44 | s32 convertPathToEntryID(const SafeString& path) const |
| 45 | { |
| 46 | SEAD_ASSERT(mEnable); |
| 47 | return convertPathToEntryIDImpl_(file_path: path); |
| 48 | } |
| 49 | |
| 50 | bool setCurrentDirectory(const SafeString& dir) |
| 51 | { |
| 52 | SEAD_ASSERT(mEnable); |
| 53 | return setCurrentDirectoryImpl_(dir); |
| 54 | } |
| 55 | |
| 56 | bool openDirectory(HandleBuffer* handle, const SafeString& dir) const |
| 57 | { |
| 58 | return openDirectoryImpl_(handle, path: dir); |
| 59 | } |
| 60 | |
| 61 | bool closeDirectory(HandleBuffer* handle) const { return closeDirectoryImpl_(handle); } |
| 62 | |
| 63 | u32 readDirectory(HandleBuffer* handle, DirectoryEntry* entries, u32 num) const |
| 64 | { |
| 65 | return readDirectoryImpl_(handle, entries, num); |
| 66 | } |
| 67 | |
| 68 | bool isExistFile(const SafeString& path) const { return isExistFileImpl_(path); } |
| 69 | |
| 70 | protected: |
| 71 | virtual const void* getFileImpl_(const SafeString& file_path, |
| 72 | FileInfo* file_info = nullptr) const = 0; |
| 73 | virtual const void* getFileFastImpl_(s32 entry_id, FileInfo* file_info) const = 0; |
| 74 | virtual s32 convertPathToEntryIDImpl_(const SafeString& file_path) const = 0; |
| 75 | virtual bool setCurrentDirectoryImpl_(const SafeString&) = 0; |
| 76 | virtual bool openDirectoryImpl_(HandleBuffer* handle, const SafeString& path) const = 0; |
| 77 | virtual bool closeDirectoryImpl_(HandleBuffer* handle) const = 0; |
| 78 | virtual u32 readDirectoryImpl_(HandleBuffer* handle, DirectoryEntry* entries, |
| 79 | u32 num) const = 0; |
| 80 | virtual bool isExistFileImpl_(const SafeString& path) const; |
| 81 | virtual bool prepareArchive_(const void* archive) = 0; |
| 82 | |
| 83 | bool mEnable; |
| 84 | }; |
| 85 | |
| 86 | } // namespace sead |
| 87 | |
| 88 | #endif // SEAD_ARCHIVE_RES_H_ |
| 89 | |