mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +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:
parent
37bac7d75d
commit
fa08b0f377
3 changed files with 57 additions and 9 deletions
|
@ -403,9 +403,15 @@ String DirAccessPack::get_drive(int p_drive) {
|
|||
return "";
|
||||
}
|
||||
|
||||
Error DirAccessPack::change_dir(String p_dir) {
|
||||
PackedData::PackedDir *DirAccessPack::_find_dir(String p_dir) {
|
||||
|
||||
String nd = p_dir.replace("\\", "/");
|
||||
|
||||
// Special handling since simplify_path() will forbid it
|
||||
if (p_dir == "..") {
|
||||
return current->parent;
|
||||
}
|
||||
|
||||
bool absolute = false;
|
||||
if (nd.begins_with("res://")) {
|
||||
nd = nd.replace_first("res://", "");
|
||||
|
@ -445,13 +451,22 @@ Error DirAccessPack::change_dir(String p_dir) {
|
|||
|
||||
} else {
|
||||
|
||||
return ERR_INVALID_PARAMETER;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
current = pd;
|
||||
return pd;
|
||||
}
|
||||
|
||||
return OK;
|
||||
Error DirAccessPack::change_dir(String p_dir) {
|
||||
|
||||
PackedData::PackedDir *pd = _find_dir(p_dir);
|
||||
if (pd) {
|
||||
current = pd;
|
||||
return OK;
|
||||
} else {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
String DirAccessPack::get_current_dir() {
|
||||
|
@ -471,14 +486,18 @@ bool DirAccessPack::file_exists(String p_file) {
|
|||
|
||||
p_file = fix_path(p_file);
|
||||
|
||||
return current->files.has(p_file);
|
||||
PackedData::PackedDir *pd = _find_dir(p_file.get_base_dir());
|
||||
if (!pd) {
|
||||
return false;
|
||||
}
|
||||
return pd->files.has(p_file.get_file());
|
||||
}
|
||||
|
||||
bool DirAccessPack::dir_exists(String p_dir) {
|
||||
|
||||
p_dir = fix_path(p_dir);
|
||||
|
||||
return current->subdirs.has(p_dir);
|
||||
return _find_dir(p_dir) != NULL;
|
||||
}
|
||||
|
||||
Error DirAccessPack::make_dir(String p_dir) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue