@@ -167,6 +167,34 @@ bool EditorExportPlatform::fill_log_messages(RichTextLabel *p_log, Error p_err)
167
167
return has_messages;
168
168
}
169
169
170
+ Error EditorExportPlatform::_load_patches (const Vector<String> &p_patches) {
171
+ Error err = OK;
172
+ if (!p_patches.is_empty ()) {
173
+ for (const String &path : p_patches) {
174
+ err = PackedData::get_singleton ()->add_pack (path, true , 0 );
175
+ if (err != OK) {
176
+ add_message (EXPORT_MESSAGE_ERROR, TTR (" Patch Creation" ), vformat (TTR (" Could not recognize pack file from path \" %s\" ." ), path));
177
+ return err;
178
+ }
179
+ }
180
+ }
181
+ return err;
182
+ }
183
+
184
+ bool EditorExportPlatform::_check_hash (const uint8_t *p_hash, const Vector<uint8_t > &p_data) {
185
+ if (p_hash) {
186
+ unsigned char hash[16 ];
187
+ CryptoCore::md5 (p_data.ptr (), p_data.size (), hash);
188
+ for (int i = 0 ; i < 16 ; i++) {
189
+ if (p_hash[i] != hash[i]) {
190
+ return false ;
191
+ }
192
+ }
193
+ return true ;
194
+ }
195
+ return false ;
196
+ }
197
+
170
198
void EditorExportPlatform::gen_debug_flags (Vector<String> &r_flags, int p_flags) {
171
199
String host = EDITOR_GET (" network/debug/remote_host" );
172
200
int remote_port = (int )EDITOR_GET (" network/debug/remote_port" );
@@ -219,6 +247,14 @@ void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags)
219
247
}
220
248
}
221
249
250
+ Error EditorExportPlatform::save_pack (const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, Vector<SharedObject> *p_so_files, bool p_embed, int64_t *r_embedded_start, int64_t *r_embedded_size) {
251
+ return _save_pack (p_preset, p_debug, p_path, _save_pack_file, p_so_files, p_embed, r_embedded_start, r_embedded_size);
252
+ }
253
+
254
+ Error EditorExportPlatform::save_zip (const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
255
+ return _save_zip (p_preset, p_debug, p_path, _save_zip_file);
256
+ }
257
+
222
258
Error EditorExportPlatform::_save_pack_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) {
223
259
ERR_FAIL_COND_V_MSG (p_total < 1 , ERR_PARAMETER_RANGE_ERROR, " Must select at least one file to export." );
224
260
@@ -289,6 +325,14 @@ Error EditorExportPlatform::_save_pack_file(void *p_userdata, const String &p_pa
289
325
return OK;
290
326
}
291
327
328
+ Error EditorExportPlatform::_save_patch_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) {
329
+ if (_check_hash (PackedData::get_singleton ()->get_file_hash (p_path), p_data)) {
330
+ return OK;
331
+ }
332
+
333
+ return _save_pack_file (p_userdata, p_path, p_data, p_file, p_total, p_enc_in_filters, p_enc_ex_filters, p_key);
334
+ }
335
+
292
336
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) {
293
337
ERR_FAIL_COND_V_MSG (p_total < 1 , ERR_PARAMETER_RANGE_ERROR, " Must select at least one file to export." );
294
338
@@ -319,6 +363,14 @@ Error EditorExportPlatform::_save_zip_file(void *p_userdata, const String &p_pat
319
363
return OK;
320
364
}
321
365
366
+ Error EditorExportPlatform::_save_zip_patch_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) {
367
+ if (_check_hash (PackedData::get_singleton ()->get_file_hash (p_path), p_data)) {
368
+ return OK;
369
+ }
370
+
371
+ return _save_zip_file (p_userdata, p_path, p_data, p_file, p_total, p_enc_in_filters, p_enc_ex_filters, p_key);
372
+ }
373
+
322
374
Ref<ImageTexture> EditorExportPlatform::get_option_icon (int p_index) const {
323
375
Ref<Theme> theme = EditorNode::get_singleton ()->get_editor_theme ();
324
376
ERR_FAIL_COND_V (theme.is_null (), Ref<ImageTexture>());
@@ -1544,7 +1596,7 @@ void EditorExportPlatform::zip_folder_recursive(zipFile &p_zip, const String &p_
1544
1596
da->list_dir_end ();
1545
1597
}
1546
1598
1547
- Error EditorExportPlatform::save_pack (const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, Vector<SharedObject> *p_so_files, bool p_embed, int64_t *r_embedded_start, int64_t *r_embedded_size) {
1599
+ Error EditorExportPlatform::_save_pack (const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, EditorExportSaveFunction p_func , Vector<SharedObject> *p_so_files, bool p_embed, int64_t *r_embedded_start, int64_t *r_embedded_size) {
1548
1600
EditorProgress ep (" savepack" , TTR (" Packing" ), 102 , true );
1549
1601
1550
1602
// Create the temporary export directory if it doesn't exist.
@@ -1563,13 +1615,13 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
1563
1615
pd.f = ftmp;
1564
1616
pd.so_files = p_so_files;
1565
1617
1566
- Error err = export_project_files (p_preset, p_debug, _save_pack_file , &pd, _add_shared_object);
1618
+ Error err = export_project_files (p_preset, p_debug, p_func , &pd, _add_shared_object);
1567
1619
1568
1620
// Close temp file.
1569
1621
pd.f .unref ();
1570
1622
ftmp.unref ();
1571
1623
1572
- if (err != OK) {
1624
+ if (err != OK || pd. file_ofs . is_empty () ) {
1573
1625
DirAccess::remove_file_or_error (tmppath);
1574
1626
add_message (EXPORT_MESSAGE_ERROR, TTR (" Save PCK" ), TTR (" Failed to export project files." ));
1575
1627
return err;
@@ -1770,7 +1822,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
1770
1822
return OK;
1771
1823
}
1772
1824
1773
- Error EditorExportPlatform::save_zip (const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
1825
+ Error EditorExportPlatform::_save_zip (const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, EditorExportSaveFunction p_func ) {
1774
1826
EditorProgress ep (" savezip" , TTR (" Packing" ), 102 , true );
1775
1827
1776
1828
Ref<FileAccess> io_fa;
@@ -1781,7 +1833,7 @@ Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, bo
1781
1833
zd.ep = &ep;
1782
1834
zd.zip = zip;
1783
1835
1784
- Error err = export_project_files (p_preset, p_debug, _save_zip_file , &zd);
1836
+ Error err = export_project_files (p_preset, p_debug, p_func , &zd);
1785
1837
if (err != OK && err != ERR_SKIP) {
1786
1838
add_message (EXPORT_MESSAGE_ERROR, TTR (" Save ZIP" ), TTR (" Failed to export project files." ));
1787
1839
}
@@ -1796,11 +1848,33 @@ Error EditorExportPlatform::export_pack(const Ref<EditorExportPreset> &p_preset,
1796
1848
return save_pack (p_preset, p_debug, p_path);
1797
1849
}
1798
1850
1851
+ Error EditorExportPlatform::export_patch (const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
1852
+ ExportNotifier notifier (*this , p_preset, p_debug, p_path, p_flags);
1853
+ Error err = _load_patches (p_preset->get_enabled_patches ());
1854
+ if (err != OK) {
1855
+ return err;
1856
+ }
1857
+ err = _save_pack (p_preset, p_debug, p_path, _save_patch_file);
1858
+ PackedData::get_singleton ()->clear ();
1859
+ return err;
1860
+ }
1861
+
1799
1862
Error EditorExportPlatform::export_zip (const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
1800
1863
ExportNotifier notifier (*this , p_preset, p_debug, p_path, p_flags);
1801
1864
return save_zip (p_preset, p_debug, p_path);
1802
1865
}
1803
1866
1867
+ Error EditorExportPlatform::export_zip_patch (const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
1868
+ ExportNotifier notifier (*this , p_preset, p_debug, p_path, p_flags);
1869
+ Error err = _load_patches (p_preset->get_enabled_patches ());
1870
+ if (err != OK) {
1871
+ return err;
1872
+ }
1873
+ err = _save_zip (p_preset, p_debug, p_path, _save_zip_patch_file);
1874
+ PackedData::get_singleton ()->clear ();
1875
+ return err;
1876
+ }
1877
+
1804
1878
void EditorExportPlatform::gen_export_flags (Vector<String> &r_flags, int p_flags) {
1805
1879
String host = EDITOR_GET (" network/debug/remote_host" );
1806
1880
int remote_port = (int )EDITOR_GET (" network/debug/remote_port" );
0 commit comments