editor_export_platform.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /**************************************************************************/
  2. /* editor_export_platform.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef EDITOR_EXPORT_PLATFORM_H
  31. #define EDITOR_EXPORT_PLATFORM_H
  32. class EditorFileSystemDirectory;
  33. struct EditorProgress;
  34. #include "core/io/dir_access.h"
  35. #include "core/io/zip_io.h"
  36. #include "editor_export_preset.h"
  37. #include "editor_export_shared_object.h"
  38. #include "scene/gui/rich_text_label.h"
  39. #include "scene/main/node.h"
  40. #include "scene/resources/image_texture.h"
  41. class EditorExportPlugin;
  42. const String ENV_SCRIPT_ENCRYPTION_KEY = "GODOT_SCRIPT_ENCRYPTION_KEY";
  43. class EditorExportPlatform : public RefCounted {
  44. GDCLASS(EditorExportPlatform, RefCounted);
  45. public:
  46. typedef Error (*EditorExportSaveFunction)(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);
  47. typedef Error (*EditorExportSaveSharedObject)(void *p_userdata, const SharedObject &p_so);
  48. enum ExportMessageType {
  49. EXPORT_MESSAGE_NONE,
  50. EXPORT_MESSAGE_INFO,
  51. EXPORT_MESSAGE_WARNING,
  52. EXPORT_MESSAGE_ERROR,
  53. };
  54. struct ExportMessage {
  55. ExportMessageType msg_type;
  56. String category;
  57. String text;
  58. };
  59. private:
  60. struct SavedData {
  61. uint64_t ofs = 0;
  62. uint64_t size = 0;
  63. bool encrypted = false;
  64. Vector<uint8_t> md5;
  65. CharString path_utf8;
  66. bool operator<(const SavedData &p_data) const {
  67. return path_utf8 < p_data.path_utf8;
  68. }
  69. };
  70. struct PackData {
  71. Ref<FileAccess> f;
  72. Vector<SavedData> file_ofs;
  73. EditorProgress *ep = nullptr;
  74. Vector<SharedObject> *so_files = nullptr;
  75. };
  76. struct ZipData {
  77. void *zip = nullptr;
  78. EditorProgress *ep = nullptr;
  79. };
  80. Vector<ExportMessage> messages;
  81. void _export_find_resources(EditorFileSystemDirectory *p_dir, HashSet<String> &p_paths);
  82. void _export_find_customized_resources(const Ref<EditorExportPreset> &p_preset, EditorFileSystemDirectory *p_dir, EditorExportPreset::FileExportMode p_mode, HashSet<String> &p_paths);
  83. void _export_find_dependencies(const String &p_path, HashSet<String> &p_paths);
  84. static Error _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);
  85. static Error _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);
  86. void _edit_files_with_filter(Ref<DirAccess> &da, const Vector<String> &p_filters, HashSet<String> &r_list, bool exclude);
  87. void _edit_filter_list(HashSet<String> &r_list, const String &p_filter, bool exclude);
  88. static Error _add_shared_object(void *p_userdata, const SharedObject &p_so);
  89. struct FileExportCache {
  90. uint64_t source_modified_time = 0;
  91. String source_md5;
  92. String saved_path;
  93. bool used = false;
  94. };
  95. bool _export_customize_dictionary(Dictionary &dict, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins);
  96. bool _export_customize_array(Array &array, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins);
  97. bool _export_customize_object(Object *p_object, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins);
  98. bool _export_customize_scene_resources(Node *p_root, Node *p_node, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins);
  99. bool _is_editable_ancestor(Node *p_root, Node *p_node);
  100. 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);
  101. String _get_script_encryption_key(const Ref<EditorExportPreset> &p_preset) const;
  102. protected:
  103. struct ExportNotifier {
  104. ExportNotifier(EditorExportPlatform &p_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags);
  105. ~ExportNotifier();
  106. };
  107. HashSet<String> get_features(const Ref<EditorExportPreset> &p_preset, bool p_debug) const;
  108. bool exists_export_template(String template_file_name, String *err) const;
  109. String find_export_template(String template_file_name, String *err = nullptr) const;
  110. void gen_export_flags(Vector<String> &r_flags, int p_flags);
  111. void gen_debug_flags(Vector<String> &r_flags, int p_flags);
  112. virtual void zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name);
  113. 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;
  114. 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;
  115. 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;
  116. public:
  117. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const = 0;
  118. struct ExportOption {
  119. PropertyInfo option;
  120. Variant default_value;
  121. bool update_visibility = false;
  122. bool required = false;
  123. ExportOption(const PropertyInfo &p_info, const Variant &p_default, bool p_update_visibility = false, bool p_required = false) :
  124. option(p_info),
  125. default_value(p_default),
  126. update_visibility(p_update_visibility),
  127. required(p_required) {
  128. }
  129. ExportOption() {}
  130. };
  131. virtual Ref<EditorExportPreset> create_preset();
  132. virtual bool is_executable(const String &p_path) const { return false; }
  133. virtual void clear_messages() { messages.clear(); }
  134. virtual void add_message(ExportMessageType p_type, const String &p_category, const String &p_message) {
  135. ExportMessage msg;
  136. msg.category = p_category;
  137. msg.text = p_message;
  138. msg.msg_type = p_type;
  139. messages.push_back(msg);
  140. switch (p_type) {
  141. case EXPORT_MESSAGE_INFO: {
  142. print_line(vformat("%s: %s", msg.category, msg.text));
  143. } break;
  144. case EXPORT_MESSAGE_WARNING: {
  145. WARN_PRINT(vformat("%s: %s", msg.category, msg.text));
  146. } break;
  147. case EXPORT_MESSAGE_ERROR: {
  148. ERR_PRINT(vformat("%s: %s", msg.category, msg.text));
  149. } break;
  150. default:
  151. break;
  152. }
  153. }
  154. virtual int get_message_count() const {
  155. return messages.size();
  156. }
  157. virtual ExportMessage get_message(int p_index) const {
  158. ERR_FAIL_INDEX_V(p_index, messages.size(), ExportMessage());
  159. return messages[p_index];
  160. }
  161. virtual ExportMessageType get_worst_message_type() const {
  162. ExportMessageType worst_type = EXPORT_MESSAGE_NONE;
  163. for (int i = 0; i < messages.size(); i++) {
  164. worst_type = MAX(worst_type, messages[i].msg_type);
  165. }
  166. return worst_type;
  167. }
  168. static Vector<String> get_forced_export_files();
  169. virtual bool fill_log_messages(RichTextLabel *p_log, Error p_err);
  170. virtual void get_export_options(List<ExportOption> *r_options) const = 0;
  171. virtual bool should_update_export_options() { return false; }
  172. virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const { return true; }
  173. virtual String get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const { return String(); }
  174. virtual String get_os_name() const = 0;
  175. virtual String get_name() const = 0;
  176. virtual Ref<Texture2D> get_logo() const = 0;
  177. Error export_project_files(const Ref<EditorExportPreset> &p_preset, bool p_debug, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func = nullptr);
  178. Error save_pack(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);
  179. Error save_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
  180. virtual bool poll_export() { return false; }
  181. virtual int get_options_count() const { return 0; }
  182. virtual String get_options_tooltip() const { return ""; }
  183. virtual Ref<ImageTexture> get_option_icon(int p_index) const;
  184. virtual String get_option_label(int p_device) const { return ""; }
  185. virtual String get_option_tooltip(int p_device) const { return ""; }
  186. enum DebugFlags {
  187. DEBUG_FLAG_DUMB_CLIENT = 1,
  188. DEBUG_FLAG_REMOTE_DEBUG = 2,
  189. DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST = 4,
  190. DEBUG_FLAG_VIEW_COLLISIONS = 8,
  191. DEBUG_FLAG_VIEW_NAVIGATION = 16,
  192. };
  193. virtual void cleanup() {}
  194. virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) { return OK; }
  195. virtual Ref<Texture2D> get_run_icon() const { return get_logo(); }
  196. String test_etc2() const;
  197. String test_bc() const;
  198. bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const;
  199. virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const = 0;
  200. virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const = 0;
  201. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const = 0;
  202. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) = 0;
  203. virtual Error export_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  204. virtual Error export_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  205. virtual void get_platform_features(List<String> *r_features) const = 0;
  206. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) = 0;
  207. virtual String get_debug_protocol() const { return "tcp://"; }
  208. EditorExportPlatform();
  209. };
  210. #endif // EDITOR_EXPORT_PLATFORM_H