Merge pull request #40748 from RandomShaper/improve_packed_fs_api

Improve/fix packed data API
This commit is contained in:
Rémi Verschelde
2020-11-10 10:59:34 +01:00
committed by GitHub
3 changed files with 55 additions and 9 deletions

View File

@ -442,8 +442,14 @@ 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://", "");
@ -483,13 +489,21 @@ Error DirAccessPack::change_dir(String p_dir) {
pd = pd->subdirs[p];
} else {
return ERR_INVALID_PARAMETER;
return nullptr;
}
}
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(bool p_include_drive) {
@ -507,13 +521,17 @@ String DirAccessPack::get_current_dir(bool p_include_drive) {
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) != nullptr;
}
Error DirAccessPack::make_dir(String p_dir) {