editor_export.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /*************************************************************************/
  2. /* editor_export.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. Vector<String> get_files_to_export() const;
  80. void add_export_file(const String &p_path);
  81. void remove_export_file(const String &p_path);
  82. bool has_export_file(const String &p_path);
  83. void set_name(const String &p_name);
  84. String get_name() const;
  85. void set_runnable(bool p_enable);
  86. bool is_runnable() const;
  87. void set_export_filter(ExportFilter p_filter);
  88. ExportFilter get_export_filter() const;
  89. void set_include_filter(const String &p_include);
  90. String get_include_filter() const;
  91. void set_exclude_filter(const String &p_exclude);
  92. String get_exclude_filter() const;
  93. void add_patch(const String &p_path, int p_at_pos = -1);
  94. void set_patch(int p_index, const String &p_path);
  95. String get_patch(int p_index);
  96. void remove_patch(int p_idx);
  97. Vector<String> get_patches() const;
  98. void set_custom_features(const String &p_custom_features);
  99. String get_custom_features() const;
  100. void set_export_path(const String &p_path);
  101. String get_export_path() const;
  102. void set_script_export_mode(int p_mode);
  103. int get_script_export_mode() const;
  104. void set_script_encryption_key(const String &p_key);
  105. String get_script_encryption_key() const;
  106. const List<PropertyInfo> &get_properties() const { return properties; }
  107. EditorExportPreset();
  108. };
  109. struct SharedObject {
  110. String path;
  111. Vector<String> tags;
  112. SharedObject(const String &p_path, const Vector<String> &p_tags) :
  113. path(p_path),
  114. tags(p_tags) {
  115. }
  116. SharedObject() {}
  117. };
  118. class EditorExportPlatform : public Reference {
  119. GDCLASS(EditorExportPlatform, Reference)
  120. public:
  121. typedef Error (*EditorExportSaveFunction)(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
  122. typedef Error (*EditorExportSaveSharedObject)(void *p_userdata, const SharedObject &p_so);
  123. private:
  124. struct SavedData {
  125. uint64_t ofs;
  126. uint64_t size;
  127. Vector<uint8_t> md5;
  128. CharString path_utf8;
  129. bool operator<(const SavedData &p_data) const {
  130. return path_utf8 < p_data.path_utf8;
  131. }
  132. };
  133. struct PackData {
  134. FileAccess *f;
  135. Vector<SavedData> file_ofs;
  136. EditorProgress *ep;
  137. Vector<SharedObject> *so_files;
  138. };
  139. struct ZipData {
  140. void *zip;
  141. EditorProgress *ep;
  142. };
  143. struct FeatureContainers {
  144. Set<String> features;
  145. PoolVector<String> features_pv;
  146. };
  147. void _export_find_resources(EditorFileSystemDirectory *p_dir, Set<String> &p_paths);
  148. void _export_find_dependencies(const String &p_path, Set<String> &p_paths);
  149. void gen_debug_flags(Vector<String> &r_flags, int p_flags);
  150. static Error _save_pack_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
  151. static Error _save_zip_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
  152. void _edit_files_with_filter(DirAccess *da, const Vector<String> &p_filters, Set<String> &r_list, bool exclude);
  153. void _edit_filter_list(Set<String> &r_list, const String &p_filter, bool exclude);
  154. static Error _add_shared_object(void *p_userdata, const SharedObject &p_so);
  155. protected:
  156. struct ExportNotifier {
  157. ExportNotifier(EditorExportPlatform &p_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags);
  158. ~ExportNotifier();
  159. };
  160. FeatureContainers get_feature_containers(const Ref<EditorExportPreset> &p_preset);
  161. bool exists_export_template(String template_file_name, String *err) const;
  162. String find_export_template(String template_file_name, String *err = NULL) const;
  163. void gen_export_flags(Vector<String> &r_flags, int p_flags);
  164. public:
  165. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) = 0;
  166. struct ExportOption {
  167. PropertyInfo option;
  168. Variant default_value;
  169. ExportOption(const PropertyInfo &p_info, const Variant &p_default) :
  170. option(p_info),
  171. default_value(p_default) {
  172. }
  173. ExportOption() {}
  174. };
  175. virtual Ref<EditorExportPreset> create_preset();
  176. virtual void get_export_options(List<ExportOption> *r_options) = 0;
  177. virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { return true; }
  178. virtual String get_os_name() const = 0;
  179. virtual String get_name() const = 0;
  180. virtual Ref<Texture> get_logo() const = 0;
  181. Error export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func = NULL);
  182. Error save_pack(const Ref<EditorExportPreset> &p_preset, const String &p_path, Vector<SharedObject> *p_so_files = NULL);
  183. Error save_zip(const Ref<EditorExportPreset> &p_preset, const String &p_path);
  184. virtual bool poll_devices() { return false; }
  185. virtual int get_device_count() const { return 0; }
  186. virtual String get_device_name(int p_device) const { return ""; }
  187. virtual String get_device_info(int p_device) const { return ""; }
  188. enum DebugFlags {
  189. DEBUG_FLAG_DUMB_CLIENT = 1,
  190. DEBUG_FLAG_REMOTE_DEBUG = 2,
  191. DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST = 4,
  192. DEBUG_FLAG_VIEW_COLLISONS = 8,
  193. DEBUG_FLAG_VIEW_NAVIGATION = 16,
  194. };
  195. virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) { return OK; }
  196. virtual Ref<Texture> get_run_icon() const { return get_logo(); }
  197. String test_etc2() const; //generic test for etc2 since most platforms use it
  198. virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const = 0;
  199. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const = 0;
  200. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) = 0;
  201. virtual Error export_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  202. virtual Error export_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  203. virtual void get_platform_features(List<String> *r_features) = 0;
  204. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) = 0;
  205. EditorExportPlatform();
  206. };
  207. class EditorExportPlugin : public Reference {
  208. GDCLASS(EditorExportPlugin, Reference)
  209. friend class EditorExportPlatform;
  210. Ref<EditorExportPreset> export_preset;
  211. Vector<SharedObject> shared_objects;
  212. struct ExtraFile {
  213. String path;
  214. Vector<uint8_t> data;
  215. bool remap;
  216. };
  217. Vector<ExtraFile> extra_files;
  218. bool skipped;
  219. Vector<String> ios_frameworks;
  220. String ios_plist_content;
  221. String ios_linker_flags;
  222. Vector<String> ios_bundle_files;
  223. String ios_cpp_code;
  224. _FORCE_INLINE_ void _clear() {
  225. shared_objects.clear();
  226. extra_files.clear();
  227. skipped = false;
  228. }
  229. _FORCE_INLINE_ void _export_end() {
  230. ios_frameworks.clear();
  231. ios_bundle_files.clear();
  232. ios_plist_content = "";
  233. ios_linker_flags = "";
  234. ios_cpp_code = "";
  235. }
  236. void _export_file_script(const String &p_path, const String &p_type, const PoolVector<String> &p_features);
  237. void _export_begin_script(const PoolVector<String> &p_features, bool p_debug, const String &p_path, int p_flags);
  238. void _export_end_script();
  239. protected:
  240. void set_export_preset(const Ref<EditorExportPreset> &p_preset);
  241. Ref<EditorExportPreset> get_export_preset() const;
  242. void add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap);
  243. void add_shared_object(const String &p_path, const Vector<String> &tags);
  244. void add_ios_framework(const String &p_path);
  245. void add_ios_plist_content(const String &p_plist_content);
  246. void add_ios_linker_flags(const String &p_flags);
  247. void add_ios_bundle_file(const String &p_path);
  248. void add_ios_cpp_code(const String &p_code);
  249. void skip();
  250. virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features);
  251. virtual void _export_begin(const Set<String> &p_features, bool p_debug, const String &p_path, int p_flags);
  252. static void _bind_methods();
  253. public:
  254. Vector<String> get_ios_frameworks() const;
  255. String get_ios_plist_content() const;
  256. String get_ios_linker_flags() const;
  257. Vector<String> get_ios_bundle_files() const;
  258. String get_ios_cpp_code() const;
  259. EditorExportPlugin();
  260. };
  261. class EditorExport : public Node {
  262. GDCLASS(EditorExport, Node);
  263. Vector<Ref<EditorExportPlatform> > export_platforms;
  264. Vector<Ref<EditorExportPreset> > export_presets;
  265. Vector<Ref<EditorExportPlugin> > export_plugins;
  266. Timer *save_timer;
  267. bool block_save;
  268. static EditorExport *singleton;
  269. void _save();
  270. protected:
  271. friend class EditorExportPreset;
  272. void save_presets();
  273. void _notification(int p_what);
  274. static void _bind_methods();
  275. public:
  276. static EditorExport *get_singleton() { return singleton; }
  277. void add_export_platform(const Ref<EditorExportPlatform> &p_platform);
  278. int get_export_platform_count();
  279. Ref<EditorExportPlatform> get_export_platform(int p_idx);
  280. void add_export_preset(const Ref<EditorExportPreset> &p_preset, int p_at_pos = -1);
  281. int get_export_preset_count() const;
  282. Ref<EditorExportPreset> get_export_preset(int p_idx);
  283. void remove_export_preset(int p_idx);
  284. void add_export_plugin(const Ref<EditorExportPlugin> &p_plugin);
  285. void remove_export_plugin(const Ref<EditorExportPlugin> &p_plugin);
  286. Vector<Ref<EditorExportPlugin> > get_export_plugins();
  287. void load_config();
  288. bool poll_export_platforms();
  289. EditorExport();
  290. ~EditorExport();
  291. };
  292. class EditorExportPlatformPC : public EditorExportPlatform {
  293. GDCLASS(EditorExportPlatformPC, EditorExportPlatform)
  294. Ref<ImageTexture> logo;
  295. String name;
  296. String os_name;
  297. Map<String, String> extensions;
  298. String release_file_32;
  299. String release_file_64;
  300. String debug_file_32;
  301. String debug_file_64;
  302. Set<String> extra_features;
  303. int chmod_flags;
  304. public:
  305. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
  306. virtual void get_export_options(List<ExportOption> *r_options);
  307. virtual String get_name() const;
  308. virtual String get_os_name() const;
  309. virtual Ref<Texture> get_logo() const;
  310. virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  311. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;
  312. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  313. void set_extension(const String &p_extension, const String &p_feature_key = "default");
  314. void set_name(const String &p_name);
  315. void set_os_name(const String &p_name);
  316. void set_logo(const Ref<Texture> &p_logo);
  317. void set_release_64(const String &p_file);
  318. void set_release_32(const String &p_file);
  319. void set_debug_64(const String &p_file);
  320. void set_debug_32(const String &p_file);
  321. void add_platform_feature(const String &p_feature);
  322. virtual void get_platform_features(List<String> *r_features);
  323. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features);
  324. int get_chmod_flags() const;
  325. void set_chmod_flags(int p_flags);
  326. EditorExportPlatformPC();
  327. };
  328. class EditorExportTextSceneToBinaryPlugin : public EditorExportPlugin {
  329. GDCLASS(EditorExportTextSceneToBinaryPlugin, EditorExportPlugin)
  330. public:
  331. virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features);
  332. EditorExportTextSceneToBinaryPlugin();
  333. };
  334. #endif // EDITOR_IMPORT_EXPORT_H