Skip to content

Commit 1b26b76

Browse files
committed
Improve PCK loading filename handling
1 parent 7598b08 commit 1b26b76

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

core/config/project_settings.cpp

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,36 @@ void ProjectSettings::_convert_to_last_version(int p_from_version) {
539539
#endif // DISABLE_DEPRECATED
540540
}
541541

542+
bool ProjectSettings::_attempt_load_from_separate_pack(const String &p_exec_path) {
543+
String exec_dir = p_exec_path.get_base_dir();
544+
String exec_filename = p_exec_path.get_file();
545+
while (true) {
546+
#ifdef MACOS_ENABLED
547+
// Attempt to load PCK from macOS .app bundle resources.
548+
if (_load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_filename + ".pck"), false, 0, true)) {
549+
return true;
550+
}
551+
#endif
552+
// Attempt to load data pack at the location of the executable.
553+
if (_load_resource_pack(exec_dir.path_join(exec_filename + ".pck"), false, 0, true)) {
554+
return true;
555+
}
556+
// Lastly, attempt to load the PCK from the current working directory.
557+
if (_load_resource_pack(exec_filename + ".pck", false, 0, true)) {
558+
return true;
559+
}
560+
if (exec_filename.contains(".")) {
561+
// If we still haven't found the PCK, and there is an
562+
// extension to strip, we strip and try again.
563+
exec_filename = exec_filename.get_basename();
564+
} else {
565+
// If we still haven't found the PCK, and there are no
566+
// more extensions to strip, we give up.
567+
return false;
568+
}
569+
}
570+
}
571+
542572
/*
543573
* This method is responsible for loading a project.godot file and/or data file
544574
* using the following merit order:
@@ -598,34 +628,9 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
598628
// Attempt with PCK bundled into executable.
599629
bool found = _load_resource_pack(exec_path, false, 0, true);
600630

601-
// Attempt with exec_name.pck.
602-
// (This is the usual case when distributing a Godot game.)
603-
String exec_dir = exec_path.get_base_dir();
604-
String exec_filename = exec_path.get_file();
605-
String exec_basename = exec_filename.get_basename();
606-
607-
// Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
608-
// or the exec path's basename + '.pck' (Windows).
609-
// We need to test both possibilities as extensions for Linux binaries are optional
610-
// (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
611-
612-
#ifdef MACOS_ENABLED
613-
if (!found) {
614-
// Attempt to load PCK from macOS .app bundle resources.
615-
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);
616-
}
617-
#endif
618-
619-
if (!found) {
620-
// Try to load data pack at the location of the executable.
621-
// As mentioned above, we have two potential names to attempt.
622-
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);
623-
}
624-
631+
// Attempt to load from a separate PCK (the more usual case).
625632
if (!found) {
626-
// If we couldn't find them next to the executable, we attempt
627-
// the current working directory. Same story, two tests.
628-
found = _load_resource_pack(exec_basename + ".pck", false, 0, true) || _load_resource_pack(exec_filename + ".pck", false, 0, true);
633+
found = _attempt_load_from_separate_pack(exec_path);
629634
}
630635

631636
// If we opened our package, try and load our project.

core/config/project_settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class ProjectSettings : public Object {
139139

140140
void _add_property_info_bind(const Dictionary &p_info);
141141

142+
bool _attempt_load_from_separate_pack(const String &p_exec_path);
142143
Error _setup(const String &p_path, const String &p_main_pack, bool p_upwards = false, bool p_ignore_override = false);
143144

144145
void _add_builtin_input_map();

0 commit comments

Comments
 (0)