Skip to content

Commit bf1c258

Browse files
committed
Merge pull request #101954 from bruvzg/uid_deref
[Export] Convert `uid://` names to `res://` when exporting files.
2 parents a592639 + f3b6a40 commit bf1c258

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

editor/export/editor_export_platform.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ Error EditorExportPlatform::_save_pack_file(void *p_userdata, const String &p_pa
256256
PackData *pd = (PackData *)p_userdata;
257257

258258
String simplified_path = p_path.simplify_path();
259+
if (simplified_path.begins_with("uid://")) {
260+
simplified_path = ResourceUID::uid_to_path(simplified_path).simplify_path();
261+
print_verbose(vformat(R"(UID referenced exported file name "%s" was replaced with "%s".)", p_path, simplified_path));
262+
}
259263

260264
SavedData sd;
261265
sd.path_utf8 = simplified_path.trim_prefix("res://").utf8();
@@ -350,7 +354,13 @@ Error EditorExportPlatform::_save_pack_patch_file(void *p_userdata, const String
350354
Error EditorExportPlatform::_save_zip_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key, uint64_t p_seed) {
351355
ERR_FAIL_COND_V_MSG(p_total < 1, ERR_PARAMETER_RANGE_ERROR, "Must select at least one file to export.");
352356

353-
String path = p_path.replace_first("res://", "");
357+
String path = p_path.simplify_path();
358+
if (path.begins_with("uid://")) {
359+
path = ResourceUID::uid_to_path(path).simplify_path();
360+
print_verbose(vformat(R"(UID referenced exported file name "%s" was replaced with "%s".)", p_path, path));
361+
}
362+
363+
path = path.replace_first("res://", "");
354364

355365
ZipData *zd = (ZipData *)p_userdata;
356366

@@ -1014,7 +1024,13 @@ Error EditorExportPlatform::_script_save_file(void *p_userdata, const String &p_
10141024
Callable cb = ((ScriptCallbackData *)p_userdata)->file_cb;
10151025
ERR_FAIL_COND_V(!cb.is_valid(), FAILED);
10161026

1017-
Variant path = p_path;
1027+
String simplified_path = p_path.simplify_path();
1028+
if (simplified_path.begins_with("uid://")) {
1029+
simplified_path = ResourceUID::uid_to_path(simplified_path).simplify_path();
1030+
print_verbose(vformat(R"(UID referenced exported file name "%s" was replaced with "%s".)", p_path, simplified_path));
1031+
}
1032+
1033+
Variant path = simplified_path;
10181034
Variant data = p_data;
10191035
Variant file = p_file;
10201036
Variant total = p_total;

platform/android/export/export_plugin.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,12 @@ Error EditorExportPlatformAndroid::save_apk_so(void *p_userdata, const SharedObj
803803

804804
Error EditorExportPlatformAndroid::save_apk_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key, uint64_t p_seed) {
805805
APKExportData *ed = static_cast<APKExportData *>(p_userdata);
806-
const String path = ResourceUID::ensure_path(p_path);
806+
807+
String path = p_path.simplify_path();
808+
if (path.begins_with("uid://")) {
809+
path = ResourceUID::uid_to_path(path).simplify_path();
810+
print_verbose(vformat(R"(UID referenced exported file name "%s" was replaced with "%s".)", p_path, path));
811+
}
807812
const String dst_path = path.replace_first("res://", "assets/");
808813

809814
store_in_apk(ed, dst_path, p_data, _should_compress_asset(path, p_data) ? Z_DEFLATED : 0);

platform/android/export/gradle_export_util.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,14 @@ Error store_string_at_path(const String &p_path, const String &p_data) {
171171
// This method will be called ONLY when gradle build is enabled.
172172
Error rename_and_store_file_in_gradle_project(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key, uint64_t p_seed) {
173173
CustomExportData *export_data = static_cast<CustomExportData *>(p_userdata);
174-
const String path = ResourceUID::ensure_path(p_path);
174+
175+
String path = p_path.simplify_path();
176+
if (path.begins_with("uid://")) {
177+
path = ResourceUID::uid_to_path(path).simplify_path();
178+
print_verbose(vformat(R"(UID referenced exported file name "%s" was replaced with "%s".)", p_path, path));
179+
}
175180
const String dst_path = path.replace_first("res://", export_data->assets_directory + "/");
181+
176182
print_verbose("Saving project files from " + path + " into " + dst_path);
177183
Error err = store_file_at_path(dst_path, p_data);
178184
return err;

0 commit comments

Comments
 (0)