export_plugin.cpp 75 KB

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