From 61655d6dc2912424de937e2870b6a5ad346c3daf Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 18 Jun 2016 11:12:08 -0300 Subject: Fixed make_dir and make_dir_recursive erros, closes #1680 closes #1872 --- core/os/dir_access.cpp | 134 +++++++++++++------------------------------------ 1 file changed, 34 insertions(+), 100 deletions(-) (limited to 'core/os/dir_access.cpp') diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 9a7135913..c2402183f 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -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; } - //int slices = full_dir.get_slice_count("/"); - - int pos = 0; - while (pos < full_dir.length()) { - - int n = full_dir.find("/", pos); - if (n < 0) { - n = full_dir.length(); - }; - pos = n + 1; - - 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) { - - 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 { + full_dir=full_dir.replace("\\","/"); - 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; + //int slices = full_dir.get_slice_count("/"); - cur_dir = p_path.substr(start, next - start); + String base; - if (cur_dir == "" || cur_dir == ".") { - continue; - }; - if (cur_dir == "..") { + 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 (curr > 0) { // pop a dir - curr -= 2; - }; - continue; - }; + full_dir=full_dir.replace_first(base,"").simplify_path(); - pos_stack[curr++] = start; - pos_stack[curr++] = next; + Vector subdirs=full_dir.split("/"); - } while (pos < p_path.length()); + String curpath=base; + for(int i=0;iget_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; -- cgit v1.2.3-70-g09d2