You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Fix icon UIDs in Project Manager
This commit is contained in:
@@ -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);
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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:
|
||||
@@ -78,6 +80,7 @@ public:
|
||||
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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user