Skip to content

Commit a17a0bc

Browse files
committed
Merge pull request #100717 from KoBeWi/icon_uncache
Fix icon UIDs in Project Manager
2 parents 29bd5c0 + 81b1138 commit a17a0bc

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

core/io/resource_uid.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ Error ResourceUID::load_from_cache(bool p_reset) {
229229
int32_t len = f->get_32();
230230
Cache c;
231231
c.cs.resize(len + 1);
232-
ERR_FAIL_COND_V(c.cs.size() != len + 1, ERR_FILE_CORRUPT); // out of memory
232+
ERR_FAIL_COND_V(c.cs.size() != len + 1, ERR_FILE_CORRUPT); // Out of memory.
233233
c.cs[len] = 0;
234234
int32_t rl = f->get_buffer((uint8_t *)c.cs.ptrw(), len);
235235
ERR_FAIL_COND_V(rl != len, ERR_FILE_CORRUPT);
@@ -257,7 +257,7 @@ Error ResourceUID::update_cache() {
257257
for (KeyValue<ID, Cache> &E : unique_ids) {
258258
if (!E.value.saved_to_cache) {
259259
if (f.is_null()) {
260-
f = FileAccess::open(get_cache_file(), FileAccess::READ_WRITE); //append
260+
f = FileAccess::open(get_cache_file(), FileAccess::READ_WRITE); // Append.
261261
if (f.is_null()) {
262262
return ERR_CANT_OPEN;
263263
}
@@ -282,6 +282,25 @@ Error ResourceUID::update_cache() {
282282
return OK;
283283
}
284284

285+
String ResourceUID::get_path_from_cache(Ref<FileAccess> &p_cache_file, const String &p_uid_string) {
286+
const uint32_t entry_count = p_cache_file->get_32();
287+
CharString cs;
288+
for (uint32_t i = 0; i < entry_count; i++) {
289+
int64_t id = p_cache_file->get_64();
290+
int32_t len = p_cache_file->get_32();
291+
cs.resize(len + 1);
292+
ERR_FAIL_COND_V(cs.size() != len + 1, String());
293+
cs[len] = 0;
294+
int32_t rl = p_cache_file->get_buffer((uint8_t *)cs.ptrw(), len);
295+
ERR_FAIL_COND_V(rl != len, String());
296+
297+
if (singleton->id_to_text(id) == p_uid_string) {
298+
return String(cs);
299+
}
300+
}
301+
return String();
302+
}
303+
285304
void ResourceUID::clear() {
286305
cache_entries = 0;
287306
unique_ids.clear();

core/io/resource_uid.h

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "core/string/string_name.h"
3636
#include "core/templates/hash_map.h"
3737

38+
class FileAccess;
39+
3840
class ResourceUID : public Object {
3941
GDCLASS(ResourceUID, Object)
4042
public:
@@ -78,6 +80,7 @@ class ResourceUID : public Object {
7880
Error load_from_cache(bool p_reset);
7981
Error save_to_cache();
8082
Error update_cache();
83+
static String get_path_from_cache(Ref<FileAccess> &p_cache_file, const String &p_uid_string);
8184

8285
void clear();
8386

editor/project_manager/project_list.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,20 @@ ProjectList::Item ProjectList::load_project_data(const String &p_path, bool p_fa
489489

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

494+
String icon = cf->get_value("application", "config/icon", "");
495+
if (icon.begins_with("uid://")) {
496+
Error err;
497+
Ref<FileAccess> file = FileAccess::open(p_path.path_join(".godot/uid_cache.bin"), FileAccess::READ, &err);
498+
if (err == OK) {
499+
icon = ResourceUID::get_path_from_cache(file, icon);
500+
if (icon.is_empty()) {
501+
WARN_PRINT(vformat("Could not load icon from UID for project at path \"%s\". Make sure UID cache exists.", p_path));
502+
}
503+
}
504+
}
505+
495506
PackedStringArray project_features = cf->get_value("application", "config/features", PackedStringArray());
496507
PackedStringArray unsupported_features = ProjectSettings::get_unsupported_features(project_features);
497508

0 commit comments

Comments
 (0)