2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2017-09-01 14:07:55 +00:00
|
|
|
/* editor_export.cpp */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2022-01-03 20:27:34 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2017-02-20 02:19:30 +00:00
|
|
|
#include "editor_export.h"
|
2017-04-28 16:29:15 +00:00
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/config/project_settings.h"
|
2019-07-11 13:21:47 +00:00
|
|
|
#include "core/crypto/crypto_core.h"
|
2021-08-20 18:32:56 +00:00
|
|
|
#include "core/extension/native_extension.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/io/config_file.h"
|
2021-06-11 12:51:48 +00:00
|
|
|
#include "core/io/dir_access.h"
|
|
|
|
#include "core/io/file_access.h"
|
2020-04-28 17:51:29 +00:00
|
|
|
#include "core/io/file_access_encrypted.h"
|
2019-11-30 16:22:22 +00:00
|
|
|
#include "core/io/file_access_pack.h" // PACK_HEADER_MAGIC, PACK_FORMAT_VERSION
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/io/resource_loader.h"
|
|
|
|
#include "core/io/resource_saver.h"
|
|
|
|
#include "core/io/zip_io.h"
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/object/script_language.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/version.h"
|
2017-03-05 13:21:25 +00:00
|
|
|
#include "editor/editor_file_system.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "editor/editor_node.h"
|
2022-02-14 13:00:03 +00:00
|
|
|
#include "editor/editor_paths.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "editor/editor_settings.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "editor/plugins/script_editor_plugin.h"
|
2019-02-12 16:18:13 +00:00
|
|
|
#include "scene/resources/resource_format_text.h"
|
2017-04-28 16:29:15 +00:00
|
|
|
|
2017-02-21 03:05:15 +00:00
|
|
|
static int _get_pad(int p_alignment, int p_n) {
|
|
|
|
int rest = p_n % p_alignment;
|
|
|
|
int pad = 0;
|
|
|
|
if (rest > 0) {
|
|
|
|
pad = p_alignment - rest;
|
|
|
|
};
|
2017-02-13 01:51:16 +00:00
|
|
|
|
2017-02-21 03:05:15 +00:00
|
|
|
return pad;
|
2017-03-21 02:31:41 +00:00
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
|
|
|
#define PCK_PADDING 16
|
2017-02-13 01:51:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool EditorExportPreset::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
if (values.has(p_name)) {
|
|
|
|
values[p_name] = p_value;
|
2017-02-20 02:19:30 +00:00
|
|
|
EditorExport::singleton->save_presets();
|
2017-02-13 01:51:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool EditorExportPreset::_get(const StringName &p_name, Variant &r_ret) const {
|
2017-02-13 01:51:16 +00:00
|
|
|
if (values.has(p_name)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_ret = values[p_name];
|
2017-02-13 01:51:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-28 01:21:21 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPreset::_get_property_list(List<PropertyInfo> *p_list) const {
|
2021-07-16 03:45:57 +00:00
|
|
|
for (const PropertyInfo &E : properties) {
|
2021-11-14 17:02:38 +00:00
|
|
|
if (platform->get_export_option_visibility(E.name, values)) {
|
2021-07-16 03:45:57 +00:00
|
|
|
p_list->push_back(E);
|
2017-03-28 01:21:21 +00:00
|
|
|
}
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-21 03:05:15 +00:00
|
|
|
Ref<EditorExportPlatform> EditorExportPreset::get_platform() const {
|
2017-02-20 02:19:30 +00:00
|
|
|
return platform;
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 09:41:42 +00:00
|
|
|
void EditorExportPreset::update_files_to_export() {
|
|
|
|
Vector<String> to_remove;
|
|
|
|
for (Set<String>::Element *E = selected_files.front(); E; E = E->next()) {
|
|
|
|
if (!FileAccess::exists(E->get())) {
|
|
|
|
to_remove.push_back(E->get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < to_remove.size(); ++i) {
|
|
|
|
selected_files.erase(to_remove[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-20 02:19:30 +00:00
|
|
|
Vector<String> EditorExportPreset::get_files_to_export() const {
|
|
|
|
Vector<String> files;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Set<String>::Element *E = selected_files.front(); E; E = E->next()) {
|
2017-02-20 02:19:30 +00:00
|
|
|
files.push_back(E->get());
|
|
|
|
}
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPreset::set_name(const String &p_name) {
|
|
|
|
name = p_name;
|
2017-02-20 02:19:30 +00:00
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPreset::get_name() const {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPreset::set_runnable(bool p_enable) {
|
2017-03-05 15:44:50 +00:00
|
|
|
runnable = p_enable;
|
2017-02-20 02:19:30 +00:00
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorExportPreset::is_runnable() const {
|
|
|
|
return runnable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPreset::set_export_filter(ExportFilter p_filter) {
|
2017-03-05 15:44:50 +00:00
|
|
|
export_filter = p_filter;
|
2017-02-20 02:19:30 +00:00
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorExportPreset::ExportFilter EditorExportPreset::get_export_filter() const {
|
|
|
|
return export_filter;
|
|
|
|
}
|
2017-02-13 01:51:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPreset::set_include_filter(const String &p_include) {
|
|
|
|
include_filter = p_include;
|
2017-02-20 02:19:30 +00:00
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPreset::get_include_filter() const {
|
|
|
|
return include_filter;
|
|
|
|
}
|
|
|
|
|
2018-10-27 13:53:05 +00:00
|
|
|
void EditorExportPreset::set_export_path(const String &p_path) {
|
|
|
|
export_path = p_path;
|
2019-08-22 20:14:45 +00:00
|
|
|
/* NOTE(SonerSound): if there is a need to implement a PropertyHint that specifically indicates a relative path,
|
|
|
|
* this should be removed. */
|
2021-06-03 13:41:22 +00:00
|
|
|
if (export_path.is_absolute_path()) {
|
2019-08-22 20:14:45 +00:00
|
|
|
String res_path = OS::get_singleton()->get_resource_dir();
|
|
|
|
export_path = res_path.path_to_file(export_path);
|
|
|
|
}
|
2018-10-27 13:53:05 +00:00
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPreset::get_export_path() const {
|
|
|
|
return export_path;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPreset::set_exclude_filter(const String &p_exclude) {
|
|
|
|
exclude_filter = p_exclude;
|
2017-02-20 02:19:30 +00:00
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPreset::get_exclude_filter() const {
|
|
|
|
return exclude_filter;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPreset::add_export_file(const String &p_path) {
|
2017-02-20 02:19:30 +00:00
|
|
|
selected_files.insert(p_path);
|
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPreset::remove_export_file(const String &p_path) {
|
2017-02-20 02:19:30 +00:00
|
|
|
selected_files.erase(p_path);
|
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool EditorExportPreset::has_export_file(const String &p_path) {
|
2017-02-20 02:19:30 +00:00
|
|
|
return selected_files.has(p_path);
|
|
|
|
}
|
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
void EditorExportPreset::set_custom_features(const String &p_custom_features) {
|
|
|
|
custom_features = p_custom_features;
|
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPreset::get_custom_features() const {
|
|
|
|
return custom_features;
|
|
|
|
}
|
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
void EditorExportPreset::set_enc_in_filter(const String &p_filter) {
|
|
|
|
enc_in_filters = p_filter;
|
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPreset::get_enc_in_filter() const {
|
|
|
|
return enc_in_filters;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPreset::set_enc_ex_filter(const String &p_filter) {
|
|
|
|
enc_ex_filters = p_filter;
|
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPreset::get_enc_ex_filter() const {
|
|
|
|
return enc_ex_filters;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPreset::set_enc_pck(bool p_enabled) {
|
|
|
|
enc_pck = p_enabled;
|
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorExportPreset::get_enc_pck() const {
|
|
|
|
return enc_pck;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPreset::set_enc_directory(bool p_enabled) {
|
|
|
|
enc_directory = p_enabled;
|
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorExportPreset::get_enc_directory() const {
|
|
|
|
return enc_directory;
|
|
|
|
}
|
|
|
|
|
2018-12-23 18:28:29 +00:00
|
|
|
void EditorExportPreset::set_script_export_mode(int p_mode) {
|
|
|
|
script_mode = p_mode;
|
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
int EditorExportPreset::get_script_export_mode() const {
|
|
|
|
return script_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPreset::set_script_encryption_key(const String &p_key) {
|
|
|
|
script_key = p_key;
|
|
|
|
EditorExport::singleton->save_presets();
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPreset::get_script_encryption_key() const {
|
|
|
|
return script_key;
|
|
|
|
}
|
|
|
|
|
2017-02-13 01:51:16 +00:00
|
|
|
///////////////////////////////////
|
|
|
|
|
|
|
|
void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags) {
|
2017-05-09 11:57:07 +00:00
|
|
|
String host = EditorSettings::get_singleton()->get("network/debug/remote_host");
|
2017-06-10 14:28:18 +00:00
|
|
|
int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
|
2017-02-13 01:51:16 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
|
2017-03-05 15:44:50 +00:00
|
|
|
host = "localhost";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-02-13 01:51:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_flags & DEBUG_FLAG_DUMB_CLIENT) {
|
2017-02-13 01:51:16 +00:00
|
|
|
int port = EditorSettings::get_singleton()->get("filesystem/file_server/port");
|
|
|
|
String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password");
|
2017-08-19 14:45:03 +00:00
|
|
|
r_flags.push_back("--remote-fs");
|
2017-03-05 15:44:50 +00:00
|
|
|
r_flags.push_back(host + ":" + itos(port));
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!passwd.is_empty()) {
|
2017-08-19 14:45:03 +00:00
|
|
|
r_flags.push_back("--remote-fs-password");
|
2017-02-13 01:51:16 +00:00
|
|
|
r_flags.push_back(passwd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_flags & DEBUG_FLAG_REMOTE_DEBUG) {
|
2017-08-19 14:45:03 +00:00
|
|
|
r_flags.push_back("--remote-debug");
|
2017-02-13 01:51:16 +00:00
|
|
|
|
2020-03-16 08:37:43 +00:00
|
|
|
r_flags.push_back(get_debug_protocol() + host + ":" + String::num(remote_port));
|
2017-02-13 01:51:16 +00:00
|
|
|
|
|
|
|
List<String> breakpoints;
|
|
|
|
ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
|
|
|
|
|
|
|
|
if (breakpoints.size()) {
|
2017-08-19 14:45:03 +00:00
|
|
|
r_flags.push_back("--breakpoints");
|
2017-02-13 01:51:16 +00:00
|
|
|
String bpoints;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
|
|
|
|
bpoints += E->get().replace(" ", "%20");
|
2020-05-14 14:41:43 +00:00
|
|
|
if (E->next()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
bpoints += ",";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r_flags.push_back(bpoints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_flags & DEBUG_FLAG_VIEW_COLLISONS) {
|
2017-08-19 14:45:03 +00:00
|
|
|
r_flags.push_back("--debug-collisions");
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
|
2017-08-19 14:45:03 +00:00
|
|
|
r_flags.push_back("--debug-navigation");
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
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) {
|
2021-03-11 21:29:21 +00:00
|
|
|
ERR_FAIL_COND_V_MSG(p_total < 1, ERR_PARAMETER_RANGE_ERROR, "Must select at least one file to export.");
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
PackData *pd = (PackData *)p_userdata;
|
2017-02-21 03:05:15 +00:00
|
|
|
|
|
|
|
SavedData sd;
|
2017-03-05 15:44:50 +00:00
|
|
|
sd.path_utf8 = p_path.utf8();
|
2017-09-10 13:37:49 +00:00
|
|
|
sd.ofs = pd->f->get_position();
|
2017-02-21 03:05:15 +00:00
|
|
|
sd.size = p_data.size();
|
2020-04-28 17:51:29 +00:00
|
|
|
sd.encrypted = false;
|
|
|
|
|
|
|
|
for (int i = 0; i < p_enc_in_filters.size(); ++i) {
|
|
|
|
if (p_path.matchn(p_enc_in_filters[i]) || p_path.replace("res://", "").matchn(p_enc_in_filters[i])) {
|
|
|
|
sd.encrypted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < p_enc_ex_filters.size(); ++i) {
|
|
|
|
if (p_path.matchn(p_enc_ex_filters[i]) || p_path.replace("res://", "").matchn(p_enc_ex_filters[i])) {
|
|
|
|
sd.encrypted = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
FileAccessEncrypted *fae = nullptr;
|
|
|
|
FileAccess *ftmp = pd->f;
|
|
|
|
|
|
|
|
if (sd.encrypted) {
|
|
|
|
fae = memnew(FileAccessEncrypted);
|
|
|
|
ERR_FAIL_COND_V(!fae, ERR_SKIP);
|
|
|
|
|
|
|
|
Error err = fae->open_and_parse(ftmp, p_key, FileAccessEncrypted::MODE_WRITE_AES256, false);
|
|
|
|
ERR_FAIL_COND_V(err != OK, ERR_SKIP);
|
|
|
|
ftmp = fae;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store file content.
|
|
|
|
ftmp->store_buffer(p_data.ptr(), p_data.size());
|
|
|
|
|
|
|
|
if (fae) {
|
|
|
|
fae->release();
|
|
|
|
memdelete(fae);
|
|
|
|
}
|
|
|
|
|
|
|
|
int pad = _get_pad(PCK_PADDING, pd->f->get_position());
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < pad; i++) {
|
2020-04-28 17:51:29 +00:00
|
|
|
pd->f->store_8(Math::rand() % 256);
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
// Store MD5 of original file.
|
2017-02-21 03:05:15 +00:00
|
|
|
{
|
2019-07-02 01:06:52 +00:00
|
|
|
unsigned char hash[16];
|
|
|
|
CryptoCore::md5(p_data.ptr(), p_data.size(), hash);
|
2017-02-21 03:05:15 +00:00
|
|
|
sd.md5.resize(16);
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 16; i++) {
|
2019-07-02 01:06:52 +00:00
|
|
|
sd.md5.write[i] = hash[i];
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pd->file_ofs.push_back(sd);
|
|
|
|
|
2018-12-19 18:50:40 +00:00
|
|
|
if (pd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false)) {
|
|
|
|
return ERR_SKIP;
|
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2017-02-20 02:19:30 +00:00
|
|
|
return OK;
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
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) {
|
2021-03-11 21:29:21 +00:00
|
|
|
ERR_FAIL_COND_V_MSG(p_total < 1, ERR_PARAMETER_RANGE_ERROR, "Must select at least one file to export.");
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String path = p_path.replace_first("res://", "");
|
2017-02-13 01:51:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ZipData *zd = (ZipData *)p_userdata;
|
2017-02-13 01:51:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
zipFile zip = (zipFile)zd->zip;
|
2017-02-13 01:51:16 +00:00
|
|
|
|
|
|
|
zipOpenNewFileInZip(zip,
|
2017-03-05 15:44:50 +00:00
|
|
|
path.utf8().get_data(),
|
2020-04-01 23:20:12 +00:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-03-05 15:44:50 +00:00
|
|
|
0,
|
2020-04-01 23:20:12 +00:00
|
|
|
nullptr,
|
2017-03-05 15:44:50 +00:00
|
|
|
0,
|
2020-04-01 23:20:12 +00:00
|
|
|
nullptr,
|
2017-03-05 15:44:50 +00:00
|
|
|
Z_DEFLATED,
|
|
|
|
Z_DEFAULT_COMPRESSION);
|
|
|
|
|
|
|
|
zipWriteInFileInZip(zip, p_data.ptr(), p_data.size());
|
2017-02-13 01:51:16 +00:00
|
|
|
zipCloseFileInZip(zip);
|
|
|
|
|
2018-12-19 18:50:40 +00:00
|
|
|
if (zd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false)) {
|
|
|
|
return ERR_SKIP;
|
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2017-02-13 01:51:16 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2019-10-11 11:47:28 +00:00
|
|
|
Ref<ImageTexture> EditorExportPlatform::get_option_icon(int p_index) const {
|
|
|
|
Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
|
|
|
|
ERR_FAIL_COND_V(theme.is_null(), Ref<ImageTexture>());
|
2020-12-19 14:17:42 +00:00
|
|
|
if (EditorNode::get_singleton()->get_main_control()->is_layout_rtl()) {
|
2022-02-06 14:53:53 +00:00
|
|
|
return theme->get_icon(SNAME("PlayBackwards"), SNAME("EditorIcons"));
|
2020-09-03 11:22:16 +00:00
|
|
|
} else {
|
2022-02-06 14:53:53 +00:00
|
|
|
return theme->get_icon(SNAME("Play"), SNAME("EditorIcons"));
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
2019-10-11 11:47:28 +00:00
|
|
|
}
|
|
|
|
|
2017-04-21 23:15:42 +00:00
|
|
|
String EditorExportPlatform::find_export_template(String template_file_name, String *err) const {
|
Refactor version macros and fix related bugs
The previous logic with VERSION_MKSTRING was a bit unwieldy, so there were
several places hardcoding their own variant of the version string, potentially
with bugs (e.g. forgetting the patch number when defined).
The new logic defines:
- VERSION_BRANCH, the main 'major.minor' version (e.g. 3.1)
- VERSION_NUMBER, which can be 'major.minor' or 'major.minor.patch',
depending on whether the latter is defined (e.g. 3.1.4)
- VERSION_FULL_CONFIG, which contains the version status (e.g. stable)
and the module-specific suffix (e.g. mono)
- VERSION_FULL_BUILD, same as above but with build/reference name
(e.g. official, custom_build, mageia, etc.)
Note: Slight change here, as the previous format had the build name
*before* the module-specific suffix; now it's after
- VERSION_FULL_NAME, same as before, so VERSION_FULL_BUILD prefixed
with "Godot v" for readability
Bugs fixed thanks to that:
- Export templates version matching now properly takes VERSION_PATCH
into account by relying on VERSION_FULL_CONFIG.
- ClassDB hash no longer takes the build name into account, but limits
itself to VERSION_FULL_CONFIG (build name is cosmetic, not relevant
for the API hash).
- Docs XML no longer hardcode the VERSION_STATUS, this was annoying.
- Small cleanup in Windows .rc file thanks to new macros.
2018-02-23 18:48:49 +00:00
|
|
|
String current_version = VERSION_FULL_CONFIG;
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(current_version).plus_file(template_file_name);
|
2017-02-13 01:51:16 +00:00
|
|
|
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
if (FileAccess::exists(template_path)) {
|
|
|
|
return template_path;
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-21 23:15:42 +00:00
|
|
|
// Not found
|
|
|
|
if (err) {
|
2019-01-21 17:34:53 +00:00
|
|
|
*err += TTR("No export template found at the expected path:") + "\n" + template_path + "\n";
|
2017-04-21 23:15:42 +00:00
|
|
|
}
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
return String();
|
2017-04-21 23:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorExportPlatform::exists_export_template(String template_file_name, String *err) const {
|
|
|
|
return find_export_template(template_file_name, err) != "";
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
|
2017-02-20 02:19:30 +00:00
|
|
|
Ref<EditorExportPreset> EditorExportPlatform::create_preset() {
|
|
|
|
Ref<EditorExportPreset> preset;
|
2021-06-17 22:03:09 +00:00
|
|
|
preset.instantiate();
|
2017-03-05 15:44:50 +00:00
|
|
|
preset->platform = Ref<EditorExportPlatform>(this);
|
2017-02-20 02:19:30 +00:00
|
|
|
|
|
|
|
List<ExportOption> options;
|
|
|
|
get_export_options(&options);
|
|
|
|
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const ExportOption &E : options) {
|
2021-07-16 03:45:57 +00:00
|
|
|
preset->properties.push_back(E.option);
|
|
|
|
preset->values[E.option.name] = E.default_value;
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return preset;
|
|
|
|
}
|
2017-02-13 01:51:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPlatform::_export_find_resources(EditorFileSystemDirectory *p_dir, Set<String> &p_paths) {
|
|
|
|
for (int i = 0; i < p_dir->get_subdir_count(); i++) {
|
|
|
|
_export_find_resources(p_dir->get_subdir(i), p_paths);
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < p_dir->get_file_count(); i++) {
|
2021-09-23 21:09:15 +00:00
|
|
|
if (p_dir->get_file_type(i) == "TextFile") {
|
|
|
|
continue;
|
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
p_paths.insert(p_dir->get_file_path(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPlatform::_export_find_dependencies(const String &p_path, Set<String> &p_paths) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_paths.has(p_path)) {
|
2017-02-21 03:05:15 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
|
|
|
p_paths.insert(p_path);
|
|
|
|
|
|
|
|
EditorFileSystemDirectory *dir;
|
|
|
|
int file_idx;
|
2017-03-05 15:44:50 +00:00
|
|
|
dir = EditorFileSystem::get_singleton()->find_file(p_path, &file_idx);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!dir) {
|
2017-02-21 03:05:15 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
|
|
|
Vector<String> deps = dir->get_file_deps(file_idx);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < deps.size(); i++) {
|
|
|
|
_export_find_dependencies(deps[i], p_paths);
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-14 13:13:09 +00:00
|
|
|
void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<String> &p_filters, Set<String> &r_list, bool exclude) {
|
|
|
|
da->list_dir_begin();
|
|
|
|
String cur_dir = da->get_current_dir().replace("\\", "/");
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!cur_dir.ends_with("/")) {
|
2017-08-14 13:13:09 +00:00
|
|
|
cur_dir += "/";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-07-18 10:20:37 +00:00
|
|
|
String cur_dir_no_prefix = cur_dir.replace("res://", "");
|
2017-08-14 13:13:09 +00:00
|
|
|
|
|
|
|
Vector<String> dirs;
|
2021-11-30 14:19:26 +00:00
|
|
|
String f = da->get_next();
|
|
|
|
while (!f.is_empty()) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (da->current_is_dir()) {
|
2017-08-14 13:13:09 +00:00
|
|
|
dirs.push_back(f);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2017-08-14 13:13:09 +00:00
|
|
|
String fullpath = cur_dir + f;
|
2018-07-18 10:20:37 +00:00
|
|
|
// Test also against path without res:// so that filters like `file.txt` can work.
|
|
|
|
String fullpath_no_prefix = cur_dir_no_prefix + f;
|
2017-08-14 13:13:09 +00:00
|
|
|
for (int i = 0; i < p_filters.size(); ++i) {
|
2018-07-18 10:20:37 +00:00
|
|
|
if (fullpath.matchn(p_filters[i]) || fullpath_no_prefix.matchn(p_filters[i])) {
|
2017-08-14 13:13:09 +00:00
|
|
|
if (!exclude) {
|
|
|
|
r_list.insert(fullpath);
|
|
|
|
} else {
|
|
|
|
r_list.erase(fullpath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-30 14:19:26 +00:00
|
|
|
f = da->get_next();
|
2017-08-14 13:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
da->list_dir_end();
|
|
|
|
|
|
|
|
for (int i = 0; i < dirs.size(); ++i) {
|
|
|
|
String dir = dirs[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
if (dir.begins_with(".")) {
|
2017-08-14 13:13:09 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2021-02-22 05:34:27 +00:00
|
|
|
|
|
|
|
if (EditorFileSystem::_should_skip_directory(cur_dir + dir)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-08-14 13:13:09 +00:00
|
|
|
da->change_dir(dir);
|
|
|
|
_edit_files_with_filter(da, p_filters, r_list, exclude);
|
|
|
|
da->change_dir("..");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPlatform::_edit_filter_list(Set<String> &r_list, const String &p_filter, bool exclude) {
|
2021-12-09 09:42:46 +00:00
|
|
|
if (p_filter.is_empty()) {
|
2017-08-14 13:13:09 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-08-14 13:13:09 +00:00
|
|
|
Vector<String> split = p_filter.split(",");
|
|
|
|
Vector<String> filters;
|
|
|
|
for (int i = 0; i < split.size(); i++) {
|
|
|
|
String f = split[i].strip_edges();
|
2020-12-15 12:04:21 +00:00
|
|
|
if (f.is_empty()) {
|
2017-08-14 13:13:09 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-08-14 13:13:09 +00:00
|
|
|
filters.push_back(f);
|
|
|
|
}
|
|
|
|
|
2022-03-06 14:01:13 +00:00
|
|
|
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
2017-08-14 13:13:09 +00:00
|
|
|
ERR_FAIL_NULL(da);
|
|
|
|
_edit_files_with_filter(da, filters, r_list, exclude);
|
|
|
|
memdelete(da);
|
|
|
|
}
|
|
|
|
|
2018-12-23 18:28:29 +00:00
|
|
|
void EditorExportPlugin::set_export_preset(const Ref<EditorExportPreset> &p_preset) {
|
|
|
|
if (p_preset.is_valid()) {
|
|
|
|
export_preset = p_preset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<EditorExportPreset> EditorExportPlugin::get_export_preset() const {
|
|
|
|
return export_preset;
|
|
|
|
}
|
|
|
|
|
2017-09-14 22:38:38 +00:00
|
|
|
void EditorExportPlugin::add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap) {
|
|
|
|
ExtraFile ef;
|
|
|
|
ef.data = p_file;
|
|
|
|
ef.path = p_path;
|
|
|
|
ef.remap = p_remap;
|
|
|
|
extra_files.push_back(ef);
|
|
|
|
}
|
|
|
|
|
2022-03-10 07:48:25 +00:00
|
|
|
void EditorExportPlugin::add_shared_object(const String &p_path, const Vector<String> &p_tags, const String &p_target) {
|
|
|
|
shared_objects.push_back(SharedObject(p_path, p_tags, p_target));
|
2017-10-02 15:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPlugin::add_ios_framework(const String &p_path) {
|
|
|
|
ios_frameworks.push_back(p_path);
|
|
|
|
}
|
|
|
|
|
2020-08-05 17:55:29 +00:00
|
|
|
void EditorExportPlugin::add_ios_embedded_framework(const String &p_path) {
|
|
|
|
ios_embedded_frameworks.push_back(p_path);
|
|
|
|
}
|
|
|
|
|
2017-10-02 15:01:43 +00:00
|
|
|
Vector<String> EditorExportPlugin::get_ios_frameworks() const {
|
|
|
|
return ios_frameworks;
|
|
|
|
}
|
|
|
|
|
2020-08-05 17:55:29 +00:00
|
|
|
Vector<String> EditorExportPlugin::get_ios_embedded_frameworks() const {
|
|
|
|
return ios_embedded_frameworks;
|
|
|
|
}
|
|
|
|
|
2017-10-02 15:01:43 +00:00
|
|
|
void EditorExportPlugin::add_ios_plist_content(const String &p_plist_content) {
|
|
|
|
ios_plist_content += p_plist_content + "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPlugin::get_ios_plist_content() const {
|
|
|
|
return ios_plist_content;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPlugin::add_ios_linker_flags(const String &p_flags) {
|
|
|
|
if (ios_linker_flags.length() > 0) {
|
|
|
|
ios_linker_flags += ' ';
|
|
|
|
}
|
|
|
|
ios_linker_flags += p_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPlugin::get_ios_linker_flags() const {
|
|
|
|
return ios_linker_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPlugin::add_ios_bundle_file(const String &p_path) {
|
|
|
|
ios_bundle_files.push_back(p_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<String> EditorExportPlugin::get_ios_bundle_files() const {
|
|
|
|
return ios_bundle_files;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPlugin::add_ios_cpp_code(const String &p_code) {
|
|
|
|
ios_cpp_code += p_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPlugin::get_ios_cpp_code() const {
|
|
|
|
return ios_cpp_code;
|
2017-09-14 22:38:38 +00:00
|
|
|
}
|
|
|
|
|
2021-12-18 09:21:08 +00:00
|
|
|
void EditorExportPlugin::add_osx_plugin_file(const String &p_path) {
|
|
|
|
osx_plugin_files.push_back(p_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Vector<String> &EditorExportPlugin::get_osx_plugin_files() const {
|
|
|
|
return osx_plugin_files;
|
|
|
|
}
|
|
|
|
|
2020-03-18 16:40:04 +00:00
|
|
|
void EditorExportPlugin::add_ios_project_static_lib(const String &p_path) {
|
|
|
|
ios_project_static_libs.push_back(p_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<String> EditorExportPlugin::get_ios_project_static_libs() const {
|
|
|
|
return ios_project_static_libs;
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const Vector<String> &p_features) {
|
2021-08-22 01:52:44 +00:00
|
|
|
GDVIRTUAL_CALL(_export_file, p_path, p_type, p_features);
|
2017-09-14 22:38:38 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
void EditorExportPlugin::_export_begin_script(const Vector<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
|
2021-08-22 01:52:44 +00:00
|
|
|
GDVIRTUAL_CALL(_export_begin, p_features, p_debug, p_path, p_flags);
|
2017-09-15 16:45:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 18:05:10 +00:00
|
|
|
void EditorExportPlugin::_export_end_script() {
|
2021-08-22 01:52:44 +00:00
|
|
|
GDVIRTUAL_CALL(_export_end);
|
2018-12-07 18:05:10 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 16:45:03 +00:00
|
|
|
void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const Set<String> &p_features) {
|
|
|
|
}
|
|
|
|
|
2017-10-02 15:01:43 +00:00
|
|
|
void EditorExportPlugin::_export_begin(const Set<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
|
2017-09-14 22:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPlugin::skip() {
|
|
|
|
skipped = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPlugin::_bind_methods() {
|
2022-03-10 07:48:25 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_shared_object", "path", "tags", "target"), &EditorExportPlugin::add_shared_object);
|
2020-03-18 16:40:04 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_ios_project_static_lib", "path"), &EditorExportPlugin::add_ios_project_static_lib);
|
2017-09-14 22:38:38 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file);
|
2017-10-02 15:01:43 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_ios_framework", "path"), &EditorExportPlugin::add_ios_framework);
|
2020-08-05 17:55:29 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_ios_embedded_framework", "path"), &EditorExportPlugin::add_ios_embedded_framework);
|
2017-10-02 15:01:43 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_ios_plist_content", "plist_content"), &EditorExportPlugin::add_ios_plist_content);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_ios_linker_flags", "flags"), &EditorExportPlugin::add_ios_linker_flags);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_ios_bundle_file", "path"), &EditorExportPlugin::add_ios_bundle_file);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_ios_cpp_code", "code"), &EditorExportPlugin::add_ios_cpp_code);
|
2021-12-18 09:21:08 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_osx_plugin_file", "path"), &EditorExportPlugin::add_osx_plugin_file);
|
2017-09-14 22:38:38 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip);
|
|
|
|
|
2021-08-22 01:52:44 +00:00
|
|
|
GDVIRTUAL_BIND(_export_file, "path", "type", "features");
|
|
|
|
GDVIRTUAL_BIND(_export_begin, "features", "is_debug", "path", "flags");
|
|
|
|
GDVIRTUAL_BIND(_export_end);
|
2017-09-14 22:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorExportPlugin::EditorExportPlugin() {
|
|
|
|
}
|
|
|
|
|
2022-03-10 07:48:25 +00:00
|
|
|
EditorExportPlatform::FeatureContainers EditorExportPlatform::get_feature_containers(const Ref<EditorExportPreset> &p_preset, bool p_debug) {
|
2017-02-21 03:05:15 +00:00
|
|
|
Ref<EditorExportPlatform> platform = p_preset->get_platform();
|
|
|
|
List<String> feature_list;
|
2017-10-02 15:01:43 +00:00
|
|
|
platform->get_platform_features(&feature_list);
|
2017-03-05 15:44:50 +00:00
|
|
|
platform->get_preset_features(p_preset, &feature_list);
|
2017-10-02 15:01:43 +00:00
|
|
|
|
|
|
|
FeatureContainers result;
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const String &E : feature_list) {
|
2021-07-16 03:45:57 +00:00
|
|
|
result.features.insert(E);
|
|
|
|
result.features_pv.push_back(E);
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
2018-12-07 19:29:47 +00:00
|
|
|
|
2022-03-10 07:48:25 +00:00
|
|
|
if (p_debug) {
|
|
|
|
result.features.insert("debug");
|
|
|
|
result.features_pv.push_back("debug");
|
|
|
|
} else {
|
|
|
|
result.features.insert("release");
|
|
|
|
result.features_pv.push_back("release");
|
|
|
|
}
|
|
|
|
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!p_preset->get_custom_features().is_empty()) {
|
2018-12-07 19:29:47 +00:00
|
|
|
Vector<String> tmp_custom_list = p_preset->get_custom_features().split(",");
|
|
|
|
|
|
|
|
for (int i = 0; i < tmp_custom_list.size(); i++) {
|
|
|
|
String f = tmp_custom_list[i].strip_edges();
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!f.is_empty()) {
|
2018-12-07 19:29:47 +00:00
|
|
|
result.features.insert(f);
|
|
|
|
result.features_pv.push_back(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 15:01:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2017-10-02 15:01:43 +00:00
|
|
|
EditorExportPlatform::ExportNotifier::ExportNotifier(EditorExportPlatform &p_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
2022-03-10 07:48:25 +00:00
|
|
|
FeatureContainers features = p_platform.get_feature_containers(p_preset, p_debug);
|
2020-03-17 06:33:00 +00:00
|
|
|
Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
|
2017-10-02 15:01:43 +00:00
|
|
|
//initial export plugin callback
|
|
|
|
for (int i = 0; i < export_plugins.size(); i++) {
|
|
|
|
if (export_plugins[i]->get_script_instance()) { //script based
|
2018-07-25 01:11:03 +00:00
|
|
|
export_plugins.write[i]->_export_begin_script(features.features_pv, p_debug, p_path, p_flags);
|
2017-10-02 15:01:43 +00:00
|
|
|
} else {
|
2018-07-25 01:11:03 +00:00
|
|
|
export_plugins.write[i]->_export_begin(features.features, p_debug, p_path, p_flags);
|
2017-10-02 15:01:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorExportPlatform::ExportNotifier::~ExportNotifier() {
|
2020-03-17 06:33:00 +00:00
|
|
|
Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
|
2017-10-02 15:01:43 +00:00
|
|
|
for (int i = 0; i < export_plugins.size(); i++) {
|
2018-12-07 18:05:10 +00:00
|
|
|
if (export_plugins[i]->get_script_instance()) {
|
|
|
|
export_plugins.write[i]->_export_end_script();
|
|
|
|
}
|
2018-07-25 01:11:03 +00:00
|
|
|
export_plugins.write[i]->_export_end();
|
2017-10-02 15:01:43 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-14 22:38:38 +00:00
|
|
|
|
2022-03-10 07:48:25 +00:00
|
|
|
Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &p_preset, bool p_debug, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func) {
|
2017-02-21 03:05:15 +00:00
|
|
|
//figure out paths of files that will be exported
|
|
|
|
Set<String> paths;
|
2017-09-14 22:38:38 +00:00
|
|
|
Vector<String> path_remaps;
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_preset->get_export_filter() == EditorExportPreset::EXPORT_ALL_RESOURCES) {
|
2017-02-21 03:05:15 +00:00
|
|
|
//find stuff
|
2017-03-05 15:44:50 +00:00
|
|
|
_export_find_resources(EditorFileSystem::get_singleton()->get_filesystem(), paths);
|
2020-11-15 00:54:24 +00:00
|
|
|
} else if (p_preset->get_export_filter() == EditorExportPreset::EXCLUDE_SELECTED_RESOURCES) {
|
|
|
|
_export_find_resources(EditorFileSystem::get_singleton()->get_filesystem(), paths);
|
|
|
|
Vector<String> files = p_preset->get_files_to_export();
|
|
|
|
for (int i = 0; i < files.size(); i++) {
|
|
|
|
paths.erase(files[i]);
|
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
bool scenes_only = p_preset->get_export_filter() == EditorExportPreset::EXPORT_SELECTED_SCENES;
|
2017-02-21 03:05:15 +00:00
|
|
|
|
|
|
|
Vector<String> files = p_preset->get_files_to_export();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < files.size(); i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (scenes_only && ResourceLoader::get_resource_type(files[i]) != "PackedScene") {
|
2017-02-21 03:05:15 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_export_find_dependencies(files[i], paths);
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
2021-01-09 22:03:48 +00:00
|
|
|
|
|
|
|
// Add autoload resources and their dependencies
|
|
|
|
List<PropertyInfo> props;
|
|
|
|
ProjectSettings::get_singleton()->get_property_list(&props);
|
|
|
|
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const PropertyInfo &pi : props) {
|
2021-01-09 22:03:48 +00:00
|
|
|
if (!pi.name.begins_with("autoload/")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
String autoload_path = ProjectSettings::get_singleton()->get(pi.name);
|
|
|
|
|
|
|
|
if (autoload_path.begins_with("*")) {
|
|
|
|
autoload_path = autoload_path.substr(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
_export_find_dependencies(autoload_path, paths);
|
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 13:43:56 +00:00
|
|
|
//add native icons to non-resource include list
|
|
|
|
_edit_filter_list(paths, String("*.icns"), false);
|
|
|
|
_edit_filter_list(paths, String("*.ico"), false);
|
|
|
|
|
2017-08-14 13:13:09 +00:00
|
|
|
_edit_filter_list(paths, p_preset->get_include_filter(), false);
|
|
|
|
_edit_filter_list(paths, p_preset->get_exclude_filter(), true);
|
|
|
|
|
2020-11-12 18:56:18 +00:00
|
|
|
// Ignore import files, since these are automatically added to the jar later with the resources
|
|
|
|
_edit_filter_list(paths, String("*.import"), true);
|
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
// Get encryption filters.
|
|
|
|
bool enc_pck = p_preset->get_enc_pck();
|
|
|
|
Vector<String> enc_in_filters;
|
|
|
|
Vector<String> enc_ex_filters;
|
|
|
|
Vector<uint8_t> key;
|
|
|
|
|
|
|
|
if (enc_pck) {
|
|
|
|
Vector<String> enc_in_split = p_preset->get_enc_in_filter().split(",");
|
|
|
|
for (int i = 0; i < enc_in_split.size(); i++) {
|
|
|
|
String f = enc_in_split[i].strip_edges();
|
2020-12-15 12:04:21 +00:00
|
|
|
if (f.is_empty()) {
|
2020-04-28 17:51:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
enc_in_filters.push_back(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<String> enc_ex_split = p_preset->get_enc_ex_filter().split(",");
|
|
|
|
for (int i = 0; i < enc_ex_split.size(); i++) {
|
|
|
|
String f = enc_ex_split[i].strip_edges();
|
2020-12-15 12:04:21 +00:00
|
|
|
if (f.is_empty()) {
|
2020-04-28 17:51:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
enc_ex_filters.push_back(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get encryption key.
|
|
|
|
String script_key = p_preset->get_script_encryption_key().to_lower();
|
|
|
|
key.resize(32);
|
|
|
|
if (script_key.length() == 64) {
|
|
|
|
for (int i = 0; i < 32; i++) {
|
|
|
|
int v = 0;
|
|
|
|
if (i * 2 < script_key.length()) {
|
|
|
|
char32_t ct = script_key[i * 2];
|
2022-02-04 08:32:20 +00:00
|
|
|
if (is_digit(ct)) {
|
2020-04-28 17:51:29 +00:00
|
|
|
ct = ct - '0';
|
|
|
|
} else if (ct >= 'a' && ct <= 'f') {
|
|
|
|
ct = 10 + ct - 'a';
|
|
|
|
}
|
|
|
|
v |= ct << 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i * 2 + 1 < script_key.length()) {
|
|
|
|
char32_t ct = script_key[i * 2 + 1];
|
2022-02-04 08:32:20 +00:00
|
|
|
if (is_digit(ct)) {
|
2020-04-28 17:51:29 +00:00
|
|
|
ct = ct - '0';
|
|
|
|
} else if (ct >= 'a' && ct <= 'f') {
|
|
|
|
ct = 10 + ct - 'a';
|
|
|
|
}
|
|
|
|
v |= ct;
|
|
|
|
}
|
|
|
|
key.write[i] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 21:29:21 +00:00
|
|
|
Error err = OK;
|
2020-03-17 06:33:00 +00:00
|
|
|
Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
|
2021-03-11 21:29:21 +00:00
|
|
|
|
2017-09-15 16:45:03 +00:00
|
|
|
for (int i = 0; i < export_plugins.size(); i++) {
|
2018-12-23 18:28:29 +00:00
|
|
|
export_plugins.write[i]->set_export_preset(p_preset);
|
|
|
|
|
2017-09-15 16:45:03 +00:00
|
|
|
if (p_so_func) {
|
|
|
|
for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
|
2021-03-11 21:29:21 +00:00
|
|
|
err = p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-09-15 16:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
|
2021-03-11 21:29:21 +00:00
|
|
|
err = p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, 0, paths.size(), enc_in_filters, enc_ex_filters, key);
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-09-15 16:45:03 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
export_plugins.write[i]->_clear();
|
2017-09-15 16:45:03 +00:00
|
|
|
}
|
|
|
|
|
2022-03-10 07:48:25 +00:00
|
|
|
FeatureContainers feature_containers = get_feature_containers(p_preset, p_debug);
|
2017-10-02 15:01:43 +00:00
|
|
|
Set<String> &features = feature_containers.features;
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<String> &features_pv = feature_containers.features_pv;
|
2017-10-02 15:01:43 +00:00
|
|
|
|
2017-02-21 03:05:15 +00:00
|
|
|
//store everything in the export medium
|
|
|
|
int idx = 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
int total = paths.size();
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Set<String>::Element *E = paths.front(); E; E = E->next()) {
|
2017-02-21 03:05:15 +00:00
|
|
|
String path = E->get();
|
2017-09-15 16:45:03 +00:00
|
|
|
String type = ResourceLoader::get_resource_type(path);
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (FileAccess::exists(path + ".import")) {
|
2017-02-21 03:05:15 +00:00
|
|
|
//file is imported, replace by what it imports
|
|
|
|
Ref<ConfigFile> config;
|
2021-06-17 22:03:09 +00:00
|
|
|
config.instantiate();
|
2021-03-11 21:29:21 +00:00
|
|
|
err = config->load(path + ".import");
|
2017-03-05 15:44:50 +00:00
|
|
|
if (err != OK) {
|
2019-11-06 16:03:04 +00:00
|
|
|
ERR_PRINT("Could not parse: '" + path + "', not exported.");
|
2017-02-21 03:05:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-22 19:41:47 +00:00
|
|
|
String importer_type = config->get_value("remap", "importer");
|
|
|
|
|
|
|
|
if (importer_type == "keep") {
|
|
|
|
//just keep file as-is
|
|
|
|
Vector<uint8_t> array = FileAccess::get_file_as_array(path);
|
|
|
|
err = p_func(p_udata, path, array, idx, total, enc_in_filters, enc_ex_filters, key);
|
|
|
|
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-02-21 03:05:15 +00:00
|
|
|
List<String> remaps;
|
2017-03-05 15:44:50 +00:00
|
|
|
config->get_section_keys("remap", &remaps);
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2018-08-22 02:56:04 +00:00
|
|
|
Set<String> remap_features;
|
|
|
|
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const String &F : remaps) {
|
2021-07-16 03:45:57 +00:00
|
|
|
String remap = F;
|
2018-08-22 02:56:04 +00:00
|
|
|
String feature = remap.get_slice(".", 1);
|
2018-08-27 16:47:13 +00:00
|
|
|
if (features.has(feature)) {
|
2018-08-22 02:56:04 +00:00
|
|
|
remap_features.insert(feature);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remap_features.size() > 1) {
|
|
|
|
this->resolve_platform_feature_priorities(p_preset, remap_features);
|
|
|
|
}
|
|
|
|
|
2018-12-19 18:50:40 +00:00
|
|
|
err = OK;
|
|
|
|
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const String &F : remaps) {
|
2021-07-16 03:45:57 +00:00
|
|
|
String remap = F;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (remap == "path") {
|
|
|
|
String remapped_path = config->get_value("remap", remap);
|
2017-02-21 03:05:15 +00:00
|
|
|
Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path);
|
2020-04-28 17:51:29 +00:00
|
|
|
err = p_func(p_udata, remapped_path, array, idx, total, enc_in_filters, enc_ex_filters, key);
|
2017-02-21 03:05:15 +00:00
|
|
|
} else if (remap.begins_with("path.")) {
|
2017-03-05 15:44:50 +00:00
|
|
|
String feature = remap.get_slice(".", 1);
|
2018-08-22 02:56:04 +00:00
|
|
|
|
|
|
|
if (remap_features.has(feature)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
String remapped_path = config->get_value("remap", remap);
|
2017-02-21 03:05:15 +00:00
|
|
|
Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path);
|
2020-04-28 17:51:29 +00:00
|
|
|
err = p_func(p_udata, remapped_path, array, idx, total, enc_in_filters, enc_ex_filters, key);
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-19 18:50:40 +00:00
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-02-21 03:05:15 +00:00
|
|
|
//also save the .import file
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector<uint8_t> array = FileAccess::get_file_as_array(path + ".import");
|
2020-04-28 17:51:29 +00:00
|
|
|
err = p_func(p_udata, path + ".import", array, idx, total, enc_in_filters, enc_ex_filters, key);
|
2018-12-19 18:50:40 +00:00
|
|
|
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
|
|
|
} else {
|
2017-09-14 22:38:38 +00:00
|
|
|
bool do_export = true;
|
|
|
|
for (int i = 0; i < export_plugins.size(); i++) {
|
|
|
|
if (export_plugins[i]->get_script_instance()) { //script based
|
2018-07-25 01:11:03 +00:00
|
|
|
export_plugins.write[i]->_export_file_script(path, type, features_pv);
|
2017-09-14 22:38:38 +00:00
|
|
|
} else {
|
2018-07-25 01:11:03 +00:00
|
|
|
export_plugins.write[i]->_export_file(path, type, features);
|
2017-09-14 22:38:38 +00:00
|
|
|
}
|
|
|
|
if (p_so_func) {
|
|
|
|
for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
|
2021-03-11 21:29:21 +00:00
|
|
|
err = p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-09-14 22:38:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
|
2021-03-11 21:29:21 +00:00
|
|
|
err = p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, idx, total, enc_in_filters, enc_ex_filters, key);
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-09-14 22:38:38 +00:00
|
|
|
if (export_plugins[i]->extra_files[j].remap) {
|
|
|
|
do_export = false; //if remap, do not
|
|
|
|
path_remaps.push_back(path);
|
|
|
|
path_remaps.push_back(export_plugins[i]->extra_files[j].path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (export_plugins[i]->skipped) {
|
|
|
|
do_export = false;
|
|
|
|
}
|
2018-07-25 01:11:03 +00:00
|
|
|
export_plugins.write[i]->_clear();
|
2017-09-14 22:38:38 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!do_export) {
|
2017-09-14 22:38:38 +00:00
|
|
|
break; //apologies, not exporting
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-14 22:38:38 +00:00
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
//just store it as it comes
|
2017-09-14 22:38:38 +00:00
|
|
|
if (do_export) {
|
|
|
|
Vector<uint8_t> array = FileAccess::get_file_as_array(path);
|
2021-03-11 21:29:21 +00:00
|
|
|
err = p_func(p_udata, path, array, idx, total, enc_in_filters, enc_ex_filters, key);
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-09-14 22:38:38 +00:00
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//save config!
|
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
Vector<String> custom_list;
|
|
|
|
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!p_preset->get_custom_features().is_empty()) {
|
2017-07-19 20:00:46 +00:00
|
|
|
Vector<String> tmp_custom_list = p_preset->get_custom_features().split(",");
|
|
|
|
|
|
|
|
for (int i = 0; i < tmp_custom_list.size(); i++) {
|
|
|
|
String f = tmp_custom_list[i].strip_edges();
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!f.is_empty()) {
|
2017-07-19 20:00:46 +00:00
|
|
|
custom_list.push_back(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-14 22:38:38 +00:00
|
|
|
ProjectSettings::CustomMap custom_map;
|
|
|
|
if (path_remaps.size()) {
|
2020-05-14 09:00:19 +00:00
|
|
|
if (true) { //new remap mode, use always as it's friendlier with multiple .pck exports
|
2017-12-18 14:21:13 +00:00
|
|
|
for (int i = 0; i < path_remaps.size(); i += 2) {
|
|
|
|
String from = path_remaps[i];
|
|
|
|
String to = path_remaps[i + 1];
|
|
|
|
String remap_file = "[remap]\n\npath=\"" + to.c_escape() + "\"\n";
|
|
|
|
CharString utf8 = remap_file.utf8();
|
|
|
|
Vector<uint8_t> new_file;
|
|
|
|
new_file.resize(utf8.length());
|
|
|
|
for (int j = 0; j < utf8.length(); j++) {
|
2018-07-25 01:11:03 +00:00
|
|
|
new_file.write[j] = utf8[j];
|
2017-12-18 14:21:13 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 21:29:21 +00:00
|
|
|
err = p_func(p_udata, from + ".remap", new_file, idx, total, enc_in_filters, enc_ex_filters, key);
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-12-18 14:21:13 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//old remap mode, will still work, but it's unused because it's not multiple pck export friendly
|
|
|
|
custom_map["path_remap/remapped_paths"] = path_remaps;
|
|
|
|
}
|
2017-09-14 22:38:38 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 23:13:58 +00:00
|
|
|
// Store icon and splash images directly, they need to bypass the import system and be loaded as images
|
|
|
|
String icon = ProjectSettings::get_singleton()->get("application/config/icon");
|
|
|
|
String splash = ProjectSettings::get_singleton()->get("application/boot_splash/image");
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!icon.is_empty() && FileAccess::exists(icon)) {
|
2017-12-05 23:13:58 +00:00
|
|
|
Vector<uint8_t> array = FileAccess::get_file_as_array(icon);
|
2021-03-11 21:29:21 +00:00
|
|
|
err = p_func(p_udata, icon, array, idx, total, enc_in_filters, enc_ex_filters, key);
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-12-05 23:13:58 +00:00
|
|
|
}
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!splash.is_empty() && FileAccess::exists(splash) && icon != splash) {
|
2017-12-05 23:13:58 +00:00
|
|
|
Vector<uint8_t> array = FileAccess::get_file_as_array(splash);
|
2021-03-11 21:29:21 +00:00
|
|
|
err = p_func(p_udata, splash, array, idx, total, enc_in_filters, enc_ex_filters, key);
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-12-05 23:13:58 +00:00
|
|
|
}
|
2021-09-10 15:32:29 +00:00
|
|
|
String resource_cache_file = ResourceUID::get_cache_file();
|
|
|
|
if (FileAccess::exists(resource_cache_file)) {
|
|
|
|
Vector<uint8_t> array = FileAccess::get_file_as_array(resource_cache_file);
|
|
|
|
err = p_func(p_udata, resource_cache_file, array, idx, total, enc_in_filters, enc_ex_filters, key);
|
2021-08-20 18:32:56 +00:00
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:32:29 +00:00
|
|
|
String extension_list_config_file = NativeExtension::get_extension_list_config_file();
|
|
|
|
if (FileAccess::exists(extension_list_config_file)) {
|
|
|
|
Vector<uint8_t> array = FileAccess::get_file_as_array(extension_list_config_file);
|
|
|
|
err = p_func(p_udata, extension_list_config_file, array, idx, total, enc_in_filters, enc_ex_filters, key);
|
2021-07-23 19:01:18 +00:00
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
2017-12-05 23:13:58 +00:00
|
|
|
|
2021-04-22 12:08:59 +00:00
|
|
|
// Store text server data if it is supported.
|
2020-09-03 11:22:16 +00:00
|
|
|
if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) {
|
2021-04-22 12:08:59 +00:00
|
|
|
bool use_data = ProjectSettings::get_singleton()->get("internationalization/locale/include_text_server_data");
|
|
|
|
if (use_data) {
|
|
|
|
// Try using user provided data file.
|
|
|
|
String ts_data = "res://" + TS->get_support_data_filename();
|
|
|
|
if (FileAccess::exists(ts_data)) {
|
|
|
|
Vector<uint8_t> array = FileAccess::get_file_as_array(ts_data);
|
|
|
|
err = p_func(p_udata, ts_data, array, idx, total, enc_in_filters, enc_ex_filters, key);
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Use default text server data.
|
2021-05-25 00:25:11 +00:00
|
|
|
String icu_data_file = EditorPaths::get_singleton()->get_cache_dir().plus_file("tmp_icu_data");
|
2021-04-22 12:08:59 +00:00
|
|
|
TS->save_support_data(icu_data_file);
|
|
|
|
Vector<uint8_t> array = FileAccess::get_file_as_array(icu_data_file);
|
|
|
|
err = p_func(p_udata, ts_data, array, idx, total, enc_in_filters, enc_ex_filters, key);
|
|
|
|
DirAccess::remove_file_or_error(icu_data_file);
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
2021-03-11 21:29:21 +00:00
|
|
|
}
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
String config_file = "project.binary";
|
2021-05-25 00:25:11 +00:00
|
|
|
String engine_cfb = EditorPaths::get_singleton()->get_cache_dir().plus_file("tmp" + config_file);
|
2017-09-14 22:38:38 +00:00
|
|
|
ProjectSettings::get_singleton()->save_custom(engine_cfb, custom_map, custom_list);
|
2017-02-21 03:05:15 +00:00
|
|
|
Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb);
|
2019-08-09 11:45:30 +00:00
|
|
|
DirAccess::remove_file_or_error(engine_cfb);
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2021-03-11 21:29:21 +00:00
|
|
|
return p_func(p_udata, "res://" + config_file, data, idx, total, enc_in_filters, enc_ex_filters, key);
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 15:01:43 +00:00
|
|
|
Error EditorExportPlatform::_add_shared_object(void *p_userdata, const SharedObject &p_so) {
|
|
|
|
PackData *pack_data = (PackData *)p_userdata;
|
|
|
|
if (pack_data->so_files) {
|
|
|
|
pack_data->so_files->push_back(p_so);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2022-03-10 07:48:25 +00:00
|
|
|
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) {
|
2018-12-19 18:50:40 +00:00
|
|
|
EditorProgress ep("savepack", TTR("Packing"), 102, true);
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2021-01-29 21:07:00 +00:00
|
|
|
// Create the temporary export directory if it doesn't exist.
|
|
|
|
DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
2021-05-25 00:25:11 +00:00
|
|
|
da->make_dir_recursive(EditorPaths::get_singleton()->get_cache_dir());
|
2021-01-29 21:07:00 +00:00
|
|
|
|
2021-05-25 00:25:11 +00:00
|
|
|
String tmppath = EditorPaths::get_singleton()->get_cache_dir().plus_file("packtmp");
|
2017-03-05 15:44:50 +00:00
|
|
|
FileAccess *ftmp = FileAccess::open(tmppath, FileAccess::WRITE);
|
2019-09-25 08:28:50 +00:00
|
|
|
ERR_FAIL_COND_V_MSG(!ftmp, ERR_CANT_CREATE, "Cannot create file '" + tmppath + "'.");
|
2017-02-21 03:05:15 +00:00
|
|
|
|
|
|
|
PackData pd;
|
2017-03-05 15:44:50 +00:00
|
|
|
pd.ep = &ep;
|
|
|
|
pd.f = ftmp;
|
2017-10-02 15:01:43 +00:00
|
|
|
pd.so_files = p_so_files;
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2022-03-10 07:48:25 +00:00
|
|
|
Error err = export_project_files(p_preset, p_debug, _save_pack_file, &pd, _add_shared_object);
|
2017-02-21 03:05:15 +00:00
|
|
|
|
|
|
|
memdelete(ftmp); //close tmp file
|
|
|
|
|
2019-08-09 11:45:30 +00:00
|
|
|
if (err != OK) {
|
|
|
|
DirAccess::remove_file_or_error(tmppath);
|
2021-03-11 21:29:21 +00:00
|
|
|
ERR_PRINT("Failed to export project files");
|
2017-02-21 03:05:15 +00:00
|
|
|
return err;
|
2019-08-09 11:45:30 +00:00
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
|
|
|
pd.file_ofs.sort(); //do sort, so we can do binary search later
|
|
|
|
|
2019-03-25 19:56:33 +00:00
|
|
|
FileAccess *f;
|
|
|
|
int64_t embed_pos = 0;
|
|
|
|
if (!p_embed) {
|
|
|
|
// Regular output to separate PCK file
|
|
|
|
f = FileAccess::open(p_path, FileAccess::WRITE);
|
2019-08-09 11:45:30 +00:00
|
|
|
if (!f) {
|
|
|
|
DirAccess::remove_file_or_error(tmppath);
|
|
|
|
ERR_FAIL_V(ERR_CANT_CREATE);
|
|
|
|
}
|
2019-03-25 19:56:33 +00:00
|
|
|
} else {
|
|
|
|
// Append to executable
|
|
|
|
f = FileAccess::open(p_path, FileAccess::READ_WRITE);
|
2019-08-09 11:45:30 +00:00
|
|
|
if (!f) {
|
|
|
|
DirAccess::remove_file_or_error(tmppath);
|
|
|
|
ERR_FAIL_V(ERR_FILE_CANT_OPEN);
|
|
|
|
}
|
2019-03-25 19:56:33 +00:00
|
|
|
|
|
|
|
f->seek_end();
|
|
|
|
embed_pos = f->get_position();
|
|
|
|
|
|
|
|
if (r_embedded_start) {
|
|
|
|
*r_embedded_start = embed_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure embedded PCK starts at a 64-bit multiple
|
|
|
|
int pad = f->get_position() % 8;
|
|
|
|
for (int i = 0; i < pad; i++) {
|
|
|
|
f->store_8(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t pck_start_pos = f->get_position();
|
|
|
|
|
2019-11-30 16:22:22 +00:00
|
|
|
f->store_32(PACK_HEADER_MAGIC);
|
|
|
|
f->store_32(PACK_FORMAT_VERSION);
|
2017-02-21 03:05:15 +00:00
|
|
|
f->store_32(VERSION_MAJOR);
|
|
|
|
f->store_32(VERSION_MINOR);
|
2019-11-30 16:22:22 +00:00
|
|
|
f->store_32(VERSION_PATCH);
|
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
uint32_t pack_flags = 0;
|
|
|
|
bool enc_pck = p_preset->get_enc_pck();
|
|
|
|
bool enc_directory = p_preset->get_enc_directory();
|
|
|
|
if (enc_pck && enc_directory) {
|
|
|
|
pack_flags |= PACK_DIR_ENCRYPTED;
|
|
|
|
}
|
|
|
|
f->store_32(pack_flags); // flags
|
|
|
|
|
|
|
|
uint64_t file_base_ofs = f->get_position();
|
|
|
|
f->store_64(0); // files base
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 16; i++) {
|
2017-02-21 03:05:15 +00:00
|
|
|
//reserved
|
|
|
|
f->store_32(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
f->store_32(pd.file_ofs.size()); //amount of files
|
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
FileAccessEncrypted *fae = nullptr;
|
|
|
|
FileAccess *fhead = f;
|
|
|
|
|
|
|
|
if (enc_pck && enc_directory) {
|
|
|
|
String script_key = p_preset->get_script_encryption_key().to_lower();
|
|
|
|
Vector<uint8_t> key;
|
|
|
|
key.resize(32);
|
|
|
|
if (script_key.length() == 64) {
|
|
|
|
for (int i = 0; i < 32; i++) {
|
|
|
|
int v = 0;
|
|
|
|
if (i * 2 < script_key.length()) {
|
|
|
|
char32_t ct = script_key[i * 2];
|
2022-02-04 08:32:20 +00:00
|
|
|
if (is_digit(ct)) {
|
2020-04-28 17:51:29 +00:00
|
|
|
ct = ct - '0';
|
|
|
|
} else if (ct >= 'a' && ct <= 'f') {
|
|
|
|
ct = 10 + ct - 'a';
|
|
|
|
}
|
|
|
|
v |= ct << 4;
|
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
if (i * 2 + 1 < script_key.length()) {
|
|
|
|
char32_t ct = script_key[i * 2 + 1];
|
2022-02-04 08:32:20 +00:00
|
|
|
if (is_digit(ct)) {
|
2020-04-28 17:51:29 +00:00
|
|
|
ct = ct - '0';
|
|
|
|
} else if (ct >= 'a' && ct <= 'f') {
|
|
|
|
ct = 10 + ct - 'a';
|
|
|
|
}
|
|
|
|
v |= ct;
|
|
|
|
}
|
|
|
|
key.write[i] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fae = memnew(FileAccessEncrypted);
|
|
|
|
ERR_FAIL_COND_V(!fae, ERR_SKIP);
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
err = fae->open_and_parse(f, key, FileAccessEncrypted::MODE_WRITE_AES256, false);
|
|
|
|
ERR_FAIL_COND_V(err != OK, ERR_SKIP);
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
fhead = fae;
|
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < pd.file_ofs.size(); i++) {
|
2019-03-26 17:51:13 +00:00
|
|
|
uint32_t string_len = pd.file_ofs[i].path_utf8.length();
|
|
|
|
uint32_t pad = _get_pad(4, string_len);
|
2019-03-25 19:56:33 +00:00
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
fhead->store_32(string_len + pad);
|
|
|
|
fhead->store_buffer((const uint8_t *)pd.file_ofs[i].path_utf8.get_data(), string_len);
|
2019-03-26 17:51:13 +00:00
|
|
|
for (uint32_t j = 0; j < pad; j++) {
|
2020-04-28 17:51:29 +00:00
|
|
|
fhead->store_8(0);
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
fhead->store_64(pd.file_ofs[i].ofs);
|
|
|
|
fhead->store_64(pd.file_ofs[i].size); // pay attention here, this is where file is
|
|
|
|
fhead->store_buffer(pd.file_ofs[i].md5.ptr(), 16); //also save md5 for file
|
|
|
|
uint32_t flags = 0;
|
|
|
|
if (pd.file_ofs[i].encrypted) {
|
|
|
|
flags |= PACK_FILE_ENCRYPTED;
|
|
|
|
}
|
|
|
|
fhead->store_32(flags);
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
if (fae) {
|
|
|
|
fae->release();
|
|
|
|
memdelete(fae);
|
|
|
|
}
|
|
|
|
|
|
|
|
int header_padding = _get_pad(PCK_PADDING, f->get_position());
|
2019-03-25 19:56:33 +00:00
|
|
|
for (int i = 0; i < header_padding; i++) {
|
2020-04-28 17:51:29 +00:00
|
|
|
f->store_8(Math::rand() % 256);
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
uint64_t file_base = f->get_position();
|
|
|
|
f->seek(file_base_ofs);
|
|
|
|
f->store_64(file_base); // update files base
|
|
|
|
f->seek(file_base);
|
|
|
|
|
2019-08-09 11:45:30 +00:00
|
|
|
// Save the rest of the data.
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ftmp = FileAccess::open(tmppath, FileAccess::READ);
|
2017-02-21 03:05:15 +00:00
|
|
|
if (!ftmp) {
|
|
|
|
memdelete(f);
|
2019-08-09 11:45:30 +00:00
|
|
|
DirAccess::remove_file_or_error(tmppath);
|
2019-09-25 08:28:50 +00:00
|
|
|
ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't open file to read from path '" + String(tmppath) + "'.");
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const int bufsize = 16384;
|
2017-02-21 03:05:15 +00:00
|
|
|
uint8_t buf[bufsize];
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (true) {
|
2019-03-26 17:51:13 +00:00
|
|
|
uint64_t got = ftmp->get_buffer(buf, bufsize);
|
|
|
|
if (got == 0) {
|
2017-02-21 03:05:15 +00:00
|
|
|
break;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
f->store_buffer(buf, got);
|
2017-02-21 03:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memdelete(ftmp);
|
|
|
|
|
2019-03-25 19:56:33 +00:00
|
|
|
if (p_embed) {
|
|
|
|
// Ensure embedded data ends at a 64-bit multiple
|
2019-03-26 17:51:13 +00:00
|
|
|
uint64_t embed_end = f->get_position() - embed_pos + 12;
|
|
|
|
uint64_t pad = embed_end % 8;
|
|
|
|
for (uint64_t i = 0; i < pad; i++) {
|
2019-03-25 19:56:33 +00:00
|
|
|
f->store_8(0);
|
|
|
|
}
|
|
|
|
|
2019-03-26 17:51:13 +00:00
|
|
|
uint64_t pck_size = f->get_position() - pck_start_pos;
|
2019-03-25 19:56:33 +00:00
|
|
|
f->store_64(pck_size);
|
2019-11-30 16:22:22 +00:00
|
|
|
f->store_32(PACK_HEADER_MAGIC);
|
2019-03-25 19:56:33 +00:00
|
|
|
|
|
|
|
if (r_embedded_size) {
|
|
|
|
*r_embedded_size = f->get_position() - embed_pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-21 03:05:15 +00:00
|
|
|
memdelete(f);
|
2019-08-09 11:45:30 +00:00
|
|
|
DirAccess::remove_file_or_error(tmppath);
|
2017-02-13 01:51:16 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2022-03-10 07:48:25 +00:00
|
|
|
Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
|
2018-12-19 18:50:40 +00:00
|
|
|
EditorProgress ep("savezip", TTR("Packing"), 102, true);
|
2017-02-21 03:05:15 +00:00
|
|
|
|
|
|
|
FileAccess *src_f;
|
|
|
|
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
|
2020-04-01 23:20:12 +00:00
|
|
|
zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io);
|
2017-02-21 03:05:15 +00:00
|
|
|
|
|
|
|
ZipData zd;
|
2017-03-05 15:44:50 +00:00
|
|
|
zd.ep = &ep;
|
|
|
|
zd.zip = zip;
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2022-03-10 07:48:25 +00:00
|
|
|
Error err = export_project_files(p_preset, p_debug, _save_zip_file, &zd);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (err != OK && err != ERR_SKIP) {
|
2017-09-02 20:32:31 +00:00
|
|
|
ERR_PRINT("Failed to export project files");
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
zipClose(zip, nullptr);
|
2017-02-21 03:05:15 +00:00
|
|
|
|
2017-02-13 01:51:16 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2018-04-26 21:08:19 +00:00
|
|
|
Error EditorExportPlatform::export_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
|
|
|
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
|
2022-03-10 07:48:25 +00:00
|
|
|
return save_pack(p_preset, p_debug, p_path);
|
2018-04-26 21:08:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Error EditorExportPlatform::export_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
|
|
|
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
|
2022-03-10 07:48:25 +00:00
|
|
|
return save_zip(p_preset, p_debug, p_path);
|
2018-04-26 21:08:19 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 23:14:12 +00:00
|
|
|
void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags) {
|
2017-05-09 11:57:07 +00:00
|
|
|
String host = EditorSettings::get_singleton()->get("network/debug/remote_host");
|
2017-06-10 14:28:18 +00:00
|
|
|
int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
|
2017-03-23 23:14:12 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
|
2017-03-23 23:14:12 +00:00
|
|
|
host = "localhost";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-23 23:14:12 +00:00
|
|
|
|
|
|
|
if (p_flags & DEBUG_FLAG_DUMB_CLIENT) {
|
|
|
|
int port = EditorSettings::get_singleton()->get("filesystem/file_server/port");
|
|
|
|
String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password");
|
2017-08-19 14:45:03 +00:00
|
|
|
r_flags.push_back("--remote-fs");
|
2017-03-23 23:14:12 +00:00
|
|
|
r_flags.push_back(host + ":" + itos(port));
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!passwd.is_empty()) {
|
2017-08-19 14:45:03 +00:00
|
|
|
r_flags.push_back("--remote-fs-password");
|
2017-03-23 23:14:12 +00:00
|
|
|
r_flags.push_back(passwd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_flags & DEBUG_FLAG_REMOTE_DEBUG) {
|
2017-08-19 14:45:03 +00:00
|
|
|
r_flags.push_back("--remote-debug");
|
2017-03-23 23:14:12 +00:00
|
|
|
|
2020-03-16 08:37:43 +00:00
|
|
|
r_flags.push_back(get_debug_protocol() + host + ":" + String::num(remote_port));
|
2017-03-23 23:14:12 +00:00
|
|
|
|
|
|
|
List<String> breakpoints;
|
|
|
|
ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
|
|
|
|
|
|
|
|
if (breakpoints.size()) {
|
2017-08-19 14:45:03 +00:00
|
|
|
r_flags.push_back("--breakpoints");
|
2017-03-23 23:14:12 +00:00
|
|
|
String bpoints;
|
2021-07-16 03:45:57 +00:00
|
|
|
for (List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
|
2017-03-23 23:14:12 +00:00
|
|
|
bpoints += E->get().replace(" ", "%20");
|
2020-05-14 14:41:43 +00:00
|
|
|
if (E->next()) {
|
2017-03-23 23:14:12 +00:00
|
|
|
bpoints += ",";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-23 23:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r_flags.push_back(bpoints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_flags & DEBUG_FLAG_VIEW_COLLISONS) {
|
2017-08-19 14:45:03 +00:00
|
|
|
r_flags.push_back("--debug-collisions");
|
2017-03-23 23:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
|
2017-08-19 14:45:03 +00:00
|
|
|
r_flags.push_back("--debug-navigation");
|
2017-03-23 23:14:12 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-02-13 01:51:16 +00:00
|
|
|
EditorExportPlatform::EditorExportPlatform() {
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
EditorExport *EditorExport::singleton = nullptr;
|
2017-02-20 02:19:30 +00:00
|
|
|
|
|
|
|
void EditorExport::_save() {
|
|
|
|
Ref<ConfigFile> config;
|
2021-06-17 22:03:09 +00:00
|
|
|
config.instantiate();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < export_presets.size(); i++) {
|
2017-02-20 02:19:30 +00:00
|
|
|
Ref<EditorExportPreset> preset = export_presets[i];
|
2017-03-05 15:44:50 +00:00
|
|
|
String section = "preset." + itos(i);
|
2017-02-20 02:19:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
config->set_value(section, "name", preset->get_name());
|
|
|
|
config->set_value(section, "platform", preset->get_platform()->get_name());
|
|
|
|
config->set_value(section, "runnable", preset->is_runnable());
|
2017-07-20 09:48:00 +00:00
|
|
|
config->set_value(section, "custom_features", preset->get_custom_features());
|
2018-12-23 18:28:29 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool save_files = false;
|
|
|
|
switch (preset->get_export_filter()) {
|
2017-02-20 02:19:30 +00:00
|
|
|
case EditorExportPreset::EXPORT_ALL_RESOURCES: {
|
2017-03-05 15:44:50 +00:00
|
|
|
config->set_value(section, "export_filter", "all_resources");
|
2017-02-20 02:19:30 +00:00
|
|
|
} break;
|
|
|
|
case EditorExportPreset::EXPORT_SELECTED_SCENES: {
|
2017-03-05 15:44:50 +00:00
|
|
|
config->set_value(section, "export_filter", "scenes");
|
|
|
|
save_files = true;
|
2017-02-20 02:19:30 +00:00
|
|
|
} break;
|
|
|
|
case EditorExportPreset::EXPORT_SELECTED_RESOURCES: {
|
2017-03-05 15:44:50 +00:00
|
|
|
config->set_value(section, "export_filter", "resources");
|
|
|
|
save_files = true;
|
2017-02-20 02:19:30 +00:00
|
|
|
} break;
|
2020-11-15 00:54:24 +00:00
|
|
|
case EditorExportPreset::EXCLUDE_SELECTED_RESOURCES: {
|
|
|
|
config->set_value(section, "export_filter", "exclude");
|
|
|
|
save_files = true;
|
|
|
|
} break;
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (save_files) {
|
|
|
|
Vector<String> export_files = preset->get_files_to_export();
|
2017-03-05 15:44:50 +00:00
|
|
|
config->set_value(section, "export_files", export_files);
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
config->set_value(section, "include_filter", preset->get_include_filter());
|
|
|
|
config->set_value(section, "exclude_filter", preset->get_exclude_filter());
|
2018-10-27 13:53:05 +00:00
|
|
|
config->set_value(section, "export_path", preset->get_export_path());
|
2020-04-28 17:51:29 +00:00
|
|
|
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());
|
|
|
|
config->set_value(section, "encrypt_directory", preset->get_enc_directory());
|
2018-12-23 18:28:29 +00:00
|
|
|
config->set_value(section, "script_export_mode", preset->get_script_export_mode());
|
|
|
|
config->set_value(section, "script_encryption_key", preset->get_script_encryption_key());
|
2017-02-20 02:19:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String option_section = "preset." + itos(i) + ".options";
|
2017-02-20 02:19:30 +00:00
|
|
|
|
2021-07-16 03:45:57 +00:00
|
|
|
for (const PropertyInfo &E : preset->get_properties()) {
|
|
|
|
config->set_value(option_section, E.name, preset->get(E.name));
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
config->save("res://export_presets.cfg");
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExport::save_presets() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (block_save) {
|
2017-02-20 02:19:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-02-20 02:19:30 +00:00
|
|
|
save_timer->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExport::_bind_methods() {
|
2020-04-24 07:45:14 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("export_presets_updated"));
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExport::add_export_platform(const Ref<EditorExportPlatform> &p_platform) {
|
2017-02-13 01:51:16 +00:00
|
|
|
export_platforms.push_back(p_platform);
|
|
|
|
}
|
|
|
|
|
|
|
|
int EditorExport::get_export_platform_count() {
|
|
|
|
return export_platforms.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<EditorExportPlatform> EditorExport::get_export_platform(int p_idx) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, export_platforms.size(), Ref<EditorExportPlatform>());
|
2017-02-13 01:51:16 +00:00
|
|
|
|
|
|
|
return export_platforms[p_idx];
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExport::add_export_preset(const Ref<EditorExportPreset> &p_preset, int p_at_pos) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_at_pos < 0) {
|
2017-02-13 01:51:16 +00:00
|
|
|
export_presets.push_back(p_preset);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
export_presets.insert(p_at_pos, p_preset);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 21:43:37 +00:00
|
|
|
String EditorExportPlatform::test_etc2() const {
|
2021-12-29 01:06:12 +00:00
|
|
|
const bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2");
|
2019-02-26 21:43:37 +00:00
|
|
|
|
2021-12-29 01:06:12 +00:00
|
|
|
if (!etc2_supported) {
|
|
|
|
return TTR("Target platform requires 'ETC2' texture compression. Enable 'Import Etc 2' in Project Settings.");
|
2020-09-16 15:07:54 +00:00
|
|
|
}
|
2021-12-29 01:06:12 +00:00
|
|
|
|
2020-09-16 15:07:54 +00:00
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-02-13 01:51:16 +00:00
|
|
|
int EditorExport::get_export_preset_count() const {
|
|
|
|
return export_presets.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<EditorExportPreset> EditorExport::get_export_preset(int p_idx) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, export_presets.size(), Ref<EditorExportPreset>());
|
2017-02-13 01:51:16 +00:00
|
|
|
return export_presets[p_idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExport::remove_export_preset(int p_idx) {
|
2021-07-03 22:17:03 +00:00
|
|
|
export_presets.remove_at(p_idx);
|
2018-10-03 16:03:03 +00:00
|
|
|
save_presets();
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 22:38:38 +00:00
|
|
|
void EditorExport::add_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
|
2022-02-01 18:19:13 +00:00
|
|
|
if (!export_plugins.has(p_plugin)) {
|
2017-09-14 22:38:38 +00:00
|
|
|
export_plugins.push_back(p_plugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExport::remove_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
|
|
|
|
export_plugins.erase(p_plugin);
|
|
|
|
}
|
|
|
|
|
2020-03-17 06:33:00 +00:00
|
|
|
Vector<Ref<EditorExportPlugin>> EditorExport::get_export_plugins() {
|
2017-09-14 22:38:38 +00:00
|
|
|
return export_plugins;
|
|
|
|
}
|
|
|
|
|
2017-02-20 02:19:30 +00:00
|
|
|
void EditorExport::_notification(int p_what) {
|
2020-04-24 07:45:14 +00:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
|
|
load_config();
|
|
|
|
} break;
|
2022-02-15 23:52:32 +00:00
|
|
|
|
2020-04-24 07:45:14 +00:00
|
|
|
case NOTIFICATION_PROCESS: {
|
|
|
|
update_export_presets();
|
|
|
|
} break;
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 01:51:16 +00:00
|
|
|
void EditorExport::load_config() {
|
2017-02-20 02:19:30 +00:00
|
|
|
Ref<ConfigFile> config;
|
2021-06-17 22:03:09 +00:00
|
|
|
config.instantiate();
|
2017-02-20 02:19:30 +00:00
|
|
|
Error err = config->load("res://export_presets.cfg");
|
2020-05-14 14:41:43 +00:00
|
|
|
if (err != OK) {
|
2017-02-20 02:19:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-02-13 01:51:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
block_save = true;
|
2017-02-20 02:19:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int index = 0;
|
|
|
|
while (true) {
|
|
|
|
String section = "preset." + itos(index);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!config->has_section(section)) {
|
2017-02-20 02:19:30 +00:00
|
|
|
break;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-02-20 02:19:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String platform = config->get_value(section, "platform");
|
2017-02-20 02:19:30 +00:00
|
|
|
|
|
|
|
Ref<EditorExportPreset> preset;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < export_platforms.size(); i++) {
|
|
|
|
if (export_platforms[i]->get_name() == platform) {
|
2018-07-25 01:11:03 +00:00
|
|
|
preset = export_platforms.write[i]->create_preset();
|
2017-02-20 02:19:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!preset.is_valid()) {
|
|
|
|
index++;
|
|
|
|
ERR_CONTINUE(!preset.is_valid());
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
preset->set_name(config->get_value(section, "name"));
|
|
|
|
preset->set_runnable(config->get_value(section, "runnable"));
|
2017-02-20 02:19:30 +00:00
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
if (config->has_section_key(section, "custom_features")) {
|
|
|
|
preset->set_custom_features(config->get_value(section, "custom_features"));
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String export_filter = config->get_value(section, "export_filter");
|
2017-02-20 02:19:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool get_files = false;
|
2017-02-20 02:19:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (export_filter == "all_resources") {
|
2017-02-20 02:19:30 +00:00
|
|
|
preset->set_export_filter(EditorExportPreset::EXPORT_ALL_RESOURCES);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (export_filter == "scenes") {
|
2017-02-20 02:19:30 +00:00
|
|
|
preset->set_export_filter(EditorExportPreset::EXPORT_SELECTED_SCENES);
|
2017-03-05 15:44:50 +00:00
|
|
|
get_files = true;
|
|
|
|
} else if (export_filter == "resources") {
|
2017-02-20 02:19:30 +00:00
|
|
|
preset->set_export_filter(EditorExportPreset::EXPORT_SELECTED_RESOURCES);
|
2017-03-05 15:44:50 +00:00
|
|
|
get_files = true;
|
2020-11-15 00:54:24 +00:00
|
|
|
} else if (export_filter == "exclude") {
|
|
|
|
preset->set_export_filter(EditorExportPreset::EXCLUDE_SELECTED_RESOURCES);
|
|
|
|
get_files = true;
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (get_files) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector<String> files = config->get_value(section, "export_files");
|
2017-02-20 02:19:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < files.size(); i++) {
|
2020-06-10 09:41:42 +00:00
|
|
|
if (!FileAccess::exists(files[i])) {
|
|
|
|
preset->remove_export_file(files[i]);
|
|
|
|
} else {
|
|
|
|
preset->add_export_file(files[i]);
|
|
|
|
}
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
preset->set_include_filter(config->get_value(section, "include_filter"));
|
|
|
|
preset->set_exclude_filter(config->get_value(section, "exclude_filter"));
|
2018-10-27 13:53:05 +00:00
|
|
|
preset->set_export_path(config->get_value(section, "export_path", ""));
|
2017-02-20 02:19:30 +00:00
|
|
|
|
2020-04-28 17:51:29 +00:00
|
|
|
if (config->has_section_key(section, "encrypt_pck")) {
|
|
|
|
preset->set_enc_pck(config->get_value(section, "encrypt_pck"));
|
|
|
|
}
|
|
|
|
if (config->has_section_key(section, "encrypt_directory")) {
|
|
|
|
preset->set_enc_directory(config->get_value(section, "encrypt_directory"));
|
|
|
|
}
|
|
|
|
if (config->has_section_key(section, "encryption_include_filters")) {
|
|
|
|
preset->set_enc_in_filter(config->get_value(section, "encryption_include_filters"));
|
|
|
|
}
|
|
|
|
if (config->has_section_key(section, "encryption_exclude_filters")) {
|
|
|
|
preset->set_enc_ex_filter(config->get_value(section, "encryption_exclude_filters"));
|
|
|
|
}
|
2018-12-23 18:28:29 +00:00
|
|
|
if (config->has_section_key(section, "script_export_mode")) {
|
|
|
|
preset->set_script_export_mode(config->get_value(section, "script_export_mode"));
|
|
|
|
}
|
|
|
|
if (config->has_section_key(section, "script_encryption_key")) {
|
|
|
|
preset->set_script_encryption_key(config->get_value(section, "script_encryption_key"));
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String option_section = "preset." + itos(index) + ".options";
|
2017-02-20 02:19:30 +00:00
|
|
|
|
|
|
|
List<String> options;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
config->get_section_keys(option_section, &options);
|
2017-02-13 01:51:16 +00:00
|
|
|
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const String &E : options) {
|
2021-07-16 03:45:57 +00:00
|
|
|
Variant value = config->get_value(option_section, E);
|
2017-02-20 02:19:30 +00:00
|
|
|
|
2021-07-16 03:45:57 +00:00
|
|
|
preset->set(E, value);
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
add_export_preset(preset);
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
block_save = false;
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 07:45:14 +00:00
|
|
|
void EditorExport::update_export_presets() {
|
|
|
|
Map<StringName, List<EditorExportPlatform::ExportOption>> platform_options;
|
|
|
|
|
|
|
|
for (int i = 0; i < export_platforms.size(); i++) {
|
|
|
|
Ref<EditorExportPlatform> platform = export_platforms[i];
|
|
|
|
|
|
|
|
if (platform->should_update_export_options()) {
|
|
|
|
List<EditorExportPlatform::ExportOption> options;
|
|
|
|
platform->get_export_options(&options);
|
|
|
|
|
|
|
|
platform_options[platform->get_name()] = options;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool export_presets_updated = false;
|
|
|
|
for (int i = 0; i < export_presets.size(); i++) {
|
|
|
|
Ref<EditorExportPreset> preset = export_presets[i];
|
|
|
|
if (platform_options.has(preset->get_platform()->get_name())) {
|
|
|
|
export_presets_updated = true;
|
|
|
|
|
|
|
|
List<EditorExportPlatform::ExportOption> options = platform_options[preset->get_platform()->get_name()];
|
|
|
|
|
|
|
|
// Copy the previous preset values
|
|
|
|
Map<StringName, Variant> previous_values = preset->values;
|
|
|
|
|
|
|
|
// Clear the preset properties and values prior to reloading
|
|
|
|
preset->properties.clear();
|
|
|
|
preset->values.clear();
|
|
|
|
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const EditorExportPlatform::ExportOption &E : options) {
|
2021-07-16 03:45:57 +00:00
|
|
|
preset->properties.push_back(E.option);
|
2020-04-24 07:45:14 +00:00
|
|
|
|
2021-07-16 03:45:57 +00:00
|
|
|
StringName option_name = E.option.name;
|
|
|
|
preset->values[option_name] = previous_values.has(option_name) ? previous_values[option_name] : E.default_value;
|
2020-04-24 07:45:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (export_presets_updated) {
|
|
|
|
emit_signal(_export_presets_updated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-23 23:14:12 +00:00
|
|
|
bool EditorExport::poll_export_platforms() {
|
|
|
|
bool changed = false;
|
|
|
|
for (int i = 0; i < export_platforms.size(); i++) {
|
2019-10-11 11:47:28 +00:00
|
|
|
if (export_platforms.write[i]->poll_export()) {
|
2017-03-23 23:14:12 +00:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2017-02-13 01:51:16 +00:00
|
|
|
EditorExport::EditorExport() {
|
2017-03-05 15:44:50 +00:00
|
|
|
save_timer = memnew(Timer);
|
2017-02-20 02:19:30 +00:00
|
|
|
add_child(save_timer);
|
|
|
|
save_timer->set_wait_time(0.8);
|
|
|
|
save_timer->set_one_shot(true);
|
2020-02-21 17:28:45 +00:00
|
|
|
save_timer->connect("timeout", callable_mp(this, &EditorExport::_save));
|
2017-02-13 01:51:16 +00:00
|
|
|
|
2020-04-24 07:45:14 +00:00
|
|
|
_export_presets_updated = "export_presets_updated";
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
singleton = this;
|
2020-04-24 07:45:14 +00:00
|
|
|
set_process(true);
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorExport::~EditorExport() {
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPlatformPC::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
|
2017-02-20 02:19:30 +00:00
|
|
|
if (p_preset->get("texture_format/s3tc")) {
|
|
|
|
r_features->push_back("s3tc");
|
|
|
|
}
|
|
|
|
if (p_preset->get("texture_format/etc")) {
|
|
|
|
r_features->push_back("etc");
|
|
|
|
}
|
|
|
|
if (p_preset->get("texture_format/etc2")) {
|
|
|
|
r_features->push_back("etc2");
|
|
|
|
}
|
2017-10-02 19:38:39 +00:00
|
|
|
|
|
|
|
if (p_preset->get("binary_format/64_bits")) {
|
|
|
|
r_features->push_back("64");
|
|
|
|
} else {
|
|
|
|
r_features->push_back("32");
|
|
|
|
}
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPlatformPC::get_export_options(List<ExportOption> *r_options) {
|
2020-11-20 09:45:39 +00:00
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE), ""));
|
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE), ""));
|
|
|
|
|
2022-02-23 06:44:38 +00:00
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "debug/export_console_script", PROPERTY_HINT_ENUM, "No,Debug Only,Debug and Release"), 1));
|
|
|
|
|
2020-11-20 09:45:39 +00:00
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "binary_format/64_bits"), true));
|
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "binary_format/embed_pck"), false));
|
|
|
|
|
2018-08-22 02:56:04 +00:00
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/bptc"), false));
|
2017-03-05 15:44:50 +00:00
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
|
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
|
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
|
2018-08-22 02:56:04 +00:00
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/no_bptc_fallbacks"), true));
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPlatformPC::get_name() const {
|
|
|
|
return name;
|
|
|
|
}
|
2017-07-19 20:00:46 +00:00
|
|
|
|
|
|
|
String EditorExportPlatformPC::get_os_name() const {
|
|
|
|
return os_name;
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> EditorExportPlatformPC::get_logo() const {
|
2017-02-20 02:19:30 +00:00
|
|
|
return logo;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
|
2017-04-21 23:15:42 +00:00
|
|
|
String err;
|
2020-01-07 12:29:02 +00:00
|
|
|
bool valid = false;
|
2017-04-21 23:15:42 +00:00
|
|
|
|
2020-01-07 12:29:02 +00:00
|
|
|
// Look for export templates (first official, and if defined custom templates).
|
2017-04-21 23:15:42 +00:00
|
|
|
|
2020-01-07 12:29:02 +00:00
|
|
|
bool use64 = p_preset->get("binary_format/64_bits");
|
|
|
|
bool dvalid = exists_export_template(use64 ? debug_file_64 : debug_file_32, &err);
|
|
|
|
bool rvalid = exists_export_template(use64 ? release_file_64 : release_file_32, &err);
|
2017-04-21 23:15:42 +00:00
|
|
|
|
2020-01-07 12:29:02 +00:00
|
|
|
if (p_preset->get("custom_template/debug") != "") {
|
|
|
|
dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
|
|
|
|
if (!dvalid) {
|
|
|
|
err += TTR("Custom debug template not found.") + "\n";
|
|
|
|
}
|
2017-04-21 23:15:42 +00:00
|
|
|
}
|
2020-01-07 12:29:02 +00:00
|
|
|
if (p_preset->get("custom_template/release") != "") {
|
|
|
|
rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
|
|
|
|
if (!rvalid) {
|
|
|
|
err += TTR("Custom release template not found.") + "\n";
|
|
|
|
}
|
2017-02-22 00:30:20 +00:00
|
|
|
}
|
2017-03-21 02:31:41 +00:00
|
|
|
|
2019-06-26 13:08:25 +00:00
|
|
|
valid = dvalid || rvalid;
|
2020-01-07 12:29:02 +00:00
|
|
|
r_missing_templates = !valid;
|
2017-04-21 23:15:42 +00:00
|
|
|
|
2020-12-15 12:04:21 +00:00
|
|
|
if (!err.is_empty()) {
|
2017-04-21 23:15:42 +00:00
|
|
|
r_error = err;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-04-21 23:15:42 +00:00
|
|
|
return valid;
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 21:18:49 +00:00
|
|
|
List<String> EditorExportPlatformPC::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
|
|
|
|
List<String> list;
|
2021-08-09 20:13:42 +00:00
|
|
|
for (const KeyValue<String, String> &E : extensions) {
|
|
|
|
if (p_preset->get(E.key)) {
|
|
|
|
list.push_back(extensions[E.key]);
|
2018-10-29 21:18:49 +00:00
|
|
|
return list;
|
2017-12-12 21:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extensions.has("default")) {
|
2018-10-29 21:18:49 +00:00
|
|
|
list.push_back(extensions["default"]);
|
|
|
|
return list;
|
2017-12-12 21:09:48 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 21:18:49 +00:00
|
|
|
return list;
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Error EditorExportPlatformPC::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
2017-10-02 15:01:43 +00:00
|
|
|
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
|
2017-02-20 02:19:30 +00:00
|
|
|
|
2017-03-21 22:34:26 +00:00
|
|
|
String custom_debug = p_preset->get("custom_template/debug");
|
|
|
|
String custom_release = p_preset->get("custom_template/release");
|
|
|
|
|
|
|
|
String template_path = p_debug ? custom_debug : custom_release;
|
|
|
|
|
|
|
|
template_path = template_path.strip_edges();
|
|
|
|
|
2021-12-09 09:42:46 +00:00
|
|
|
if (template_path.is_empty()) {
|
2017-03-21 22:34:26 +00:00
|
|
|
if (p_preset->get("binary_format/64_bits")) {
|
|
|
|
if (p_debug) {
|
|
|
|
template_path = find_export_template(debug_file_64);
|
|
|
|
} else {
|
|
|
|
template_path = find_export_template(release_file_64);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (p_debug) {
|
|
|
|
template_path = find_export_template(debug_file_32);
|
|
|
|
} else {
|
|
|
|
template_path = find_export_template(release_file_32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!template_path.is_empty() && !FileAccess::exists(template_path)) {
|
2018-01-04 19:00:39 +00:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Template file not found:") + "\n" + template_path);
|
2017-03-21 22:34:26 +00:00
|
|
|
return ERR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2022-03-10 12:33:54 +00:00
|
|
|
DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
da->make_dir_recursive(p_path.get_base_dir());
|
2017-09-17 17:40:58 +00:00
|
|
|
Error err = da->copy(template_path, p_path, get_chmod_flags());
|
2019-03-25 19:56:33 +00:00
|
|
|
|
2018-03-06 15:13:18 +00:00
|
|
|
if (err == OK) {
|
2019-03-25 19:56:33 +00:00
|
|
|
String pck_path;
|
|
|
|
if (p_preset->get("binary_format/embed_pck")) {
|
|
|
|
pck_path = p_path;
|
|
|
|
} else {
|
|
|
|
pck_path = p_path.get_basename() + ".pck";
|
|
|
|
}
|
2017-03-21 22:34:26 +00:00
|
|
|
|
2018-03-06 15:13:18 +00:00
|
|
|
Vector<SharedObject> so_files;
|
2018-01-04 18:42:29 +00:00
|
|
|
|
2019-03-25 19:56:33 +00:00
|
|
|
int64_t embedded_pos;
|
|
|
|
int64_t embedded_size;
|
2022-03-10 07:48:25 +00:00
|
|
|
err = save_pack(p_preset, p_debug, pck_path, &so_files, p_preset->get("binary_format/embed_pck"), &embedded_pos, &embedded_size);
|
2019-03-25 19:56:33 +00:00
|
|
|
if (err == OK && p_preset->get("binary_format/embed_pck")) {
|
|
|
|
if (embedded_size >= 0x100000000 && !p_preset->get("binary_format/64_bits")) {
|
|
|
|
EditorNode::get_singleton()->show_warning(TTR("On 32-bit exports the embedded PCK cannot be bigger than 4 GiB."));
|
2020-01-07 12:29:02 +00:00
|
|
|
return ERR_INVALID_PARAMETER;
|
2019-03-25 19:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FixUpEmbeddedPckFunc fixup_func = get_fixup_embedded_pck_func();
|
|
|
|
if (fixup_func) {
|
|
|
|
err = fixup_func(p_path, embedded_pos, embedded_size);
|
|
|
|
}
|
|
|
|
}
|
2018-01-04 18:42:29 +00:00
|
|
|
|
2020-12-15 12:04:21 +00:00
|
|
|
if (err == OK && !so_files.is_empty()) {
|
2022-03-10 07:48:25 +00:00
|
|
|
// If shared object files, copy them.
|
2018-03-06 15:13:18 +00:00
|
|
|
da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
for (int i = 0; i < so_files.size() && err == OK; i++) {
|
2022-03-10 07:48:25 +00:00
|
|
|
String src_path = ProjectSettings::get_singleton()->globalize_path(so_files[i].path);
|
|
|
|
String target_path;
|
|
|
|
if (so_files[i].target.is_empty()) {
|
|
|
|
target_path = p_path.get_base_dir().plus_file(src_path.get_file());
|
|
|
|
} else {
|
|
|
|
target_path = p_path.get_base_dir().plus_file(so_files[i].target).plus_file(src_path.get_file());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (da->dir_exists(src_path)) {
|
|
|
|
err = da->make_dir_recursive(target_path);
|
|
|
|
if (err == OK) {
|
|
|
|
err = da->copy_dir(src_path, target_path, -1, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
err = da->copy(src_path, target_path);
|
|
|
|
if (err == OK) {
|
|
|
|
err = sign_shared_object(p_preset, p_debug, target_path);
|
|
|
|
}
|
2019-10-04 15:01:13 +00:00
|
|
|
}
|
2018-03-06 15:13:18 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-04 18:42:29 +00:00
|
|
|
}
|
2018-03-06 15:13:18 +00:00
|
|
|
|
|
|
|
return err;
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 15:01:13 +00:00
|
|
|
Error EditorExportPlatformPC::sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-12-12 21:09:48 +00:00
|
|
|
void EditorExportPlatformPC::set_extension(const String &p_extension, const String &p_feature_key) {
|
|
|
|
extensions[p_feature_key] = p_extension;
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPlatformPC::set_name(const String &p_name) {
|
|
|
|
name = p_name;
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
void EditorExportPlatformPC::set_os_name(const String &p_name) {
|
|
|
|
os_name = p_name;
|
|
|
|
}
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
void EditorExportPlatformPC::set_logo(const Ref<Texture2D> &p_logo) {
|
2017-03-05 15:44:50 +00:00
|
|
|
logo = p_logo;
|
2017-02-20 02:19:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPlatformPC::set_release_64(const String &p_file) {
|
|
|
|
release_file_64 = p_file;
|
2017-02-22 00:30:20 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPlatformPC::set_release_32(const String &p_file) {
|
|
|
|
release_file_32 = p_file;
|
2017-02-22 00:30:20 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPlatformPC::set_debug_64(const String &p_file) {
|
|
|
|
debug_file_64 = p_file;
|
2017-02-22 00:30:20 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorExportPlatformPC::set_debug_32(const String &p_file) {
|
|
|
|
debug_file_32 = p_file;
|
2017-02-22 00:30:20 +00:00
|
|
|
}
|
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
void EditorExportPlatformPC::get_platform_features(List<String> *r_features) {
|
|
|
|
r_features->push_back("pc"); //all pcs support "pc"
|
|
|
|
r_features->push_back("s3tc"); //all pcs support "s3tc" compression
|
2021-03-26 14:33:36 +00:00
|
|
|
r_features->push_back(get_os_name().to_lower()); //OS name is a feature
|
2017-07-19 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 02:56:04 +00:00
|
|
|
void EditorExportPlatformPC::resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
|
|
|
|
if (p_features.has("bptc")) {
|
|
|
|
if (p_preset->has("texture_format/no_bptc_fallbacks")) {
|
|
|
|
p_features.erase("s3tc");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-17 17:40:58 +00:00
|
|
|
int EditorExportPlatformPC::get_chmod_flags() const {
|
|
|
|
return chmod_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPlatformPC::set_chmod_flags(int p_flags) {
|
|
|
|
chmod_flags = p_flags;
|
|
|
|
}
|
|
|
|
|
2019-03-25 19:56:33 +00:00
|
|
|
EditorExportPlatformPC::FixUpEmbeddedPckFunc EditorExportPlatformPC::get_fixup_embedded_pck_func() const {
|
|
|
|
return fixup_embedded_pck_func;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPlatformPC::set_fixup_embedded_pck_func(FixUpEmbeddedPckFunc p_fixup_embedded_pck_func) {
|
|
|
|
fixup_embedded_pck_func = p_fixup_embedded_pck_func;
|
|
|
|
}
|
|
|
|
|
2017-02-20 02:19:30 +00:00
|
|
|
EditorExportPlatformPC::EditorExportPlatformPC() {
|
2017-09-17 17:40:58 +00:00
|
|
|
chmod_flags = -1;
|
2020-04-01 23:20:12 +00:00
|
|
|
fixup_embedded_pck_func = nullptr;
|
2017-02-13 01:51:16 +00:00
|
|
|
}
|
2017-12-15 11:38:24 +00:00
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
|
|
|
|
void EditorExportTextSceneToBinaryPlugin::_export_file(const String &p_path, const String &p_type, const Set<String> &p_features) {
|
|
|
|
String extension = p_path.get_extension().to_lower();
|
|
|
|
if (extension != "tres" && extension != "tscn") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-17 16:44:49 +00:00
|
|
|
bool convert = GLOBAL_GET("editor/export/convert_text_resources_to_binary");
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!convert) {
|
2017-12-15 11:38:24 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2021-05-25 00:25:11 +00:00
|
|
|
String tmp_path = EditorPaths::get_singleton()->get_cache_dir().plus_file("tmpfile.res");
|
2017-12-15 11:38:24 +00:00
|
|
|
Error err = ResourceFormatLoaderText::convert_file_to_binary(p_path, tmp_path);
|
2019-08-09 11:45:30 +00:00
|
|
|
if (err != OK) {
|
|
|
|
DirAccess::remove_file_or_error(tmp_path);
|
|
|
|
ERR_FAIL();
|
|
|
|
}
|
2017-12-15 11:38:24 +00:00
|
|
|
Vector<uint8_t> data = FileAccess::get_file_as_array(tmp_path);
|
2019-08-09 11:45:30 +00:00
|
|
|
if (data.size() == 0) {
|
|
|
|
DirAccess::remove_file_or_error(tmp_path);
|
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
DirAccess::remove_file_or_error(tmp_path);
|
2017-12-15 11:38:24 +00:00
|
|
|
add_file(p_path + ".converted.res", data, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorExportTextSceneToBinaryPlugin::EditorExportTextSceneToBinaryPlugin() {
|
2021-02-17 16:44:49 +00:00
|
|
|
GLOBAL_DEF("editor/export/convert_text_resources_to_binary", false);
|
2017-12-15 11:38:24 +00:00
|
|
|
}
|