editor_export_platform.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*************************************************************************/
  2. /* editor_export_platform.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 "editor_export_preset.h"
  36. #include "editor_export_shared_object.h"
  37. #include "scene/gui/rich_text_label.h"
  38. #include "scene/main/node.h"
  39. class EditorExportPlatform : public RefCounted {
  40. GDCLASS(EditorExportPlatform, RefCounted);
  41. public:
  42. 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);
  43. typedef Error (*EditorExportSaveSharedObject)(void *p_userdata, const SharedObject &p_so);
  44. enum ExportMessageType {
  45. EXPORT_MESSAGE_NONE,
  46. EXPORT_MESSAGE_INFO,
  47. EXPORT_MESSAGE_WARNING,
  48. EXPORT_MESSAGE_ERROR,
  49. };
  50. struct ExportMessage {
  51. ExportMessageType msg_type;
  52. String category;
  53. String text;
  54. };
  55. private:
  56. struct SavedData {
  57. uint64_t ofs = 0;
  58. uint64_t size = 0;
  59. bool encrypted = false;
  60. Vector<uint8_t> md5;
  61. CharString path_utf8;
  62. bool operator<(const SavedData &p_data) const {
  63. return path_utf8 < p_data.path_utf8;
  64. }
  65. };
  66. struct PackData {
  67. Ref<FileAccess> f;
  68. Vector<SavedData> file_ofs;
  69. EditorProgress *ep = nullptr;
  70. Vector<SharedObject> *so_files = nullptr;
  71. };
  72. struct ZipData {
  73. void *zip = nullptr;
  74. EditorProgress *ep = nullptr;
  75. };
  76. Vector<ExportMessage> messages;
  77. void _export_find_resources(EditorFileSystemDirectory *p_dir, HashSet<String> &p_paths);
  78. void _export_find_dependencies(const String &p_path, HashSet<String> &p_paths);
  79. void gen_debug_flags(Vector<String> &r_flags, int p_flags);
  80. 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);
  81. 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);
  82. void _edit_files_with_filter(Ref<DirAccess> &da, const Vector<String> &p_filters, HashSet<String> &r_list, bool exclude);
  83. void _edit_filter_list(HashSet<String> &r_list, const String &p_filter, bool exclude);
  84. static Error _add_shared_object(void *p_userdata, const SharedObject &p_so);
  85. protected:
  86. struct ExportNotifier {
  87. ExportNotifier(EditorExportPlatform &p_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags);
  88. ~ExportNotifier();
  89. };
  90. HashSet<String> get_features(const Ref<EditorExportPreset> &p_preset, bool p_debug) const;
  91. bool exists_export_template(String template_file_name, String *err) const;
  92. String find_export_template(String template_file_name, String *err = nullptr) const;
  93. void gen_export_flags(Vector<String> &r_flags, int p_flags);
  94. public:
  95. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const = 0;
  96. struct ExportOption {
  97. PropertyInfo option;
  98. Variant default_value;
  99. bool update_visibility = false;
  100. ExportOption(const PropertyInfo &p_info, const Variant &p_default, bool p_update_visibility = false) :
  101. option(p_info),
  102. default_value(p_default),
  103. update_visibility(p_update_visibility) {
  104. }
  105. ExportOption() {}
  106. };
  107. virtual Ref<EditorExportPreset> create_preset();
  108. virtual void clear_messages() { messages.clear(); }
  109. virtual void add_message(ExportMessageType p_type, const String &p_category, const String &p_message) {
  110. ExportMessage msg;
  111. msg.category = p_category;
  112. msg.text = p_message;
  113. msg.msg_type = p_type;
  114. messages.push_back(msg);
  115. switch (p_type) {
  116. case EXPORT_MESSAGE_INFO: {
  117. print_line(vformat("%s: %s", msg.category, msg.text));
  118. } break;
  119. case EXPORT_MESSAGE_WARNING: {
  120. WARN_PRINT(vformat("%s: %s", msg.category, msg.text));
  121. } break;
  122. case EXPORT_MESSAGE_ERROR: {
  123. ERR_PRINT(vformat("%s: %s", msg.category, msg.text));
  124. } break;
  125. default:
  126. break;
  127. }
  128. }
  129. virtual int get_message_count() const {
  130. return messages.size();
  131. }
  132. virtual ExportMessage get_message(int p_index) const {
  133. ERR_FAIL_INDEX_V(p_index, messages.size(), ExportMessage());
  134. return messages[p_index];
  135. }
  136. virtual ExportMessageType get_worst_message_type() const {
  137. ExportMessageType worst_type = EXPORT_MESSAGE_NONE;
  138. for (int i = 0; i < messages.size(); i++) {
  139. worst_type = MAX(worst_type, messages[i].msg_type);
  140. }
  141. return worst_type;
  142. }
  143. virtual bool fill_log_messages(RichTextLabel *p_log, Error p_err);
  144. virtual void get_export_options(List<ExportOption> *r_options) = 0;
  145. virtual bool should_update_export_options() { return false; }
  146. virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option, const HashMap<StringName, Variant> &p_options) const { return true; }
  147. virtual String get_os_name() const = 0;
  148. virtual String get_name() const = 0;
  149. virtual Ref<Texture2D> get_logo() const = 0;
  150. Error export_project_files(const Ref<EditorExportPreset> &p_preset, bool p_debug, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func = nullptr);
  151. 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);
  152. Error save_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
  153. virtual bool poll_export() { return false; }
  154. virtual int get_options_count() const { return 0; }
  155. virtual String get_options_tooltip() const { return ""; }
  156. virtual Ref<ImageTexture> get_option_icon(int p_index) const;
  157. virtual String get_option_label(int p_device) const { return ""; }
  158. virtual String get_option_tooltip(int p_device) const { return ""; }
  159. enum DebugFlags {
  160. DEBUG_FLAG_DUMB_CLIENT = 1,
  161. DEBUG_FLAG_REMOTE_DEBUG = 2,
  162. DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST = 4,
  163. DEBUG_FLAG_VIEW_COLLISONS = 8,
  164. DEBUG_FLAG_VIEW_NAVIGATION = 16,
  165. };
  166. virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) { return OK; }
  167. virtual Ref<Texture2D> get_run_icon() const { return get_logo(); }
  168. String test_etc2() const;
  169. bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  170. virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const = 0;
  171. virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const = 0;
  172. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const = 0;
  173. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) = 0;
  174. virtual Error export_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  175. virtual Error export_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  176. virtual void get_platform_features(List<String> *r_features) const = 0;
  177. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) = 0;
  178. virtual String get_debug_protocol() const { return "tcp://"; }
  179. EditorExportPlatform();
  180. };
  181. #endif // EDITOR_EXPORT_PLATFORM_H