Skip to content

Commit 2912cb9

Browse files
committed
Merge pull request #97118 from mihe/patch-exports
Add ability to export patch packs
2 parents 991e6c9 + d3be030 commit 2912cb9

18 files changed

+619
-20
lines changed

core/io/file_access_pack.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ void PackedData::add_pack_source(PackSource *p_source) {
102102
}
103103
}
104104

105+
uint8_t *PackedData::get_file_hash(const String &p_path) {
106+
PathMD5 pmd5(p_path.md5_buffer());
107+
HashMap<PathMD5, PackedFile, PathMD5>::Iterator E = files.find(pmd5);
108+
if (!E || E->value.offset == 0) {
109+
return nullptr;
110+
}
111+
112+
return E->value.md5;
113+
}
114+
115+
void PackedData::clear() {
116+
files.clear();
117+
_free_packed_dirs(root);
118+
root = memnew(PackedDir);
119+
}
120+
105121
PackedData *PackedData::singleton = nullptr;
106122

107123
PackedData::PackedData() {

core/io/file_access_pack.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,16 @@ class PackedData {
111111
public:
112112
void add_pack_source(PackSource *p_source);
113113
void add_path(const String &p_pkg_path, const String &p_path, uint64_t p_ofs, uint64_t p_size, const uint8_t *p_md5, PackSource *p_src, bool p_replace_files, bool p_encrypted = false); // for PackSource
114+
uint8_t *get_file_hash(const String &p_path);
114115

115116
void set_disabled(bool p_disabled) { disabled = p_disabled; }
116117
_FORCE_INLINE_ bool is_disabled() const { return disabled; }
117118

118119
static PackedData *get_singleton() { return singleton; }
119120
Error add_pack(const String &p_path, bool p_replace_files, uint64_t p_offset);
120121

122+
void clear();
123+
121124
_FORCE_INLINE_ Ref<FileAccess> try_open_path(const String &p_path);
122125
_FORCE_INLINE_ bool has_path(const String &p_path);
123126

doc/classes/EditorExportPlatform.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@
4242
Creates a PCK archive at [param path] for the specified [param preset].
4343
</description>
4444
</method>
45+
<method name="export_pack_patch">
46+
<return type="int" enum="Error" />
47+
<param index="0" name="preset" type="EditorExportPreset" />
48+
<param index="1" name="debug" type="bool" />
49+
<param index="2" name="path" type="String" />
50+
<param index="3" name="patches" type="PackedStringArray" default="PackedStringArray()" />
51+
<param index="4" name="flags" type="int" enum="EditorExportPlatform.DebugFlags" is_bitfield="true" default="0" />
52+
<description>
53+
Creates a patch PCK archive at [param path] for the specified [param preset], containing only the files that have changed since the last patch.
54+
[b]Note:[/b] [param patches] is an optional override of the set of patches defined in the export preset. When empty the patches defined in the export preset will be used instead.
55+
</description>
56+
</method>
4557
<method name="export_project">
4658
<return type="int" enum="Error" />
4759
<param index="0" name="preset" type="EditorExportPreset" />
@@ -75,6 +87,18 @@
7587
Create a ZIP archive at [param path] for the specified [param preset].
7688
</description>
7789
</method>
90+
<method name="export_zip_patch">
91+
<return type="int" enum="Error" />
92+
<param index="0" name="preset" type="EditorExportPreset" />
93+
<param index="1" name="debug" type="bool" />
94+
<param index="2" name="path" type="String" />
95+
<param index="3" name="patches" type="PackedStringArray" default="PackedStringArray()" />
96+
<param index="4" name="flags" type="int" enum="EditorExportPlatform.DebugFlags" is_bitfield="true" default="0" />
97+
<description>
98+
Create a patch ZIP archive at [param path] for the specified [param preset], containing only the files that have changed since the last patch.
99+
[b]Note:[/b] [param patches] is an optional override of the set of patches defined in the export preset. When empty the patches defined in the export preset will be used instead.
100+
</description>
101+
</method>
78102
<method name="find_export_template" qualifiers="const">
79103
<return type="Dictionary" />
80104
<param index="0" name="template_file_name" type="String" />
@@ -151,6 +175,15 @@
151175
If [param embed] is [code]true[/code], PCK content is appended to the end of [param path] file and return [Dictionary] additionally include following keys: [code]embedded_start: int[/code] (embedded PCK offset) and [code]embedded_size: int[/code] (embedded PCK size).
152176
</description>
153177
</method>
178+
<method name="save_pack_patch">
179+
<return type="Dictionary" />
180+
<param index="0" name="preset" type="EditorExportPreset" />
181+
<param index="1" name="debug" type="bool" />
182+
<param index="2" name="path" type="String" />
183+
<description>
184+
Saves patch PCK archive and returns [Dictionary] with the following keys: [code]result: Error[/code], [code]so_files: Array[/code] (array of the shared/static objects which contains dictionaries with the following keys: [code]path: String[/code], [code]tags: PackedStringArray[/code], and [code]target_folder: String[/code]).
185+
</description>
186+
</method>
154187
<method name="save_zip">
155188
<return type="Dictionary" />
156189
<param index="0" name="preset" type="EditorExportPreset" />
@@ -160,6 +193,15 @@
160193
Saves ZIP archive and returns [Dictionary] with the following keys: [code]result: Error[/code], [code]so_files: Array[/code] (array of the shared/static objects which contains dictionaries with the following keys: [code]path: String[/code], [code]tags: PackedStringArray[/code], and [code]target_folder: String[/code]).
161194
</description>
162195
</method>
196+
<method name="save_zip_patch">
197+
<return type="Dictionary" />
198+
<param index="0" name="preset" type="EditorExportPreset" />
199+
<param index="1" name="debug" type="bool" />
200+
<param index="2" name="path" type="String" />
201+
<description>
202+
Saves patch ZIP archive and returns [Dictionary] with the following keys: [code]result: Error[/code], [code]so_files: Array[/code] (array of the shared/static objects which contains dictionaries with the following keys: [code]path: String[/code], [code]tags: PackedStringArray[/code], and [code]target_folder: String[/code]).
203+
</description>
204+
</method>
163205
<method name="ssh_push_to_remote" qualifiers="const">
164206
<return type="int" enum="Error" />
165207
<param index="0" name="host" type="String" />

doc/classes/EditorExportPlatformExtension.xml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,21 @@
3636
<description>
3737
[b]Optional.[/b]
3838
Creates a PCK archive at [param path] for the specified [param preset].
39-
This method is called when "Export PCK/ZIP" button is pressed in the export dialog, and PCK is selected as a file type.
39+
This method is called when "Export PCK/ZIP" button is pressed in the export dialog, with "Export as Patch" disabled, and PCK is selected as a file type.
40+
</description>
41+
</method>
42+
<method name="_export_pack_patch" qualifiers="virtual">
43+
<return type="int" enum="Error" />
44+
<param index="0" name="preset" type="EditorExportPreset" />
45+
<param index="1" name="debug" type="bool" />
46+
<param index="2" name="path" type="String" />
47+
<param index="3" name="patches" type="PackedStringArray" />
48+
<param index="4" name="flags" type="int" enum="EditorExportPlatform.DebugFlags" is_bitfield="true" />
49+
<description>
50+
[b]Optional.[/b]
51+
Creates a patch PCK archive at [param path] for the specified [param preset], containing only the files that have changed since the last patch.
52+
This method is called when "Export PCK/ZIP" button is pressed in the export dialog, with "Export as Patch" enabled, and PCK is selected as a file type.
53+
[b]Note:[/b] The patches provided in [param patches] have already been loaded when this method is called and are merely provided as context. When empty the patches defined in the export preset have been loaded instead.
4054
</description>
4155
</method>
4256
<method name="_export_project" qualifiers="virtual">
@@ -61,7 +75,21 @@
6175
<description>
6276
[b]Optional.[/b]
6377
Create a ZIP archive at [param path] for the specified [param preset].
64-
This method is called when "Export PCK/ZIP" button is pressed in the export dialog, and ZIP is selected as a file type.
78+
This method is called when "Export PCK/ZIP" button is pressed in the export dialog, with "Export as Patch" disabled, and ZIP is selected as a file type.
79+
</description>
80+
</method>
81+
<method name="_export_zip_patch" qualifiers="virtual">
82+
<return type="int" enum="Error" />
83+
<param index="0" name="preset" type="EditorExportPreset" />
84+
<param index="1" name="debug" type="bool" />
85+
<param index="2" name="path" type="String" />
86+
<param index="3" name="patches" type="PackedStringArray" />
87+
<param index="4" name="flags" type="int" enum="EditorExportPlatform.DebugFlags" is_bitfield="true" />
88+
<description>
89+
[b]Optional.[/b]
90+
Create a ZIP archive at [param path] for the specified [param preset], containing only the files that have changed since the last patch.
91+
This method is called when "Export PCK/ZIP" button is pressed in the export dialog, with "Export as Patch" enabled, and ZIP is selected as a file type.
92+
[b]Note:[/b] The patches provided in [param patches] have already been loaded when this method is called and are merely provided as context. When empty the patches defined in the export preset have been loaded instead.
6593
</description>
6694
</method>
6795
<method name="_get_binary_extensions" qualifiers="virtual const">

doc/classes/EditorExportPreset.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@
109109
Returns export option value or value of environment variable if it is set.
110110
</description>
111111
</method>
112+
<method name="get_patches" qualifiers="const">
113+
<return type="PackedStringArray" />
114+
<description>
115+
Returns the list of packs on which to base a patch export on.
116+
</description>
117+
</method>
112118
<method name="get_preset_name" qualifiers="const">
113119
<return type="String" />
114120
<description>

editor/editor_node.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,9 +1007,17 @@ void EditorNode::_fs_changed() {
10071007
export_preset->update_value_overrides();
10081008
if (export_defer.pack_only) { // Only export .pck or .zip data pack.
10091009
if (export_path.ends_with(".zip")) {
1010-
err = platform->export_zip(export_preset, export_defer.debug, export_path);
1010+
if (export_defer.patch) {
1011+
err = platform->export_zip_patch(export_preset, export_defer.debug, export_path, export_defer.patches);
1012+
} else {
1013+
err = platform->export_zip(export_preset, export_defer.debug, export_path);
1014+
}
10111015
} else if (export_path.ends_with(".pck")) {
1012-
err = platform->export_pack(export_preset, export_defer.debug, export_path);
1016+
if (export_defer.patch) {
1017+
err = platform->export_pack_patch(export_preset, export_defer.debug, export_path, export_defer.patches);
1018+
} else {
1019+
err = platform->export_pack(export_preset, export_defer.debug, export_path);
1020+
}
10131021
} else {
10141022
ERR_PRINT(vformat("Export path \"%s\" doesn't end with a supported extension.", export_path));
10151023
err = FAILED;
@@ -5149,12 +5157,14 @@ void EditorNode::_begin_first_scan() {
51495157
requested_first_scan = true;
51505158
}
51515159

5152-
Error EditorNode::export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only, bool p_android_build_template) {
5160+
Error EditorNode::export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only, bool p_android_build_template, bool p_patch, const Vector<String> &p_patches) {
51535161
export_defer.preset = p_preset;
51545162
export_defer.path = p_path;
51555163
export_defer.debug = p_debug;
51565164
export_defer.pack_only = p_pack_only;
51575165
export_defer.android_build_template = p_android_build_template;
5166+
export_defer.patch = p_patch;
5167+
export_defer.patches = p_patches;
51585168
cmdline_export_mode = true;
51595169
return OK;
51605170
}

editor/editor_node.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ class EditorNode : public Node {
246246
bool debug = false;
247247
bool pack_only = false;
248248
bool android_build_template = false;
249+
bool patch = false;
250+
Vector<String> patches;
249251
} export_defer;
250252

251253
static EditorNode *singleton;
@@ -880,7 +882,7 @@ class EditorNode : public Node {
880882

881883
void _copy_warning(const String &p_str);
882884

883-
Error export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only, bool p_android_build_template);
885+
Error export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only, bool p_android_build_template, bool p_patch, const Vector<String> &p_patches);
884886
bool is_project_exporting() const;
885887

886888
Control *get_gui_base() { return gui_base; }

editor/export/editor_export.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ void EditorExport::_save() {
8383
config->set_value(section, "include_filter", preset->get_include_filter());
8484
config->set_value(section, "exclude_filter", preset->get_exclude_filter());
8585
config->set_value(section, "export_path", preset->get_export_path());
86+
config->set_value(section, "patches", preset->get_patches());
87+
8688
config->set_value(section, "encryption_include_filters", preset->get_enc_in_filter());
8789
config->set_value(section, "encryption_exclude_filters", preset->get_enc_ex_filter());
8890
config->set_value(section, "encrypt_pck", preset->get_enc_pck());
@@ -303,6 +305,7 @@ void EditorExport::load_config() {
303305
preset->set_exclude_filter(config->get_value(section, "exclude_filter"));
304306
preset->set_export_path(config->get_value(section, "export_path", ""));
305307
preset->set_script_export_mode(config->get_value(section, "script_export_mode", EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS_COMPRESSED));
308+
preset->set_patches(config->get_value(section, "patches", Vector<String>()));
306309

307310
if (config->has_section_key(section, "encrypt_pck")) {
308311
preset->set_enc_pck(config->get_value(section, "encrypt_pck"));

0 commit comments

Comments
 (0)