int parse_and_set_libdir(char *c, int contains_flag) { char n[MAX_NAME_LENGTH]; int i; /* skip the flag? */ if (contains_flag == YES) c += 2; for (i = 0; i < (MAX_NAME_LENGTH - 1) && *c != 0; i++, c++) n[i] = *c; n[i] = 0; if (*c != 0) return FAILED; localize_path(n); #if defined(MSDOS) sprintf(ext_libdir, "%s\\", n); #else sprintf(ext_libdir, "%s/", n); #endif use_libdir = YES; return SUCCEEDED; }
int parse_and_set_libdir(char *c) { char n[MAX_NAME_LENGTH]; int i; if (strlen(c) > 2) { if (c[0] == '-' && c[1] == 'L') { c += 2; for (i = 0; i < (MAX_NAME_LENGTH - 1) && *c != 0; i++, c++) n[i] = *c; n[i] = 0; if (*c == 0) { localize_path(n); #if defined(MSDOS) sprintf(ext_libdir, "%s\\", n); #else sprintf(ext_libdir, "%s/", n); #endif use_libdir = YES; return SUCCEEDED; } } } return FAILED; }
String ProjectSettings::localize_path(const String &p_path) const { if (resource_path == "") return p_path; //not initialized yet if (p_path.begins_with("res://") || p_path.begins_with("user://") || (p_path.is_abs_path() && !p_path.begins_with(resource_path))) return p_path.simplify_path(); DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); String path = p_path.replace("\\", "/").simplify_path(); if (dir->change_dir(path) == OK) { String cwd = dir->get_current_dir(); cwd = cwd.replace("\\", "/"); memdelete(dir); // Ensure that we end with a '/'. // This is important to ensure that we do not wrongly localize the resource path // in an absolute path that just happens to contain this string but points to a // different folder (e.g. "/my/project" as resource_path would be contained in // "/my/project_data", even though the latter is not part of res://. // `plus_file("")` is an easy way to ensure we have a trailing '/'. const String res_path = resource_path.plus_file(""); if (!cwd.begins_with(res_path)) { return p_path; }; return cwd.replace_first(res_path, "res://"); } else { memdelete(dir); int sep = path.find_last("/"); if (sep == -1) { return "res://" + path; }; String parent = path.substr(0, sep); String plocal = localize_path(parent); if (plocal == "") { return ""; }; return plocal + path.substr(sep, path.size() - sep); }; }
String Globals::localize_path(const String& p_path) const { if (resource_path=="") return p_path; //not initialied yet if (p_path.begins_with("res://") || p_path.begins_with("user://") || (p_path.is_abs_path() && !p_path.begins_with(resource_path))) return p_path.simplify_path(); DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); String path = p_path.replace("\\","/").simplify_path(); if (dir->change_dir(path)==OK) { String cwd = dir->get_current_dir(); cwd = cwd.replace("\\","/"); memdelete(dir); if (!cwd.begins_with(resource_path)) { return p_path; }; return cwd.replace_first(resource_path, "res:/"); } else { memdelete(dir); int sep = path.find_last("/"); if (sep == -1) { return "res://"+path; }; String parent = path.substr(0, sep); String plocal = localize_path(parent); if (plocal == "") { return ""; }; return plocal + path.substr(sep, path.size() - sep); }; }