|
39 | 39 | #include "core/io/file_access_pack.h" // PACK_HEADER_MAGIC, PACK_FORMAT_VERSION |
40 | 40 | #include "core/io/image_loader.h" |
41 | 41 | #include "core/io/resource_uid.h" |
| 42 | +#include "core/io/stream_peer.h" |
42 | 43 | #include "core/io/zip_io.h" |
43 | 44 | #include "core/math/random_pcg.h" |
44 | 45 | #include "core/version.h" |
@@ -1029,10 +1030,6 @@ Vector<String> EditorExportPlatform::get_forced_export_files(const Ref<EditorExp |
1029 | 1030 | if (!splash.is_empty() && FileAccess::exists(splash) && icon != splash) { |
1030 | 1031 | files.push_back(splash); |
1031 | 1032 | } |
1032 | | - String resource_cache_file = ResourceUID::get_cache_file(); |
1033 | | - if (FileAccess::exists(resource_cache_file)) { |
1034 | | - files.push_back(resource_cache_file); |
1035 | | - } |
1036 | 1033 |
|
1037 | 1034 | String extension_list_config_file = GDExtension::get_extension_list_config_file(); |
1038 | 1035 | if (FileAccess::exists(extension_list_config_file)) { |
@@ -1609,21 +1606,35 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & |
1609 | 1606 |
|
1610 | 1607 | Vector<String> forced_export = get_forced_export_files(p_preset); |
1611 | 1608 | for (int i = 0; i < forced_export.size(); i++) { |
| 1609 | + const String &file = forced_export[i]; |
1612 | 1610 | 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); |
1618 | 1616 | } else { |
1619 | | - array = FileAccess::get_file_as_bytes(forced_export[i]); |
| 1617 | + array = FileAccess::get_file_as_bytes(file); |
1620 | 1618 | } |
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); |
1622 | 1625 | if (err != OK) { |
1623 | 1626 | return err; |
1624 | 1627 | } |
1625 | 1628 | } |
1626 | 1629 |
|
| 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 | + |
1627 | 1638 | Dictionary int_export = get_internal_export_files(p_preset, p_debug); |
1628 | 1639 | for (const KeyValue<Variant, Variant> &int_export_kv : int_export) { |
1629 | 1640 | const PackedByteArray &array = int_export_kv.value; |
@@ -1676,6 +1687,59 @@ Vector<uint8_t> EditorExportPlatform::_filter_extension_list_config_file(const S |
1676 | 1687 | return data; |
1677 | 1688 | } |
1678 | 1689 |
|
| 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 | + |
1679 | 1743 | Error EditorExportPlatform::_pack_add_shared_object(void *p_userdata, const SharedObject &p_so) { |
1680 | 1744 | PackData *pack_data = (PackData *)p_userdata; |
1681 | 1745 | if (pack_data->so_files) { |
|
0 commit comments