mirror of
https://github.com/godotengine/godot.git
synced 2024-11-10 22:23:07 +00:00
Fix crash when trying to export zero files.
Fixes crash that happened while exporting if zero files were selected
and adds more error handling to EditorExportPlatform class.
(cherry picked from commit 15656d4182
)
This commit is contained in:
parent
82b900bdda
commit
0def17e80a
@ -299,6 +299,7 @@ void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags)
|
||||
}
|
||||
|
||||
Error EditorExportPlatform::_save_pack_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total) {
|
||||
ERR_FAIL_COND_V_MSG(p_total < 1, ERR_PARAMETER_RANGE_ERROR, "Must select at least one file to export.");
|
||||
|
||||
PackData *pd = (PackData *)p_userdata;
|
||||
|
||||
@ -332,6 +333,7 @@ Error EditorExportPlatform::_save_pack_file(void *p_userdata, const String &p_pa
|
||||
}
|
||||
|
||||
Error EditorExportPlatform::_save_zip_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total) {
|
||||
ERR_FAIL_COND_V_MSG(p_total < 1, ERR_PARAMETER_RANGE_ERROR, "Must select at least one file to export.");
|
||||
|
||||
String path = p_path.replace_first("res://", "");
|
||||
|
||||
@ -740,18 +742,26 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
|
||||
// Ignore import files, since these are automatically added to the jar later with the resources
|
||||
_edit_filter_list(paths, String("*.import"), true);
|
||||
|
||||
Error err = OK;
|
||||
Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
|
||||
|
||||
for (int i = 0; i < export_plugins.size(); i++) {
|
||||
|
||||
export_plugins.write[i]->set_export_preset(p_preset);
|
||||
|
||||
if (p_so_func) {
|
||||
for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
|
||||
p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
|
||||
err = p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
|
||||
p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, 0, paths.size());
|
||||
err = p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, 0, paths.size());
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
export_plugins.write[i]->_clear();
|
||||
@ -774,7 +784,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
|
||||
//file is imported, replace by what it imports
|
||||
Ref<ConfigFile> config;
|
||||
config.instance();
|
||||
Error err = config->load(path + ".import");
|
||||
err = config->load(path + ".import");
|
||||
if (err != OK) {
|
||||
ERR_PRINTS("Could not parse: '" + path + "', not exported.");
|
||||
continue;
|
||||
@ -841,12 +851,18 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
|
||||
}
|
||||
if (p_so_func) {
|
||||
for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
|
||||
p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
|
||||
err = p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
|
||||
p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, idx, total);
|
||||
err = p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, idx, total);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
if (export_plugins[i]->extra_files[j].remap) {
|
||||
do_export = false; //if remap, do not
|
||||
path_remaps.push_back(path);
|
||||
@ -865,7 +881,10 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
|
||||
//just store it as it comes
|
||||
if (do_export) {
|
||||
Vector<uint8_t> array = FileAccess::get_file_as_array(path);
|
||||
p_func(p_udata, path, array, idx, total);
|
||||
err = p_func(p_udata, path, array, idx, total);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -902,7 +921,10 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
|
||||
new_file.write[j] = utf8[j];
|
||||
}
|
||||
|
||||
p_func(p_udata, from + ".remap", new_file, idx, total);
|
||||
err = p_func(p_udata, from + ".remap", new_file, idx, total);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//old remap mode, will still work, but it's unused because it's not multiple pck export friendly
|
||||
@ -915,11 +937,17 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
|
||||
String splash = ProjectSettings::get_singleton()->get("application/boot_splash/image");
|
||||
if (icon != String() && FileAccess::exists(icon)) {
|
||||
Vector<uint8_t> array = FileAccess::get_file_as_array(icon);
|
||||
p_func(p_udata, icon, array, idx, total);
|
||||
err = p_func(p_udata, icon, array, idx, total);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
if (splash != String() && FileAccess::exists(splash) && icon != splash) {
|
||||
Vector<uint8_t> array = FileAccess::get_file_as_array(splash);
|
||||
p_func(p_udata, splash, array, idx, total);
|
||||
err = p_func(p_udata, splash, array, idx, total);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
String config_file = "project.binary";
|
||||
@ -928,9 +956,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
|
||||
Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb);
|
||||
DirAccess::remove_file_or_error(engine_cfb);
|
||||
|
||||
p_func(p_udata, "res://" + config_file, data, idx, total);
|
||||
|
||||
return OK;
|
||||
return p_func(p_udata, "res://" + config_file, data, idx, total);
|
||||
}
|
||||
|
||||
Error EditorExportPlatform::_add_shared_object(void *p_userdata, const SharedObject &p_so) {
|
||||
@ -965,6 +991,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c
|
||||
|
||||
if (err != OK) {
|
||||
DirAccess::remove_file_or_error(tmppath);
|
||||
ERR_PRINT("Failed to export project files");
|
||||
return err;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user