You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-23 15:16:17 +00:00
Improve/fix packed data API
- Enhance directory API - Fix `FileAccess::exists()` not checking for PackedData being disabled - Fix moving to the parent directory (`..`) - Allow absolute paths in existence checks
This commit is contained in:
@@ -118,6 +118,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();
|
||||
};
|
||||
@@ -197,6 +200,17 @@ 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;
|
||||
@@ -205,6 +219,8 @@ class DirAccessPack : public DirAccess {
|
||||
List<String> list_files;
|
||||
bool cdir;
|
||||
|
||||
PackedData::PackedDir *_find_dir(String p_dir);
|
||||
|
||||
public:
|
||||
virtual Error list_dir_begin();
|
||||
virtual String get_next();
|
||||
@@ -234,4 +250,14 @@ 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 = NULL;
|
||||
}
|
||||
return da;
|
||||
}
|
||||
|
||||
#endif // FILE_ACCESS_PACK_H
|
||||
|
||||
Reference in New Issue
Block a user