editor_export.h 16 KB

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