You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-11 13:10:58 +00:00
@@ -143,118 +143,52 @@ Error DirAccess::make_dir_recursive(String p_dir) {
|
||||
};
|
||||
|
||||
String full_dir;
|
||||
Globals* g = Globals::get_singleton();
|
||||
|
||||
if (!p_dir.is_abs_path()) {
|
||||
//append current
|
||||
if (p_dir.is_rel_path()) {
|
||||
//append current
|
||||
full_dir=get_current_dir().plus_file(p_dir);
|
||||
|
||||
String cur = normalize_path(g->globalize_path(get_current_dir()));
|
||||
if (cur[cur.length()-1] != '/') {
|
||||
cur = cur + "/";
|
||||
};
|
||||
|
||||
full_dir=(cur+"/"+p_dir).simplify_path();
|
||||
} else {
|
||||
//validate and use given
|
||||
String dir = normalize_path(g->globalize_path(p_dir));
|
||||
if (dir.length() < 1) {
|
||||
return OK;
|
||||
};
|
||||
if (dir[dir.length()-1] != '/') {
|
||||
dir = dir + "/";
|
||||
};
|
||||
full_dir=dir;
|
||||
full_dir=p_dir;
|
||||
}
|
||||
|
||||
full_dir=full_dir.replace("\\","/");
|
||||
|
||||
//int slices = full_dir.get_slice_count("/");
|
||||
|
||||
int pos = 0;
|
||||
while (pos < full_dir.length()) {
|
||||
String base;
|
||||
|
||||
int n = full_dir.find("/", pos);
|
||||
if (n < 0) {
|
||||
n = full_dir.length();
|
||||
};
|
||||
pos = n + 1;
|
||||
if (full_dir.begins_with("res://"))
|
||||
base="res://";
|
||||
else if (full_dir.begins_with("user://"))
|
||||
base="user://";
|
||||
else if (full_dir.begins_with("/"))
|
||||
base="/";
|
||||
else if (full_dir.find(":/")!=-1) {
|
||||
base=full_dir.substr(0,full_dir.find(":/")+2);
|
||||
} else {
|
||||
ERR_FAIL_V(ERR_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
if (pos > 1) {
|
||||
String to_create = full_dir.substr(0, pos -1);
|
||||
//print_line("MKDIR: "+to_create);
|
||||
Error err = make_dir(to_create);
|
||||
if (err != OK && err != ERR_ALREADY_EXISTS) {
|
||||
full_dir=full_dir.replace_first(base,"").simplify_path();
|
||||
|
||||
ERR_FAIL_V(err);
|
||||
};
|
||||
};
|
||||
};
|
||||
Vector<String> subdirs=full_dir.split("/");
|
||||
|
||||
String curpath=base;
|
||||
for(int i=0;i<subdirs.size();i++) {
|
||||
|
||||
curpath=curpath.plus_file(subdirs[i]);
|
||||
Error err = make_dir(curpath);
|
||||
if (err != OK && err != ERR_ALREADY_EXISTS) {
|
||||
|
||||
ERR_FAIL_V(err);
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
String DirAccess::normalize_path(const String &p_path) {
|
||||
|
||||
static const int max_depth = 64;
|
||||
int pos_stack[max_depth];
|
||||
int curr = 0;
|
||||
|
||||
int pos = 0;
|
||||
String cur_dir;
|
||||
|
||||
do {
|
||||
|
||||
if (curr >= max_depth) {
|
||||
|
||||
ERR_PRINT("Directory depth too deep.");
|
||||
return "";
|
||||
};
|
||||
|
||||
int start = pos;
|
||||
|
||||
int next = p_path.find("/", pos);
|
||||
if (next < 0) {
|
||||
next = p_path.length() - 1;
|
||||
};
|
||||
|
||||
pos = next + 1;
|
||||
|
||||
cur_dir = p_path.substr(start, next - start);
|
||||
|
||||
if (cur_dir == "" || cur_dir == ".") {
|
||||
continue;
|
||||
};
|
||||
if (cur_dir == "..") {
|
||||
|
||||
if (curr > 0) { // pop a dir
|
||||
curr -= 2;
|
||||
};
|
||||
continue;
|
||||
};
|
||||
|
||||
pos_stack[curr++] = start;
|
||||
pos_stack[curr++] = next;
|
||||
|
||||
} while (pos < p_path.length());
|
||||
|
||||
String path;
|
||||
if (p_path[0] == '/') {
|
||||
path = "/";
|
||||
};
|
||||
|
||||
int i=0;
|
||||
while (i < curr) {
|
||||
|
||||
int start = pos_stack[i++];
|
||||
|
||||
while ( ((i+1)<curr) && (pos_stack[i] == pos_stack[i+1]) ) {
|
||||
|
||||
++i;
|
||||
};
|
||||
path = path + p_path.substr(start, (pos_stack[i++] - start) + 1);
|
||||
};
|
||||
|
||||
return path;
|
||||
};
|
||||
|
||||
String DirAccess::get_next(bool* p_is_dir) {
|
||||
|
||||
@@ -276,9 +210,9 @@ String DirAccess::fix_path(String p_path) const {
|
||||
String resource_path = Globals::get_singleton()->get_resource_path();
|
||||
if (resource_path != "") {
|
||||
|
||||
return p_path.replace("res:/",resource_path);
|
||||
return p_path.replace_first("res:/",resource_path);
|
||||
};
|
||||
return p_path.replace("res://", "");
|
||||
return p_path.replace_first("res://", "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,9 +226,9 @@ String DirAccess::fix_path(String p_path) const {
|
||||
String data_dir=OS::get_singleton()->get_data_dir();
|
||||
if (data_dir != "") {
|
||||
|
||||
return p_path.replace("user:/",data_dir);
|
||||
return p_path.replace_first("user:/",data_dir);
|
||||
};
|
||||
return p_path.replace("user://", "");
|
||||
return p_path.replace_first("user://", "");
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
Reference in New Issue
Block a user