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

Fix icon UIDs in Project Manager #100717

Merged
merged 1 commit into from
Jan 3, 2025
Merged
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
23 changes: 21 additions & 2 deletions core/io/resource_uid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Error ResourceUID::load_from_cache(bool p_reset) {
int32_t len = f->get_32();
Cache c;
c.cs.resize(len + 1);
ERR_FAIL_COND_V(c.cs.size() != len + 1, ERR_FILE_CORRUPT); // out of memory
ERR_FAIL_COND_V(c.cs.size() != len + 1, ERR_FILE_CORRUPT); // Out of memory.
c.cs[len] = 0;
int32_t rl = f->get_buffer((uint8_t *)c.cs.ptrw(), len);
ERR_FAIL_COND_V(rl != len, ERR_FILE_CORRUPT);
Expand Down Expand Up @@ -257,7 +257,7 @@ Error ResourceUID::update_cache() {
for (KeyValue<ID, Cache> &E : unique_ids) {
if (!E.value.saved_to_cache) {
if (f.is_null()) {
f = FileAccess::open(get_cache_file(), FileAccess::READ_WRITE); //append
f = FileAccess::open(get_cache_file(), FileAccess::READ_WRITE); // Append.
if (f.is_null()) {
return ERR_CANT_OPEN;
}
Expand All @@ -282,6 +282,25 @@ Error ResourceUID::update_cache() {
return OK;
}

String ResourceUID::get_path_from_cache(Ref<FileAccess> &p_cache_file, const String &p_uid_string) {
const uint32_t entry_count = p_cache_file->get_32();
CharString cs;
for (uint32_t i = 0; i < entry_count; i++) {
int64_t id = p_cache_file->get_64();
int32_t len = p_cache_file->get_32();
cs.resize(len + 1);
ERR_FAIL_COND_V(cs.size() != len + 1, String());
cs[len] = 0;
int32_t rl = p_cache_file->get_buffer((uint8_t *)cs.ptrw(), len);
ERR_FAIL_COND_V(rl != len, String());

if (singleton->id_to_text(id) == p_uid_string) {
return String(cs);
}
}
return String();
}

void ResourceUID::clear() {
cache_entries = 0;
unique_ids.clear();
Expand Down
3 changes: 3 additions & 0 deletions core/io/resource_uid.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "core/string/string_name.h"
#include "core/templates/hash_map.h"

class FileAccess;

class ResourceUID : public Object {
GDCLASS(ResourceUID, Object)
public:
Expand Down Expand Up @@ -78,6 +80,7 @@ class ResourceUID : public Object {
Error load_from_cache(bool p_reset);
Error save_to_cache();
Error update_cache();
static String get_path_from_cache(Ref<FileAccess> &p_cache_file, const String &p_uid_string);

void clear();

Expand Down
13 changes: 12 additions & 1 deletion editor/project_manager/project_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,20 @@ ProjectList::Item ProjectList::load_project_data(const String &p_path, bool p_fa

const String description = cf->get_value("application", "config/description", "");
const PackedStringArray tags = cf->get_value("application", "config/tags", PackedStringArray());
const String icon = cf->get_value("application", "config/icon", "");
const String main_scene = cf->get_value("application", "run/main_scene", "");

String icon = cf->get_value("application", "config/icon", "");
if (icon.begins_with("uid://")) {
Error err;
Ref<FileAccess> file = FileAccess::open(p_path.path_join(".godot/uid_cache.bin"), FileAccess::READ, &err);
if (err == OK) {
icon = ResourceUID::get_path_from_cache(file, icon);
if (icon.is_empty()) {
WARN_PRINT(vformat("Could not load icon from UID for project at path \"%s\". Make sure UID cache exists.", p_path));
}
}
}

PackedStringArray project_features = cf->get_value("application", "config/features", PackedStringArray());
PackedStringArray unsupported_features = ProjectSettings::get_unsupported_features(project_features);

Expand Down