editor_export.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /**************************************************************************/
  2. /* editor_export.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_H
  31. #define EDITOR_EXPORT_H
  32. #include "core/os/dir_access.h"
  33. #include "core/resource.h"
  34. #include "scene/gui/rich_text_label.h"
  35. #include "scene/main/node.h"
  36. #include "scene/main/timer.h"
  37. #include "scene/resources/texture.h"
  38. class FileAccess;
  39. class EditorExportPlatform;
  40. class EditorFileSystemDirectory;
  41. struct EditorProgress;
  42. class EditorExportPreset : public Reference {
  43. GDCLASS(EditorExportPreset, Reference);
  44. public:
  45. enum ExportFilter {
  46. EXPORT_ALL_RESOURCES,
  47. EXPORT_SELECTED_SCENES,
  48. EXPORT_SELECTED_RESOURCES,
  49. };
  50. enum ScriptExportMode {
  51. MODE_SCRIPT_TEXT,
  52. MODE_SCRIPT_COMPILED,
  53. MODE_SCRIPT_ENCRYPTED,
  54. };
  55. private:
  56. Ref<EditorExportPlatform> platform;
  57. ExportFilter export_filter;
  58. String include_filter;
  59. String exclude_filter;
  60. String export_path;
  61. String exporter;
  62. Set<String> selected_files;
  63. bool runnable;
  64. friend class EditorExport;
  65. friend class EditorExportPlatform;
  66. List<PropertyInfo> properties;
  67. Map<StringName, Variant> values;
  68. Map<StringName, bool> update_visibility;
  69. String name;
  70. String custom_features;
  71. int script_mode;
  72. String script_key;
  73. protected:
  74. bool _set(const StringName &p_name, const Variant &p_value);
  75. bool _get(const StringName &p_name, Variant &r_ret) const;
  76. void _get_property_list(List<PropertyInfo> *p_list) const;
  77. public:
  78. Ref<EditorExportPlatform> get_platform() const;
  79. bool has(const StringName &p_property) const { return values.has(p_property); }
  80. void update_files_to_export();
  81. Vector<String> get_files_to_export() const;
  82. void add_export_file(const String &p_path);
  83. void remove_export_file(const String &p_path);
  84. bool has_export_file(const String &p_path);
  85. void set_name(const String &p_name);
  86. String get_name() const;
  87. void set_runnable(bool p_enable);
  88. bool is_runnable() const;
  89. void set_export_filter(ExportFilter p_filter);
  90. ExportFilter get_export_filter() const;
  91. void set_include_filter(const String &p_include);
  92. String get_include_filter() const;
  93. void set_exclude_filter(const String &p_exclude);
  94. String get_exclude_filter() const;
  95. void set_custom_features(const String &p_custom_features);
  96. String get_custom_features() const;
  97. void set_export_path(const String &p_path);
  98. String get_export_path() const;
  99. void set_script_export_mode(int p_mode);
  100. int get_script_export_mode() const;
  101. void set_script_encryption_key(const String &p_key);
  102. String get_script_encryption_key() const;
  103. const List<PropertyInfo> &get_properties() const { return properties; }
  104. EditorExportPreset();
  105. };
  106. struct SharedObject {
  107. String path;
  108. Vector<String> tags;
  109. SharedObject(const String &p_path, const Vector<String> &p_tags) :
  110. path(p_path),
  111. tags(p_tags) {
  112. }
  113. SharedObject() {}
  114. };
  115. class EditorExportPlatform : public Reference {
  116. GDCLASS(EditorExportPlatform, Reference);
  117. public:
  118. typedef Error (*EditorExportSaveFunction)(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
  119. typedef Error (*EditorExportSaveSharedObject)(void *p_userdata, const SharedObject &p_so);
  120. enum ExportMessageType {
  121. EXPORT_MESSAGE_NONE,
  122. EXPORT_MESSAGE_INFO,
  123. EXPORT_MESSAGE_WARNING,
  124. EXPORT_MESSAGE_ERROR,
  125. };
  126. struct ExportMessage {
  127. ExportMessageType msg_type;
  128. String category;
  129. String text;
  130. };
  131. private:
  132. struct SavedData {
  133. uint64_t ofs;
  134. uint64_t size;
  135. Vector<uint8_t> md5;
  136. CharString path_utf8;
  137. bool operator<(const SavedData &p_data) const {
  138. return path_utf8 < p_data.path_utf8;
  139. }
  140. };
  141. struct PackData {
  142. FileAccess *f;
  143. Vector<SavedData> file_ofs;
  144. EditorProgress *ep;
  145. Vector<SharedObject> *so_files;
  146. };
  147. struct ZipData {
  148. void *zip;
  149. EditorProgress *ep;
  150. };
  151. struct FeatureContainers {
  152. Set<String> features;
  153. PoolVector<String> features_pv;
  154. };
  155. Vector<ExportMessage> messages;
  156. void _export_find_resources(EditorFileSystemDirectory *p_dir, Set<String> &p_paths);
  157. void _export_find_dependencies(const String &p_path, Set<String> &p_paths);
  158. void gen_debug_flags(Vector<String> &r_flags, int p_flags);
  159. static Error _save_pack_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
  160. static Error _save_zip_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
  161. void _edit_files_with_filter(DirAccess *da, const Vector<String> &p_filters, Set<String> &r_list, bool exclude);
  162. void _edit_filter_list(Set<String> &r_list, const String &p_filter, bool exclude);
  163. static Error _add_shared_object(void *p_userdata, const SharedObject &p_so);
  164. protected:
  165. struct ExportNotifier {
  166. ExportNotifier(EditorExportPlatform &p_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags);
  167. ~ExportNotifier();
  168. };
  169. FeatureContainers get_feature_containers(const Ref<EditorExportPreset> &p_preset);
  170. bool exists_export_template(String template_file_name, String *err) const;
  171. String find_export_template(String template_file_name, String *err = nullptr) const;
  172. void gen_export_flags(Vector<String> &r_flags, int p_flags);
  173. public:
  174. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) = 0;
  175. struct ExportOption {
  176. PropertyInfo option;
  177. Variant default_value;
  178. bool update_visibility = false;
  179. ExportOption(const PropertyInfo &p_info, const Variant &p_default, bool p_update_visibility = false) :
  180. option(p_info),
  181. default_value(p_default),
  182. update_visibility(p_update_visibility) {
  183. }
  184. ExportOption() {}
  185. };
  186. virtual Ref<EditorExportPreset> create_preset();
  187. virtual void clear_messages() { messages.clear(); }
  188. virtual void add_message(ExportMessageType p_type, const String &p_category, const String &p_message) {
  189. ExportMessage msg;
  190. msg.category = p_category;
  191. msg.text = p_message;
  192. msg.msg_type = p_type;
  193. messages.push_back(msg);
  194. switch (p_type) {
  195. case EXPORT_MESSAGE_INFO: {
  196. print_line(vformat("%s: %s", msg.category, msg.text));
  197. } break;
  198. case EXPORT_MESSAGE_WARNING: {
  199. WARN_PRINT(vformat("%s: %s", msg.category, msg.text));
  200. } break;
  201. case EXPORT_MESSAGE_ERROR: {
  202. ERR_PRINT(vformat("%s: %s", msg.category, msg.text));
  203. } break;
  204. default:
  205. break;
  206. }
  207. }
  208. virtual int get_message_count() const {
  209. return messages.size();
  210. }
  211. virtual ExportMessage get_message(int p_index) const {
  212. ERR_FAIL_INDEX_V(p_index, messages.size(), ExportMessage());
  213. return messages[p_index];
  214. }
  215. virtual ExportMessageType get_worst_message_type() const {
  216. ExportMessageType worst_type = EXPORT_MESSAGE_NONE;
  217. for (int i = 0; i < messages.size(); i++) {
  218. worst_type = MAX(worst_type, messages[i].msg_type);
  219. }
  220. return worst_type;
  221. }
  222. virtual bool fill_log_messages(RichTextLabel *p_log, Error p_err);
  223. virtual void get_export_options(List<ExportOption> *r_options) = 0;
  224. virtual bool should_update_export_options() { return false; }
  225. virtual bool get_option_visibility(const EditorExportPreset *p_preset, const String &p_option, const Map<StringName, Variant> &p_options) const { return true; }
  226. virtual String get_os_name() const = 0;
  227. virtual String get_name() const = 0;
  228. virtual Ref<Texture> get_logo() const = 0;
  229. Error export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func = nullptr);
  230. Error save_pack(const Ref<EditorExportPreset> &p_preset, 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);
  231. Error save_zip(const Ref<EditorExportPreset> &p_preset, const String &p_path);
  232. virtual bool poll_export() { return false; }
  233. virtual int get_options_count() const { return 0; }
  234. virtual String get_options_tooltip() const { return ""; }
  235. virtual Ref<ImageTexture> get_option_icon(int p_index) const;
  236. virtual String get_option_label(int p_device) const { return ""; }
  237. virtual String get_option_tooltip(int p_device) const { return ""; }
  238. enum DebugFlags {
  239. DEBUG_FLAG_DUMB_CLIENT = 1,
  240. DEBUG_FLAG_REMOTE_DEBUG = 2,
  241. DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST = 4,
  242. DEBUG_FLAG_VIEW_COLLISONS = 8,
  243. DEBUG_FLAG_VIEW_NAVIGATION = 16,
  244. DEBUG_FLAG_SHADER_FALLBACKS = 32,
  245. };
  246. virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) { return OK; }
  247. virtual Ref<Texture> get_run_icon() const { return get_logo(); }
  248. String test_etc2() const; //generic test for etc2 since most platforms use it
  249. String test_etc2_or_pvrtc() const; // test for etc2 or pvrtc support for iOS
  250. bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  251. virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const = 0;
  252. virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const = 0;
  253. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const = 0;
  254. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) = 0;
  255. virtual Error export_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  256. virtual Error export_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  257. virtual void get_platform_features(List<String> *r_features) = 0;
  258. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) = 0;
  259. EditorExportPlatform();
  260. };
  261. class EditorExportPlugin : public Reference {
  262. GDCLASS(EditorExportPlugin, Reference);
  263. friend class EditorExportPlatform;
  264. Ref<EditorExportPreset> export_preset;
  265. Vector<SharedObject> shared_objects;
  266. struct ExtraFile {
  267. String path;
  268. Vector<uint8_t> data;
  269. bool remap;
  270. };
  271. Vector<ExtraFile> extra_files;
  272. bool skipped;
  273. Vector<String> ios_frameworks;
  274. Vector<String> ios_embedded_frameworks;
  275. Vector<String> ios_project_static_libs;
  276. String ios_plist_content;
  277. String ios_linker_flags;
  278. Vector<String> ios_bundle_files;
  279. String ios_cpp_code;
  280. Vector<String> osx_plugin_files;
  281. _FORCE_INLINE_ void _clear() {
  282. shared_objects.clear();
  283. extra_files.clear();
  284. skipped = false;
  285. }
  286. _FORCE_INLINE_ void _export_end() {
  287. ios_frameworks.clear();
  288. ios_embedded_frameworks.clear();
  289. ios_bundle_files.clear();
  290. ios_plist_content = "";
  291. ios_linker_flags = "";
  292. ios_cpp_code = "";
  293. osx_plugin_files.clear();
  294. }
  295. void _export_file_script(const String &p_path, const String &p_type, const PoolVector<String> &p_features);
  296. void _export_begin_script(const PoolVector<String> &p_features, bool p_debug, const String &p_path, int p_flags);
  297. void _export_end_script();
  298. protected:
  299. void set_export_preset(const Ref<EditorExportPreset> &p_preset);
  300. Ref<EditorExportPreset> get_export_preset() const;
  301. void add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap);
  302. void add_shared_object(const String &p_path, const Vector<String> &tags);
  303. void add_ios_framework(const String &p_path);
  304. void add_ios_embedded_framework(const String &p_path);
  305. void add_ios_project_static_lib(const String &p_path);
  306. void add_ios_plist_content(const String &p_plist_content);
  307. void add_ios_linker_flags(const String &p_flags);
  308. void add_ios_bundle_file(const String &p_path);
  309. void add_ios_cpp_code(const String &p_code);
  310. void add_osx_plugin_file(const String &p_path);
  311. void skip();
  312. virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features);
  313. virtual void _export_begin(const Set<String> &p_features, bool p_debug, const String &p_path, int p_flags);
  314. static void _bind_methods();
  315. public:
  316. Vector<String> get_ios_frameworks() const;
  317. Vector<String> get_ios_embedded_frameworks() const;
  318. Vector<String> get_ios_project_static_libs() const;
  319. String get_ios_plist_content() const;
  320. String get_ios_linker_flags() const;
  321. Vector<String> get_ios_bundle_files() const;
  322. String get_ios_cpp_code() const;
  323. const Vector<String> &get_osx_plugin_files() const;
  324. EditorExportPlugin();
  325. };
  326. class EditorExport : public Node {
  327. GDCLASS(EditorExport, Node);
  328. Vector<Ref<EditorExportPlatform>> export_platforms;
  329. Vector<Ref<EditorExportPreset>> export_presets;
  330. Vector<Ref<EditorExportPlugin>> export_plugins;
  331. StringName _export_presets_updated;
  332. Timer *save_timer;
  333. bool block_save;
  334. static EditorExport *singleton;
  335. void _save();
  336. protected:
  337. friend class EditorExportPreset;
  338. void save_presets();
  339. void _notification(int p_what);
  340. static void _bind_methods();
  341. public:
  342. static EditorExport *get_singleton() { return singleton; }
  343. void add_export_platform(const Ref<EditorExportPlatform> &p_platform);
  344. int get_export_platform_count();
  345. Ref<EditorExportPlatform> get_export_platform(int p_idx);
  346. void add_export_preset(const Ref<EditorExportPreset> &p_preset, int p_at_pos = -1);
  347. int get_export_preset_count() const;
  348. Ref<EditorExportPreset> get_export_preset(int p_idx);
  349. void remove_export_preset(int p_idx);
  350. void add_export_plugin(const Ref<EditorExportPlugin> &p_plugin);
  351. void remove_export_plugin(const Ref<EditorExportPlugin> &p_plugin);
  352. Vector<Ref<EditorExportPlugin>> get_export_plugins();
  353. void load_config();
  354. void update_export_presets();
  355. bool poll_export_platforms();
  356. EditorExport();
  357. ~EditorExport();
  358. };
  359. class EditorExportPlatformPC : public EditorExportPlatform {
  360. GDCLASS(EditorExportPlatformPC, EditorExportPlatform);
  361. private:
  362. Ref<ImageTexture> logo;
  363. String name;
  364. String os_name;
  365. Map<String, String> extensions;
  366. String release_file_32;
  367. String release_file_64;
  368. String debug_file_32;
  369. String debug_file_64;
  370. // For Linux only.
  371. Map<String, String> release_files;
  372. Map<String, String> debug_files;
  373. Set<String> extra_features;
  374. int chmod_flags;
  375. public:
  376. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
  377. virtual void get_export_options(List<ExportOption> *r_options);
  378. virtual String get_name() const;
  379. virtual String get_os_name() const;
  380. virtual Ref<Texture> get_logo() const;
  381. virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  382. virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const;
  383. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;
  384. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  385. virtual Error sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
  386. virtual Error prepare_template(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags);
  387. virtual Error modify_template(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) { return OK; }
  388. virtual Error export_project_data(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags);
  389. virtual Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) { return OK; }
  390. void set_extension(const String &p_extension, const String &p_feature_key = "default");
  391. void set_name(const String &p_name);
  392. void set_os_name(const String &p_name);
  393. void set_logo(const Ref<Texture> &p_logo);
  394. void set_release_64(const String &p_file);
  395. void set_release_32(const String &p_file);
  396. void set_debug_64(const String &p_file);
  397. void set_debug_32(const String &p_file);
  398. // For Linux only.
  399. void set_release_files(const String &p_arch, const String &p_file);
  400. void set_debug_files(const String &p_arch, const String &p_file);
  401. String get_preset_arch(const Ref<EditorExportPreset> &p_preset) const;
  402. void add_platform_feature(const String &p_feature);
  403. virtual void get_platform_features(List<String> *r_features);
  404. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features);
  405. int get_chmod_flags() const;
  406. void set_chmod_flags(int p_flags);
  407. EditorExportPlatformPC();
  408. };
  409. class EditorExportTextSceneToBinaryPlugin : public EditorExportPlugin {
  410. GDCLASS(EditorExportTextSceneToBinaryPlugin, EditorExportPlugin);
  411. public:
  412. virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features);
  413. EditorExportTextSceneToBinaryPlugin();
  414. };
  415. #endif // EDITOR_EXPORT_H