@@ -580,6 +580,36 @@ void ProjectSettings::_convert_to_last_version(int p_from_version) {
580580#endif // DISABLE_DEPRECATED
581581}
582582
583+ bool ProjectSettings::_attempt_load_from_separate_pack (const String &p_exec_path) {
584+ String exec_dir = p_exec_path.get_base_dir ();
585+ String exec_filename = p_exec_path.get_file ();
586+ while (true ) {
587+ #ifdef MACOS_ENABLED
588+ // Attempt to load PCK from macOS .app bundle resources.
589+ if (_load_resource_pack (OS::get_singleton ()->get_bundle_resource_dir ().path_join (exec_filename + " .pck" ), false , 0 , true )) {
590+ return true ;
591+ }
592+ #endif
593+ // Attempt to load data pack at the location of the executable.
594+ if (_load_resource_pack (exec_dir.path_join (exec_filename + " .pck" ), false , 0 , true )) {
595+ return true ;
596+ }
597+ // Lastly, attempt to load the PCK from the current working directory.
598+ if (_load_resource_pack (exec_filename + " .pck" , false , 0 , true )) {
599+ return true ;
600+ }
601+ if (exec_filename.contains (" ." )) {
602+ // If we still haven't found the PCK, and there is an
603+ // extension to strip, we strip and try again.
604+ exec_filename = exec_filename.get_basename ();
605+ } else {
606+ // If we still haven't found the PCK, and there are no
607+ // more extensions to strip, we give up.
608+ return false ;
609+ }
610+ }
611+ }
612+
583613/*
584614 * This method is responsible for loading a project.godot file and/or data file
585615 * using the following merit order:
@@ -639,34 +669,9 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
639669 // Attempt with PCK bundled into executable.
640670 bool found = _load_resource_pack (exec_path, false , 0 , true );
641671
642- // Attempt with exec_name.pck.
643- // (This is the usual case when distributing a Godot game.)
644- String exec_dir = exec_path.get_base_dir ();
645- String exec_filename = exec_path.get_file ();
646- String exec_basename = exec_filename.get_basename ();
647-
648- // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
649- // or the exec path's basename + '.pck' (Windows).
650- // We need to test both possibilities as extensions for Linux binaries are optional
651- // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
652-
653- #ifdef MACOS_ENABLED
654- if (!found) {
655- // Attempt to load PCK from macOS .app bundle resources.
656- 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 );
657- }
658- #endif
659-
660- if (!found) {
661- // Try to load data pack at the location of the executable.
662- // As mentioned above, we have two potential names to attempt.
663- 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 );
664- }
665-
672+ // Attempt to load from a separate PCK (the more usual case).
666673 if (!found) {
667- // If we couldn't find them next to the executable, we attempt
668- // the current working directory. Same story, two tests.
669- found = _load_resource_pack (exec_basename + " .pck" , false , 0 , true ) || _load_resource_pack (exec_filename + " .pck" , false , 0 , true );
674+ found = _attempt_load_from_separate_pack (exec_path);
670675 }
671676
672677 // If we opened our package, try and load our project.
0 commit comments