MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / localize_path

Method localize_path

utility/gdre_settings.cpp:1420–1510  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1418}
1419
1420String GDRESettings::localize_path(const String &p_path, const String &resource_dir) const {
1421 String res_path = resource_dir != "" ? resource_dir : project_path;
1422#ifdef TOOLS_ENABLED
1423 if (res_path.is_empty() && Engine::get_singleton()->is_editor_hint()) {
1424 res_path = ProjectSettings::get_singleton()->get_resource_path();
1425 }
1426#endif
1427
1428 if (p_path.begins_with("res://") || p_path.begins_with("user://")) {
1429 return p_path.simplify_path();
1430 }
1431 if (!res_path.is_empty() && p_path.simplify_path().begins_with(res_path)) {
1432 return p_path.replace(res_path, "res://").simplify_path();
1433 }
1434 if ((p_path.is_absolute_path())) {
1435 if (!res_path.is_empty()) {
1436 if (p_path.begins_with(res_path)) {
1437 return p_path.replace(res_path, "res://").simplify_path();
1438 }
1439 String path = p_path.simplify_path();
1440 if (path.begins_with(res_path)) {
1441 return path.replace(res_path, "res://").simplify_path();
1442 }
1443 }
1444 if (is_pack_loaded() && (res_path == "" || !p_path.begins_with(res_path))) {
1445 // On rare occasions, import files can sometimes contain absolute paths for the source file(e.g. "C:\Users\John\Desktop\icon.png")
1446 // we need to start popping off the left-hand sides of the path until we find a directory that exists in the pack
1447 String dir_path = p_path.get_base_dir().simplify_path();
1448 // LEFT hand side, not right
1449 while (!dir_path.is_empty() && !DirAccess::dir_exists_absolute("res://" + dir_path)) {
1450 auto parts = dir_path.split("/", false, 1);
1451 if (parts.size() < 2) {
1452 dir_path = "";
1453 break;
1454 }
1455 dir_path = parts[1];
1456 }
1457 if (!dir_path.is_empty()) {
1458 return "res://" + dir_path.path_join(p_path.get_file());
1459 }
1460 }
1461 return p_path.simplify_path();
1462 }
1463
1464 if (res_path == "") {
1465 //not initialized yet
1466 if (!p_path.is_absolute_path()) {
1467 //just tack on a "res://" here
1468 return "res://" + p_path;
1469 }
1470 return p_path.simplify_path();
1471 }
1472
1473 Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
1474
1475 String path = p_path.replace("\\", "/").simplify_path();
1476
1477 if (dir->change_dir(path) == OK) {

Callers 15

_validate_local_pathFunction · 0.80
loadMethod · 0.80
get_dependenciesMethod · 0.80
get_classes_usedMethod · 0.80
rename_dependenciesMethod · 0.80
set_uidMethod · 0.80
custom_loadMethod · 0.80
get_resource_infoMethod · 0.80
get_local_pathMethod · 0.80
parse_variantMethod · 0.80
loadMethod · 0.80
rename_dependenciesMethod · 0.80

Calls 8

createFunction · 0.85
get_resource_pathMethod · 0.80
splitMethod · 0.80
change_dirMethod · 0.80
get_current_dirMethod · 0.80
lengthMethod · 0.80
sizeMethod · 0.45
get_fileMethod · 0.45

Tested by

no test coverage detected