| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/io/zip_io.h" |
| 34 |
#include "core/os/os.h" |
| 35 |
#include "editor/export/editor_export_preset.h" |
| 36 |
|
| 37 |
class DirAccess; |
| 38 |
class EditorExportPlugin; |
| 39 |
class EditorFileSystemDirectory; |
| 40 |
class Image; |
| 41 |
class Node; |
| 42 |
class RichTextLabel; |
| 43 |
class Texture2D; |
| 44 |
struct EditorProgress; |
| 45 |
struct SharedObject; |
| 46 |
|
| 47 |
const String ENV_SCRIPT_ENCRYPTION_KEY = "GODOT_SCRIPT_ENCRYPTION_KEY"; |
| 48 |
|
| 49 |
class EditorExportPlatform : public RefCounted { |
| 50 |
GDCLASS(EditorExportPlatform, RefCounted); |
| 51 |
|
| 52 |
protected: |
| 53 |
static void _bind_methods(); |
| 54 |
|
| 55 |
public: |
| 56 |
typedef Error (*EditorExportSaveFunction)(const Ref<EditorExportPreset> &p_preset, 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, uint64_t p_seed, bool p_delta); |
| 57 |
typedef Error (*EditorExportRemoveFunction)(const Ref<EditorExportPreset> &p_preset, void *p_userdata, const String &p_path); |
| 58 |
typedef Error (*EditorExportSaveSharedObject)(const Ref<EditorExportPreset> &p_preset, void *p_userdata, const SharedObject &p_so); |
| 59 |
|
| 60 |
enum DebugFlags { |
| 61 |
DEBUG_FLAG_DUMB_CLIENT = 1, |
| 62 |
DEBUG_FLAG_REMOTE_DEBUG = 2, |
| 63 |
DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST = 4, |
| 64 |
DEBUG_FLAG_VIEW_COLLISIONS = 8, |
| 65 |
DEBUG_FLAG_VIEW_NAVIGATION = 16, |
| 66 |
}; |
| 67 |
|
| 68 |
enum ExportMessageType { |
| 69 |
EXPORT_MESSAGE_NONE, |
| 70 |
EXPORT_MESSAGE_INFO, |
| 71 |
EXPORT_MESSAGE_WARNING, |
| 72 |
EXPORT_MESSAGE_ERROR, |
| 73 |
}; |
| 74 |
|
| 75 |
struct ExportMessage { |
| 76 |
ExportMessageType msg_type; |
| 77 |
String category; |
| 78 |
String text; |
| 79 |
}; |
| 80 |
|
| 81 |
struct SavedData { |
| 82 |
uint64_t ofs = 0; |
| 83 |
uint64_t size = 0; |
| 84 |
bool encrypted = false; |
| 85 |
bool removal = false; |
| 86 |
bool delta = false; |
| 87 |
Vector<uint8_t> md5; |
| 88 |
CharString path_utf8; |
| 89 |
|
| 90 |
bool operator<(const SavedData &p_data) const { |
| 91 |
return path_utf8 < p_data.path_utf8; |
| 92 |
} |
| 93 |
}; |
| 94 |
|
| 95 |
struct PackData { |
| 96 |
String path; |
| 97 |
Ref<FileAccess> f; |
| 98 |
Vector<SavedData> file_ofs; |
| 99 |
EditorProgress *ep = nullptr; |
| 100 |
Vector<SharedObject> *so_files = nullptr; |
| 101 |
bool use_sparse_pck = false; |
| 102 |
}; |
| 103 |
|
| 104 |
static bool _store_header(Ref<FileAccess> p_fd, bool p_enc, bool p_sparse, uint64_t &r_file_base_ofs, uint64_t &r_dir_base_ofs); |
| 105 |
static bool _encrypt_and_store_directory(Ref<FileAccess> p_fd, PackData &p_pack_data, const Vector<uint8_t> &p_key, uint64_t p_seed, uint64_t p_file_base); |
| 106 |
static Error _encrypt_and_store_data(Ref<FileAccess> p_fd, const String &p_path, const Vector<uint8_t> &p_data, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key, uint64_t p_seed, bool &r_encrypt); |
| 107 |
String _get_script_encryption_key(const Ref<EditorExportPreset> &p_preset) const; |
| 108 |
|
| 109 |
private: |
| 110 |
struct ZipData { |
| 111 |
void *zip = nullptr; |
| 112 |
EditorProgress *ep = nullptr; |
| 113 |
Vector<SharedObject> *so_files = nullptr; |
| 114 |
int file_count = 0; |
| 115 |
}; |
| 116 |
|
| 117 |
Vector<ExportMessage> messages; |
| 118 |
|
| 119 |
void _export_find_resources(EditorFileSystemDirectory *p_dir, HashSet<String> &p_paths); |
| 120 |
void _export_find_customized_resources(const Ref<EditorExportPreset> &p_preset, EditorFileSystemDirectory *p_dir, EditorExportPreset::FileExportMode p_mode, HashSet<String> &p_paths); |
| 121 |
void _export_find_dependencies(const String &p_path, HashSet<String> &p_paths); |
| 122 |
|
| 123 |
static Error _save_pack_file(const Ref<EditorExportPreset> &p_preset, 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, uint64_t p_seed, bool p_delta); |
| 124 |
static Error _save_pack_patch_file(const Ref<EditorExportPreset> &p_preset, 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, uint64_t p_seed, bool p_delta); |
| 125 |
static Error _pack_add_shared_object(const Ref<EditorExportPreset> &p_preset, void *p_userdata, const SharedObject &p_so); |
| 126 |
|
| 127 |
static Error _remove_pack_file(const Ref<EditorExportPreset> &p_preset, void *p_userdata, const String &p_path); |
| 128 |
|
| 129 |
static Error _save_zip_file(const Ref<EditorExportPreset> &p_preset, 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, uint64_t p_seed, bool p_delta); |
| 130 |
static Error _save_zip_patch_file(const Ref<EditorExportPreset> &p_preset, 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, uint64_t p_seed, bool p_delta); |
| 131 |
static Error _zip_add_shared_object(const Ref<EditorExportPreset> &p_preset, void *p_userdata, const SharedObject &p_so); |
| 132 |
|
| 133 |
struct ScriptCallbackData { |
| 134 |
Callable file_cb; |
| 135 |
Callable so_cb; |
| 136 |
}; |
| 137 |
|
| 138 |
static Error _script_save_file(const Ref<EditorExportPreset> &p_preset, 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, uint64_t p_seed, bool p_delta); |
| 139 |
static Error _script_add_shared_object(const Ref<EditorExportPreset> &p_preset, void *p_userdata, const SharedObject &p_so); |
| 140 |
|
| 141 |
void _edit_files_with_filter(Ref<DirAccess> &da, const Vector<String> &p_filters, HashSet<String> &r_list, bool exclude); |
| 142 |
void _edit_filter_list(HashSet<String> &r_list, const String &p_filter, bool exclude); |
| 143 |
|
| 144 |
static Vector<uint8_t> _filter_extension_list_config_file(const String &p_config_path, const HashSet<String> &p_paths); |
| 145 |
|
| 146 |
struct FileExportCache { |
| 147 |
uint64_t source_modified_time = 0; |
| 148 |
String source_md5; |
| 149 |
String saved_path; |
| 150 |
bool used = false; |
| 151 |
}; |
| 152 |
|
| 153 |
bool _export_customize_dictionary(Dictionary &dict, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins); |
| 154 |
bool _export_customize_array(Array &array, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins); |
| 155 |
bool _export_customize_object(Object *p_object, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins); |
| 156 |
bool _export_customize_scene_resources(Node *p_root, Node *p_node, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins); |
| 157 |
bool _is_editable_ancestor(Node *p_root, Node *p_node); |
| 158 |
|
| 159 |
String _export_customize(const String &p_path, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins, LocalVector<Ref<EditorExportPlugin>> &customize_scenes_plugins, HashMap<String, FileExportCache> &export_cache, const String &export_base_path, bool p_force_save); |
| 160 |
|
| 161 |
protected: |
| 162 |
struct ExportNotifier { |
| 163 |
ExportNotifier(EditorExportPlatform &p_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags); |
| 164 |
~ExportNotifier(); |
| 165 |
}; |
| 166 |
|
| 167 |
HashSet<String> get_features(const Ref<EditorExportPreset> &p_preset, bool p_debug) const; |
| 168 |
|
| 169 |
Dictionary _find_export_template(const String &p_template_file_name) const { |
| 170 |
Dictionary ret; |
| 171 |
String err; |
| 172 |
|
| 173 |
String path = find_export_template(p_template_file_name, &err); |
| 174 |
ret["result"] = (err.is_empty() && !path.is_empty()) ? OK : FAILED; |
| 175 |
ret["path"] = path; |
| 176 |
ret["error_string"] = err; |
| 177 |
|
| 178 |
return ret; |
| 179 |
} |
| 180 |
|
| 181 |
bool exists_export_template(const String &p_template_file_name, String *r_err) const; |
| 182 |
String find_export_template(const String &p_template_file_name, String *r_err = nullptr) const; |
| 183 |
Vector<String> gen_export_flags(BitField<EditorExportPlatform::DebugFlags> p_flags); |
| 184 |
|
| 185 |
virtual void zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name); |
| 186 |
|
| 187 |
Error _ssh_run_on_remote(const String &p_host, const String &p_port, const Vector<String> &p_ssh_args, const String &p_cmd_args, Array r_output = Array(), int p_port_fwd = -1) const { |
| 188 |
String pipe; |
| 189 |
Error err = ssh_run_on_remote(p_host, p_port, p_ssh_args, p_cmd_args, &pipe, p_port_fwd); |
| 190 |
r_output.push_back(pipe); |
| 191 |
return err; |
| 192 |
} |
| 193 |
OS::ProcessID _ssh_run_on_remote_no_wait(const String &p_host, const String &p_port, const Vector<String> &p_ssh_args, const String &p_cmd_args, int p_port_fwd = -1) const { |
| 194 |
OS::ProcessID pid = 0; |
| 195 |
Error err = ssh_run_on_remote_no_wait(p_host, p_port, p_ssh_args, p_cmd_args, &pid, p_port_fwd); |
| 196 |
if (err != OK) { |
| 197 |
return -1; |
| 198 |
} else { |
| 199 |
return pid; |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
Error ssh_run_on_remote(const String &p_host, const String &p_port, const Vector<String> &p_ssh_args, const String &p_cmd_args, String *r_out = nullptr, int p_port_fwd = -1) const; |
| 204 |
Error ssh_run_on_remote_no_wait(const String &p_host, const String &p_port, const Vector<String> &p_ssh_args, const String &p_cmd_args, OS::ProcessID *r_pid = nullptr, int p_port_fwd = -1) const; |
| 205 |
Error ssh_push_to_remote(const String &p_host, const String &p_port, const Vector<String> &p_scp_args, const String &p_src_file, const String &p_dst_file) const; |
| 206 |
|
| 207 |
Error _load_patches(const Vector<String> &p_patches); |
| 208 |
void _unload_patches(); |
| 209 |
|
| 210 |
Ref<Image> _load_icon_or_splash_image(const String &p_path, Error *r_error) const; |
| 211 |
|
| 212 |
#ifndef DISABLE_DEPRECATED |
| 213 |
static Vector<String> _get_forced_export_files_bind_compat_71542(); |
| 214 |
static void _bind_compatibility_methods(); |
| 215 |
#endif |
| 216 |
|
| 217 |
public: |
| 218 |
static String simplify_path(const String &p_path); |
| 219 |
static Variant get_project_setting(const Ref<EditorExportPreset> &p_preset, const StringName &p_name); |
| 220 |
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const = 0; |
| 221 |
|
| 222 |
struct ExportOption { |
| 223 |
PropertyInfo option; |
| 224 |
Variant default_value; |
| 225 |
bool update_visibility = false; |
| 226 |
bool required = false; |
| 227 |
|
| 228 |
ExportOption(const PropertyInfo &p_info, const Variant &p_default, bool p_update_visibility = false, bool p_required = false) : |
| 229 |
option(p_info), |
| 230 |
default_value(p_default), |
| 231 |
update_visibility(p_update_visibility), |
| 232 |
required(p_required) { |
| 233 |
} |
| 234 |
ExportOption() {} |
| 235 |
}; |
| 236 |
|
| 237 |
virtual Ref<EditorExportPreset> create_preset(); |
| 238 |
virtual bool is_executable(const String &p_path) const { return false; } |
| 239 |
|
| 240 |
virtual void clear_messages() { messages.clear(); } |
| 241 |
virtual void add_message(ExportMessageType p_type, const String &p_category, const String &p_message) { |
| 242 |
ExportMessage msg; |
| 243 |
msg.category = p_category; |
| 244 |
msg.text = p_message; |
| 245 |
msg.msg_type = p_type; |
| 246 |
messages.push_back(msg); |
| 247 |
switch (p_type) { |
| 248 |
case EXPORT_MESSAGE_INFO: { |
| 249 |
print_line(vformat("%s: %s", msg.category, msg.text)); |
| 250 |
} break; |
| 251 |
case EXPORT_MESSAGE_WARNING: { |
| 252 |
WARN_PRINT(vformat("%s: %s", msg.category, msg.text)); |
| 253 |
} break; |
| 254 |
case EXPORT_MESSAGE_ERROR: { |
| 255 |
ERR_PRINT(vformat("%s: %s", msg.category, msg.text)); |
| 256 |
} break; |
| 257 |
default: |
| 258 |
break; |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
virtual int get_message_count() const { |
| 263 |
return messages.size(); |
| 264 |
} |
| 265 |
|
| 266 |
virtual ExportMessage get_message(int p_index) const { |
| 267 |
ERR_FAIL_INDEX_V(p_index, messages.size(), ExportMessage()); |
| 268 |
return messages[p_index]; |
| 269 |
} |
| 270 |
|
| 271 |
virtual ExportMessageType _get_message_type(int p_index) const { |
| 272 |
ERR_FAIL_INDEX_V(p_index, messages.size(), EXPORT_MESSAGE_NONE); |
| 273 |
return messages[p_index].msg_type; |
| 274 |
} |
| 275 |
|
| 276 |
virtual String _get_message_category(int p_index) const { |
| 277 |
ERR_FAIL_INDEX_V(p_index, messages.size(), String()); |
| 278 |
return messages[p_index].category; |
| 279 |
} |
| 280 |
|
| 281 |
virtual String _get_message_text(int p_index) const { |
| 282 |
ERR_FAIL_INDEX_V(p_index, messages.size(), String()); |
| 283 |
return messages[p_index].text; |
| 284 |
} |
| 285 |
|
| 286 |
virtual ExportMessageType get_worst_message_type() const { |
| 287 |
ExportMessageType worst_type = EXPORT_MESSAGE_NONE; |
| 288 |
for (int i = 0; i < messages.size(); i++) { |
| 289 |
worst_type = MAX(worst_type, messages[i].msg_type); |
| 290 |
} |
| 291 |
return worst_type; |
| 292 |
} |
| 293 |
|
| 294 |
Dictionary get_internal_export_files(const Ref<EditorExportPreset> &p_preset, bool p_debug); |
| 295 |
|
| 296 |
static Vector<String> get_forced_export_files(const Ref<EditorExportPreset> &p_preset); |
| 297 |
|
| 298 |
virtual bool fill_log_messages(RichTextLabel *p_log, Error p_err); |
| 299 |
|
| 300 |
virtual void get_export_options(List<ExportOption> *r_options) const = 0; |
| 301 |
virtual bool should_update_export_options() { return false; } |
| 302 |
virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const { return true; } |
| 303 |
virtual String get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const { return String(); } |
| 304 |
|
| 305 |
virtual String get_os_name() const = 0; |
| 306 |
virtual String get_name() const = 0; |
| 307 |
virtual Ref<Texture2D> get_logo() const = 0; |
| 308 |
|
| 309 |
Array get_current_presets() const; |
| 310 |
|
| 311 |
Error _export_project_files(const Ref<EditorExportPreset> &p_preset, bool p_debug, const Callable &p_save_func, const Callable &p_so_func); |
| 312 |
Error export_project_files(const Ref<EditorExportPreset> &p_preset, bool p_debug, EditorExportSaveFunction p_save_func, EditorExportRemoveFunction p_remove_func, void *p_udata, EditorExportSaveSharedObject p_so_func = nullptr); |
| 313 |
|
| 314 |
Dictionary _save_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, bool p_embed = false); |
| 315 |
Dictionary _save_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path); |
| 316 |
|
| 317 |
Dictionary _save_pack_patch(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path); |
| 318 |
Dictionary _save_zip_patch(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path); |
| 319 |
|
| 320 |
Error save_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, Vector<SharedObject> *p_so_files = nullptr, EditorExportSaveFunction p_save_func = nullptr, EditorExportRemoveFunction p_remove_func = nullptr, bool p_embed = false, int64_t *r_embedded_start = nullptr, int64_t *r_embedded_size = nullptr); |
| 321 |
Error save_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, Vector<SharedObject> *p_so_files = nullptr, EditorExportSaveFunction p_save_func = nullptr); |
| 322 |
|
| 323 |
Error save_pack_patch(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, Vector<SharedObject> *p_so_files = nullptr, bool p_embed = false, int64_t *r_embedded_start = nullptr, int64_t *r_embedded_size = nullptr); |
| 324 |
Error save_zip_patch(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, Vector<SharedObject> *p_so_files = nullptr); |
| 325 |
|
| 326 |
virtual bool poll_export() { return false; } |
| 327 |
virtual int get_options_count() const { return 0; } |
| 328 |
virtual bool is_option_runnable(int p_index) const { return true; } |
| 329 |
virtual String get_options_tooltip() const { return ""; } |
| 330 |
virtual Ref<Texture2D> get_option_icon(int p_index) const; |
| 331 |
virtual String get_option_label(int p_device) const { return ""; } |
| 332 |
virtual String get_option_tooltip(int p_device) const { return ""; } |
| 333 |
virtual String get_device_architecture(int p_device) const { return ""; } |
| 334 |
|
| 335 |
virtual void cleanup() {} |
| 336 |
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) { return OK; } |
| 337 |
virtual Ref<Texture2D> get_run_icon() const { return get_logo(); } |
| 338 |
|
| 339 |
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const; |
| 340 |
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const = 0; |
| 341 |
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const = 0; |
| 342 |
|
| 343 |
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const = 0; |
| 344 |
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags = 0) = 0; |
| 345 |
virtual Error export_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags = 0); |
| 346 |
virtual Error export_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags = 0); |
| 347 |
virtual Error export_pack_patch(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, const Vector<String> &p_patches = Vector<String>(), BitField<EditorExportPlatform::DebugFlags> p_flags = 0); |
| 348 |
virtual Error export_zip_patch(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, const Vector<String> &p_patches = Vector<String>(), BitField<EditorExportPlatform::DebugFlags> p_flags = 0); |
| 349 |
virtual void get_platform_features(List<String> *r_features) const = 0; |
| 350 |
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) {} |
| 351 |
virtual String get_debug_protocol() const { return "tcp://"; } |
| 352 |
virtual HashMap<String, Variant> get_custom_project_settings(const Ref<EditorExportPreset> &p_preset) const { return HashMap<String, Variant>(); } |
| 353 |
|
| 354 |
virtual void initialize() {} |
| 355 |
}; |
| 356 |
|
| 357 |
VARIANT_ENUM_CAST(EditorExportPlatform::ExportMessageType) |
| 358 |
VARIANT_BITFIELD_CAST(EditorExportPlatform::DebugFlags); |