From 3b6705a641d9dfd2fcee24cbbdfa88efca79a840 Mon Sep 17 00:00:00 2001 From: kobewi Date: Fri, 15 Nov 2024 16:14:38 +0100 Subject: [PATCH] Support uid:// in more places --- core/config/project_settings.cpp | 6 ++++++ core/io/file_access.cpp | 8 ++++++-- core/io/image.cpp | 2 +- core/io/image_loader.cpp | 9 +++++---- main/main.cpp | 2 +- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index fa0e4037ba3..0c546403c58 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -262,6 +262,12 @@ String ProjectSettings::globalize_path(const String &p_path) const { return p_path.replace("res:/", resource_path); } return p_path.replace("res://", ""); + } else if (p_path.begins_with("uid://")) { + const String path = ResourceUID::uid_to_path(p_path); + if (!resource_path.is_empty()) { + return path.replace("res:/", resource_path); + } + return path.replace("res://", ""); } else if (p_path.begins_with("user://")) { String data_dir = OS::get_singleton()->get_user_data_dir(); if (!data_dir.is_empty()) { diff --git a/core/io/file_access.cpp b/core/io/file_access.cpp index dd826e626ba..ef5ca502d44 100644 --- a/core/io/file_access.cpp +++ b/core/io/file_access.cpp @@ -71,7 +71,7 @@ void FileAccess::_set_access_type(AccessType p_access) { Ref FileAccess::create_for_path(const String &p_path) { Ref ret; - if (p_path.begins_with("res://")) { + if (p_path.begins_with("res://") || p_path.begins_with("uid://")) { ret = create(ACCESS_RESOURCES); } else if (p_path.begins_with("user://")) { ret = create(ACCESS_USERDATA); @@ -183,13 +183,17 @@ FileAccess::AccessType FileAccess::get_access_type() const { } String FileAccess::fix_path(const String &p_path) const { - //helper used by file accesses that use a single filesystem + // Helper used by file accesses that use a single filesystem. String r_path = p_path.replace("\\", "/"); switch (_access_type) { case ACCESS_RESOURCES: { if (ProjectSettings::get_singleton()) { + if (r_path.begins_with("uid://")) { + r_path = ResourceUID::uid_to_path(r_path); + } + if (r_path.begins_with("res://")) { String resource_path = ProjectSettings::get_singleton()->get_resource_path(); if (!resource_path.is_empty()) { diff --git a/core/io/image.cpp b/core/io/image.cpp index fa4484bb63b..128bbf3e6f0 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -2617,7 +2617,7 @@ Error Image::load(const String &p_path) { WARN_PRINT(vformat("Loaded resource as image file, this will not work on export: '%s'. Instead, import the image file as an Image resource and load it normally as a resource.", path)); } #endif - return ImageLoader::load_image(ResourceUID::ensure_path(p_path), this); + return ImageLoader::load_image(path, this); } Ref Image::load_from_file(const String &p_path) { diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 50c4704aa3f..58e63a4cc99 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -82,15 +82,16 @@ void ImageFormatLoaderExtension::_bind_methods() { Error ImageLoader::load_image(const String &p_file, Ref p_image, Ref p_custom, BitField p_flags, float p_scale) { ERR_FAIL_COND_V_MSG(p_image.is_null(), ERR_INVALID_PARAMETER, "Can't load an image: invalid Image object."); + const String file = ResourceUID::ensure_path(p_file); Ref f = p_custom; if (f.is_null()) { Error err; - f = FileAccess::open(p_file, FileAccess::READ, &err); - ERR_FAIL_COND_V_MSG(f.is_null(), err, vformat("Error opening file '%s'.", p_file)); + f = FileAccess::open(file, FileAccess::READ, &err); + ERR_FAIL_COND_V_MSG(f.is_null(), err, vformat("Error opening file '%s'.", file)); } - String extension = p_file.get_extension(); + String extension = file.get_extension(); for (int i = 0; i < loader.size(); i++) { if (!loader[i]->recognize(extension)) { @@ -98,7 +99,7 @@ Error ImageLoader::load_image(const String &p_file, Ref p_image, Refload_image(p_image, f, p_flags, p_scale); if (err != OK) { - ERR_PRINT(vformat("Error loading image: '%s'.", p_file)); + ERR_PRINT(vformat("Error loading image: '%s'.", file)); } if (err != ERR_FILE_UNRECOGNIZED) { diff --git a/main/main.cpp b/main/main.cpp index 2c41acef8bc..2ac019ca539 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -3450,7 +3450,7 @@ void Main::setup_boot_logo() { if (show_logo) { //boot logo! const bool boot_logo_image = GLOBAL_DEF_BASIC("application/boot_splash/show_image", true); - const String boot_logo_path = String(GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png"), String())).strip_edges(); + const String boot_logo_path = ResourceUID::ensure_path(GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png"), String())).strip_edges(); const bool boot_logo_scale = GLOBAL_DEF_BASIC("application/boot_splash/fullsize", true); const bool boot_logo_filter = GLOBAL_DEF_BASIC("application/boot_splash/use_filter", true);