Skip to content

Commit 6c62e9a

Browse files
committed
Filter out metadata of excluded files on export
1 parent 06827c9 commit 6c62e9a

File tree

2 files changed

+77
-11
lines changed

2 files changed

+77
-11
lines changed

editor/export/editor_export_platform.cpp

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "core/io/file_access_pack.h" // PACK_HEADER_MAGIC, PACK_FORMAT_VERSION
4040
#include "core/io/image_loader.h"
4141
#include "core/io/resource_uid.h"
42+
#include "core/io/stream_peer.h"
4243
#include "core/io/zip_io.h"
4344
#include "core/math/random_pcg.h"
4445
#include "core/version.h"
@@ -1029,10 +1030,6 @@ Vector<String> EditorExportPlatform::get_forced_export_files(const Ref<EditorExp
10291030
if (!splash.is_empty() && FileAccess::exists(splash) && icon != splash) {
10301031
files.push_back(splash);
10311032
}
1032-
String resource_cache_file = ResourceUID::get_cache_file();
1033-
if (FileAccess::exists(resource_cache_file)) {
1034-
files.push_back(resource_cache_file);
1035-
}
10361033

10371034
String extension_list_config_file = GDExtension::get_extension_list_config_file();
10381035
if (FileAccess::exists(extension_list_config_file)) {
@@ -1609,21 +1606,35 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
16091606

16101607
Vector<String> forced_export = get_forced_export_files(p_preset);
16111608
for (int i = 0; i < forced_export.size(); i++) {
1609+
const String &file = forced_export[i];
16121610
Vector<uint8_t> array;
1613-
if (GDExtension::get_extension_list_config_file() == forced_export[i]) {
1614-
array = _filter_extension_list_config_file(forced_export[i], paths);
1615-
if (array.is_empty()) {
1616-
continue;
1617-
}
1611+
1612+
if (file == GDExtension::get_extension_list_config_file()) {
1613+
array = _filter_extension_list_config_file(file, paths);
1614+
} else if (file == ProjectSettings::get_singleton()->get_global_class_list_path()) {
1615+
array = _get_filtered_global_class_cache(file, paths);
16181616
} else {
1619-
array = FileAccess::get_file_as_bytes(forced_export[i]);
1617+
array = FileAccess::get_file_as_bytes(file);
16201618
}
1621-
err = save_proxy.save_file(p_udata, forced_export[i], array, idx, total, enc_in_filters, enc_ex_filters, key, seed);
1619+
1620+
if (array.is_empty()) {
1621+
continue;
1622+
}
1623+
1624+
err = save_proxy.save_file(p_udata, file, array, idx, total, enc_in_filters, enc_ex_filters, key, seed);
16221625
if (err != OK) {
16231626
return err;
16241627
}
16251628
}
16261629

1630+
// Generate a UID cache from the exported paths.
1631+
Vector<uint8_t> uid_cache_data = _get_filtered_uid_cache(paths);
1632+
String uid_cache_file_path = ResourceUID::get_cache_file();
1633+
err = save_proxy.save_file(p_udata, uid_cache_file_path, uid_cache_data, idx, total, enc_in_filters, enc_ex_filters, key, seed);
1634+
if (err != OK) {
1635+
return err;
1636+
}
1637+
16271638
Dictionary int_export = get_internal_export_files(p_preset, p_debug);
16281639
for (const KeyValue<Variant, Variant> &int_export_kv : int_export) {
16291640
const PackedByteArray &array = int_export_kv.value;
@@ -1676,6 +1687,59 @@ Vector<uint8_t> EditorExportPlatform::_filter_extension_list_config_file(const S
16761687
return data;
16771688
}
16781689

1690+
Vector<uint8_t> EditorExportPlatform::_get_filtered_uid_cache(const HashSet<String> &p_paths) {
1691+
Vector<Pair<ResourceUID::ID, String>> valid_entries;
1692+
valid_entries.reserve(p_paths.size());
1693+
1694+
for (const String &path : p_paths) {
1695+
ResourceUID::ID uid = ResourceLoader::get_resource_uid(path);
1696+
if (uid != ResourceUID::INVALID_ID) {
1697+
valid_entries.push_back(Pair<ResourceUID::ID, String>(uid, path));
1698+
}
1699+
}
1700+
1701+
// Same binary format as in ResourceUID::save_to_cache():
1702+
Ref<StreamPeerBuffer> buffer;
1703+
buffer.instantiate();
1704+
buffer->put_u32(valid_entries.size());
1705+
1706+
for (const Pair<ResourceUID::ID, String> &entry : valid_entries) {
1707+
buffer->put_u64(uint64_t(entry.first));
1708+
CharString cs = entry.second.utf8();
1709+
buffer->put_u32(cs.length());
1710+
buffer->put_data((const uint8_t *)cs.ptr(), cs.length());
1711+
}
1712+
1713+
return buffer->get_data_array();
1714+
}
1715+
1716+
Vector<uint8_t> EditorExportPlatform::_get_filtered_global_class_cache(const String &p_cache_path, const HashSet<String> &p_paths) {
1717+
Ref<ConfigFile> cf;
1718+
cf.instantiate();
1719+
if (cf->load(p_cache_path) != OK) {
1720+
return Vector<uint8_t>();
1721+
}
1722+
1723+
Array original_list = cf->get_value("", "list", Array());
1724+
Array filtered_list;
1725+
filtered_list.reserve(original_list.size());
1726+
1727+
for (const Variant &item : original_list) {
1728+
const Dictionary class_dict = item;
1729+
ERR_CONTINUE(!class_dict.has("path"));
1730+
if (p_paths.has(class_dict["path"])) {
1731+
filtered_list.push_back(class_dict);
1732+
}
1733+
}
1734+
1735+
if (filtered_list.size() == original_list.size()) {
1736+
return FileAccess::get_file_as_bytes(p_cache_path);
1737+
}
1738+
1739+
cf->set_value("", "list", filtered_list);
1740+
return cf->encode_to_text().to_utf8_buffer();
1741+
}
1742+
16791743
Error EditorExportPlatform::_pack_add_shared_object(void *p_userdata, const SharedObject &p_so) {
16801744
PackData *pack_data = (PackData *)p_userdata;
16811745
if (pack_data->so_files) {

editor/export/editor_export_platform.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class EditorExportPlatform : public RefCounted {
143143
void _edit_filter_list(HashSet<String> &r_list, const String &p_filter, bool exclude);
144144

145145
static Vector<uint8_t> _filter_extension_list_config_file(const String &p_config_path, const HashSet<String> &p_paths);
146+
static Vector<uint8_t> _get_filtered_uid_cache(const HashSet<String> &p_paths);
147+
static Vector<uint8_t> _get_filtered_global_class_cache(const String &p_cache_path, const HashSet<String> &p_paths);
146148

147149
struct FileExportCache {
148150
uint64_t source_modified_time = 0;

0 commit comments

Comments
 (0)