editor_export_platform.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. class EditorExportPlugin;
  41. class EditorExportPlatform : public RefCounted {
  42. GDCLASS(EditorExportPlatform, RefCounted);
  43. public:
  44. 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);
  45. typedef Error (*EditorExportSaveSharedObject)(void *p_userdata, const SharedObject &p_so);
  46. enum ExportMessageType {
  47. EXPORT_MESSAGE_NONE,
  48. EXPORT_MESSAGE_INFO,
  49. EXPORT_MESSAGE_WARNING,
  50. EXPORT_MESSAGE_ERROR,
  51. };
  52. struct ExportMessage {
  53. ExportMessageType msg_type;
  54. String category;
  55. String text;
  56. };
  57. private:
  58. struct SavedData {
  59. uint64_t ofs = 0;
  60. uint64_t size = 0;
  61. bool encrypted = false;
  62. Vector<uint8_t> md5;
  63. CharString path_utf8;
  64. bool operator<(const SavedData &p_data) const {
  65. return path_utf8 < p_data.path_utf8;
  66. }
  67. };
  68. struct PackData {
  69. Ref<FileAccess> f;
  70. Vector<SavedData> file_ofs;
  71. EditorProgress *ep = nullptr;
  72. Vector<SharedObject> *so_files = nullptr;
  73. };
  74. struct ZipData {
  75. void *zip = nullptr;
  76. EditorProgress *ep = nullptr;
  77. };
  78. Vector<ExportMessage> messages;
  79. void _export_find_resources(EditorFileSystemDirectory *p_dir, HashSet<String> &p_paths);
  80. void _export_find_customized_resources(const Ref<EditorExportPreset> &p_preset, EditorFileSystemDirectory *p_dir, EditorExportPreset::FileExportMode p_mode, HashSet<String> &p_paths);
  81. void _export_find_dependencies(const String &p_path, HashSet<String> &p_paths);
  82. 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);
  83. 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);
  84. void _edit_files_with_filter(Ref<DirAccess> &da, const Vector<String> &p_filters, HashSet<String> &r_list, bool exclude);
  85. void _edit_filter_list(HashSet<String> &r_list, const String &p_filter, bool exclude);
  86. static Error _add_shared_object(void *p_userdata, const SharedObject &p_so);
  87. struct FileExportCache {
  88. uint64_t source_modified_time = 0;
  89. String source_md5;
  90. String saved_path;
  91. bool used = false;
  92. };
  93. bool _export_customize_dictionary(Dictionary &dict, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins);
  94. bool _export_customize_array(Array &array, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins);
  95. bool _export_customize_object(Object *p_object, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins);
  96. bool _export_customize_scene_resources(Node *p_root, Node *p_node, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins);
  97. bool _is_editable_ancestor(Node *p_root, Node *p_node);
  98. 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);
  99. protected:
  100. struct ExportNotifier {
  101. ExportNotifier(EditorExportPlatform &p_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags);
  102. ~ExportNotifier();
  103. };
  104. HashSet<String> get_features(const Ref<EditorExportPreset> &p_preset, bool p_debug) const;
  105. bool exists_export_template(String template_file_name, String *err) const;
  106. String find_export_template(String template_file_name, String *err = nullptr) const;
  107. void gen_export_flags(Vector<String> &r_flags, int p_flags);
  108. void gen_debug_flags(Vector<String> &r_flags, int p_flags);
  109. virtual void zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name);
  110. 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;
  111. 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;
  112. 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;
  113. public:
  114. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const = 0;
  115. struct ExportOption {
  116. PropertyInfo option;
  117. Variant default_value;
  118. bool update_visibility = false;
  119. bool required = false;
  120. ExportOption(const PropertyInfo &p_info, const Variant &p_default, bool p_update_visibility = false, bool p_required = false) :
  121. option(p_info),
  122. default_value(p_default),
  123. update_visibility(p_update_visibility),
  124. required(p_required) {
  125. }
  126. ExportOption() {}
  127. };
  128. virtual Ref<EditorExportPreset> create_preset();
  129. virtual bool is_executable(const String &p_path) const { return false; }
  130. virtual void clear_messages() { messages.clear(); }
  131. virtual void add_message(ExportMessageType p_type, const String &p_category, const String &p_message) {
  132. ExportMessage msg;
  133. msg.category = p_category;
  134. msg.text = p_message;
  135. msg.msg_type = p_type;
  136. messages.push_back(msg);
  137. switch (p_type) {
  138. case EXPORT_MESSAGE_INFO: {
  139. print_line(vformat("%s: %s", msg.category, msg.text));
  140. } break;
  141. case EXPORT_MESSAGE_WARNING: {
  142. WARN_PRINT(vformat("%s: %s", msg.category, msg.text));
  143. } break;
  144. case EXPORT_MESSAGE_ERROR: {
  145. ERR_PRINT(vformat("%s: %s", msg.category, msg.text));
  146. } break;
  147. default:
  148. break;
  149. }
  150. }
  151. virtual int get_message_count() const {
  152. return messages.size();
  153. }
  154. virtual ExportMessage get_message(int p_index) const {
  155. ERR_FAIL_INDEX_V(p_index, messages.size(), ExportMessage());
  156. return messages[p_index];
  157. }
  158. virtual ExportMessageType get_worst_message_type() const {
  159. ExportMessageType worst_type = EXPORT_MESSAGE_NONE;
  160. for (int i = 0; i < messages.size(); i++) {
  161. worst_type = MAX(worst_type, messages[i].msg_type);
  162. }
  163. return worst_type;
  164. }
  165. virtual bool fill_log_messages(RichTextLabel *p_log, Error p_err);
  166. virtual void get_export_options(List<ExportOption> *r_options) const = 0;
  167. virtual bool should_update_export_options() { return false; }
  168. virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const { return true; }
  169. virtual String get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const { return String(); }
  170. virtual String get_os_name() const = 0;
  171. virtual String get_name() const = 0;
  172. virtual Ref<Texture2D> get_logo() const = 0;
  173. Error export_project_files(const Ref<EditorExportPreset> &p_preset, bool p_debug, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func = nullptr);
  174. 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);
  175. Error save_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
  176. virtual bool poll_export() { return false; }
  177. virtual int get_options_count() const { return 0; }
  178. virtual String get_options_tooltip() const { return ""; }
  179. virtual Ref<ImageTexture> get_option_icon(int p_index) const;
  180. virtual String get_option_label(int p_device) const { return ""; }
  181. virtual String get_option_tooltip(int p_device) const { return ""; }
  182. enum DebugFlags {
  183. DEBUG_FLAG_DUMB_CLIENT = 1,
  184. DEBUG_FLAG_REMOTE_DEBUG = 2,
  185. DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST = 4,
  186. DEBUG_FLAG_VIEW_COLLISIONS = 8,
  187. DEBUG_FLAG_VIEW_NAVIGATION = 16,
  188. };
  189. virtual void cleanup() {}
  190. virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) { return OK; }
  191. virtual Ref<Texture2D> get_run_icon() const { return get_logo(); }
  192. String test_etc2() const;
  193. String test_bc() const;
  194. bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  195. virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const = 0;
  196. virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const = 0;
  197. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const = 0;
  198. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) = 0;
  199. virtual Error export_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  200. virtual Error export_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  201. virtual void get_platform_features(List<String> *r_features) const = 0;
  202. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) = 0;
  203. virtual String get_debug_protocol() const { return "tcp://"; }
  204. EditorExportPlatform();
  205. };
  206. #endif // EDITOR_EXPORT_PLATFORM_H