Skip to content

Commit

Permalink
Add ability to export patch packs
Browse files Browse the repository at this point in the history
Co-authored-by: Poq Xert <poqxert@poqxert.ru>
  • Loading branch information
mihe and PoqXert committed Sep 25, 2024
1 parent 4254946 commit d3be030
Show file tree
Hide file tree
Showing 18 changed files with 619 additions and 20 deletions.
16 changes: 16 additions & 0 deletions core/io/file_access_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ void PackedData::add_pack_source(PackSource *p_source) {
}
}

uint8_t *PackedData::get_file_hash(const String &p_path) {
PathMD5 pmd5(p_path.md5_buffer());
HashMap<PathMD5, PackedFile, PathMD5>::Iterator E = files.find(pmd5);
if (!E || E->value.offset == 0) {
return nullptr;
}

return E->value.md5;
}

void PackedData::clear() {
files.clear();
_free_packed_dirs(root);
root = memnew(PackedDir);
}

PackedData *PackedData::singleton = nullptr;

PackedData::PackedData() {
Expand Down
3 changes: 3 additions & 0 deletions core/io/file_access_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,16 @@ class PackedData {
public:
void add_pack_source(PackSource *p_source);
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
uint8_t *get_file_hash(const String &p_path);

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

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

void clear();

_FORCE_INLINE_ Ref<FileAccess> try_open_path(const String &p_path);
_FORCE_INLINE_ bool has_path(const String &p_path);

Expand Down
42 changes: 42 additions & 0 deletions doc/classes/EditorExportPlatform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
Creates a PCK archive at [param path] for the specified [param preset].
</description>
</method>
<method name="export_pack_patch">
<return type="int" enum="Error" />
<param index="0" name="preset" type="EditorExportPreset" />
<param index="1" name="debug" type="bool" />
<param index="2" name="path" type="String" />
<param index="3" name="patches" type="PackedStringArray" default="PackedStringArray()" />
<param index="4" name="flags" type="int" enum="EditorExportPlatform.DebugFlags" is_bitfield="true" default="0" />
<description>
Creates a patch PCK archive at [param path] for the specified [param preset], containing only the files that have changed since the last patch.
[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.
</description>
</method>
<method name="export_project">
<return type="int" enum="Error" />
<param index="0" name="preset" type="EditorExportPreset" />
Expand Down Expand Up @@ -75,6 +87,18 @@
Create a ZIP archive at [param path] for the specified [param preset].
</description>
</method>
<method name="export_zip_patch">
<return type="int" enum="Error" />
<param index="0" name="preset" type="EditorExportPreset" />
<param index="1" name="debug" type="bool" />
<param index="2" name="path" type="String" />
<param index="3" name="patches" type="PackedStringArray" default="PackedStringArray()" />
<param index="4" name="flags" type="int" enum="EditorExportPlatform.DebugFlags" is_bitfield="true" default="0" />
<description>
Create a patch ZIP archive at [param path] for the specified [param preset], containing only the files that have changed since the last patch.
[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.
</description>
</method>
<method name="find_export_template" qualifiers="const">
<return type="Dictionary" />
<param index="0" name="template_file_name" type="String" />
Expand Down Expand Up @@ -151,6 +175,15 @@
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).
</description>
</method>
<method name="save_pack_patch">
<return type="Dictionary" />
<param index="0" name="preset" type="EditorExportPreset" />
<param index="1" name="debug" type="bool" />
<param index="2" name="path" type="String" />
<description>
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]).
</description>
</method>
<method name="save_zip">
<return type="Dictionary" />
<param index="0" name="preset" type="EditorExportPreset" />
Expand All @@ -160,6 +193,15 @@
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]).
</description>
</method>
<method name="save_zip_patch">
<return type="Dictionary" />
<param index="0" name="preset" type="EditorExportPreset" />
<param index="1" name="debug" type="bool" />
<param index="2" name="path" type="String" />
<description>
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]).
</description>
</method>
<method name="ssh_push_to_remote" qualifiers="const">
<return type="int" enum="Error" />
<param index="0" name="host" type="String" />
Expand Down
32 changes: 30 additions & 2 deletions doc/classes/EditorExportPlatformExtension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@
<description>
[b]Optional.[/b]
Creates a PCK archive at [param path] for the specified [param preset].
This method is called when "Export PCK/ZIP" button is pressed in the export dialog, and PCK is selected as a file type.
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.
</description>
</method>
<method name="_export_pack_patch" qualifiers="virtual">
<return type="int" enum="Error" />
<param index="0" name="preset" type="EditorExportPreset" />
<param index="1" name="debug" type="bool" />
<param index="2" name="path" type="String" />
<param index="3" name="patches" type="PackedStringArray" />
<param index="4" name="flags" type="int" enum="EditorExportPlatform.DebugFlags" is_bitfield="true" />
<description>
[b]Optional.[/b]
Creates a patch PCK archive at [param path] for the specified [param preset], containing only the files that have changed since the last patch.
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.
[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.
</description>
</method>
<method name="_export_project" qualifiers="virtual">
Expand All @@ -61,7 +75,21 @@
<description>
[b]Optional.[/b]
Create a ZIP archive at [param path] for the specified [param preset].
This method is called when "Export PCK/ZIP" button is pressed in the export dialog, and ZIP is selected as a file type.
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.
</description>
</method>
<method name="_export_zip_patch" qualifiers="virtual">
<return type="int" enum="Error" />
<param index="0" name="preset" type="EditorExportPreset" />
<param index="1" name="debug" type="bool" />
<param index="2" name="path" type="String" />
<param index="3" name="patches" type="PackedStringArray" />
<param index="4" name="flags" type="int" enum="EditorExportPlatform.DebugFlags" is_bitfield="true" />
<description>
[b]Optional.[/b]
Create a ZIP archive at [param path] for the specified [param preset], containing only the files that have changed since the last patch.
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.
[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.
</description>
</method>
<method name="_get_binary_extensions" qualifiers="virtual const">
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/EditorExportPreset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@
Returns export option value or value of environment variable if it is set.
</description>
</method>
<method name="get_patches" qualifiers="const">
<return type="PackedStringArray" />
<description>
Returns the list of packs on which to base a patch export on.
</description>
</method>
<method name="get_preset_name" qualifiers="const">
<return type="String" />
<description>
Expand Down
16 changes: 13 additions & 3 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,9 +1007,17 @@ void EditorNode::_fs_changed() {
export_preset->update_value_overrides();
if (export_defer.pack_only) { // Only export .pck or .zip data pack.
if (export_path.ends_with(".zip")) {
err = platform->export_zip(export_preset, export_defer.debug, export_path);
if (export_defer.patch) {
err = platform->export_zip_patch(export_preset, export_defer.debug, export_path, export_defer.patches);
} else {
err = platform->export_zip(export_preset, export_defer.debug, export_path);
}
} else if (export_path.ends_with(".pck")) {
err = platform->export_pack(export_preset, export_defer.debug, export_path);
if (export_defer.patch) {
err = platform->export_pack_patch(export_preset, export_defer.debug, export_path, export_defer.patches);
} else {
err = platform->export_pack(export_preset, export_defer.debug, export_path);
}
} else {
ERR_PRINT(vformat("Export path \"%s\" doesn't end with a supported extension.", export_path));
err = FAILED;
Expand Down Expand Up @@ -5147,12 +5155,14 @@ void EditorNode::_begin_first_scan() {
requested_first_scan = true;
}

Error EditorNode::export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only, bool p_android_build_template) {
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) {
export_defer.preset = p_preset;
export_defer.path = p_path;
export_defer.debug = p_debug;
export_defer.pack_only = p_pack_only;
export_defer.android_build_template = p_android_build_template;
export_defer.patch = p_patch;
export_defer.patches = p_patches;
cmdline_export_mode = true;
return OK;
}
Expand Down
4 changes: 3 additions & 1 deletion editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ class EditorNode : public Node {
bool debug = false;
bool pack_only = false;
bool android_build_template = false;
bool patch = false;
Vector<String> patches;
} export_defer;

static EditorNode *singleton;
Expand Down Expand Up @@ -879,7 +881,7 @@ class EditorNode : public Node {

void _copy_warning(const String &p_str);

Error export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only, bool p_android_build_template);
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);
bool is_project_exporting() const;

Control *get_gui_base() { return gui_base; }
Expand Down
3 changes: 3 additions & 0 deletions editor/export/editor_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ void EditorExport::_save() {
config->set_value(section, "include_filter", preset->get_include_filter());
config->set_value(section, "exclude_filter", preset->get_exclude_filter());
config->set_value(section, "export_path", preset->get_export_path());
config->set_value(section, "patches", preset->get_patches());

config->set_value(section, "encryption_include_filters", preset->get_enc_in_filter());
config->set_value(section, "encryption_exclude_filters", preset->get_enc_ex_filter());
config->set_value(section, "encrypt_pck", preset->get_enc_pck());
Expand Down Expand Up @@ -303,6 +305,7 @@ void EditorExport::load_config() {
preset->set_exclude_filter(config->get_value(section, "exclude_filter"));
preset->set_export_path(config->get_value(section, "export_path", ""));
preset->set_script_export_mode(config->get_value(section, "script_export_mode", EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS_COMPRESSED));
preset->set_patches(config->get_value(section, "patches", Vector<String>()));

if (config->has_section_key(section, "encrypt_pck")) {
preset->set_enc_pck(config->get_value(section, "encrypt_pck"));
Expand Down
Loading

0 comments on commit d3be030

Please sign in to comment.