diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-11-10 10:59:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 10:59:34 +0100 |
commit | 32464e569f8e9d8b4146e49ee5daee777a8e3323 (patch) | |
tree | cc74b6c4aef73de30f8a07fa9300aec4ff721753 /core/io/file_access_pack.h | |
parent | cb5d5ff41359c94af2fdc6b2effe2af430080135 (diff) | |
parent | f38949a44d3164acdaf501ebd6a593a2a20b56f0 (diff) | |
download | redot-engine-32464e569f8e9d8b4146e49ee5daee777a8e3323.tar.gz |
Merge pull request #40748 from RandomShaper/improve_packed_fs_api
Improve/fix packed data API
Diffstat (limited to 'core/io/file_access_pack.h')
-rw-r--r-- | core/io/file_access_pack.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index 5c58dc01b4..c13626a5aa 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -122,6 +122,9 @@ public: _FORCE_INLINE_ FileAccess *try_open_path(const String &p_path); _FORCE_INLINE_ bool has_path(const String &p_path); + _FORCE_INLINE_ DirAccess *try_open_directory(const String &p_path); + _FORCE_INLINE_ bool has_directory(const String &p_path); + PackedData(); ~PackedData(); }; @@ -199,6 +202,16 @@ bool PackedData::has_path(const String &p_path) { return files.has(PathMD5(p_path.md5_buffer())); } +bool PackedData::has_directory(const String &p_path) { + DirAccess *da = try_open_directory(p_path); + if (da) { + memdelete(da); + return true; + } else { + return false; + } +} + class DirAccessPack : public DirAccess { PackedData::PackedDir *current; @@ -206,6 +219,8 @@ class DirAccessPack : public DirAccess { List<String> list_files; bool cdir = false; + PackedData::PackedDir *_find_dir(String p_dir); + public: virtual Error list_dir_begin(); virtual String get_next(); @@ -235,4 +250,13 @@ public: ~DirAccessPack() {} }; +DirAccess *PackedData::try_open_directory(const String &p_path) { + DirAccess *da = memnew(DirAccessPack()); + if (da->change_dir(p_path) != OK) { + memdelete(da); + da = nullptr; + } + return da; +} + #endif // FILE_ACCESS_PACK_H |