@@ -592,6 +592,36 @@ void ProjectSettings::_convert_to_last_version(int p_from_version) {
592592#endif // DISABLE_DEPRECATED
593593}
594594
595+ bool ProjectSettings::_attempt_load_from_separate_pack (const String &p_exec_path) {
596+ String exec_dir = p_exec_path.get_base_dir ();
597+ String exec_filename = p_exec_path.get_file ();
598+ while (true ) {
599+ #ifdef MACOS_ENABLED
600+ // Attempt to load PCK from macOS .app bundle resources.
601+ if (_load_resource_pack (OS::get_singleton ()->get_bundle_resource_dir ().path_join (exec_filename + " .pck" ), false , 0 , true )) {
602+ return true ;
603+ }
604+ #endif
605+ // Attempt to load data pack at the location of the executable.
606+ if (_load_resource_pack (exec_dir.path_join (exec_filename + " .pck" ), false , 0 , true )) {
607+ return true ;
608+ }
609+ // Lastly, attempt to load the PCK from the current working directory.
610+ if (_load_resource_pack (exec_filename + " .pck" , false , 0 , true )) {
611+ return true ;
612+ }
613+ if (exec_filename.contains (" ." )) {
614+ // If we still haven't found the PCK, and there is an
615+ // extension to strip, we strip and try again.
616+ exec_filename = exec_filename.get_basename ();
617+ } else {
618+ // If we still haven't found the PCK, and there are no
619+ // more extensions to strip, we give up.
620+ return false ;
621+ }
622+ }
623+ }
624+
595625/*
596626 * This method is responsible for loading a project.godot file and/or data file
597627 * using the following merit order:
@@ -651,34 +681,9 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
651681 // Attempt with PCK bundled into executable.
652682 bool found = _load_resource_pack (exec_path, false , 0 , true );
653683
654- // Attempt with exec_name.pck.
655- // (This is the usual case when distributing a Godot game.)
656- String exec_dir = exec_path.get_base_dir ();
657- String exec_filename = exec_path.get_file ();
658- String exec_basename = exec_filename.get_basename ();
659-
660- // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
661- // or the exec path's basename + '.pck' (Windows).
662- // We need to test both possibilities as extensions for Linux binaries are optional
663- // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
664-
665- #ifdef MACOS_ENABLED
666- if (!found) {
667- // Attempt to load PCK from macOS .app bundle resources.
668- 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 );
669- }
670- #endif
671-
672- if (!found) {
673- // Try to load data pack at the location of the executable.
674- // As mentioned above, we have two potential names to attempt.
675- 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 );
676- }
677-
684+ // Attempt to load from a separate PCK (the more usual case).
678685 if (!found) {
679- // If we couldn't find them next to the executable, we attempt
680- // the current working directory. Same story, two tests.
681- found = _load_resource_pack (exec_basename + " .pck" , false , 0 , true ) || _load_resource_pack (exec_filename + " .pck" , false , 0 , true );
686+ found = _attempt_load_from_separate_pack (exec_path);
682687 }
683688
684689 // If we opened our package, try and load our project.
0 commit comments