export.cpp 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034
  1. /*************************************************************************/
  2. /* export.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. #include "export.h"
  31. #include "core/io/image_loader.h"
  32. #include "core/io/marshalls.h"
  33. #include "core/io/resource_saver.h"
  34. #include "core/io/zip_io.h"
  35. #include "core/os/file_access.h"
  36. #include "core/os/os.h"
  37. #include "core/project_settings.h"
  38. #include "core/safe_refcount.h"
  39. #include "core/version.h"
  40. #include "editor/editor_export.h"
  41. #include "editor/editor_node.h"
  42. #include "editor/editor_settings.h"
  43. #include "main/splash.gen.h"
  44. #include "platform/iphone/logo.gen.h"
  45. #include "platform/iphone/plugin/godot_plugin_config.h"
  46. #include "string.h"
  47. #include <sys/stat.h>
  48. class EditorExportPlatformIOS : public EditorExportPlatform {
  49. GDCLASS(EditorExportPlatformIOS, EditorExportPlatform);
  50. int version_code;
  51. Ref<ImageTexture> logo;
  52. // Plugins
  53. SafeFlag plugins_changed;
  54. Thread check_for_changes_thread;
  55. SafeFlag quit_request;
  56. Mutex plugins_lock;
  57. Vector<PluginConfigIOS> plugins;
  58. typedef Error (*FileHandler)(String p_file, void *p_userdata);
  59. static Error _walk_dir_recursive(DirAccess *p_da, FileHandler p_handler, void *p_userdata);
  60. static Error _codesign(String p_file, void *p_userdata);
  61. void _blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot);
  62. struct IOSConfigData {
  63. String pkg_name;
  64. String binary_name;
  65. String plist_content;
  66. String architectures;
  67. String linker_flags;
  68. String cpp_code;
  69. String modules_buildfile;
  70. String modules_fileref;
  71. String modules_buildphase;
  72. String modules_buildgrp;
  73. Vector<String> capabilities;
  74. };
  75. struct ExportArchitecture {
  76. String name;
  77. bool is_default;
  78. ExportArchitecture() :
  79. name(""),
  80. is_default(false) {
  81. }
  82. ExportArchitecture(String p_name, bool p_is_default) {
  83. name = p_name;
  84. is_default = p_is_default;
  85. }
  86. };
  87. struct IOSExportAsset {
  88. String exported_path;
  89. bool is_framework; // framework is anything linked to the binary, otherwise it's a resource
  90. bool should_embed;
  91. };
  92. String _get_additional_plist_content();
  93. String _get_linker_flags();
  94. String _get_cpp_code();
  95. void _fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const IOSConfigData &p_config, bool p_debug);
  96. Error _export_loading_screen_images(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir);
  97. Error _export_loading_screen_file(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir);
  98. Error _export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir);
  99. Vector<ExportArchitecture> _get_supported_architectures();
  100. Vector<String> _get_preset_architectures(const Ref<EditorExportPreset> &p_preset);
  101. void _add_assets_to_project(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets);
  102. Error _copy_asset(const String &p_out_dir, const String &p_asset, const String *p_custom_file_name, bool p_is_framework, bool p_should_embed, Vector<IOSExportAsset> &r_exported_assets);
  103. Error _export_additional_assets(const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, bool p_should_embed, Vector<IOSExportAsset> &r_exported_assets);
  104. Error _export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets);
  105. Error _export_ios_plugins(const Ref<EditorExportPreset> &p_preset, IOSConfigData &p_config_data, const String &dest_dir, Vector<IOSExportAsset> &r_exported_assets, bool p_debug);
  106. bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const {
  107. String pname = p_package;
  108. if (pname.length() == 0) {
  109. if (r_error) {
  110. *r_error = TTR("Identifier is missing.");
  111. }
  112. return false;
  113. }
  114. for (int i = 0; i < pname.length(); i++) {
  115. CharType c = pname[i];
  116. if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '.')) {
  117. if (r_error) {
  118. *r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
  119. }
  120. return false;
  121. }
  122. }
  123. return true;
  124. }
  125. static void _check_for_changes_poll_thread(void *ud) {
  126. EditorExportPlatformIOS *ea = (EditorExportPlatformIOS *)ud;
  127. while (!ea->quit_request.is_set()) {
  128. // Nothing to do if we already know the plugins have changed.
  129. if (!ea->plugins_changed.is_set()) {
  130. ea->plugins_lock.lock();
  131. Vector<PluginConfigIOS> loaded_plugins = get_plugins();
  132. if (ea->plugins.size() != loaded_plugins.size()) {
  133. ea->plugins_changed.set();
  134. } else {
  135. for (int i = 0; i < ea->plugins.size(); i++) {
  136. if (ea->plugins[i].name != loaded_plugins[i].name || ea->plugins[i].last_updated != loaded_plugins[i].last_updated) {
  137. ea->plugins_changed.set();
  138. break;
  139. }
  140. }
  141. }
  142. ea->plugins_lock.unlock();
  143. }
  144. uint64_t wait = 3000000;
  145. uint64_t time = OS::get_singleton()->get_ticks_usec();
  146. while (OS::get_singleton()->get_ticks_usec() - time < wait) {
  147. OS::get_singleton()->delay_usec(300000);
  148. if (ea->quit_request.is_set()) {
  149. break;
  150. }
  151. }
  152. }
  153. }
  154. protected:
  155. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
  156. virtual void get_export_options(List<ExportOption> *r_options);
  157. public:
  158. virtual String get_name() const { return "iOS"; }
  159. virtual String get_os_name() const { return "iOS"; }
  160. virtual Ref<Texture> get_logo() const { return logo; }
  161. virtual bool should_update_export_options() {
  162. bool export_options_changed = plugins_changed.is_set();
  163. if (export_options_changed) {
  164. // don't clear unless we're reporting true, to avoid race
  165. plugins_changed.clear();
  166. }
  167. return export_options_changed;
  168. }
  169. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
  170. List<String> list;
  171. list.push_back("ipa");
  172. return list;
  173. }
  174. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  175. virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  176. virtual void get_platform_features(List<String> *r_features) {
  177. r_features->push_back("mobile");
  178. r_features->push_back("iOS");
  179. }
  180. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
  181. }
  182. EditorExportPlatformIOS();
  183. ~EditorExportPlatformIOS();
  184. /// List the gdip files in the directory specified by the p_path parameter.
  185. static Vector<String> list_plugin_config_files(const String &p_path, bool p_check_directories) {
  186. Vector<String> dir_files;
  187. DirAccessRef da = DirAccess::open(p_path);
  188. if (da) {
  189. da->list_dir_begin();
  190. while (true) {
  191. String file = da->get_next();
  192. if (file.empty()) {
  193. break;
  194. }
  195. if (file == "." || file == "..") {
  196. continue;
  197. }
  198. if (da->current_is_hidden()) {
  199. continue;
  200. }
  201. if (da->current_is_dir()) {
  202. if (p_check_directories) {
  203. Vector<String> directory_files = list_plugin_config_files(p_path.plus_file(file), false);
  204. for (int i = 0; i < directory_files.size(); ++i) {
  205. dir_files.push_back(file.plus_file(directory_files[i]));
  206. }
  207. }
  208. continue;
  209. }
  210. if (file.ends_with(PluginConfigIOS::PLUGIN_CONFIG_EXT)) {
  211. dir_files.push_back(file);
  212. }
  213. }
  214. da->list_dir_end();
  215. }
  216. return dir_files;
  217. }
  218. static Vector<PluginConfigIOS> get_plugins() {
  219. Vector<PluginConfigIOS> loaded_plugins;
  220. String plugins_dir = ProjectSettings::get_singleton()->get_resource_path().plus_file("ios/plugins");
  221. if (DirAccess::exists(plugins_dir)) {
  222. Vector<String> plugins_filenames = list_plugin_config_files(plugins_dir, true);
  223. if (!plugins_filenames.empty()) {
  224. Ref<ConfigFile> config_file = memnew(ConfigFile);
  225. for (int i = 0; i < plugins_filenames.size(); i++) {
  226. PluginConfigIOS config = load_plugin_config(config_file, plugins_dir.plus_file(plugins_filenames[i]));
  227. if (config.valid_config) {
  228. loaded_plugins.push_back(config);
  229. } else {
  230. print_error("Invalid plugin config file " + plugins_filenames[i]);
  231. }
  232. }
  233. }
  234. }
  235. return loaded_plugins;
  236. }
  237. static Vector<PluginConfigIOS> get_enabled_plugins(const Ref<EditorExportPreset> &p_presets) {
  238. Vector<PluginConfigIOS> enabled_plugins;
  239. Vector<PluginConfigIOS> all_plugins = get_plugins();
  240. for (int i = 0; i < all_plugins.size(); i++) {
  241. PluginConfigIOS plugin = all_plugins[i];
  242. bool enabled = p_presets->get("plugins/" + plugin.name);
  243. if (enabled) {
  244. enabled_plugins.push_back(plugin);
  245. }
  246. }
  247. return enabled_plugins;
  248. }
  249. };
  250. void EditorExportPlatformIOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
  251. String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name");
  252. r_features->push_back("pvrtc");
  253. if (driver == "GLES3") {
  254. r_features->push_back("etc2");
  255. }
  256. Vector<String> architectures = _get_preset_architectures(p_preset);
  257. for (int i = 0; i < architectures.size(); ++i) {
  258. r_features->push_back(architectures[i]);
  259. }
  260. }
  261. Vector<EditorExportPlatformIOS::ExportArchitecture> EditorExportPlatformIOS::_get_supported_architectures() {
  262. Vector<ExportArchitecture> archs;
  263. archs.push_back(ExportArchitecture("armv7", false)); // Disabled by default, not included in official templates.
  264. archs.push_back(ExportArchitecture("arm64", true));
  265. return archs;
  266. }
  267. struct LoadingScreenInfo {
  268. const char *preset_key;
  269. const char *export_name;
  270. int width;
  271. int height;
  272. bool rotate;
  273. };
  274. static const LoadingScreenInfo loading_screen_infos[] = {
  275. { "landscape_launch_screens/iphone_2436x1125", "Default-Landscape-X.png", 2436, 1125, false },
  276. { "landscape_launch_screens/iphone_2208x1242", "[email protected]", 2208, 1242, false },
  277. { "landscape_launch_screens/ipad_1024x768", "Default-Landscape.png", 1024, 768, false },
  278. { "landscape_launch_screens/ipad_2048x1536", "[email protected]", 2048, 1536, false },
  279. { "portrait_launch_screens/iphone_640x960", "[email protected]", 640, 960, true },
  280. { "portrait_launch_screens/iphone_640x1136", "[email protected]", 640, 1136, true },
  281. { "portrait_launch_screens/iphone_750x1334", "[email protected]", 750, 1334, true },
  282. { "portrait_launch_screens/iphone_1125x2436", "Default-Portrait-X.png", 1125, 2436, true },
  283. { "portrait_launch_screens/ipad_768x1024", "Default-Portrait.png", 768, 1024, true },
  284. { "portrait_launch_screens/ipad_1536x2048", "[email protected]", 1536, 2048, true },
  285. { "portrait_launch_screens/iphone_1242x2208", "[email protected]", 1242, 2208, true }
  286. };
  287. void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options) {
  288. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  289. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  290. Vector<ExportArchitecture> architectures = _get_supported_architectures();
  291. for (int i = 0; i < architectures.size(); ++i) {
  292. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "architectures/" + architectures[i].name), architectures[i].is_default));
  293. }
  294. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_store_team_id"), ""));
  295. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_debug"), ""));
  296. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_debug", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Developer"), "iPhone Developer"));
  297. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_debug", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 1));
  298. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_release"), ""));
  299. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_release", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Distribution"), ""));
  300. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_release", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 0));
  301. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/targeted_device_family", PROPERTY_HINT_ENUM, "iPhone,iPad,iPhone & iPad"), 2));
  302. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
  303. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/info"), "Made with Godot Engine"));
  304. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), ""));
  305. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  306. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
  307. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
  308. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
  309. Vector<PluginConfigIOS> found_plugins = get_plugins();
  310. for (int i = 0; i < found_plugins.size(); i++) {
  311. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "plugins/" + found_plugins[i].name), false));
  312. }
  313. plugins_changed.clear();
  314. plugins = found_plugins;
  315. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/access_wifi"), false));
  316. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/push_notifications"), false));
  317. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_files_app"), false));
  318. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_itunes_sharing"), false));
  319. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/camera_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the camera"), ""));
  320. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/microphone_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the microphone"), ""));
  321. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/photolibrary_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need access to the photo library"), ""));
  322. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "icons/generate_missing"), false));
  323. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/iphone_120x120", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPhone/iPod Touch with retina display
  324. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/ipad_76x76", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPad
  325. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/app_store_1024x1024", PROPERTY_HINT_FILE, "*.png"), "")); // App Store
  326. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/iphone_180x180", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPhone with retina HD display
  327. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/ipad_152x152", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPad with retina display
  328. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/ipad_167x167", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPad Pro
  329. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/spotlight_40x40", PROPERTY_HINT_FILE, "*.png"), "")); // Spotlight
  330. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/spotlight_80x80", PROPERTY_HINT_FILE, "*.png"), "")); // Spotlight on devices with retina display
  331. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "storyboard/use_launch_screen_storyboard"), false));
  332. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "storyboard/image_scale_mode", PROPERTY_HINT_ENUM, "Same as Logo,Center,Scale To Fit,Scale To Fill,Scale"), 0));
  333. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@2x", PROPERTY_HINT_FILE, "*.png"), ""));
  334. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@3x", PROPERTY_HINT_FILE, "*.png"), ""));
  335. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "storyboard/use_custom_bg_color"), false));
  336. r_options->push_back(ExportOption(PropertyInfo(Variant::COLOR, "storyboard/custom_bg_color"), Color()));
  337. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "launch_screens/generate_missing"), false));
  338. for (uint64_t i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  339. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, loading_screen_infos[i].preset_key, PROPERTY_HINT_FILE, "*.png"), ""));
  340. }
  341. }
  342. void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const IOSConfigData &p_config, bool p_debug) {
  343. static const String export_method_string[] = {
  344. "app-store",
  345. "development",
  346. "ad-hoc",
  347. "enterprise"
  348. };
  349. static const String storyboard_image_scale_mode[] = {
  350. "center",
  351. "scaleAspectFit",
  352. "scaleAspectFill",
  353. "scaleToFill"
  354. };
  355. String str;
  356. String strnew;
  357. str.parse_utf8((const char *)pfile.ptr(), pfile.size());
  358. Vector<String> lines = str.split("\n");
  359. for (int i = 0; i < lines.size(); i++) {
  360. if (lines[i].find("$binary") != -1) {
  361. strnew += lines[i].replace("$binary", p_config.binary_name) + "\n";
  362. } else if (lines[i].find("$modules_buildfile") != -1) {
  363. strnew += lines[i].replace("$modules_buildfile", p_config.modules_buildfile) + "\n";
  364. } else if (lines[i].find("$modules_fileref") != -1) {
  365. strnew += lines[i].replace("$modules_fileref", p_config.modules_fileref) + "\n";
  366. } else if (lines[i].find("$modules_buildphase") != -1) {
  367. strnew += lines[i].replace("$modules_buildphase", p_config.modules_buildphase) + "\n";
  368. } else if (lines[i].find("$modules_buildgrp") != -1) {
  369. strnew += lines[i].replace("$modules_buildgrp", p_config.modules_buildgrp) + "\n";
  370. } else if (lines[i].find("$name") != -1) {
  371. strnew += lines[i].replace("$name", p_config.pkg_name) + "\n";
  372. } else if (lines[i].find("$info") != -1) {
  373. strnew += lines[i].replace("$info", p_preset->get("application/info")) + "\n";
  374. } else if (lines[i].find("$identifier") != -1) {
  375. strnew += lines[i].replace("$identifier", p_preset->get("application/identifier")) + "\n";
  376. } else if (lines[i].find("$short_version") != -1) {
  377. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  378. } else if (lines[i].find("$version") != -1) {
  379. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  380. } else if (lines[i].find("$signature") != -1) {
  381. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  382. } else if (lines[i].find("$copyright") != -1) {
  383. strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
  384. } else if (lines[i].find("$team_id") != -1) {
  385. strnew += lines[i].replace("$team_id", p_preset->get("application/app_store_team_id")) + "\n";
  386. } else if (lines[i].find("$default_build_config") != -1) {
  387. strnew += lines[i].replace("$default_build_config", p_debug ? "Debug" : "Release") + "\n";
  388. } else if (lines[i].find("$export_method") != -1) {
  389. int export_method = p_preset->get(p_debug ? "application/export_method_debug" : "application/export_method_release");
  390. strnew += lines[i].replace("$export_method", export_method_string[export_method]) + "\n";
  391. } else if (lines[i].find("$provisioning_profile_uuid_release") != -1) {
  392. strnew += lines[i].replace("$provisioning_profile_uuid_release", p_preset->get("application/provisioning_profile_uuid_release")) + "\n";
  393. } else if (lines[i].find("$provisioning_profile_uuid_debug") != -1) {
  394. strnew += lines[i].replace("$provisioning_profile_uuid_debug", p_preset->get("application/provisioning_profile_uuid_debug")) + "\n";
  395. } else if (lines[i].find("$provisioning_profile_uuid") != -1) {
  396. String uuid = p_debug ? p_preset->get("application/provisioning_profile_uuid_debug") : p_preset->get("application/provisioning_profile_uuid_release");
  397. strnew += lines[i].replace("$provisioning_profile_uuid", uuid) + "\n";
  398. } else if (lines[i].find("$code_sign_identity_debug") != -1) {
  399. strnew += lines[i].replace("$code_sign_identity_debug", p_preset->get("application/code_sign_identity_debug")) + "\n";
  400. } else if (lines[i].find("$code_sign_identity_release") != -1) {
  401. strnew += lines[i].replace("$code_sign_identity_release", p_preset->get("application/code_sign_identity_release")) + "\n";
  402. } else if (lines[i].find("$additional_plist_content") != -1) {
  403. strnew += lines[i].replace("$additional_plist_content", p_config.plist_content) + "\n";
  404. } else if (lines[i].find("$godot_archs") != -1) {
  405. strnew += lines[i].replace("$godot_archs", p_config.architectures) + "\n";
  406. } else if (lines[i].find("$linker_flags") != -1) {
  407. strnew += lines[i].replace("$linker_flags", p_config.linker_flags) + "\n";
  408. } else if (lines[i].find("$targeted_device_family") != -1) {
  409. String xcode_value;
  410. switch ((int)p_preset->get("application/targeted_device_family")) {
  411. case 0: // iPhone
  412. xcode_value = "1";
  413. break;
  414. case 1: // iPad
  415. xcode_value = "2";
  416. break;
  417. case 2: // iPhone & iPad
  418. xcode_value = "1,2";
  419. break;
  420. }
  421. strnew += lines[i].replace("$targeted_device_family", xcode_value) + "\n";
  422. } else if (lines[i].find("$cpp_code") != -1) {
  423. strnew += lines[i].replace("$cpp_code", p_config.cpp_code) + "\n";
  424. } else if (lines[i].find("$docs_in_place") != -1) {
  425. strnew += lines[i].replace("$docs_in_place", ((bool)p_preset->get("user_data/accessible_from_files_app")) ? "<true/>" : "<false/>") + "\n";
  426. } else if (lines[i].find("$docs_sharing") != -1) {
  427. strnew += lines[i].replace("$docs_sharing", ((bool)p_preset->get("user_data/accessible_from_itunes_sharing")) ? "<true/>" : "<false/>") + "\n";
  428. } else if (lines[i].find("$entitlements_push_notifications") != -1) {
  429. bool is_on = p_preset->get("capabilities/push_notifications");
  430. strnew += lines[i].replace("$entitlements_push_notifications", is_on ? "<key>aps-environment</key><string>development</string>" : "") + "\n";
  431. } else if (lines[i].find("$required_device_capabilities") != -1) {
  432. String capabilities;
  433. // I've removed armv7 as we can run on 64bit only devices
  434. // Note that capabilities listed here are requirements for the app to be installed.
  435. // They don't enable anything.
  436. Vector<String> capabilities_list = p_config.capabilities;
  437. if ((bool)p_preset->get("capabilities/access_wifi") && capabilities_list.find("wifi") != -1) {
  438. capabilities_list.push_back("wifi");
  439. }
  440. for (int idx = 0; idx < capabilities_list.size(); idx++) {
  441. capabilities += "<string>" + capabilities_list[idx] + "</string>\n";
  442. }
  443. strnew += lines[i].replace("$required_device_capabilities", capabilities);
  444. } else if (lines[i].find("$interface_orientations") != -1) {
  445. String orientations;
  446. const OS::ScreenOrientation screen_orientation =
  447. OS::get_singleton()->get_screen_orientation_from_string(GLOBAL_GET("display/window/handheld/orientation"));
  448. switch (screen_orientation) {
  449. case OS::SCREEN_LANDSCAPE:
  450. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  451. break;
  452. case OS::SCREEN_PORTRAIT:
  453. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  454. break;
  455. case OS::SCREEN_REVERSE_LANDSCAPE:
  456. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  457. break;
  458. case OS::SCREEN_REVERSE_PORTRAIT:
  459. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  460. break;
  461. case OS::SCREEN_SENSOR_LANDSCAPE:
  462. // Allow both landscape orientations depending on sensor direction.
  463. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  464. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  465. break;
  466. case OS::SCREEN_SENSOR_PORTRAIT:
  467. // Allow both portrait orientations depending on sensor direction.
  468. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  469. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  470. break;
  471. case OS::SCREEN_SENSOR:
  472. // Allow all screen orientations depending on sensor direction.
  473. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  474. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  475. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  476. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  477. break;
  478. }
  479. strnew += lines[i].replace("$interface_orientations", orientations);
  480. } else if (lines[i].find("$camera_usage_description") != -1) {
  481. String description = p_preset->get("privacy/camera_usage_description");
  482. strnew += lines[i].replace("$camera_usage_description", description) + "\n";
  483. } else if (lines[i].find("$microphone_usage_description") != -1) {
  484. String description = p_preset->get("privacy/microphone_usage_description");
  485. strnew += lines[i].replace("$microphone_usage_description", description) + "\n";
  486. } else if (lines[i].find("$photolibrary_usage_description") != -1) {
  487. String description = p_preset->get("privacy/photolibrary_usage_description");
  488. strnew += lines[i].replace("$photolibrary_usage_description", description) + "\n";
  489. } else if (lines[i].find("$plist_launch_screen_name") != -1) {
  490. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  491. String value = is_on ? "<key>UILaunchStoryboardName</key>\n<string>Launch Screen</string>" : "";
  492. strnew += lines[i].replace("$plist_launch_screen_name", value) + "\n";
  493. } else if (lines[i].find("$pbx_launch_screen_file_reference") != -1) {
  494. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  495. String value = is_on ? "90DD2D9D24B36E8000717FE1 = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = \"Launch Screen.storyboard\"; sourceTree = \"<group>\"; };" : "";
  496. strnew += lines[i].replace("$pbx_launch_screen_file_reference", value) + "\n";
  497. } else if (lines[i].find("$pbx_launch_screen_copy_files") != -1) {
  498. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  499. String value = is_on ? "90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */," : "";
  500. strnew += lines[i].replace("$pbx_launch_screen_copy_files", value) + "\n";
  501. } else if (lines[i].find("$pbx_launch_screen_build_phase") != -1) {
  502. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  503. String value = is_on ? "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */," : "";
  504. strnew += lines[i].replace("$pbx_launch_screen_build_phase", value) + "\n";
  505. } else if (lines[i].find("$pbx_launch_screen_build_reference") != -1) {
  506. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  507. String value = is_on ? "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */; };" : "";
  508. strnew += lines[i].replace("$pbx_launch_screen_build_reference", value) + "\n";
  509. } else if (lines[i].find("$pbx_launch_image_usage_setting") != -1) {
  510. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  511. String value = is_on ? "" : "ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;";
  512. strnew += lines[i].replace("$pbx_launch_image_usage_setting", value) + "\n";
  513. } else if (lines[i].find("$launch_screen_image_mode") != -1) {
  514. int image_scale_mode = p_preset->get("storyboard/image_scale_mode");
  515. String value;
  516. switch (image_scale_mode) {
  517. case 0: {
  518. String logo_path = ProjectSettings::get_singleton()->get("application/boot_splash/image");
  519. bool is_on = ProjectSettings::get_singleton()->get("application/boot_splash/fullsize");
  520. // If custom logo is not specified, Godot does not scale default one, so we should do the same.
  521. value = (is_on && logo_path.length() > 0) ? "scaleAspectFit" : "center";
  522. } break;
  523. default: {
  524. value = storyboard_image_scale_mode[image_scale_mode - 1];
  525. }
  526. }
  527. strnew += lines[i].replace("$launch_screen_image_mode", value) + "\n";
  528. } else if (lines[i].find("$launch_screen_background_color") != -1) {
  529. bool use_custom = p_preset->get("storyboard/use_custom_bg_color");
  530. Color color = use_custom ? p_preset->get("storyboard/custom_bg_color") : ProjectSettings::get_singleton()->get("application/boot_splash/bg_color");
  531. const String value_format = "red=\"$red\" green=\"$green\" blue=\"$blue\" alpha=\"$alpha\"";
  532. Dictionary value_dictionary;
  533. value_dictionary["red"] = color.r;
  534. value_dictionary["green"] = color.g;
  535. value_dictionary["blue"] = color.b;
  536. value_dictionary["alpha"] = color.a;
  537. String value = value_format.format(value_dictionary, "$_");
  538. strnew += lines[i].replace("$launch_screen_background_color", value) + "\n";
  539. } else {
  540. strnew += lines[i] + "\n";
  541. }
  542. }
  543. // !BAS! I'm assuming the 9 in the original code was a typo. I've added -1 or else it seems to also be adding our terminating zero...
  544. // should apply the same fix in our OSX export.
  545. CharString cs = strnew.utf8();
  546. pfile.resize(cs.size() - 1);
  547. for (int i = 0; i < cs.size() - 1; i++) {
  548. pfile.write[i] = cs[i];
  549. }
  550. }
  551. String EditorExportPlatformIOS::_get_additional_plist_content() {
  552. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  553. String result;
  554. for (int i = 0; i < export_plugins.size(); ++i) {
  555. result += export_plugins[i]->get_ios_plist_content();
  556. }
  557. return result;
  558. }
  559. String EditorExportPlatformIOS::_get_linker_flags() {
  560. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  561. String result;
  562. for (int i = 0; i < export_plugins.size(); ++i) {
  563. String flags = export_plugins[i]->get_ios_linker_flags();
  564. if (flags.length() == 0) {
  565. continue;
  566. }
  567. if (result.length() > 0) {
  568. result += ' ';
  569. }
  570. result += flags;
  571. }
  572. // the flags will be enclosed in quotes, so need to escape them
  573. return result.replace("\"", "\\\"");
  574. }
  575. String EditorExportPlatformIOS::_get_cpp_code() {
  576. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  577. String result;
  578. for (int i = 0; i < export_plugins.size(); ++i) {
  579. result += export_plugins[i]->get_ios_cpp_code();
  580. }
  581. return result;
  582. }
  583. void EditorExportPlatformIOS::_blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot) {
  584. ERR_FAIL_COND(p_dst.is_null());
  585. ERR_FAIL_COND(p_src.is_null());
  586. p_dst->lock();
  587. p_src->lock();
  588. int sw = p_rot ? p_src->get_height() : p_src->get_width();
  589. int sh = p_rot ? p_src->get_width() : p_src->get_height();
  590. int x_pos = (p_dst->get_width() - sw) / 2;
  591. int y_pos = (p_dst->get_height() - sh) / 2;
  592. int xs = (x_pos >= 0) ? 0 : -x_pos;
  593. int ys = (y_pos >= 0) ? 0 : -y_pos;
  594. if (sw + x_pos > p_dst->get_width()) {
  595. sw = p_dst->get_width() - x_pos;
  596. }
  597. if (sh + y_pos > p_dst->get_height()) {
  598. sh = p_dst->get_height() - y_pos;
  599. }
  600. for (int y = ys; y < sh; y++) {
  601. for (int x = xs; x < sw; x++) {
  602. Color sc = p_rot ? p_src->get_pixel(p_src->get_width() - y - 1, x) : p_src->get_pixel(x, y);
  603. Color dc = p_dst->get_pixel(x_pos + x, y_pos + y);
  604. dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r);
  605. dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g);
  606. dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b);
  607. dc.a = (double)(sc.a + dc.a * (1.0 - sc.a));
  608. p_dst->set_pixel(x_pos + x, y_pos + y, dc);
  609. }
  610. }
  611. p_dst->unlock();
  612. p_src->unlock();
  613. }
  614. struct IconInfo {
  615. const char *preset_key;
  616. const char *idiom;
  617. const char *export_name;
  618. const char *actual_size_side;
  619. const char *scale;
  620. const char *unscaled_size;
  621. bool is_required;
  622. };
  623. static const IconInfo icon_infos[] = {
  624. { "required_icons/iphone_120x120", "iphone", "Icon-120.png", "120", "2x", "60x60", true },
  625. { "required_icons/iphone_120x120", "iphone", "Icon-120.png", "120", "3x", "40x40", true },
  626. { "required_icons/ipad_76x76", "ipad", "Icon-76.png", "76", "1x", "76x76", true },
  627. { "required_icons/app_store_1024x1024", "ios-marketing", "Icon-1024.png", "1024", "1x", "1024x1024", true },
  628. { "optional_icons/iphone_180x180", "iphone", "Icon-180.png", "180", "3x", "60x60", false },
  629. { "optional_icons/ipad_152x152", "ipad", "Icon-152.png", "152", "2x", "76x76", false },
  630. { "optional_icons/ipad_167x167", "ipad", "Icon-167.png", "167", "2x", "83.5x83.5", false },
  631. { "optional_icons/spotlight_40x40", "ipad", "Icon-40.png", "40", "1x", "40x40", false },
  632. { "optional_icons/spotlight_80x80", "iphone", "Icon-80.png", "80", "2x", "40x40", false },
  633. { "optional_icons/spotlight_80x80", "ipad", "Icon-80.png", "80", "2x", "40x40", false }
  634. };
  635. Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
  636. String json_description = "{\"images\":[";
  637. String sizes;
  638. DirAccess *da = DirAccess::open(p_iconset_dir);
  639. ERR_FAIL_COND_V_MSG(!da, ERR_CANT_OPEN, "Cannot open directory '" + p_iconset_dir + "'.");
  640. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  641. IconInfo info = icon_infos[i];
  642. int side_size = String(info.actual_size_side).to_int();
  643. String icon_path = p_preset->get(info.preset_key);
  644. if (icon_path.length() == 0) {
  645. if ((bool)p_preset->get("icons/generate_missing")) {
  646. // Resize main app icon
  647. icon_path = ProjectSettings::get_singleton()->get("application/config/icon");
  648. Ref<Image> img = memnew(Image);
  649. Error err = ImageLoader::load_image(icon_path, img);
  650. if (err != OK) {
  651. ERR_PRINT("Invalid icon (" + String(info.preset_key) + "): '" + icon_path + "'.");
  652. return ERR_UNCONFIGURED;
  653. }
  654. img->resize(side_size, side_size);
  655. err = img->save_png(p_iconset_dir + info.export_name);
  656. if (err) {
  657. String err_str = String("Failed to export icon(" + String(info.preset_key) + "): '" + icon_path + "'.");
  658. ERR_PRINT(err_str.utf8().get_data());
  659. return err;
  660. }
  661. } else {
  662. if (info.is_required) {
  663. String err_str = String("Required icon (") + info.preset_key + ") is not specified in the preset.";
  664. ERR_PRINT(err_str);
  665. return ERR_UNCONFIGURED;
  666. } else {
  667. String err_str = String("Icon (") + info.preset_key + ") is not specified in the preset.";
  668. WARN_PRINT(err_str);
  669. }
  670. continue;
  671. }
  672. } else {
  673. // Load custom icon
  674. Ref<Image> img = memnew(Image);
  675. Error err = ImageLoader::load_image(icon_path, img);
  676. if (err != OK) {
  677. ERR_PRINT("Invalid icon (" + String(info.preset_key) + "): '" + icon_path + "'.");
  678. return ERR_UNCONFIGURED;
  679. }
  680. if (img->get_width() != side_size || img->get_height() != side_size) {
  681. ERR_PRINT("Invalid icon size (" + String(info.preset_key) + "): '" + icon_path + "'.");
  682. return ERR_UNCONFIGURED;
  683. }
  684. err = da->copy(icon_path, p_iconset_dir + info.export_name);
  685. if (err) {
  686. memdelete(da);
  687. String err_str = String("Failed to export icon(" + String(info.preset_key) + "): '" + icon_path + "'.");
  688. ERR_PRINT(err_str.utf8().get_data());
  689. return err;
  690. }
  691. }
  692. sizes += String(info.actual_size_side) + "\n";
  693. if (i > 0) {
  694. json_description += ",";
  695. }
  696. json_description += String("{");
  697. json_description += String("\"idiom\":") + "\"" + info.idiom + "\",";
  698. json_description += String("\"size\":") + "\"" + info.unscaled_size + "\",";
  699. json_description += String("\"scale\":") + "\"" + info.scale + "\",";
  700. json_description += String("\"filename\":") + "\"" + info.export_name + "\"";
  701. json_description += String("}");
  702. }
  703. json_description += "]}";
  704. memdelete(da);
  705. FileAccess *json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
  706. ERR_FAIL_COND_V(!json_file, ERR_CANT_CREATE);
  707. CharString json_utf8 = json_description.utf8();
  708. json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length());
  709. memdelete(json_file);
  710. FileAccess *sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE);
  711. ERR_FAIL_COND_V(!sizes_file, ERR_CANT_CREATE);
  712. CharString sizes_utf8 = sizes.utf8();
  713. sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length());
  714. memdelete(sizes_file);
  715. return OK;
  716. }
  717. Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  718. const String custom_launch_image_2x = p_preset->get("storyboard/custom_image@2x");
  719. const String custom_launch_image_3x = p_preset->get("storyboard/custom_image@3x");
  720. if (custom_launch_image_2x.length() > 0 && custom_launch_image_3x.length() > 0) {
  721. Ref<Image> image;
  722. String image_path = p_dest_dir.plus_file("[email protected]");
  723. image.instance();
  724. Error err = image->load(custom_launch_image_2x);
  725. if (err) {
  726. image.unref();
  727. return err;
  728. }
  729. if (image->save_png(image_path) != OK) {
  730. return ERR_FILE_CANT_WRITE;
  731. }
  732. image.unref();
  733. image_path = p_dest_dir.plus_file("[email protected]");
  734. image.instance();
  735. err = image->load(custom_launch_image_3x);
  736. if (err) {
  737. image.unref();
  738. return err;
  739. }
  740. if (image->save_png(image_path) != OK) {
  741. return ERR_FILE_CANT_WRITE;
  742. }
  743. } else {
  744. Ref<Image> splash;
  745. const String splash_path = ProjectSettings::get_singleton()->get("application/boot_splash/image");
  746. if (!splash_path.empty()) {
  747. splash.instance();
  748. const Error err = splash->load(splash_path);
  749. if (err) {
  750. splash.unref();
  751. }
  752. }
  753. if (splash.is_null()) {
  754. splash = Ref<Image>(memnew(Image(boot_splash_png)));
  755. }
  756. // Using same image for both @2x and @3x
  757. // because Godot's own boot logo uses single image for all resolutions.
  758. // Also not using @1x image, because devices using this image variant
  759. // are not supported by iOS 9, which is minimal target.
  760. const String splash_png_path_2x = p_dest_dir.plus_file("[email protected]");
  761. const String splash_png_path_3x = p_dest_dir.plus_file("[email protected]");
  762. if (splash->save_png(splash_png_path_2x) != OK) {
  763. return ERR_FILE_CANT_WRITE;
  764. }
  765. if (splash->save_png(splash_png_path_3x) != OK) {
  766. return ERR_FILE_CANT_WRITE;
  767. }
  768. }
  769. return OK;
  770. }
  771. Error EditorExportPlatformIOS::_export_loading_screen_images(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  772. DirAccess *da = DirAccess::open(p_dest_dir);
  773. ERR_FAIL_COND_V_MSG(!da, ERR_CANT_OPEN, "Cannot open directory '" + p_dest_dir + "'.");
  774. for (uint64_t i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  775. LoadingScreenInfo info = loading_screen_infos[i];
  776. String loading_screen_file = p_preset->get(info.preset_key);
  777. if (loading_screen_file.size() > 0) {
  778. // Load custom loading screens
  779. Ref<Image> img = memnew(Image);
  780. Error err = ImageLoader::load_image(loading_screen_file, img);
  781. if (err != OK) {
  782. ERR_PRINT("Invalid loading screen (" + String(info.preset_key) + "): '" + loading_screen_file + "'.");
  783. return ERR_UNCONFIGURED;
  784. }
  785. if (img->get_width() != info.width || img->get_height() != info.height) {
  786. ERR_PRINT("Invalid loading screen size (" + String(info.preset_key) + "): '" + loading_screen_file + "'.");
  787. return ERR_UNCONFIGURED;
  788. }
  789. err = da->copy(loading_screen_file, p_dest_dir + info.export_name);
  790. if (err) {
  791. memdelete(da);
  792. String err_str = String("Failed to export loading screen (") + info.preset_key + ") from path '" + loading_screen_file + "'.";
  793. ERR_PRINT(err_str.utf8().get_data());
  794. return err;
  795. }
  796. } else if ((bool)p_preset->get("launch_screens/generate_missing")) {
  797. // Generate loading screen from the splash screen
  798. Color boot_bg_color = ProjectSettings::get_singleton()->get("application/boot_splash/bg_color");
  799. String boot_logo_path = ProjectSettings::get_singleton()->get("application/boot_splash/image");
  800. bool boot_logo_scale = ProjectSettings::get_singleton()->get("application/boot_splash/fullsize");
  801. Ref<Image> img = memnew(Image);
  802. img->create(info.width, info.height, false, Image::FORMAT_RGBA8);
  803. img->fill(boot_bg_color);
  804. Ref<Image> img_bs;
  805. if (boot_logo_path.length() > 0) {
  806. img_bs = Ref<Image>(memnew(Image));
  807. ImageLoader::load_image(boot_logo_path, img_bs);
  808. }
  809. if (!img_bs.is_valid()) {
  810. img_bs = Ref<Image>(memnew(Image(boot_splash_png)));
  811. }
  812. if (img_bs.is_valid()) {
  813. float aspect_ratio = (float)img_bs->get_width() / (float)img_bs->get_height();
  814. if (info.rotate) {
  815. if (boot_logo_scale) {
  816. if (info.width * aspect_ratio <= info.height) {
  817. img_bs->resize(info.width * aspect_ratio, info.width);
  818. } else {
  819. img_bs->resize(info.height, info.height / aspect_ratio);
  820. }
  821. }
  822. } else {
  823. if (boot_logo_scale) {
  824. if (info.height * aspect_ratio <= info.width) {
  825. img_bs->resize(info.height * aspect_ratio, info.height);
  826. } else {
  827. img_bs->resize(info.width, info.width / aspect_ratio);
  828. }
  829. }
  830. }
  831. _blend_and_rotate(img, img_bs, info.rotate);
  832. }
  833. Error err = img->save_png(p_dest_dir + info.export_name);
  834. if (err) {
  835. String err_str = String("Failed to export loading screen (") + info.preset_key + ") from splash screen.";
  836. WARN_PRINT(err_str.utf8().get_data());
  837. }
  838. } else {
  839. String err_str = String("No loading screen (") + info.preset_key + ") specified.";
  840. WARN_PRINT(err_str.utf8().get_data());
  841. }
  842. }
  843. memdelete(da);
  844. return OK;
  845. }
  846. Error EditorExportPlatformIOS::_walk_dir_recursive(DirAccess *p_da, FileHandler p_handler, void *p_userdata) {
  847. Vector<String> dirs;
  848. String path;
  849. String current_dir = p_da->get_current_dir();
  850. p_da->list_dir_begin();
  851. while ((path = p_da->get_next()).length() != 0) {
  852. if (p_da->current_is_dir()) {
  853. if (path != "." && path != "..") {
  854. dirs.push_back(path);
  855. }
  856. } else {
  857. Error err = p_handler(current_dir.plus_file(path), p_userdata);
  858. if (err) {
  859. p_da->list_dir_end();
  860. return err;
  861. }
  862. }
  863. }
  864. p_da->list_dir_end();
  865. for (int i = 0; i < dirs.size(); ++i) {
  866. String dir = dirs[i];
  867. p_da->change_dir(dir);
  868. Error err = _walk_dir_recursive(p_da, p_handler, p_userdata);
  869. p_da->change_dir("..");
  870. if (err) {
  871. return err;
  872. }
  873. }
  874. return OK;
  875. }
  876. struct CodesignData {
  877. const Ref<EditorExportPreset> &preset;
  878. bool debug;
  879. CodesignData(const Ref<EditorExportPreset> &p_preset, bool p_debug) :
  880. preset(p_preset),
  881. debug(p_debug) {
  882. }
  883. };
  884. Error EditorExportPlatformIOS::_codesign(String p_file, void *p_userdata) {
  885. if (p_file.ends_with(".dylib")) {
  886. CodesignData *data = (CodesignData *)p_userdata;
  887. print_line(String("Signing ") + p_file);
  888. List<String> codesign_args;
  889. codesign_args.push_back("-f");
  890. codesign_args.push_back("-s");
  891. codesign_args.push_back(data->preset->get(data->debug ? "application/code_sign_identity_debug" : "application/code_sign_identity_release"));
  892. codesign_args.push_back(p_file);
  893. return OS::get_singleton()->execute("codesign", codesign_args, true);
  894. }
  895. return OK;
  896. }
  897. struct PbxId {
  898. private:
  899. static char _hex_char(uint8_t four_bits) {
  900. if (four_bits < 10) {
  901. return ('0' + four_bits);
  902. }
  903. return 'A' + (four_bits - 10);
  904. }
  905. static String _hex_pad(uint32_t num) {
  906. Vector<char> ret;
  907. ret.resize(sizeof(num) * 2);
  908. for (uint64_t i = 0; i < sizeof(num) * 2; ++i) {
  909. uint8_t four_bits = (num >> (sizeof(num) * 8 - (i + 1) * 4)) & 0xF;
  910. ret.write[i] = _hex_char(four_bits);
  911. }
  912. return String::utf8(ret.ptr(), ret.size());
  913. }
  914. public:
  915. uint32_t high_bits;
  916. uint32_t mid_bits;
  917. uint32_t low_bits;
  918. String str() const {
  919. return _hex_pad(high_bits) + _hex_pad(mid_bits) + _hex_pad(low_bits);
  920. }
  921. PbxId &operator++() {
  922. low_bits++;
  923. if (!low_bits) {
  924. mid_bits++;
  925. if (!mid_bits) {
  926. high_bits++;
  927. }
  928. }
  929. return *this;
  930. }
  931. };
  932. struct ExportLibsData {
  933. Vector<String> lib_paths;
  934. String dest_dir;
  935. };
  936. void EditorExportPlatformIOS::_add_assets_to_project(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets) {
  937. // that is just a random number, we just need Godot IDs not to clash with
  938. // existing IDs in the project.
  939. PbxId current_id = { 0x58938401, 0, 0 };
  940. String pbx_files;
  941. String pbx_frameworks_build;
  942. String pbx_frameworks_refs;
  943. String pbx_resources_build;
  944. String pbx_resources_refs;
  945. String pbx_embeded_frameworks;
  946. const String file_info_format = String("$build_id = {isa = PBXBuildFile; fileRef = $ref_id; };\n") +
  947. "$ref_id = {isa = PBXFileReference; lastKnownFileType = $file_type; name = \"$name\"; path = \"$file_path\"; sourceTree = \"<group>\"; };\n";
  948. for (int i = 0; i < p_additional_assets.size(); ++i) {
  949. String additional_asset_info_format = file_info_format;
  950. String build_id = (++current_id).str();
  951. String ref_id = (++current_id).str();
  952. String framework_id = "";
  953. const IOSExportAsset &asset = p_additional_assets[i];
  954. String type;
  955. if (asset.exported_path.ends_with(".framework")) {
  956. if (asset.should_embed) {
  957. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  958. framework_id = (++current_id).str();
  959. pbx_embeded_frameworks += framework_id + ",\n";
  960. }
  961. type = "wrapper.framework";
  962. } else if (asset.exported_path.ends_with(".xcframework")) {
  963. if (asset.should_embed) {
  964. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  965. framework_id = (++current_id).str();
  966. pbx_embeded_frameworks += framework_id + ",\n";
  967. }
  968. type = "wrapper.xcframework";
  969. } else if (asset.exported_path.ends_with(".dylib")) {
  970. type = "compiled.mach-o.dylib";
  971. } else if (asset.exported_path.ends_with(".a")) {
  972. type = "archive.ar";
  973. } else {
  974. type = "file";
  975. }
  976. String &pbx_build = asset.is_framework ? pbx_frameworks_build : pbx_resources_build;
  977. String &pbx_refs = asset.is_framework ? pbx_frameworks_refs : pbx_resources_refs;
  978. if (pbx_build.length() > 0) {
  979. pbx_build += ",\n";
  980. pbx_refs += ",\n";
  981. }
  982. pbx_build += build_id;
  983. pbx_refs += ref_id;
  984. Dictionary format_dict;
  985. format_dict["build_id"] = build_id;
  986. format_dict["ref_id"] = ref_id;
  987. format_dict["name"] = asset.exported_path.get_file();
  988. format_dict["file_path"] = asset.exported_path;
  989. format_dict["file_type"] = type;
  990. if (framework_id.length() > 0) {
  991. format_dict["framework_id"] = framework_id;
  992. }
  993. pbx_files += additional_asset_info_format.format(format_dict, "$_");
  994. }
  995. // Note, frameworks like gamekit are always included in our project.pbxprof file
  996. // even if turned off in capabilities.
  997. String str = String::utf8((const char *)p_project_data.ptr(), p_project_data.size());
  998. str = str.replace("$additional_pbx_files", pbx_files);
  999. str = str.replace("$additional_pbx_frameworks_build", pbx_frameworks_build);
  1000. str = str.replace("$additional_pbx_frameworks_refs", pbx_frameworks_refs);
  1001. str = str.replace("$additional_pbx_resources_build", pbx_resources_build);
  1002. str = str.replace("$additional_pbx_resources_refs", pbx_resources_refs);
  1003. str = str.replace("$pbx_embeded_frameworks", pbx_embeded_frameworks);
  1004. CharString cs = str.utf8();
  1005. p_project_data.resize(cs.size() - 1);
  1006. for (int i = 0; i < cs.size() - 1; i++) {
  1007. p_project_data.write[i] = cs[i];
  1008. }
  1009. }
  1010. Error EditorExportPlatformIOS::_copy_asset(const String &p_out_dir, const String &p_asset, const String *p_custom_file_name, bool p_is_framework, bool p_should_embed, Vector<IOSExportAsset> &r_exported_assets) {
  1011. DirAccess *filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1012. ERR_FAIL_COND_V_MSG(!filesystem_da, ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_out_dir + "'.");
  1013. String binary_name = p_out_dir.get_file().get_basename();
  1014. DirAccess *da = DirAccess::create_for_path(p_asset);
  1015. if (!da) {
  1016. memdelete(filesystem_da);
  1017. ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't create directory: " + p_asset + ".");
  1018. }
  1019. bool file_exists = da->file_exists(p_asset);
  1020. bool dir_exists = da->dir_exists(p_asset);
  1021. if (!file_exists && !dir_exists) {
  1022. memdelete(da);
  1023. memdelete(filesystem_da);
  1024. return ERR_FILE_NOT_FOUND;
  1025. }
  1026. String base_dir = p_asset.get_base_dir().replace("res://", "");
  1027. String destination_dir;
  1028. String destination;
  1029. String asset_path;
  1030. bool create_framework = false;
  1031. if (p_is_framework && p_asset.ends_with(".dylib")) {
  1032. // For iOS we need to turn .dylib into .framework
  1033. // to be able to send application to AppStore
  1034. asset_path = String("dylibs").plus_file(base_dir);
  1035. String file_name;
  1036. if (!p_custom_file_name) {
  1037. file_name = p_asset.get_basename().get_file();
  1038. } else {
  1039. file_name = *p_custom_file_name;
  1040. }
  1041. String framework_name = file_name + ".framework";
  1042. asset_path = asset_path.plus_file(framework_name);
  1043. destination_dir = p_out_dir.plus_file(asset_path);
  1044. destination = destination_dir.plus_file(file_name);
  1045. create_framework = true;
  1046. } else if (p_is_framework && (p_asset.ends_with(".framework") || p_asset.ends_with(".xcframework"))) {
  1047. asset_path = String("dylibs").plus_file(base_dir);
  1048. String file_name;
  1049. if (!p_custom_file_name) {
  1050. file_name = p_asset.get_file();
  1051. } else {
  1052. file_name = *p_custom_file_name;
  1053. }
  1054. asset_path = asset_path.plus_file(file_name);
  1055. destination_dir = p_out_dir.plus_file(asset_path);
  1056. destination = destination_dir;
  1057. } else {
  1058. asset_path = base_dir;
  1059. String file_name;
  1060. if (!p_custom_file_name) {
  1061. file_name = p_asset.get_file();
  1062. } else {
  1063. file_name = *p_custom_file_name;
  1064. }
  1065. destination_dir = p_out_dir.plus_file(asset_path);
  1066. asset_path = asset_path.plus_file(file_name);
  1067. destination = p_out_dir.plus_file(asset_path);
  1068. }
  1069. if (!filesystem_da->dir_exists(destination_dir)) {
  1070. Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir);
  1071. if (make_dir_err) {
  1072. memdelete(da);
  1073. memdelete(filesystem_da);
  1074. return make_dir_err;
  1075. }
  1076. }
  1077. Error err = dir_exists ? da->copy_dir(p_asset, destination) : da->copy(p_asset, destination);
  1078. memdelete(da);
  1079. if (err) {
  1080. memdelete(filesystem_da);
  1081. return err;
  1082. }
  1083. IOSExportAsset exported_asset = { binary_name.plus_file(asset_path), p_is_framework, p_should_embed };
  1084. r_exported_assets.push_back(exported_asset);
  1085. if (create_framework) {
  1086. String file_name;
  1087. if (!p_custom_file_name) {
  1088. file_name = p_asset.get_basename().get_file();
  1089. } else {
  1090. file_name = *p_custom_file_name;
  1091. }
  1092. String framework_name = file_name + ".framework";
  1093. // Performing `install_name_tool -id @rpath/{name}.framework/{name} ./{name}` on dylib
  1094. {
  1095. List<String> install_name_args;
  1096. install_name_args.push_back("-id");
  1097. install_name_args.push_back(String("@rpath").plus_file(framework_name).plus_file(file_name));
  1098. install_name_args.push_back(destination);
  1099. OS::get_singleton()->execute("install_name_tool", install_name_args, true);
  1100. }
  1101. // Creating Info.plist
  1102. {
  1103. String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1104. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  1105. "<plist version=\"1.0\">\n"
  1106. "<dict>\n"
  1107. "<key>CFBundleShortVersionString</key>\n"
  1108. "<string>1.0</string>\n"
  1109. "<key>CFBundleIdentifier</key>\n"
  1110. "<string>com.gdnative.framework.$name</string>\n"
  1111. "<key>CFBundleName</key>\n"
  1112. "<string>$name</string>\n"
  1113. "<key>CFBundleExecutable</key>\n"
  1114. "<string>$name</string>\n"
  1115. "<key>DTPlatformName</key>\n"
  1116. "<string>iphoneos</string>\n"
  1117. "<key>CFBundleInfoDictionaryVersion</key>\n"
  1118. "<string>6.0</string>\n"
  1119. "<key>CFBundleVersion</key>\n"
  1120. "<string>1</string>\n"
  1121. "<key>CFBundlePackageType</key>\n"
  1122. "<string>FMWK</string>\n"
  1123. "<key>MinimumOSVersion</key>\n"
  1124. "<string>10.0</string>\n"
  1125. "</dict>\n"
  1126. "</plist>";
  1127. String info_plist = info_plist_format.replace("$name", file_name);
  1128. FileAccess *f = FileAccess::open(destination_dir.plus_file("Info.plist"), FileAccess::WRITE);
  1129. if (f) {
  1130. f->store_string(info_plist);
  1131. f->close();
  1132. memdelete(f);
  1133. }
  1134. }
  1135. }
  1136. memdelete(filesystem_da);
  1137. return OK;
  1138. }
  1139. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, bool p_should_embed, Vector<IOSExportAsset> &r_exported_assets) {
  1140. for (int f_idx = 0; f_idx < p_assets.size(); ++f_idx) {
  1141. String asset = p_assets[f_idx];
  1142. if (!asset.begins_with("res://")) {
  1143. // either SDK-builtin or already a part of the export template
  1144. IOSExportAsset exported_asset = { asset, p_is_framework, p_should_embed };
  1145. r_exported_assets.push_back(exported_asset);
  1146. } else {
  1147. Error err = _copy_asset(p_out_dir, asset, nullptr, p_is_framework, p_should_embed, r_exported_assets);
  1148. ERR_FAIL_COND_V(err, err);
  1149. }
  1150. }
  1151. return OK;
  1152. }
  1153. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets) {
  1154. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  1155. for (int i = 0; i < export_plugins.size(); i++) {
  1156. Vector<String> linked_frameworks = export_plugins[i]->get_ios_frameworks();
  1157. Error err = _export_additional_assets(p_out_dir, linked_frameworks, true, false, r_exported_assets);
  1158. ERR_FAIL_COND_V(err, err);
  1159. Vector<String> embedded_frameworks = export_plugins[i]->get_ios_embedded_frameworks();
  1160. err = _export_additional_assets(p_out_dir, embedded_frameworks, true, true, r_exported_assets);
  1161. ERR_FAIL_COND_V(err, err);
  1162. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  1163. for (int j = 0; j < project_static_libs.size(); j++) {
  1164. project_static_libs.write[j] = project_static_libs[j].get_file(); // Only the file name as it's copied to the project
  1165. }
  1166. err = _export_additional_assets(p_out_dir, project_static_libs, true, true, r_exported_assets);
  1167. ERR_FAIL_COND_V(err, err);
  1168. Vector<String> ios_bundle_files = export_plugins[i]->get_ios_bundle_files();
  1169. err = _export_additional_assets(p_out_dir, ios_bundle_files, false, false, r_exported_assets);
  1170. ERR_FAIL_COND_V(err, err);
  1171. }
  1172. Vector<String> library_paths;
  1173. for (int i = 0; i < p_libraries.size(); ++i) {
  1174. library_paths.push_back(p_libraries[i].path);
  1175. }
  1176. Error err = _export_additional_assets(p_out_dir, library_paths, true, true, r_exported_assets);
  1177. ERR_FAIL_COND_V(err, err);
  1178. return OK;
  1179. }
  1180. Vector<String> EditorExportPlatformIOS::_get_preset_architectures(const Ref<EditorExportPreset> &p_preset) {
  1181. Vector<ExportArchitecture> all_archs = _get_supported_architectures();
  1182. Vector<String> enabled_archs;
  1183. for (int i = 0; i < all_archs.size(); ++i) {
  1184. bool is_enabled = p_preset->get("architectures/" + all_archs[i].name);
  1185. if (is_enabled) {
  1186. enabled_archs.push_back(all_archs[i].name);
  1187. }
  1188. }
  1189. return enabled_archs;
  1190. }
  1191. Error EditorExportPlatformIOS::_export_ios_plugins(const Ref<EditorExportPreset> &p_preset, IOSConfigData &p_config_data, const String &dest_dir, Vector<IOSExportAsset> &r_exported_assets, bool p_debug) {
  1192. String plugin_definition_cpp_code;
  1193. String plugin_initialization_cpp_code;
  1194. String plugin_deinitialization_cpp_code;
  1195. Vector<String> plugin_linked_dependencies;
  1196. Vector<String> plugin_embedded_dependencies;
  1197. Vector<String> plugin_files;
  1198. Vector<PluginConfigIOS> enabled_plugins = get_enabled_plugins(p_preset);
  1199. Vector<String> added_linked_dependenciy_names;
  1200. Vector<String> added_embedded_dependenciy_names;
  1201. HashMap<String, String> plist_values;
  1202. Set<String> plugin_linker_flags;
  1203. Error err;
  1204. for (int i = 0; i < enabled_plugins.size(); i++) {
  1205. PluginConfigIOS plugin = enabled_plugins[i];
  1206. // Export plugin binary.
  1207. String plugin_main_binary = get_plugin_main_binary(plugin, p_debug);
  1208. String plugin_binary_result_file = plugin.binary.get_file();
  1209. // We shouldn't embed .xcframework that contains static libraries.
  1210. // Static libraries are not embedded anyway.
  1211. err = _copy_asset(dest_dir, plugin_main_binary, &plugin_binary_result_file, true, false, r_exported_assets);
  1212. ERR_FAIL_COND_V(err, err);
  1213. // Adding dependencies.
  1214. // Use separate container for names to check for duplicates.
  1215. for (int j = 0; j < plugin.linked_dependencies.size(); j++) {
  1216. String dependency = plugin.linked_dependencies[j];
  1217. String name = dependency.get_file();
  1218. if (added_linked_dependenciy_names.find(name) != -1) {
  1219. continue;
  1220. }
  1221. added_linked_dependenciy_names.push_back(name);
  1222. plugin_linked_dependencies.push_back(dependency);
  1223. }
  1224. for (int j = 0; j < plugin.system_dependencies.size(); j++) {
  1225. String dependency = plugin.system_dependencies[j];
  1226. String name = dependency.get_file();
  1227. if (added_linked_dependenciy_names.find(name) != -1) {
  1228. continue;
  1229. }
  1230. added_linked_dependenciy_names.push_back(name);
  1231. plugin_linked_dependencies.push_back(dependency);
  1232. }
  1233. for (int j = 0; j < plugin.embedded_dependencies.size(); j++) {
  1234. String dependency = plugin.embedded_dependencies[j];
  1235. String name = dependency.get_file();
  1236. if (added_embedded_dependenciy_names.find(name) != -1) {
  1237. continue;
  1238. }
  1239. added_embedded_dependenciy_names.push_back(name);
  1240. plugin_embedded_dependencies.push_back(dependency);
  1241. }
  1242. plugin_files.append_array(plugin.files_to_copy);
  1243. // Capabilities
  1244. // Also checking for duplicates.
  1245. for (int j = 0; j < plugin.capabilities.size(); j++) {
  1246. String capability = plugin.capabilities[j];
  1247. if (p_config_data.capabilities.find(capability) != -1) {
  1248. continue;
  1249. }
  1250. p_config_data.capabilities.push_back(capability);
  1251. }
  1252. // Linker flags
  1253. // Checking duplicates
  1254. for (int j = 0; j < plugin.linker_flags.size(); j++) {
  1255. String linker_flag = plugin.linker_flags[j];
  1256. plugin_linker_flags.insert(linker_flag);
  1257. }
  1258. // Plist
  1259. // Using hash map container to remove duplicates
  1260. const String *K = nullptr;
  1261. while ((K = plugin.plist.next(K))) {
  1262. String key = *K;
  1263. String value = plugin.plist[key];
  1264. if (key.empty() || value.empty()) {
  1265. continue;
  1266. }
  1267. plist_values[key] = value;
  1268. }
  1269. // CPP Code
  1270. String definition_comment = "// Plugin: " + plugin.name + "\n";
  1271. String initialization_method = plugin.initialization_method + "();\n";
  1272. String deinitialization_method = plugin.deinitialization_method + "();\n";
  1273. plugin_definition_cpp_code += definition_comment +
  1274. "extern void " + initialization_method +
  1275. "extern void " + deinitialization_method + "\n";
  1276. plugin_initialization_cpp_code += "\t" + initialization_method;
  1277. plugin_deinitialization_cpp_code += "\t" + deinitialization_method;
  1278. }
  1279. // Updating `Info.plist`
  1280. {
  1281. const String *K = nullptr;
  1282. while ((K = plist_values.next(K))) {
  1283. String key = *K;
  1284. String value = plist_values[key];
  1285. if (key.empty() || value.empty()) {
  1286. continue;
  1287. }
  1288. p_config_data.plist_content += "<key>" + key + "</key><string>" + value + "</string>\n";
  1289. }
  1290. }
  1291. // Export files
  1292. {
  1293. // Export linked plugin dependency
  1294. err = _export_additional_assets(dest_dir, plugin_linked_dependencies, true, false, r_exported_assets);
  1295. ERR_FAIL_COND_V(err, err);
  1296. // Export embedded plugin dependency
  1297. err = _export_additional_assets(dest_dir, plugin_embedded_dependencies, true, true, r_exported_assets);
  1298. ERR_FAIL_COND_V(err, err);
  1299. // Export plugin files
  1300. err = _export_additional_assets(dest_dir, plugin_files, false, false, r_exported_assets);
  1301. ERR_FAIL_COND_V(err, err);
  1302. }
  1303. // Update CPP
  1304. {
  1305. Dictionary plugin_format;
  1306. plugin_format["definition"] = plugin_definition_cpp_code;
  1307. plugin_format["initialization"] = plugin_initialization_cpp_code;
  1308. plugin_format["deinitialization"] = plugin_deinitialization_cpp_code;
  1309. String plugin_cpp_code = "\n// Godot Plugins\n"
  1310. "void godot_ios_plugins_initialize();\n"
  1311. "void godot_ios_plugins_deinitialize();\n"
  1312. "// Exported Plugins\n\n"
  1313. "$definition"
  1314. "// Use Plugins\n"
  1315. "void godot_ios_plugins_initialize() {\n"
  1316. "$initialization"
  1317. "}\n\n"
  1318. "void godot_ios_plugins_deinitialize() {\n"
  1319. "$deinitialization"
  1320. "}\n";
  1321. p_config_data.cpp_code += plugin_cpp_code.format(plugin_format, "$_");
  1322. }
  1323. // Update Linker Flag Values
  1324. {
  1325. String result_linker_flags = " ";
  1326. for (Set<String>::Element *E = plugin_linker_flags.front(); E; E = E->next()) {
  1327. const String &flag = E->get();
  1328. if (flag.length() == 0) {
  1329. continue;
  1330. }
  1331. if (result_linker_flags.length() > 0) {
  1332. result_linker_flags += ' ';
  1333. }
  1334. result_linker_flags += flag;
  1335. }
  1336. result_linker_flags = result_linker_flags.replace("\"", "\\\"");
  1337. p_config_data.linker_flags += result_linker_flags;
  1338. }
  1339. return OK;
  1340. }
  1341. Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  1342. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  1343. String src_pkg_name;
  1344. String dest_dir = p_path.get_base_dir() + "/";
  1345. String binary_name = p_path.get_file().get_basename();
  1346. EditorProgress ep("export", "Exporting for iOS", 5, true);
  1347. String team_id = p_preset->get("application/app_store_team_id");
  1348. ERR_FAIL_COND_V_MSG(team_id.length() == 0, ERR_CANT_OPEN, "App Store Team ID not specified - cannot configure the project.");
  1349. if (p_debug) {
  1350. src_pkg_name = p_preset->get("custom_template/debug");
  1351. } else {
  1352. src_pkg_name = p_preset->get("custom_template/release");
  1353. }
  1354. if (src_pkg_name == "") {
  1355. String err;
  1356. src_pkg_name = find_export_template("iphone.zip", &err);
  1357. if (src_pkg_name == "") {
  1358. EditorNode::add_io_error(err);
  1359. return ERR_FILE_NOT_FOUND;
  1360. }
  1361. }
  1362. if (!DirAccess::exists(dest_dir)) {
  1363. return ERR_FILE_BAD_PATH;
  1364. }
  1365. DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1366. if (da) {
  1367. String current_dir = da->get_current_dir();
  1368. // remove leftovers from last export so they don't interfere
  1369. // in case some files are no longer needed
  1370. if (da->change_dir(dest_dir + binary_name + ".xcodeproj") == OK) {
  1371. da->erase_contents_recursive();
  1372. }
  1373. if (da->change_dir(dest_dir + binary_name) == OK) {
  1374. da->erase_contents_recursive();
  1375. }
  1376. da->change_dir(current_dir);
  1377. if (!da->dir_exists(dest_dir + binary_name)) {
  1378. Error err = da->make_dir(dest_dir + binary_name);
  1379. if (err) {
  1380. memdelete(da);
  1381. return err;
  1382. }
  1383. }
  1384. memdelete(da);
  1385. }
  1386. if (ep.step("Making .pck", 0)) {
  1387. return ERR_SKIP;
  1388. }
  1389. String pack_path = dest_dir + binary_name + ".pck";
  1390. Vector<SharedObject> libraries;
  1391. Error err = save_pack(p_preset, pack_path, &libraries);
  1392. if (err) {
  1393. return err;
  1394. }
  1395. if (ep.step("Extracting and configuring Xcode project", 1)) {
  1396. return ERR_SKIP;
  1397. }
  1398. String library_to_use = "libgodot.iphone." + String(p_debug ? "debug" : "release") + ".xcframework";
  1399. print_line("Static framework: " + library_to_use);
  1400. String pkg_name;
  1401. if (p_preset->get("application/name") != "") {
  1402. pkg_name = p_preset->get("application/name"); // app_name
  1403. } else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") {
  1404. pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
  1405. } else {
  1406. pkg_name = "Unnamed";
  1407. }
  1408. bool found_library = false;
  1409. int total_size = 0;
  1410. const String project_file = "godot_ios.xcodeproj/project.pbxproj";
  1411. Set<String> files_to_parse;
  1412. files_to_parse.insert("godot_ios/godot_ios-Info.plist");
  1413. files_to_parse.insert(project_file);
  1414. files_to_parse.insert("godot_ios/export_options.plist");
  1415. files_to_parse.insert("godot_ios/dummy.cpp");
  1416. files_to_parse.insert("godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata");
  1417. files_to_parse.insert("godot_ios.xcodeproj/xcshareddata/xcschemes/godot_ios.xcscheme");
  1418. files_to_parse.insert("godot_ios/godot_ios.entitlements");
  1419. files_to_parse.insert("godot_ios/Launch Screen.storyboard");
  1420. IOSConfigData config_data = {
  1421. pkg_name,
  1422. binary_name,
  1423. _get_additional_plist_content(),
  1424. String(" ").join(_get_preset_architectures(p_preset)),
  1425. _get_linker_flags(),
  1426. _get_cpp_code(),
  1427. "",
  1428. "",
  1429. "",
  1430. "",
  1431. Vector<String>()
  1432. };
  1433. Vector<IOSExportAsset> assets;
  1434. DirAccess *tmp_app_path = DirAccess::create_for_path(dest_dir);
  1435. ERR_FAIL_COND_V(!tmp_app_path, ERR_CANT_CREATE);
  1436. print_line("Unzipping...");
  1437. FileAccess *src_f = nullptr;
  1438. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  1439. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  1440. if (!src_pkg_zip) {
  1441. EditorNode::add_io_error("Could not open export template (not a zip file?):\n" + src_pkg_name);
  1442. return ERR_CANT_OPEN;
  1443. }
  1444. err = _export_ios_plugins(p_preset, config_data, dest_dir + binary_name, assets, p_debug);
  1445. ERR_FAIL_COND_V(err, err);
  1446. //export rest of the files
  1447. int ret = unzGoToFirstFile(src_pkg_zip);
  1448. Vector<uint8_t> project_file_data;
  1449. while (ret == UNZ_OK) {
  1450. #if defined(OSX_ENABLED) || defined(X11_ENABLED)
  1451. bool is_execute = false;
  1452. #endif
  1453. //get filename
  1454. unz_file_info info;
  1455. char fname[16384];
  1456. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  1457. String file = fname;
  1458. print_line("READ: " + file);
  1459. Vector<uint8_t> data;
  1460. data.resize(info.uncompressed_size);
  1461. //read
  1462. unzOpenCurrentFile(src_pkg_zip);
  1463. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  1464. unzCloseCurrentFile(src_pkg_zip);
  1465. //write
  1466. file = file.replace_first("iphone/", "");
  1467. if (files_to_parse.has(file)) {
  1468. _fix_config_file(p_preset, data, config_data, p_debug);
  1469. } else if (file.begins_with("libgodot.iphone")) {
  1470. if (!file.begins_with(library_to_use) || file.ends_with(String("/empty"))) {
  1471. ret = unzGoToNextFile(src_pkg_zip);
  1472. continue; //ignore!
  1473. }
  1474. found_library = true;
  1475. #if defined(OSX_ENABLED) || defined(X11_ENABLED)
  1476. is_execute = true;
  1477. #endif
  1478. file = file.replace(library_to_use, binary_name + ".xcframework");
  1479. }
  1480. if (file == project_file) {
  1481. project_file_data = data;
  1482. }
  1483. ///@TODO need to parse logo files
  1484. if (data.size() > 0) {
  1485. file = file.replace("godot_ios", binary_name);
  1486. print_line("ADDING: " + file + " size: " + itos(data.size()));
  1487. total_size += data.size();
  1488. /* write it into our folder structure */
  1489. file = dest_dir + file;
  1490. /* make sure this folder exists */
  1491. String dir_name = file.get_base_dir();
  1492. if (!tmp_app_path->dir_exists(dir_name)) {
  1493. print_line("Creating " + dir_name);
  1494. Error dir_err = tmp_app_path->make_dir_recursive(dir_name);
  1495. if (dir_err) {
  1496. ERR_PRINTS("Can't create '" + dir_name + "'.");
  1497. unzClose(src_pkg_zip);
  1498. memdelete(tmp_app_path);
  1499. return ERR_CANT_CREATE;
  1500. }
  1501. }
  1502. /* write the file */
  1503. FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
  1504. if (!f) {
  1505. ERR_PRINTS("Can't write '" + file + "'.");
  1506. unzClose(src_pkg_zip);
  1507. memdelete(tmp_app_path);
  1508. return ERR_CANT_CREATE;
  1509. };
  1510. f->store_buffer(data.ptr(), data.size());
  1511. f->close();
  1512. memdelete(f);
  1513. #if defined(OSX_ENABLED) || defined(X11_ENABLED)
  1514. if (is_execute) {
  1515. // we need execute rights on this file
  1516. chmod(file.utf8().get_data(), 0755);
  1517. }
  1518. #endif
  1519. }
  1520. ret = unzGoToNextFile(src_pkg_zip);
  1521. }
  1522. /* we're done with our source zip */
  1523. unzClose(src_pkg_zip);
  1524. if (!found_library) {
  1525. ERR_PRINTS("Requested template library '" + library_to_use + "' not found. It might be missing from your template archive.");
  1526. memdelete(tmp_app_path);
  1527. return ERR_FILE_NOT_FOUND;
  1528. }
  1529. // Copy project static libs to the project
  1530. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  1531. for (int i = 0; i < export_plugins.size(); i++) {
  1532. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  1533. for (int j = 0; j < project_static_libs.size(); j++) {
  1534. const String &static_lib_path = project_static_libs[j];
  1535. String dest_lib_file_path = dest_dir + static_lib_path.get_file();
  1536. bool dir_exists = tmp_app_path->dir_exists(static_lib_path);
  1537. Error lib_copy_err = dir_exists ? tmp_app_path->copy_dir(static_lib_path, dest_lib_file_path) : tmp_app_path->copy(static_lib_path, dest_lib_file_path);
  1538. if (lib_copy_err != OK) {
  1539. ERR_PRINTS("Can't copy '" + static_lib_path + "'.");
  1540. memdelete(tmp_app_path);
  1541. return lib_copy_err;
  1542. }
  1543. }
  1544. }
  1545. String iconset_dir = dest_dir + binary_name + "/Images.xcassets/AppIcon.appiconset/";
  1546. err = OK;
  1547. if (!tmp_app_path->dir_exists(iconset_dir)) {
  1548. err = tmp_app_path->make_dir_recursive(iconset_dir);
  1549. }
  1550. memdelete(tmp_app_path);
  1551. if (err) {
  1552. return err;
  1553. }
  1554. err = _export_icons(p_preset, iconset_dir);
  1555. if (err) {
  1556. return err;
  1557. }
  1558. bool use_storyboard = p_preset->get("storyboard/use_launch_screen_storyboard");
  1559. String launch_image_path = dest_dir + binary_name + "/Images.xcassets/LaunchImage.launchimage/";
  1560. String splash_image_path = dest_dir + binary_name + "/Images.xcassets/SplashImage.imageset/";
  1561. DirAccess *launch_screen_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1562. if (!launch_screen_da) {
  1563. return ERR_CANT_CREATE;
  1564. }
  1565. if (use_storyboard) {
  1566. print_line("Using Launch Storyboard");
  1567. if (launch_screen_da->change_dir(launch_image_path) == OK) {
  1568. launch_screen_da->erase_contents_recursive();
  1569. launch_screen_da->remove(launch_image_path);
  1570. }
  1571. err = _export_loading_screen_file(p_preset, splash_image_path);
  1572. } else {
  1573. print_line("Using Launch Images");
  1574. const String launch_screen_path = dest_dir + binary_name + "/Launch Screen.storyboard";
  1575. launch_screen_da->remove(launch_screen_path);
  1576. if (launch_screen_da->change_dir(splash_image_path) == OK) {
  1577. launch_screen_da->erase_contents_recursive();
  1578. launch_screen_da->remove(splash_image_path);
  1579. }
  1580. err = _export_loading_screen_images(p_preset, launch_image_path);
  1581. }
  1582. memdelete(launch_screen_da);
  1583. if (err) {
  1584. return err;
  1585. }
  1586. print_line("Exporting additional assets");
  1587. _export_additional_assets(dest_dir + binary_name, libraries, assets);
  1588. _add_assets_to_project(p_preset, project_file_data, assets);
  1589. String project_file_name = dest_dir + binary_name + ".xcodeproj/project.pbxproj";
  1590. FileAccess *f = FileAccess::open(project_file_name, FileAccess::WRITE);
  1591. if (!f) {
  1592. ERR_PRINTS("Can't write '" + project_file_name + "'.");
  1593. return ERR_CANT_CREATE;
  1594. };
  1595. f->store_buffer(project_file_data.ptr(), project_file_data.size());
  1596. f->close();
  1597. memdelete(f);
  1598. #ifdef OSX_ENABLED
  1599. if (ep.step("Code-signing dylibs", 2)) {
  1600. return ERR_SKIP;
  1601. }
  1602. DirAccess *dylibs_dir = DirAccess::open(dest_dir + binary_name + "/dylibs");
  1603. ERR_FAIL_COND_V(!dylibs_dir, ERR_CANT_OPEN);
  1604. CodesignData codesign_data(p_preset, p_debug);
  1605. err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data);
  1606. memdelete(dylibs_dir);
  1607. ERR_FAIL_COND_V(err, err);
  1608. if (ep.step("Making .xcarchive", 3)) {
  1609. return ERR_SKIP;
  1610. }
  1611. String archive_path = p_path.get_basename() + ".xcarchive";
  1612. List<String> archive_args;
  1613. archive_args.push_back("-project");
  1614. archive_args.push_back(dest_dir + binary_name + ".xcodeproj");
  1615. archive_args.push_back("-scheme");
  1616. archive_args.push_back(binary_name);
  1617. archive_args.push_back("-sdk");
  1618. archive_args.push_back("iphoneos");
  1619. archive_args.push_back("-configuration");
  1620. archive_args.push_back(p_debug ? "Debug" : "Release");
  1621. archive_args.push_back("-destination");
  1622. archive_args.push_back("generic/platform=iOS");
  1623. archive_args.push_back("archive");
  1624. archive_args.push_back("-archivePath");
  1625. archive_args.push_back(archive_path);
  1626. err = OS::get_singleton()->execute("xcodebuild", archive_args, true);
  1627. ERR_FAIL_COND_V(err, err);
  1628. if (ep.step("Making .ipa", 4)) {
  1629. return ERR_SKIP;
  1630. }
  1631. List<String> export_args;
  1632. export_args.push_back("-exportArchive");
  1633. export_args.push_back("-archivePath");
  1634. export_args.push_back(archive_path);
  1635. export_args.push_back("-exportOptionsPlist");
  1636. export_args.push_back(dest_dir + binary_name + "/export_options.plist");
  1637. export_args.push_back("-allowProvisioningUpdates");
  1638. export_args.push_back("-exportPath");
  1639. export_args.push_back(dest_dir);
  1640. err = OS::get_singleton()->execute("xcodebuild", export_args, true);
  1641. ERR_FAIL_COND_V(err, err);
  1642. #else
  1643. print_line(".ipa can only be built on macOS. Leaving Xcode project without building the package.");
  1644. #endif
  1645. return OK;
  1646. }
  1647. bool EditorExportPlatformIOS::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  1648. String err;
  1649. bool valid = false;
  1650. // Look for export templates (first official, and if defined custom templates).
  1651. bool dvalid = exists_export_template("iphone.zip", &err);
  1652. bool rvalid = dvalid; // Both in the same ZIP.
  1653. if (p_preset->get("custom_template/debug") != "") {
  1654. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  1655. if (!dvalid) {
  1656. err += TTR("Custom debug template not found.") + "\n";
  1657. }
  1658. }
  1659. if (p_preset->get("custom_template/release") != "") {
  1660. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  1661. if (!rvalid) {
  1662. err += TTR("Custom release template not found.") + "\n";
  1663. }
  1664. }
  1665. valid = dvalid || rvalid;
  1666. r_missing_templates = !valid;
  1667. // Validate the rest of the configuration.
  1668. String team_id = p_preset->get("application/app_store_team_id");
  1669. if (team_id.length() == 0) {
  1670. err += TTR("App Store Team ID not specified - cannot configure the project.") + "\n";
  1671. valid = false;
  1672. }
  1673. String identifier = p_preset->get("application/identifier");
  1674. String pn_err;
  1675. if (!is_package_name_valid(identifier, &pn_err)) {
  1676. err += TTR("Invalid Identifier:") + " " + pn_err + "\n";
  1677. valid = false;
  1678. }
  1679. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  1680. IconInfo info = icon_infos[i];
  1681. String icon_path = p_preset->get(info.preset_key);
  1682. if (icon_path.length() == 0) {
  1683. if (info.is_required) {
  1684. err += TTR("Required icon is not specified in the preset.") + "\n";
  1685. valid = false;
  1686. }
  1687. break;
  1688. }
  1689. }
  1690. String etc_error = test_etc2_or_pvrtc();
  1691. if (etc_error != String()) {
  1692. valid = false;
  1693. err += etc_error;
  1694. }
  1695. if (!err.empty()) {
  1696. r_error = err;
  1697. }
  1698. return valid;
  1699. }
  1700. EditorExportPlatformIOS::EditorExportPlatformIOS() {
  1701. Ref<Image> img = memnew(Image(_iphone_logo));
  1702. logo.instance();
  1703. logo->create_from_image(img);
  1704. plugins_changed.set();
  1705. check_for_changes_thread.start(_check_for_changes_poll_thread, this);
  1706. }
  1707. EditorExportPlatformIOS::~EditorExportPlatformIOS() {
  1708. quit_request.set();
  1709. check_for_changes_thread.wait_to_finish();
  1710. }
  1711. void register_iphone_exporter() {
  1712. Ref<EditorExportPlatformIOS> platform;
  1713. platform.instance();
  1714. EditorExport::get_singleton()->add_export_platform(platform);
  1715. }