Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete unused compression formats from .import files when exporting #74684

Merged
merged 1 commit into from
Mar 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions editor/export/editor_export_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,13 +1026,13 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
String type = ResourceLoader::get_resource_type(path);

if (FileAccess::exists(path + ".import")) {
// Before doing this, try to see if it can be customized
// Before doing this, try to see if it can be customized.

String export_path = _export_customize(path, customize_resources_plugins, customize_scenes_plugins, export_cache, export_base_path, false);

if (export_path != path) {
// It was actually customized..
// Since the original file is likely not recognized, just use the import system
// It was actually customized.
// Since the original file is likely not recognized, just use the import system.

Ref<ConfigFile> config;
config.instantiate();
Expand All @@ -1043,18 +1043,18 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
}
config->set_value("remap", "type", ResourceLoader::get_resource_type(export_path));

// Erase all PAths
// Erase all Paths.
List<String> keys;
config->get_section_keys("remap", &keys);
for (const String &K : keys) {
if (E.begins_with("path")) {
if (K.begins_with("path")) {
config->erase_section_key("remap", K);
}
}
// Set actual converted path.
config->set_value("remap", "path", export_path);

// erase useless sections
// Erase useless sections.
config->erase_section("deps");
config->erase_section("params");

Expand All @@ -1075,7 +1075,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
return err;
}
} else {
// file is imported and not customized, replace by what it imports
// File is imported and not customized, replace by what it imports.
Ref<ConfigFile> config;
config.instantiate();
err = config->load(path + ".import");
Expand All @@ -1087,7 +1087,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
String importer_type = config->get_value("remap", "importer");

if (importer_type == "keep") {
//just keep file as-is
// Just keep file as-is.
Vector<uint8_t> array = FileAccess::get_file_as_bytes(path);
err = p_func(p_udata, path, array, idx, total, enc_in_filters, enc_ex_filters, key);

Expand Down Expand Up @@ -1130,6 +1130,9 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
String remapped_path = config->get_value("remap", remap);
Vector<uint8_t> array = FileAccess::get_file_as_bytes(remapped_path);
err = p_func(p_udata, remapped_path, array, idx, total, enc_in_filters, enc_ex_filters, key);
} else {
// Remove paths if feature not enabled.
config->erase_section_key("remap", remap);
}
}
}
Expand All @@ -1138,17 +1141,25 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
return err;
}

//also save the .import file
Vector<uint8_t> array = FileAccess::get_file_as_bytes(path + ".import");
err = p_func(p_udata, path + ".import", array, idx, total, enc_in_filters, enc_ex_filters, key);
// Erase useless sections.
config->erase_section("deps");
config->erase_section("params");

String import_text = config->encode_to_text();
CharString cs = import_text.utf8();
Vector<uint8_t> sarr;
sarr.resize(cs.size());
memcpy(sarr.ptrw(), cs.ptr(), sarr.size());

err = p_func(p_udata, path + ".import", sarr, idx, total, enc_in_filters, enc_ex_filters, key);

if (err != OK) {
return err;
}
}

} else {
// Customize
// Customize.

bool do_export = true;
for (int i = 0; i < export_plugins.size(); i++) {
Expand Down