Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PCK loading filename handling #59527

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 32 additions & 27 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,36 @@ void ProjectSettings::_convert_to_last_version(int p_from_version) {
}
}

bool ProjectSettings::_attempt_load_from_separate_pack(const String &p_exec_path) {
String exec_dir = p_exec_path.get_base_dir();
String exec_filename = p_exec_path.get_file();
while (true) {
#ifdef MACOS_ENABLED
// Attempt to load PCK from macOS .app bundle resources.
if (_load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_filename + ".pck"))) {
return true;
}
#endif
// Attempt to load data pack at the location of the executable.
if (_load_resource_pack(exec_dir.path_join(exec_filename + ".pck"))) {
return true;
}
// Lastly, attempt to load the PCK from the current working directory.
if (_load_resource_pack(exec_filename + ".pck")) {
return true;
}
if (exec_filename.contains(".")) {
// If we still haven't found the PCK, and there is an
// extension to strip, we strip and try again.
exec_filename = exec_filename.get_basename();
} else {
// If we still haven't found the PCK, and there are no
// more extensions to strip, we give up.
return false;
}
}
}

/*
* This method is responsible for loading a project.godot file and/or data file
* using the following merit order:
Expand Down Expand Up @@ -569,34 +599,9 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
// Attempt with PCK bundled into executable.
bool found = _load_resource_pack(exec_path);

// Attempt with exec_name.pck.
// (This is the usual case when distributing a Godot game.)
String exec_dir = exec_path.get_base_dir();
String exec_filename = exec_path.get_file();
String exec_basename = exec_filename.get_basename();

// Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
// or the exec path's basename + '.pck' (Windows).
// We need to test both possibilities as extensions for Linux binaries are optional
// (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').

#ifdef MACOS_ENABLED
if (!found) {
// Attempt to load PCK from macOS .app bundle resources.
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"));
}
#endif

if (!found) {
// Try to load data pack at the location of the executable.
// As mentioned above, we have two potential names to attempt.
found = _load_resource_pack(exec_dir.path_join(exec_basename + ".pck")) || _load_resource_pack(exec_dir.path_join(exec_filename + ".pck"));
}

// Attempt to load from a separate PCK (the more usual case).
if (!found) {
// If we couldn't find them next to the executable, we attempt
// the current working directory. Same story, two tests.
found = _load_resource_pack(exec_basename + ".pck") || _load_resource_pack(exec_filename + ".pck");
found = _attempt_load_from_separate_pack(exec_path);
}

// If we opened our package, try and load our project.
Expand Down
1 change: 1 addition & 0 deletions core/config/project_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class ProjectSettings : public Object {

void _add_property_info_bind(const Dictionary &p_info);

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

void _add_builtin_input_map();
Expand Down
Loading