editor_export.h 14 KB

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