MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _setup

Method _setup

core/config/project_settings.cpp:607–767  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

605}
606
607Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) {
608 if (!OS::get_singleton()->get_resource_dir().is_empty()) {
609 // OS will call ProjectSettings->get_resource_path which will be empty if not overridden!
610 // If the OS would rather use a specific location, then it will not be empty.
611 resource_path = OS::get_singleton()->get_resource_dir().replace_char('\\', '/');
612 if (!resource_path.is_empty() && resource_path[resource_path.length() - 1] == '/') {
613 resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
614 }
615 }
616
617 // Attempt with a user-defined main pack first
618
619 if (!p_main_pack.is_empty()) {
620 bool ok = _load_resource_pack(p_main_pack, false, 0, true);
621 ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, vformat("Cannot open resource pack '%s'.", p_main_pack));
622
623 Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
624 if (err == OK && !p_ignore_override) {
625 // Load override from location of the main pack
626 // Optional, we don't mind if it fails
627 _load_settings_text(p_main_pack.get_base_dir().path_join("override.cfg"));
628 }
629 return err;
630 }
631
632 String exec_path = OS::get_singleton()->get_executable_path();
633
634 if (!exec_path.is_empty()) {
635 // We do several tests sequentially until one succeeds to find a PCK,
636 // and if so, we attempt loading it at the end.
637
638 // Attempt with PCK bundled into executable.
639 bool found = _load_resource_pack(exec_path, false, 0, true);
640
641 // Attempt with exec_name.pck.
642 // (This is the usual case when distributing a Redot game.)
643 String exec_dir = exec_path.get_base_dir();
644 String exec_filename = exec_path.get_file();
645 String exec_basename = exec_filename.get_basename();
646
647 // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
648 // or the exec path's basename + '.pck' (Windows).
649 // We need to test both possibilities as extensions for Linux binaries are optional
650 // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
651
652#ifdef MACOS_ENABLED
653 if (!found) {
654 // Attempt to load PCK from macOS .app bundle resources.
655 found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_basename + ".pck"), false, 0, true) || _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_filename + ".pck"), false, 0, true);
656 }
657#endif
658
659 if (!found) {
660 // Try to load data pack at the location of the executable.
661 // As mentioned above, we have two potential names to attempt.
662 found = _load_resource_pack(exec_dir.path_join(exec_basename + ".pck"), false, 0, true) || _load_resource_pack(exec_dir.path_join(exec_filename + ".pck"), false, 0, true);
663 }
664

Callers

nothing calls this directly

Calls 15

vformatFunction · 0.85
replace_charMethod · 0.80
substrMethod · 0.80
path_joinMethod · 0.80
get_base_dirMethod · 0.80
get_basenameMethod · 0.80
createFunction · 0.50
is_emptyMethod · 0.45
get_resource_dirMethod · 0.45
lengthMethod · 0.45
get_executable_pathMethod · 0.45

Tested by

no test coverage detected