Skip to content

Commit 2eb5dc0

Browse files
committed
Improve PCK loading filename handling
1 parent 4ce466d commit 2eb5dc0

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
@@ -534,6 +534,36 @@ void ProjectSettings::_convert_to_last_version(int p_from_version) {
534534
#endif // DISABLE_DEPRECATED
535535
}
536536

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

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

626631
// 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)