export_plugin.cpp 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410
  1. /**************************************************************************/
  2. /* export_plugin.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "logo_svg.gen.h"
  32. #include "run_icon_svg.gen.h"
  33. #include "core/io/json.h"
  34. #include "core/string/translation.h"
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_paths.h"
  37. #include "editor/editor_scale.h"
  38. #include "editor/export/editor_export.h"
  39. #include "editor/plugins/script_editor_plugin.h"
  40. #include "modules/modules_enabled.gen.h" // For mono and svg.
  41. #ifdef MODULE_SVG_ENABLED
  42. #include "modules/svg/image_loader_svg.h"
  43. #endif
  44. void EditorExportPlatformIOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
  45. // Vulkan and OpenGL ES 3.0 both mandate ETC2 support.
  46. r_features->push_back("etc2");
  47. r_features->push_back("astc");
  48. Vector<String> architectures = _get_preset_architectures(p_preset);
  49. for (int i = 0; i < architectures.size(); ++i) {
  50. r_features->push_back(architectures[i]);
  51. }
  52. }
  53. Vector<EditorExportPlatformIOS::ExportArchitecture> EditorExportPlatformIOS::_get_supported_architectures() const {
  54. Vector<ExportArchitecture> archs;
  55. archs.push_back(ExportArchitecture("arm64", true));
  56. return archs;
  57. }
  58. struct IconInfo {
  59. const char *preset_key;
  60. const char *idiom;
  61. const char *export_name;
  62. const char *actual_size_side;
  63. const char *scale;
  64. const char *unscaled_size;
  65. const bool force_opaque;
  66. };
  67. static const IconInfo icon_infos[] = {
  68. // Home screen on iPhone
  69. { PNAME("icons/iphone_120x120"), "iphone", "Icon-120.png", "120", "2x", "60x60", false },
  70. { PNAME("icons/iphone_120x120"), "iphone", "Icon-120.png", "120", "3x", "40x40", false },
  71. { PNAME("icons/iphone_180x180"), "iphone", "Icon-180.png", "180", "3x", "60x60", false },
  72. // Home screen on iPad
  73. { PNAME("icons/ipad_76x76"), "ipad", "Icon-76.png", "76", "1x", "76x76", false },
  74. { PNAME("icons/ipad_152x152"), "ipad", "Icon-152.png", "152", "2x", "76x76", false },
  75. { PNAME("icons/ipad_167x167"), "ipad", "Icon-167.png", "167", "2x", "83.5x83.5", false },
  76. // App Store
  77. { PNAME("icons/app_store_1024x1024"), "ios-marketing", "Icon-1024.png", "1024", "1x", "1024x1024", true },
  78. // Spotlight
  79. { PNAME("icons/spotlight_40x40"), "ipad", "Icon-40.png", "40", "1x", "40x40", false },
  80. { PNAME("icons/spotlight_80x80"), "iphone", "Icon-80.png", "80", "2x", "40x40", false },
  81. { PNAME("icons/spotlight_80x80"), "ipad", "Icon-80.png", "80", "2x", "40x40", false },
  82. // Settings
  83. { PNAME("icons/settings_58x58"), "iphone", "Icon-58.png", "58", "2x", "29x29", false },
  84. { PNAME("icons/settings_58x58"), "ipad", "Icon-58.png", "58", "2x", "29x29", false },
  85. { PNAME("icons/settings_87x87"), "iphone", "Icon-87.png", "87", "3x", "29x29", false },
  86. // Notification
  87. { PNAME("icons/notification_40x40"), "iphone", "Icon-40.png", "40", "2x", "20x20", false },
  88. { PNAME("icons/notification_40x40"), "ipad", "Icon-40.png", "40", "2x", "20x20", false },
  89. { PNAME("icons/notification_60x60"), "iphone", "Icon-60.png", "60", "3x", "20x20", false }
  90. };
  91. struct LoadingScreenInfo {
  92. const char *preset_key;
  93. const char *export_name;
  94. int width = 0;
  95. int height = 0;
  96. bool rotate = false;
  97. };
  98. static const LoadingScreenInfo loading_screen_infos[] = {
  99. { PNAME("landscape_launch_screens/iphone_2436x1125"), "Default-Landscape-X.png", 2436, 1125, false },
  100. { PNAME("landscape_launch_screens/iphone_2208x1242"), "[email protected]", 2208, 1242, false },
  101. { PNAME("landscape_launch_screens/ipad_1024x768"), "Default-Landscape.png", 1024, 768, false },
  102. { PNAME("landscape_launch_screens/ipad_2048x1536"), "[email protected]", 2048, 1536, false },
  103. { PNAME("portrait_launch_screens/iphone_640x960"), "[email protected]", 640, 960, false },
  104. { PNAME("portrait_launch_screens/iphone_640x1136"), "[email protected]", 640, 1136, false },
  105. { PNAME("portrait_launch_screens/iphone_750x1334"), "[email protected]", 750, 1334, false },
  106. { PNAME("portrait_launch_screens/iphone_1125x2436"), "Default-Portrait-X.png", 1125, 2436, false },
  107. { PNAME("portrait_launch_screens/ipad_768x1024"), "Default-Portrait.png", 768, 1024, false },
  108. { PNAME("portrait_launch_screens/ipad_1536x2048"), "[email protected]", 1536, 2048, false },
  109. { PNAME("portrait_launch_screens/iphone_1242x2208"), "[email protected]", 1242, 2208, false }
  110. };
  111. String EditorExportPlatformIOS::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const {
  112. if (p_preset) {
  113. if (p_name == "application/app_store_team_id") {
  114. String team_id = p_preset->get("application/app_store_team_id");
  115. if (team_id.is_empty()) {
  116. return TTR("App Store Team ID not specified.") + "\n";
  117. }
  118. } else if (p_name == "application/bundle_identifier") {
  119. String identifier = p_preset->get("application/bundle_identifier");
  120. String pn_err;
  121. if (!is_package_name_valid(identifier, &pn_err)) {
  122. return TTR("Invalid Identifier:") + " " + pn_err;
  123. }
  124. }
  125. }
  126. return String();
  127. }
  128. bool EditorExportPlatformIOS::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const {
  129. if (p_preset) {
  130. bool sb = p_preset->get("storyboard/use_launch_screen_storyboard");
  131. if (!sb && p_option != "storyboard/use_launch_screen_storyboard" && p_option.begins_with("storyboard/")) {
  132. return false;
  133. }
  134. }
  135. return true;
  136. }
  137. void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options) const {
  138. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  139. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  140. Vector<ExportArchitecture> architectures = _get_supported_architectures();
  141. for (int i = 0; i < architectures.size(); ++i) {
  142. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("architectures"), architectures[i].name)), architectures[i].is_default));
  143. }
  144. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_store_team_id"), "", false, true));
  145. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_debug", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
  146. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_debug", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Developer"), ""));
  147. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_debug", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 1));
  148. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_release", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
  149. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_release", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Distribution"), ""));
  150. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_release", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 0));
  151. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/targeted_device_family", PROPERTY_HINT_ENUM, "iPhone,iPad,iPhone & iPad"), 2));
  152. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "", false, true));
  153. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  154. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
  155. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
  156. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
  157. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/launch_screens_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
  158. Vector<PluginConfigIOS> found_plugins = get_plugins();
  159. for (int i = 0; i < found_plugins.size(); i++) {
  160. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("plugins"), found_plugins[i].name)), false));
  161. }
  162. HashSet<String> plist_keys;
  163. for (int i = 0; i < found_plugins.size(); i++) {
  164. // Editable plugin plist values
  165. PluginConfigIOS plugin = found_plugins[i];
  166. for (const KeyValue<String, PluginConfigIOS::PlistItem> &E : plugin.plist) {
  167. switch (E.value.type) {
  168. case PluginConfigIOS::PlistItemType::STRING_INPUT: {
  169. String preset_name = "plugins_plist/" + E.key;
  170. if (!plist_keys.has(preset_name)) {
  171. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, preset_name), E.value.value));
  172. plist_keys.insert(preset_name);
  173. }
  174. } break;
  175. default:
  176. continue;
  177. }
  178. }
  179. }
  180. plugins_changed.clear();
  181. plugins = found_plugins;
  182. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/access_wifi"), false));
  183. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/push_notifications"), false));
  184. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_files_app"), false));
  185. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_itunes_sharing"), false));
  186. 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"), ""));
  187. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  188. 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"), ""));
  189. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  190. 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"), ""));
  191. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photolibrary_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  192. HashSet<String> used_names;
  193. for (uint64_t i = 0; i < sizeof(icon_infos) / sizeof(icon_infos[0]); ++i) {
  194. if (!used_names.has(icon_infos[i].preset_key)) {
  195. used_names.insert(icon_infos[i].preset_key);
  196. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, icon_infos[i].preset_key, PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  197. }
  198. }
  199. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "storyboard/use_launch_screen_storyboard"), false, true));
  200. 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));
  201. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@2x", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  202. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@3x", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  203. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "storyboard/use_custom_bg_color"), false));
  204. r_options->push_back(ExportOption(PropertyInfo(Variant::COLOR, "storyboard/custom_bg_color"), Color()));
  205. for (uint64_t i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  206. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, loading_screen_infos[i].preset_key, PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  207. }
  208. }
  209. void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const IOSConfigData &p_config, bool p_debug) {
  210. static const String export_method_string[] = {
  211. "app-store",
  212. "development",
  213. "ad-hoc",
  214. "enterprise"
  215. };
  216. static const String storyboard_image_scale_mode[] = {
  217. "center",
  218. "scaleAspectFit",
  219. "scaleAspectFill",
  220. "scaleToFill"
  221. };
  222. 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");
  223. 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");
  224. bool dbg_manual = !p_preset->get_or_env("application/provisioning_profile_uuid_debug", ENV_IOS_PROFILE_UUID_DEBUG).operator String().is_empty() || (dbg_sign_id != "iPhone Developer");
  225. bool rel_manual = !p_preset->get_or_env("application/provisioning_profile_uuid_release", ENV_IOS_PROFILE_UUID_RELEASE).operator String().is_empty() || (rel_sign_id != "iPhone Distribution");
  226. String str;
  227. String strnew;
  228. str.parse_utf8((const char *)pfile.ptr(), pfile.size());
  229. Vector<String> lines = str.split("\n");
  230. for (int i = 0; i < lines.size(); i++) {
  231. if (lines[i].find("$binary") != -1) {
  232. strnew += lines[i].replace("$binary", p_config.binary_name) + "\n";
  233. } else if (lines[i].find("$modules_buildfile") != -1) {
  234. strnew += lines[i].replace("$modules_buildfile", p_config.modules_buildfile) + "\n";
  235. } else if (lines[i].find("$modules_fileref") != -1) {
  236. strnew += lines[i].replace("$modules_fileref", p_config.modules_fileref) + "\n";
  237. } else if (lines[i].find("$modules_buildphase") != -1) {
  238. strnew += lines[i].replace("$modules_buildphase", p_config.modules_buildphase) + "\n";
  239. } else if (lines[i].find("$modules_buildgrp") != -1) {
  240. strnew += lines[i].replace("$modules_buildgrp", p_config.modules_buildgrp) + "\n";
  241. } else if (lines[i].find("$name") != -1) {
  242. strnew += lines[i].replace("$name", p_config.pkg_name) + "\n";
  243. } else if (lines[i].find("$bundle_identifier") != -1) {
  244. strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
  245. } else if (lines[i].find("$short_version") != -1) {
  246. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  247. } else if (lines[i].find("$version") != -1) {
  248. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  249. } else if (lines[i].find("$signature") != -1) {
  250. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  251. } else if (lines[i].find("$team_id") != -1) {
  252. strnew += lines[i].replace("$team_id", p_preset->get("application/app_store_team_id")) + "\n";
  253. } else if (lines[i].find("$default_build_config") != -1) {
  254. strnew += lines[i].replace("$default_build_config", p_debug ? "Debug" : "Release") + "\n";
  255. } else if (lines[i].find("$export_method") != -1) {
  256. int export_method = p_preset->get(p_debug ? "application/export_method_debug" : "application/export_method_release");
  257. strnew += lines[i].replace("$export_method", export_method_string[export_method]) + "\n";
  258. } else if (lines[i].find("$provisioning_profile_uuid_release") != -1) {
  259. strnew += lines[i].replace("$provisioning_profile_uuid_release", p_preset->get_or_env("application/provisioning_profile_uuid_release", ENV_IOS_PROFILE_UUID_RELEASE)) + "\n";
  260. } else if (lines[i].find("$provisioning_profile_uuid_debug") != -1) {
  261. strnew += lines[i].replace("$provisioning_profile_uuid_debug", p_preset->get_or_env("application/provisioning_profile_uuid_debug", ENV_IOS_PROFILE_UUID_DEBUG)) + "\n";
  262. } else if (lines[i].find("$code_sign_style_debug") != -1) {
  263. if (dbg_manual) {
  264. strnew += lines[i].replace("$code_sign_style_debug", "Manual") + "\n";
  265. } else {
  266. strnew += lines[i].replace("$code_sign_style_debug", "Automatic") + "\n";
  267. }
  268. } else if (lines[i].find("$code_sign_style_release") != -1) {
  269. if (rel_manual) {
  270. strnew += lines[i].replace("$code_sign_style_release", "Manual") + "\n";
  271. } else {
  272. strnew += lines[i].replace("$code_sign_style_release", "Automatic") + "\n";
  273. }
  274. } else if (lines[i].find("$provisioning_profile_uuid") != -1) {
  275. String uuid = p_debug ? p_preset->get_or_env("application/provisioning_profile_uuid_debug", ENV_IOS_PROFILE_UUID_DEBUG) : p_preset->get_or_env("application/provisioning_profile_uuid_release", ENV_IOS_PROFILE_UUID_RELEASE);
  276. strnew += lines[i].replace("$provisioning_profile_uuid", uuid) + "\n";
  277. } else if (lines[i].find("$code_sign_identity_debug") != -1) {
  278. strnew += lines[i].replace("$code_sign_identity_debug", dbg_sign_id) + "\n";
  279. } else if (lines[i].find("$code_sign_identity_release") != -1) {
  280. strnew += lines[i].replace("$code_sign_identity_release", rel_sign_id) + "\n";
  281. } else if (lines[i].find("$additional_plist_content") != -1) {
  282. strnew += lines[i].replace("$additional_plist_content", p_config.plist_content) + "\n";
  283. } else if (lines[i].find("$godot_archs") != -1) {
  284. strnew += lines[i].replace("$godot_archs", p_config.architectures) + "\n";
  285. } else if (lines[i].find("$linker_flags") != -1) {
  286. strnew += lines[i].replace("$linker_flags", p_config.linker_flags) + "\n";
  287. } else if (lines[i].find("$targeted_device_family") != -1) {
  288. String xcode_value;
  289. switch ((int)p_preset->get("application/targeted_device_family")) {
  290. case 0: // iPhone
  291. xcode_value = "1";
  292. break;
  293. case 1: // iPad
  294. xcode_value = "2";
  295. break;
  296. case 2: // iPhone & iPad
  297. xcode_value = "1,2";
  298. break;
  299. }
  300. strnew += lines[i].replace("$targeted_device_family", xcode_value) + "\n";
  301. } else if (lines[i].find("$cpp_code") != -1) {
  302. strnew += lines[i].replace("$cpp_code", p_config.cpp_code) + "\n";
  303. } else if (lines[i].find("$docs_in_place") != -1) {
  304. strnew += lines[i].replace("$docs_in_place", ((bool)p_preset->get("user_data/accessible_from_files_app")) ? "<true/>" : "<false/>") + "\n";
  305. } else if (lines[i].find("$docs_sharing") != -1) {
  306. strnew += lines[i].replace("$docs_sharing", ((bool)p_preset->get("user_data/accessible_from_itunes_sharing")) ? "<true/>" : "<false/>") + "\n";
  307. } else if (lines[i].find("$entitlements_push_notifications") != -1) {
  308. bool is_on = p_preset->get("capabilities/push_notifications");
  309. strnew += lines[i].replace("$entitlements_push_notifications", is_on ? "<key>aps-environment</key><string>development</string>" : "") + "\n";
  310. } else if (lines[i].find("$required_device_capabilities") != -1) {
  311. String capabilities;
  312. // I've removed armv7 as we can run on 64bit only devices
  313. // Note that capabilities listed here are requirements for the app to be installed.
  314. // They don't enable anything.
  315. Vector<String> capabilities_list = p_config.capabilities;
  316. if ((bool)p_preset->get("capabilities/access_wifi") && !capabilities_list.has("wifi")) {
  317. capabilities_list.push_back("wifi");
  318. }
  319. for (int idx = 0; idx < capabilities_list.size(); idx++) {
  320. capabilities += "<string>" + capabilities_list[idx] + "</string>\n";
  321. }
  322. strnew += lines[i].replace("$required_device_capabilities", capabilities);
  323. } else if (lines[i].find("$interface_orientations") != -1) {
  324. String orientations;
  325. const DisplayServer::ScreenOrientation screen_orientation =
  326. DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation")));
  327. switch (screen_orientation) {
  328. case DisplayServer::SCREEN_LANDSCAPE:
  329. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  330. break;
  331. case DisplayServer::SCREEN_PORTRAIT:
  332. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  333. break;
  334. case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
  335. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  336. break;
  337. case DisplayServer::SCREEN_REVERSE_PORTRAIT:
  338. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  339. break;
  340. case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
  341. // Allow both landscape orientations depending on sensor direction.
  342. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  343. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  344. break;
  345. case DisplayServer::SCREEN_SENSOR_PORTRAIT:
  346. // Allow both portrait orientations depending on sensor direction.
  347. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  348. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  349. break;
  350. case DisplayServer::SCREEN_SENSOR:
  351. // Allow all screen orientations depending on sensor direction.
  352. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  353. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  354. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  355. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  356. break;
  357. }
  358. strnew += lines[i].replace("$interface_orientations", orientations);
  359. } else if (lines[i].find("$camera_usage_description") != -1) {
  360. String description = p_preset->get("privacy/camera_usage_description");
  361. strnew += lines[i].replace("$camera_usage_description", description) + "\n";
  362. } else if (lines[i].find("$microphone_usage_description") != -1) {
  363. String description = p_preset->get("privacy/microphone_usage_description");
  364. strnew += lines[i].replace("$microphone_usage_description", description) + "\n";
  365. } else if (lines[i].find("$photolibrary_usage_description") != -1) {
  366. String description = p_preset->get("privacy/photolibrary_usage_description");
  367. strnew += lines[i].replace("$photolibrary_usage_description", description) + "\n";
  368. } else if (lines[i].find("$plist_launch_screen_name") != -1) {
  369. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  370. String value = is_on ? "<key>UILaunchStoryboardName</key>\n<string>Launch Screen</string>" : "";
  371. strnew += lines[i].replace("$plist_launch_screen_name", value) + "\n";
  372. } else if (lines[i].find("$pbx_launch_screen_file_reference") != -1) {
  373. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  374. String value = is_on ? "90DD2D9D24B36E8000717FE1 = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = \"Launch Screen.storyboard\"; sourceTree = \"<group>\"; };" : "";
  375. strnew += lines[i].replace("$pbx_launch_screen_file_reference", value) + "\n";
  376. } else if (lines[i].find("$pbx_launch_screen_copy_files") != -1) {
  377. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  378. String value = is_on ? "90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */," : "";
  379. strnew += lines[i].replace("$pbx_launch_screen_copy_files", value) + "\n";
  380. } else if (lines[i].find("$pbx_launch_screen_build_phase") != -1) {
  381. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  382. String value = is_on ? "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */," : "";
  383. strnew += lines[i].replace("$pbx_launch_screen_build_phase", value) + "\n";
  384. } else if (lines[i].find("$pbx_launch_screen_build_reference") != -1) {
  385. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  386. String value = is_on ? "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */; };" : "";
  387. strnew += lines[i].replace("$pbx_launch_screen_build_reference", value) + "\n";
  388. } else if (lines[i].find("$pbx_launch_image_usage_setting") != -1) {
  389. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  390. String value = is_on ? "" : "ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;";
  391. strnew += lines[i].replace("$pbx_launch_image_usage_setting", value) + "\n";
  392. } else if (lines[i].find("$launch_screen_image_mode") != -1) {
  393. int image_scale_mode = p_preset->get("storyboard/image_scale_mode");
  394. String value;
  395. switch (image_scale_mode) {
  396. case 0: {
  397. String logo_path = GLOBAL_GET("application/boot_splash/image");
  398. bool is_on = GLOBAL_GET("application/boot_splash/fullsize");
  399. // If custom logo is not specified, Godot does not scale default one, so we should do the same.
  400. value = (is_on && logo_path.length() > 0) ? "scaleAspectFit" : "center";
  401. } break;
  402. default: {
  403. value = storyboard_image_scale_mode[image_scale_mode - 1];
  404. }
  405. }
  406. strnew += lines[i].replace("$launch_screen_image_mode", value) + "\n";
  407. } else if (lines[i].find("$launch_screen_background_color") != -1) {
  408. bool use_custom = p_preset->get("storyboard/use_custom_bg_color");
  409. Color color = use_custom ? p_preset->get("storyboard/custom_bg_color") : GLOBAL_GET("application/boot_splash/bg_color");
  410. const String value_format = "red=\"$red\" green=\"$green\" blue=\"$blue\" alpha=\"$alpha\"";
  411. Dictionary value_dictionary;
  412. value_dictionary["red"] = color.r;
  413. value_dictionary["green"] = color.g;
  414. value_dictionary["blue"] = color.b;
  415. value_dictionary["alpha"] = color.a;
  416. String value = value_format.format(value_dictionary, "$_");
  417. strnew += lines[i].replace("$launch_screen_background_color", value) + "\n";
  418. } else if (lines[i].find("$pbx_locale_file_reference") != -1) {
  419. String locale_files;
  420. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  421. if (translations.size() > 0) {
  422. HashSet<String> languages;
  423. for (const String &E : translations) {
  424. Ref<Translation> tr = ResourceLoader::load(E);
  425. if (tr.is_valid() && tr->get_locale() != "en") {
  426. languages.insert(tr->get_locale());
  427. }
  428. }
  429. int index = 0;
  430. for (const String &lang : languages) {
  431. 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";
  432. index++;
  433. }
  434. }
  435. strnew += lines[i].replace("$pbx_locale_file_reference", locale_files);
  436. } else if (lines[i].find("$pbx_locale_build_reference") != -1) {
  437. String locale_files;
  438. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  439. if (translations.size() > 0) {
  440. HashSet<String> languages;
  441. for (const String &E : translations) {
  442. Ref<Translation> tr = ResourceLoader::load(E);
  443. if (tr.is_valid() && tr->get_locale() != "en") {
  444. languages.insert(tr->get_locale());
  445. }
  446. }
  447. int index = 0;
  448. for (const String &lang : languages) {
  449. locale_files += "D0BCFE4518AEBDA2004A" + itos(index).pad_zeros(4) + " /* " + lang + " */,\n";
  450. index++;
  451. }
  452. }
  453. strnew += lines[i].replace("$pbx_locale_build_reference", locale_files);
  454. } else if (lines[i].find("$swift_runtime_migration") != -1) {
  455. String value = !p_config.use_swift_runtime ? "" : "LastSwiftMigration = 1250;";
  456. strnew += lines[i].replace("$swift_runtime_migration", value) + "\n";
  457. } else if (lines[i].find("$swift_runtime_build_settings") != -1) {
  458. String value = !p_config.use_swift_runtime ? "" : R"(
  459. CLANG_ENABLE_MODULES = YES;
  460. SWIFT_OBJC_BRIDGING_HEADER = "$binary/dummy.h";
  461. SWIFT_VERSION = 5.0;
  462. )";
  463. value = value.replace("$binary", p_config.binary_name);
  464. strnew += lines[i].replace("$swift_runtime_build_settings", value) + "\n";
  465. } else if (lines[i].find("$swift_runtime_fileref") != -1) {
  466. String value = !p_config.use_swift_runtime ? "" : R"(
  467. 90B4C2AA2680BC560039117A /* dummy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "dummy.h"; sourceTree = "<group>"; };
  468. 90B4C2B52680C7E90039117A /* dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "dummy.swift"; sourceTree = "<group>"; };
  469. )";
  470. strnew += lines[i].replace("$swift_runtime_fileref", value) + "\n";
  471. } else if (lines[i].find("$swift_runtime_binary_files") != -1) {
  472. String value = !p_config.use_swift_runtime ? "" : R"(
  473. 90B4C2AA2680BC560039117A /* dummy.h */,
  474. 90B4C2B52680C7E90039117A /* dummy.swift */,
  475. )";
  476. strnew += lines[i].replace("$swift_runtime_binary_files", value) + "\n";
  477. } else if (lines[i].find("$swift_runtime_buildfile") != -1) {
  478. String value = !p_config.use_swift_runtime ? "" : "90B4C2B62680C7E90039117A /* dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B4C2B52680C7E90039117A /* dummy.swift */; };";
  479. strnew += lines[i].replace("$swift_runtime_buildfile", value) + "\n";
  480. } else if (lines[i].find("$swift_runtime_build_phase") != -1) {
  481. String value = !p_config.use_swift_runtime ? "" : "90B4C2B62680C7E90039117A /* dummy.swift */,";
  482. strnew += lines[i].replace("$swift_runtime_build_phase", value) + "\n";
  483. } else {
  484. strnew += lines[i] + "\n";
  485. }
  486. }
  487. // !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...
  488. // should apply the same fix in our macOS export.
  489. CharString cs = strnew.utf8();
  490. pfile.resize(cs.size() - 1);
  491. for (int i = 0; i < cs.size() - 1; i++) {
  492. pfile.write[i] = cs[i];
  493. }
  494. }
  495. String EditorExportPlatformIOS::_get_additional_plist_content() {
  496. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  497. String result;
  498. for (int i = 0; i < export_plugins.size(); ++i) {
  499. result += export_plugins[i]->get_ios_plist_content();
  500. }
  501. return result;
  502. }
  503. String EditorExportPlatformIOS::_get_linker_flags() {
  504. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  505. String result;
  506. for (int i = 0; i < export_plugins.size(); ++i) {
  507. String flags = export_plugins[i]->get_ios_linker_flags();
  508. if (flags.length() == 0) {
  509. continue;
  510. }
  511. if (result.length() > 0) {
  512. result += ' ';
  513. }
  514. result += flags;
  515. }
  516. // the flags will be enclosed in quotes, so need to escape them
  517. return result.replace("\"", "\\\"");
  518. }
  519. String EditorExportPlatformIOS::_get_cpp_code() {
  520. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  521. String result;
  522. for (int i = 0; i < export_plugins.size(); ++i) {
  523. result += export_plugins[i]->get_ios_cpp_code();
  524. }
  525. return result;
  526. }
  527. void EditorExportPlatformIOS::_blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot) {
  528. ERR_FAIL_COND(p_dst.is_null());
  529. ERR_FAIL_COND(p_src.is_null());
  530. int sw = p_rot ? p_src->get_height() : p_src->get_width();
  531. int sh = p_rot ? p_src->get_width() : p_src->get_height();
  532. int x_pos = (p_dst->get_width() - sw) / 2;
  533. int y_pos = (p_dst->get_height() - sh) / 2;
  534. int xs = (x_pos >= 0) ? 0 : -x_pos;
  535. int ys = (y_pos >= 0) ? 0 : -y_pos;
  536. if (sw + x_pos > p_dst->get_width()) {
  537. sw = p_dst->get_width() - x_pos;
  538. }
  539. if (sh + y_pos > p_dst->get_height()) {
  540. sh = p_dst->get_height() - y_pos;
  541. }
  542. for (int y = ys; y < sh; y++) {
  543. for (int x = xs; x < sw; x++) {
  544. Color sc = p_rot ? p_src->get_pixel(p_src->get_width() - y - 1, x) : p_src->get_pixel(x, y);
  545. Color dc = p_dst->get_pixel(x_pos + x, y_pos + y);
  546. dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r);
  547. dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g);
  548. dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b);
  549. dc.a = (double)(sc.a + dc.a * (1.0 - sc.a));
  550. p_dst->set_pixel(x_pos + x, y_pos + y, dc);
  551. }
  552. }
  553. }
  554. Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
  555. String json_description = "{\"images\":[";
  556. String sizes;
  557. Ref<DirAccess> da = DirAccess::open(p_iconset_dir);
  558. ERR_FAIL_COND_V_MSG(da.is_null(), ERR_CANT_OPEN, "Cannot open directory '" + p_iconset_dir + "'.");
  559. Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color");
  560. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  561. IconInfo info = icon_infos[i];
  562. int side_size = String(info.actual_size_side).to_int();
  563. String icon_path = p_preset->get(info.preset_key);
  564. if (icon_path.length() == 0) {
  565. // Resize main app icon
  566. icon_path = GLOBAL_GET("application/config/icon");
  567. Ref<Image> img = memnew(Image);
  568. Error err = ImageLoader::load_image(icon_path, img);
  569. if (err != OK) {
  570. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
  571. return ERR_UNCONFIGURED;
  572. } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
  573. add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
  574. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  575. Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
  576. new_img->fill(boot_bg_color);
  577. _blend_and_rotate(new_img, img, false);
  578. err = new_img->save_png(p_iconset_dir + info.export_name);
  579. } else {
  580. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  581. err = img->save_png(p_iconset_dir + info.export_name);
  582. }
  583. if (err) {
  584. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
  585. return err;
  586. }
  587. } else {
  588. // Load custom icon and resize if required
  589. Ref<Image> img = memnew(Image);
  590. Error err = ImageLoader::load_image(icon_path, img);
  591. if (err != OK) {
  592. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
  593. return ERR_UNCONFIGURED;
  594. } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
  595. add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
  596. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  597. Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
  598. new_img->fill(boot_bg_color);
  599. _blend_and_rotate(new_img, img, false);
  600. err = new_img->save_png(p_iconset_dir + info.export_name);
  601. } else if (img->get_width() != side_size || img->get_height() != side_size) {
  602. add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s): '%s' has incorrect size %s and was automatically resized to %s.", info.preset_key, icon_path, img->get_size(), Vector2i(side_size, side_size)));
  603. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  604. err = img->save_png(p_iconset_dir + info.export_name);
  605. } else {
  606. err = da->copy(icon_path, p_iconset_dir + info.export_name);
  607. }
  608. if (err) {
  609. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
  610. return err;
  611. }
  612. }
  613. sizes += String(info.actual_size_side) + "\n";
  614. if (i > 0) {
  615. json_description += ",";
  616. }
  617. json_description += String("{");
  618. json_description += String("\"idiom\":") + "\"" + info.idiom + "\",";
  619. json_description += String("\"size\":") + "\"" + info.unscaled_size + "\",";
  620. json_description += String("\"scale\":") + "\"" + info.scale + "\",";
  621. json_description += String("\"filename\":") + "\"" + info.export_name + "\"";
  622. json_description += String("}");
  623. }
  624. json_description += "]}";
  625. Ref<FileAccess> json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
  626. ERR_FAIL_COND_V(json_file.is_null(), ERR_CANT_CREATE);
  627. CharString json_utf8 = json_description.utf8();
  628. json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length());
  629. Ref<FileAccess> sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE);
  630. ERR_FAIL_COND_V(sizes_file.is_null(), ERR_CANT_CREATE);
  631. CharString sizes_utf8 = sizes.utf8();
  632. sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length());
  633. return OK;
  634. }
  635. Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  636. const String custom_launch_image_2x = p_preset->get("storyboard/custom_image@2x");
  637. const String custom_launch_image_3x = p_preset->get("storyboard/custom_image@3x");
  638. if (custom_launch_image_2x.length() > 0 && custom_launch_image_3x.length() > 0) {
  639. Ref<Image> image;
  640. String image_path = p_dest_dir.path_join("[email protected]");
  641. image.instantiate();
  642. Error err = ImageLoader::load_image(custom_launch_image_2x, image);
  643. if (err) {
  644. image.unref();
  645. return err;
  646. }
  647. if (image->save_png(image_path) != OK) {
  648. return ERR_FILE_CANT_WRITE;
  649. }
  650. image.unref();
  651. image_path = p_dest_dir.path_join("[email protected]");
  652. image.instantiate();
  653. err = ImageLoader::load_image(custom_launch_image_3x, image);
  654. if (err) {
  655. image.unref();
  656. return err;
  657. }
  658. if (image->save_png(image_path) != OK) {
  659. return ERR_FILE_CANT_WRITE;
  660. }
  661. } else {
  662. Ref<Image> splash;
  663. const String splash_path = GLOBAL_GET("application/boot_splash/image");
  664. if (!splash_path.is_empty()) {
  665. splash.instantiate();
  666. const Error err = ImageLoader::load_image(splash_path, splash);
  667. if (err) {
  668. splash.unref();
  669. }
  670. }
  671. if (splash.is_null()) {
  672. splash = Ref<Image>(memnew(Image(boot_splash_png)));
  673. }
  674. // Using same image for both @2x and @3x
  675. // because Godot's own boot logo uses single image for all resolutions.
  676. // Also not using @1x image, because devices using this image variant
  677. // are not supported by iOS 9, which is minimal target.
  678. const String splash_png_path_2x = p_dest_dir.path_join("[email protected]");
  679. const String splash_png_path_3x = p_dest_dir.path_join("[email protected]");
  680. if (splash->save_png(splash_png_path_2x) != OK) {
  681. return ERR_FILE_CANT_WRITE;
  682. }
  683. if (splash->save_png(splash_png_path_3x) != OK) {
  684. return ERR_FILE_CANT_WRITE;
  685. }
  686. }
  687. return OK;
  688. }
  689. Error EditorExportPlatformIOS::_export_loading_screen_images(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  690. Ref<DirAccess> da = DirAccess::open(p_dest_dir);
  691. ERR_FAIL_COND_V_MSG(da.is_null(), ERR_CANT_OPEN, "Cannot open directory '" + p_dest_dir + "'.");
  692. for (uint64_t i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  693. LoadingScreenInfo info = loading_screen_infos[i];
  694. String loading_screen_file = p_preset->get(info.preset_key);
  695. Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color");
  696. String boot_logo_path = GLOBAL_GET("application/boot_splash/image");
  697. bool boot_logo_scale = GLOBAL_GET("application/boot_splash/fullsize");
  698. if (loading_screen_file.size() > 0) {
  699. // Load custom loading screens, and resize if required.
  700. Ref<Image> img = memnew(Image);
  701. Error err = ImageLoader::load_image(loading_screen_file, img);
  702. if (err != OK) {
  703. ERR_PRINT("Invalid loading screen (" + String(info.preset_key) + "): '" + loading_screen_file + "'.");
  704. return ERR_UNCONFIGURED;
  705. }
  706. if (img->get_width() != info.width || img->get_height() != info.height) {
  707. 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) + ".");
  708. float aspect_ratio = (float)img->get_width() / (float)img->get_height();
  709. if (boot_logo_scale) {
  710. if (info.height * aspect_ratio <= info.width) {
  711. img->resize(info.height * aspect_ratio, info.height, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  712. } else {
  713. img->resize(info.width, info.width / aspect_ratio, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  714. }
  715. }
  716. Ref<Image> new_img = Image::create_empty(info.width, info.height, false, Image::FORMAT_RGBA8);
  717. new_img->fill(boot_bg_color);
  718. _blend_and_rotate(new_img, img, false);
  719. err = new_img->save_png(p_dest_dir + info.export_name);
  720. } else {
  721. err = da->copy(loading_screen_file, p_dest_dir + info.export_name);
  722. }
  723. if (err) {
  724. String err_str = String("Failed to export loading screen (") + info.preset_key + ") from path '" + loading_screen_file + "'.";
  725. ERR_PRINT(err_str.utf8().get_data());
  726. return err;
  727. }
  728. } else {
  729. // Generate loading screen from the splash screen
  730. Ref<Image> img = Image::create_empty(info.width, info.height, false, Image::FORMAT_RGBA8);
  731. img->fill(boot_bg_color);
  732. Ref<Image> img_bs;
  733. if (boot_logo_path.length() > 0) {
  734. img_bs = Ref<Image>(memnew(Image));
  735. ImageLoader::load_image(boot_logo_path, img_bs);
  736. }
  737. if (!img_bs.is_valid()) {
  738. img_bs = Ref<Image>(memnew(Image(boot_splash_png)));
  739. }
  740. if (img_bs.is_valid()) {
  741. float aspect_ratio = (float)img_bs->get_width() / (float)img_bs->get_height();
  742. if (info.rotate) {
  743. if (boot_logo_scale) {
  744. if (info.width * aspect_ratio <= info.height) {
  745. img_bs->resize(info.width * aspect_ratio, info.width, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  746. } else {
  747. img_bs->resize(info.height, info.height / aspect_ratio, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  748. }
  749. }
  750. } else {
  751. if (boot_logo_scale) {
  752. if (info.height * aspect_ratio <= info.width) {
  753. img_bs->resize(info.height * aspect_ratio, info.height, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  754. } else {
  755. img_bs->resize(info.width, info.width / aspect_ratio, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  756. }
  757. }
  758. }
  759. _blend_and_rotate(img, img_bs, info.rotate);
  760. }
  761. Error err = img->save_png(p_dest_dir + info.export_name);
  762. if (err) {
  763. String err_str = String("Failed to export loading screen (") + info.preset_key + ") from splash screen.";
  764. WARN_PRINT(err_str.utf8().get_data());
  765. }
  766. }
  767. }
  768. return OK;
  769. }
  770. Error EditorExportPlatformIOS::_walk_dir_recursive(Ref<DirAccess> &p_da, FileHandler p_handler, void *p_userdata) {
  771. Vector<String> dirs;
  772. String current_dir = p_da->get_current_dir();
  773. p_da->list_dir_begin();
  774. String path = p_da->get_next();
  775. while (!path.is_empty()) {
  776. if (p_da->current_is_dir()) {
  777. if (path != "." && path != "..") {
  778. dirs.push_back(path);
  779. }
  780. } else {
  781. Error err = p_handler(current_dir.path_join(path), p_userdata);
  782. if (err) {
  783. p_da->list_dir_end();
  784. return err;
  785. }
  786. }
  787. path = p_da->get_next();
  788. }
  789. p_da->list_dir_end();
  790. for (int i = 0; i < dirs.size(); ++i) {
  791. String dir = dirs[i];
  792. p_da->change_dir(dir);
  793. Error err = _walk_dir_recursive(p_da, p_handler, p_userdata);
  794. p_da->change_dir("..");
  795. if (err) {
  796. return err;
  797. }
  798. }
  799. return OK;
  800. }
  801. struct CodesignData {
  802. const Ref<EditorExportPreset> &preset;
  803. bool debug = false;
  804. CodesignData(const Ref<EditorExportPreset> &p_preset, bool p_debug) :
  805. preset(p_preset),
  806. debug(p_debug) {
  807. }
  808. };
  809. Error EditorExportPlatformIOS::_codesign(String p_file, void *p_userdata) {
  810. if (p_file.ends_with(".dylib")) {
  811. CodesignData *data = static_cast<CodesignData *>(p_userdata);
  812. print_line(String("Signing ") + p_file);
  813. String sign_id;
  814. if (data->debug) {
  815. sign_id = data->preset->get("application/code_sign_identity_debug").operator String().is_empty() ? "iPhone Developer" : data->preset->get("application/code_sign_identity_debug");
  816. } else {
  817. sign_id = data->preset->get("application/code_sign_identity_release").operator String().is_empty() ? "iPhone Distribution" : data->preset->get("application/code_sign_identity_release");
  818. }
  819. List<String> codesign_args;
  820. codesign_args.push_back("-f");
  821. codesign_args.push_back("-s");
  822. codesign_args.push_back(sign_id);
  823. codesign_args.push_back(p_file);
  824. String str;
  825. Error err = OS::get_singleton()->execute("codesign", codesign_args, &str, nullptr, true);
  826. print_verbose("codesign (" + p_file + "):\n" + str);
  827. return err;
  828. }
  829. return OK;
  830. }
  831. struct PbxId {
  832. private:
  833. static char _hex_char(uint8_t four_bits) {
  834. if (four_bits < 10) {
  835. return ('0' + four_bits);
  836. }
  837. return 'A' + (four_bits - 10);
  838. }
  839. static String _hex_pad(uint32_t num) {
  840. Vector<char> ret;
  841. ret.resize(sizeof(num) * 2);
  842. for (uint64_t i = 0; i < sizeof(num) * 2; ++i) {
  843. uint8_t four_bits = (num >> (sizeof(num) * 8 - (i + 1) * 4)) & 0xF;
  844. ret.write[i] = _hex_char(four_bits);
  845. }
  846. return String::utf8(ret.ptr(), ret.size());
  847. }
  848. public:
  849. uint32_t high_bits;
  850. uint32_t mid_bits;
  851. uint32_t low_bits;
  852. String str() const {
  853. return _hex_pad(high_bits) + _hex_pad(mid_bits) + _hex_pad(low_bits);
  854. }
  855. PbxId &operator++() {
  856. low_bits++;
  857. if (!low_bits) {
  858. mid_bits++;
  859. if (!mid_bits) {
  860. high_bits++;
  861. }
  862. }
  863. return *this;
  864. }
  865. };
  866. struct ExportLibsData {
  867. Vector<String> lib_paths;
  868. String dest_dir;
  869. };
  870. void EditorExportPlatformIOS::_add_assets_to_project(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets) {
  871. // that is just a random number, we just need Godot IDs not to clash with
  872. // existing IDs in the project.
  873. PbxId current_id = { 0x58938401, 0, 0 };
  874. String pbx_files;
  875. String pbx_frameworks_build;
  876. String pbx_frameworks_refs;
  877. String pbx_resources_build;
  878. String pbx_resources_refs;
  879. String pbx_embeded_frameworks;
  880. const String file_info_format = String("$build_id = {isa = PBXBuildFile; fileRef = $ref_id; };\n") +
  881. "$ref_id = {isa = PBXFileReference; lastKnownFileType = $file_type; name = \"$name\"; path = \"$file_path\"; sourceTree = \"<group>\"; };\n";
  882. for (int i = 0; i < p_additional_assets.size(); ++i) {
  883. String additional_asset_info_format = file_info_format;
  884. String build_id = (++current_id).str();
  885. String ref_id = (++current_id).str();
  886. String framework_id = "";
  887. const IOSExportAsset &asset = p_additional_assets[i];
  888. String type;
  889. if (asset.exported_path.ends_with(".framework")) {
  890. if (asset.should_embed) {
  891. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  892. framework_id = (++current_id).str();
  893. pbx_embeded_frameworks += framework_id + ",\n";
  894. }
  895. type = "wrapper.framework";
  896. } else if (asset.exported_path.ends_with(".xcframework")) {
  897. if (asset.should_embed) {
  898. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  899. framework_id = (++current_id).str();
  900. pbx_embeded_frameworks += framework_id + ",\n";
  901. }
  902. type = "wrapper.xcframework";
  903. } else if (asset.exported_path.ends_with(".dylib")) {
  904. type = "compiled.mach-o.dylib";
  905. } else if (asset.exported_path.ends_with(".a")) {
  906. type = "archive.ar";
  907. } else {
  908. type = "file";
  909. }
  910. String &pbx_build = asset.is_framework ? pbx_frameworks_build : pbx_resources_build;
  911. String &pbx_refs = asset.is_framework ? pbx_frameworks_refs : pbx_resources_refs;
  912. if (pbx_build.length() > 0) {
  913. pbx_build += ",\n";
  914. pbx_refs += ",\n";
  915. }
  916. pbx_build += build_id;
  917. pbx_refs += ref_id;
  918. Dictionary format_dict;
  919. format_dict["build_id"] = build_id;
  920. format_dict["ref_id"] = ref_id;
  921. format_dict["name"] = asset.exported_path.get_file();
  922. format_dict["file_path"] = asset.exported_path;
  923. format_dict["file_type"] = type;
  924. if (framework_id.length() > 0) {
  925. format_dict["framework_id"] = framework_id;
  926. }
  927. pbx_files += additional_asset_info_format.format(format_dict, "$_");
  928. }
  929. // Note, frameworks like gamekit are always included in our project.pbxprof file
  930. // even if turned off in capabilities.
  931. String str = String::utf8((const char *)p_project_data.ptr(), p_project_data.size());
  932. str = str.replace("$additional_pbx_files", pbx_files);
  933. str = str.replace("$additional_pbx_frameworks_build", pbx_frameworks_build);
  934. str = str.replace("$additional_pbx_frameworks_refs", pbx_frameworks_refs);
  935. str = str.replace("$additional_pbx_resources_build", pbx_resources_build);
  936. str = str.replace("$additional_pbx_resources_refs", pbx_resources_refs);
  937. str = str.replace("$pbx_embeded_frameworks", pbx_embeded_frameworks);
  938. CharString cs = str.utf8();
  939. p_project_data.resize(cs.size() - 1);
  940. for (int i = 0; i < cs.size() - 1; i++) {
  941. p_project_data.write[i] = cs[i];
  942. }
  943. }
  944. 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) {
  945. String binary_name = p_out_dir.get_file().get_basename();
  946. Ref<DirAccess> da = DirAccess::create_for_path(p_asset);
  947. if (da.is_null()) {
  948. ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't create directory: " + p_asset + ".");
  949. }
  950. bool file_exists = da->file_exists(p_asset);
  951. bool dir_exists = da->dir_exists(p_asset);
  952. if (!file_exists && !dir_exists) {
  953. return ERR_FILE_NOT_FOUND;
  954. }
  955. String base_dir = p_asset.get_base_dir().replace("res://", "");
  956. String destination_dir;
  957. String destination;
  958. String asset_path;
  959. bool create_framework = false;
  960. if (p_is_framework && p_asset.ends_with(".dylib")) {
  961. // For iOS we need to turn .dylib into .framework
  962. // to be able to send application to AppStore
  963. asset_path = String("dylibs").path_join(base_dir);
  964. String file_name;
  965. if (!p_custom_file_name) {
  966. file_name = p_asset.get_basename().get_file();
  967. } else {
  968. file_name = *p_custom_file_name;
  969. }
  970. String framework_name = file_name + ".framework";
  971. asset_path = asset_path.path_join(framework_name);
  972. destination_dir = p_out_dir.path_join(asset_path);
  973. destination = destination_dir.path_join(file_name);
  974. create_framework = true;
  975. } else if (p_is_framework && (p_asset.ends_with(".framework") || p_asset.ends_with(".xcframework"))) {
  976. asset_path = String("dylibs").path_join(base_dir);
  977. String file_name;
  978. if (!p_custom_file_name) {
  979. file_name = p_asset.get_file();
  980. } else {
  981. file_name = *p_custom_file_name;
  982. }
  983. asset_path = asset_path.path_join(file_name);
  984. destination_dir = p_out_dir.path_join(asset_path);
  985. destination = destination_dir;
  986. } else {
  987. asset_path = base_dir;
  988. String file_name;
  989. if (!p_custom_file_name) {
  990. file_name = p_asset.get_file();
  991. } else {
  992. file_name = *p_custom_file_name;
  993. }
  994. destination_dir = p_out_dir.path_join(asset_path);
  995. asset_path = asset_path.path_join(file_name);
  996. destination = p_out_dir.path_join(asset_path);
  997. }
  998. Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  999. ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_out_dir + "'.");
  1000. if (!filesystem_da->dir_exists(destination_dir)) {
  1001. Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir);
  1002. if (make_dir_err) {
  1003. return make_dir_err;
  1004. }
  1005. }
  1006. Error err = dir_exists ? da->copy_dir(p_asset, destination) : da->copy(p_asset, destination);
  1007. if (err) {
  1008. return err;
  1009. }
  1010. IOSExportAsset exported_asset = { binary_name.path_join(asset_path), p_is_framework, p_should_embed };
  1011. r_exported_assets.push_back(exported_asset);
  1012. if (create_framework) {
  1013. String file_name;
  1014. if (!p_custom_file_name) {
  1015. file_name = p_asset.get_basename().get_file();
  1016. } else {
  1017. file_name = *p_custom_file_name;
  1018. }
  1019. String framework_name = file_name + ".framework";
  1020. // Performing `install_name_tool -id @rpath/{name}.framework/{name} ./{name}` on dylib
  1021. {
  1022. List<String> install_name_args;
  1023. install_name_args.push_back("-id");
  1024. install_name_args.push_back(String("@rpath").path_join(framework_name).path_join(file_name));
  1025. install_name_args.push_back(destination);
  1026. OS::get_singleton()->execute("install_name_tool", install_name_args);
  1027. }
  1028. // Creating Info.plist
  1029. {
  1030. String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1031. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  1032. "<plist version=\"1.0\">\n"
  1033. "<dict>\n"
  1034. "<key>CFBundleShortVersionString</key>\n"
  1035. "<string>1.0</string>\n"
  1036. "<key>CFBundleIdentifier</key>\n"
  1037. "<string>com.gdextension.framework.$name</string>\n"
  1038. "<key>CFBundleName</key>\n"
  1039. "<string>$name</string>\n"
  1040. "<key>CFBundleExecutable</key>\n"
  1041. "<string>$name</string>\n"
  1042. "<key>DTPlatformName</key>\n"
  1043. "<string>iphoneos</string>\n"
  1044. "<key>CFBundleInfoDictionaryVersion</key>\n"
  1045. "<string>6.0</string>\n"
  1046. "<key>CFBundleVersion</key>\n"
  1047. "<string>1</string>\n"
  1048. "<key>CFBundlePackageType</key>\n"
  1049. "<string>FMWK</string>\n"
  1050. "<key>MinimumOSVersion</key>\n"
  1051. "<string>10.0</string>\n"
  1052. "</dict>\n"
  1053. "</plist>";
  1054. String info_plist = info_plist_format.replace("$name", file_name);
  1055. Ref<FileAccess> f = FileAccess::open(destination_dir.path_join("Info.plist"), FileAccess::WRITE);
  1056. if (f.is_valid()) {
  1057. f->store_string(info_plist);
  1058. }
  1059. }
  1060. }
  1061. return OK;
  1062. }
  1063. 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) {
  1064. for (int f_idx = 0; f_idx < p_assets.size(); ++f_idx) {
  1065. String asset = p_assets[f_idx];
  1066. if (!asset.begins_with("res://")) {
  1067. // either SDK-builtin or already a part of the export template
  1068. IOSExportAsset exported_asset = { asset, p_is_framework, p_should_embed };
  1069. r_exported_assets.push_back(exported_asset);
  1070. } else {
  1071. Error err = _copy_asset(p_out_dir, asset, nullptr, p_is_framework, p_should_embed, r_exported_assets);
  1072. ERR_FAIL_COND_V(err, err);
  1073. }
  1074. }
  1075. return OK;
  1076. }
  1077. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets) {
  1078. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  1079. for (int i = 0; i < export_plugins.size(); i++) {
  1080. Vector<String> linked_frameworks = export_plugins[i]->get_ios_frameworks();
  1081. Error err = _export_additional_assets(p_out_dir, linked_frameworks, true, false, r_exported_assets);
  1082. ERR_FAIL_COND_V(err, err);
  1083. Vector<String> embedded_frameworks = export_plugins[i]->get_ios_embedded_frameworks();
  1084. err = _export_additional_assets(p_out_dir, embedded_frameworks, true, true, r_exported_assets);
  1085. ERR_FAIL_COND_V(err, err);
  1086. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  1087. for (int j = 0; j < project_static_libs.size(); j++) {
  1088. project_static_libs.write[j] = project_static_libs[j].get_file(); // Only the file name as it's copied to the project
  1089. }
  1090. err = _export_additional_assets(p_out_dir, project_static_libs, true, false, r_exported_assets);
  1091. ERR_FAIL_COND_V(err, err);
  1092. Vector<String> ios_bundle_files = export_plugins[i]->get_ios_bundle_files();
  1093. err = _export_additional_assets(p_out_dir, ios_bundle_files, false, false, r_exported_assets);
  1094. ERR_FAIL_COND_V(err, err);
  1095. }
  1096. Vector<String> library_paths;
  1097. for (int i = 0; i < p_libraries.size(); ++i) {
  1098. library_paths.push_back(p_libraries[i].path);
  1099. }
  1100. Error err = _export_additional_assets(p_out_dir, library_paths, true, true, r_exported_assets);
  1101. ERR_FAIL_COND_V(err, err);
  1102. return OK;
  1103. }
  1104. Vector<String> EditorExportPlatformIOS::_get_preset_architectures(const Ref<EditorExportPreset> &p_preset) const {
  1105. Vector<ExportArchitecture> all_archs = _get_supported_architectures();
  1106. Vector<String> enabled_archs;
  1107. for (int i = 0; i < all_archs.size(); ++i) {
  1108. bool is_enabled = p_preset->get("architectures/" + all_archs[i].name);
  1109. if (is_enabled) {
  1110. enabled_archs.push_back(all_archs[i].name);
  1111. }
  1112. }
  1113. return enabled_archs;
  1114. }
  1115. 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) {
  1116. String plugin_definition_cpp_code;
  1117. String plugin_initialization_cpp_code;
  1118. String plugin_deinitialization_cpp_code;
  1119. Vector<String> plugin_linked_dependencies;
  1120. Vector<String> plugin_embedded_dependencies;
  1121. Vector<String> plugin_files;
  1122. Vector<PluginConfigIOS> enabled_plugins = get_enabled_plugins(p_preset);
  1123. Vector<String> added_linked_dependenciy_names;
  1124. Vector<String> added_embedded_dependenciy_names;
  1125. HashMap<String, String> plist_values;
  1126. HashSet<String> plugin_linker_flags;
  1127. Error err;
  1128. for (int i = 0; i < enabled_plugins.size(); i++) {
  1129. PluginConfigIOS plugin = enabled_plugins[i];
  1130. // Export plugin binary.
  1131. String plugin_main_binary = PluginConfigIOS::get_plugin_main_binary(plugin, p_debug);
  1132. String plugin_binary_result_file = plugin.binary.get_file();
  1133. // We shouldn't embed .xcframework that contains static libraries.
  1134. // Static libraries are not embedded anyway.
  1135. err = _copy_asset(dest_dir, plugin_main_binary, &plugin_binary_result_file, true, false, r_exported_assets);
  1136. ERR_FAIL_COND_V(err, err);
  1137. // Adding dependencies.
  1138. // Use separate container for names to check for duplicates.
  1139. for (int j = 0; j < plugin.linked_dependencies.size(); j++) {
  1140. String dependency = plugin.linked_dependencies[j];
  1141. String name = dependency.get_file();
  1142. if (added_linked_dependenciy_names.has(name)) {
  1143. continue;
  1144. }
  1145. added_linked_dependenciy_names.push_back(name);
  1146. plugin_linked_dependencies.push_back(dependency);
  1147. }
  1148. for (int j = 0; j < plugin.system_dependencies.size(); j++) {
  1149. String dependency = plugin.system_dependencies[j];
  1150. String name = dependency.get_file();
  1151. if (added_linked_dependenciy_names.has(name)) {
  1152. continue;
  1153. }
  1154. added_linked_dependenciy_names.push_back(name);
  1155. plugin_linked_dependencies.push_back(dependency);
  1156. }
  1157. for (int j = 0; j < plugin.embedded_dependencies.size(); j++) {
  1158. String dependency = plugin.embedded_dependencies[j];
  1159. String name = dependency.get_file();
  1160. if (added_embedded_dependenciy_names.has(name)) {
  1161. continue;
  1162. }
  1163. added_embedded_dependenciy_names.push_back(name);
  1164. plugin_embedded_dependencies.push_back(dependency);
  1165. }
  1166. plugin_files.append_array(plugin.files_to_copy);
  1167. // Capabilities
  1168. // Also checking for duplicates.
  1169. for (int j = 0; j < plugin.capabilities.size(); j++) {
  1170. String capability = plugin.capabilities[j];
  1171. if (p_config_data.capabilities.has(capability)) {
  1172. continue;
  1173. }
  1174. p_config_data.capabilities.push_back(capability);
  1175. }
  1176. // Linker flags
  1177. // Checking duplicates
  1178. for (int j = 0; j < plugin.linker_flags.size(); j++) {
  1179. String linker_flag = plugin.linker_flags[j];
  1180. plugin_linker_flags.insert(linker_flag);
  1181. }
  1182. // Plist
  1183. // Using hash map container to remove duplicates
  1184. for (const KeyValue<String, PluginConfigIOS::PlistItem> &E : plugin.plist) {
  1185. String key = E.key;
  1186. const PluginConfigIOS::PlistItem &item = E.value;
  1187. String value;
  1188. switch (item.type) {
  1189. case PluginConfigIOS::PlistItemType::STRING_INPUT: {
  1190. String preset_name = "plugins_plist/" + key;
  1191. String input_value = p_preset->get(preset_name);
  1192. value = "<string>" + input_value + "</string>";
  1193. } break;
  1194. default:
  1195. value = item.value;
  1196. break;
  1197. }
  1198. if (key.is_empty() || value.is_empty()) {
  1199. continue;
  1200. }
  1201. String plist_key = "<key>" + key + "</key>";
  1202. plist_values[plist_key] = value;
  1203. }
  1204. // CPP Code
  1205. String definition_comment = "// Plugin: " + plugin.name + "\n";
  1206. String initialization_method = plugin.initialization_method + "();\n";
  1207. String deinitialization_method = plugin.deinitialization_method + "();\n";
  1208. plugin_definition_cpp_code += definition_comment +
  1209. "extern void " + initialization_method +
  1210. "extern void " + deinitialization_method + "\n";
  1211. plugin_initialization_cpp_code += "\t" + initialization_method;
  1212. plugin_deinitialization_cpp_code += "\t" + deinitialization_method;
  1213. if (plugin.use_swift_runtime) {
  1214. p_config_data.use_swift_runtime = true;
  1215. }
  1216. }
  1217. // Updating `Info.plist`
  1218. {
  1219. for (const KeyValue<String, String> &E : plist_values) {
  1220. String key = E.key;
  1221. String value = E.value;
  1222. if (key.is_empty() || value.is_empty()) {
  1223. continue;
  1224. }
  1225. p_config_data.plist_content += key + value + "\n";
  1226. }
  1227. }
  1228. // Export files
  1229. {
  1230. // Export linked plugin dependency
  1231. err = _export_additional_assets(dest_dir, plugin_linked_dependencies, true, false, r_exported_assets);
  1232. ERR_FAIL_COND_V(err, err);
  1233. // Export embedded plugin dependency
  1234. err = _export_additional_assets(dest_dir, plugin_embedded_dependencies, true, true, r_exported_assets);
  1235. ERR_FAIL_COND_V(err, err);
  1236. // Export plugin files
  1237. err = _export_additional_assets(dest_dir, plugin_files, false, false, r_exported_assets);
  1238. ERR_FAIL_COND_V(err, err);
  1239. }
  1240. // Update CPP
  1241. {
  1242. Dictionary plugin_format;
  1243. plugin_format["definition"] = plugin_definition_cpp_code;
  1244. plugin_format["initialization"] = plugin_initialization_cpp_code;
  1245. plugin_format["deinitialization"] = plugin_deinitialization_cpp_code;
  1246. String plugin_cpp_code = "\n// Godot Plugins\n"
  1247. "void godot_ios_plugins_initialize();\n"
  1248. "void godot_ios_plugins_deinitialize();\n"
  1249. "// Exported Plugins\n\n"
  1250. "$definition"
  1251. "// Use Plugins\n"
  1252. "void godot_ios_plugins_initialize() {\n"
  1253. "$initialization"
  1254. "}\n\n"
  1255. "void godot_ios_plugins_deinitialize() {\n"
  1256. "$deinitialization"
  1257. "}\n";
  1258. p_config_data.cpp_code += plugin_cpp_code.format(plugin_format, "$_");
  1259. }
  1260. // Update Linker Flag Values
  1261. {
  1262. String result_linker_flags = " ";
  1263. for (const String &E : plugin_linker_flags) {
  1264. const String &flag = E;
  1265. if (flag.length() == 0) {
  1266. continue;
  1267. }
  1268. if (result_linker_flags.length() > 0) {
  1269. result_linker_flags += ' ';
  1270. }
  1271. result_linker_flags += flag;
  1272. }
  1273. result_linker_flags = result_linker_flags.replace("\"", "\\\"");
  1274. p_config_data.linker_flags += result_linker_flags;
  1275. }
  1276. return OK;
  1277. }
  1278. Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  1279. return _export_project_helper(p_preset, p_debug, p_path, p_flags, false, false);
  1280. }
  1281. Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags, bool p_simulator, bool p_skip_ipa) {
  1282. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  1283. String src_pkg_name;
  1284. String dest_dir = p_path.get_base_dir() + "/";
  1285. String binary_name = p_path.get_file().get_basename();
  1286. EditorProgress ep("export", "Exporting for iOS", 5, true);
  1287. String team_id = p_preset->get("application/app_store_team_id");
  1288. ERR_FAIL_COND_V_MSG(team_id.length() == 0, ERR_CANT_OPEN, "App Store Team ID not specified - cannot configure the project.");
  1289. if (p_debug) {
  1290. src_pkg_name = p_preset->get("custom_template/debug");
  1291. } else {
  1292. src_pkg_name = p_preset->get("custom_template/release");
  1293. }
  1294. if (src_pkg_name.is_empty()) {
  1295. String err;
  1296. src_pkg_name = find_export_template("ios.zip", &err);
  1297. if (src_pkg_name.is_empty()) {
  1298. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found."));
  1299. return ERR_FILE_NOT_FOUND;
  1300. }
  1301. }
  1302. if (!DirAccess::exists(dest_dir)) {
  1303. return ERR_FILE_BAD_PATH;
  1304. }
  1305. {
  1306. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1307. if (da.is_valid()) {
  1308. String current_dir = da->get_current_dir();
  1309. // remove leftovers from last export so they don't interfere
  1310. // in case some files are no longer needed
  1311. if (da->change_dir(dest_dir + binary_name + ".xcodeproj") == OK) {
  1312. da->erase_contents_recursive();
  1313. }
  1314. if (da->change_dir(dest_dir + binary_name) == OK) {
  1315. da->erase_contents_recursive();
  1316. }
  1317. da->change_dir(current_dir);
  1318. if (!da->dir_exists(dest_dir + binary_name)) {
  1319. Error err = da->make_dir(dest_dir + binary_name);
  1320. if (err) {
  1321. return err;
  1322. }
  1323. }
  1324. }
  1325. }
  1326. if (ep.step("Making .pck", 0)) {
  1327. return ERR_SKIP;
  1328. }
  1329. String pack_path = dest_dir + binary_name + ".pck";
  1330. Vector<SharedObject> libraries;
  1331. Error err = save_pack(p_preset, p_debug, pack_path, &libraries);
  1332. if (err) {
  1333. return err;
  1334. }
  1335. if (ep.step("Extracting and configuring Xcode project", 1)) {
  1336. return ERR_SKIP;
  1337. }
  1338. String library_to_use = "libgodot.ios." + String(p_debug ? "debug" : "release") + ".xcframework";
  1339. print_line("Static framework: " + library_to_use);
  1340. String pkg_name;
  1341. if (String(GLOBAL_GET("application/config/name")) != "") {
  1342. pkg_name = String(GLOBAL_GET("application/config/name"));
  1343. } else {
  1344. pkg_name = "Unnamed";
  1345. }
  1346. bool found_library = false;
  1347. const String project_file = "godot_ios.xcodeproj/project.pbxproj";
  1348. HashSet<String> files_to_parse;
  1349. files_to_parse.insert("godot_ios/godot_ios-Info.plist");
  1350. files_to_parse.insert(project_file);
  1351. files_to_parse.insert("godot_ios/export_options.plist");
  1352. files_to_parse.insert("godot_ios/dummy.cpp");
  1353. files_to_parse.insert("godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata");
  1354. files_to_parse.insert("godot_ios.xcodeproj/xcshareddata/xcschemes/godot_ios.xcscheme");
  1355. files_to_parse.insert("godot_ios/godot_ios.entitlements");
  1356. files_to_parse.insert("godot_ios/Launch Screen.storyboard");
  1357. IOSConfigData config_data = {
  1358. pkg_name,
  1359. binary_name,
  1360. _get_additional_plist_content(),
  1361. String(" ").join(_get_preset_architectures(p_preset)),
  1362. _get_linker_flags(),
  1363. _get_cpp_code(),
  1364. "",
  1365. "",
  1366. "",
  1367. "",
  1368. Vector<String>(),
  1369. false
  1370. };
  1371. Vector<IOSExportAsset> assets;
  1372. Ref<DirAccess> tmp_app_path = DirAccess::create_for_path(dest_dir);
  1373. ERR_FAIL_COND_V(tmp_app_path.is_null(), ERR_CANT_CREATE);
  1374. print_line("Unzipping...");
  1375. Ref<FileAccess> io_fa;
  1376. zlib_filefunc_def io = zipio_create_io(&io_fa);
  1377. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  1378. if (!src_pkg_zip) {
  1379. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Could not open export template (not a zip file?): \"%s\".", src_pkg_name));
  1380. return ERR_CANT_OPEN;
  1381. }
  1382. err = _export_ios_plugins(p_preset, config_data, dest_dir + binary_name, assets, p_debug);
  1383. ERR_FAIL_COND_V(err, err);
  1384. //export rest of the files
  1385. int ret = unzGoToFirstFile(src_pkg_zip);
  1386. Vector<uint8_t> project_file_data;
  1387. while (ret == UNZ_OK) {
  1388. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  1389. bool is_execute = false;
  1390. #endif
  1391. //get filename
  1392. unz_file_info info;
  1393. char fname[16384];
  1394. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  1395. if (ret != UNZ_OK) {
  1396. break;
  1397. }
  1398. String file = String::utf8(fname);
  1399. print_line("READ: " + file);
  1400. Vector<uint8_t> data;
  1401. data.resize(info.uncompressed_size);
  1402. //read
  1403. unzOpenCurrentFile(src_pkg_zip);
  1404. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  1405. unzCloseCurrentFile(src_pkg_zip);
  1406. //write
  1407. if (files_to_parse.has(file)) {
  1408. _fix_config_file(p_preset, data, config_data, p_debug);
  1409. } else if (file.begins_with("libgodot.ios")) {
  1410. if (!file.begins_with(library_to_use) || file.ends_with(String("/empty"))) {
  1411. ret = unzGoToNextFile(src_pkg_zip);
  1412. continue; //ignore!
  1413. }
  1414. found_library = true;
  1415. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  1416. is_execute = true;
  1417. #endif
  1418. file = file.replace(library_to_use, binary_name + ".xcframework");
  1419. }
  1420. if (file == project_file) {
  1421. project_file_data = data;
  1422. }
  1423. ///@TODO need to parse logo files
  1424. if (data.size() > 0) {
  1425. file = file.replace("godot_ios", binary_name);
  1426. print_line("ADDING: " + file + " size: " + itos(data.size()));
  1427. /* write it into our folder structure */
  1428. file = dest_dir + file;
  1429. /* make sure this folder exists */
  1430. String dir_name = file.get_base_dir();
  1431. if (!tmp_app_path->dir_exists(dir_name)) {
  1432. print_line("Creating " + dir_name);
  1433. Error dir_err = tmp_app_path->make_dir_recursive(dir_name);
  1434. if (dir_err) {
  1435. ERR_PRINT("Can't create '" + dir_name + "'.");
  1436. unzClose(src_pkg_zip);
  1437. return ERR_CANT_CREATE;
  1438. }
  1439. }
  1440. /* write the file */
  1441. {
  1442. Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);
  1443. if (f.is_null()) {
  1444. ERR_PRINT("Can't write '" + file + "'.");
  1445. unzClose(src_pkg_zip);
  1446. return ERR_CANT_CREATE;
  1447. };
  1448. f->store_buffer(data.ptr(), data.size());
  1449. }
  1450. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  1451. if (is_execute) {
  1452. // we need execute rights on this file
  1453. chmod(file.utf8().get_data(), 0755);
  1454. }
  1455. #endif
  1456. }
  1457. ret = unzGoToNextFile(src_pkg_zip);
  1458. }
  1459. /* we're done with our source zip */
  1460. unzClose(src_pkg_zip);
  1461. if (!found_library) {
  1462. ERR_PRINT("Requested template library '" + library_to_use + "' not found. It might be missing from your template archive.");
  1463. return ERR_FILE_NOT_FOUND;
  1464. }
  1465. Dictionary appnames = GLOBAL_GET("application/config/name_localized");
  1466. Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");
  1467. Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");
  1468. Dictionary photolibrary_usage_descriptions = p_preset->get("privacy/photolibrary_usage_description_localized");
  1469. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  1470. if (translations.size() > 0) {
  1471. {
  1472. String fname = dest_dir + binary_name + "/en.lproj";
  1473. tmp_app_path->make_dir_recursive(fname);
  1474. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1475. f->store_line("/* Localized versions of Info.plist keys */");
  1476. f->store_line("");
  1477. f->store_line("CFBundleDisplayName = \"" + GLOBAL_GET("application/config/name").operator String() + "\";");
  1478. f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String() + "\";");
  1479. f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String() + "\";");
  1480. f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photolibrary_usage_description").operator String() + "\";");
  1481. }
  1482. HashSet<String> languages;
  1483. for (const String &E : translations) {
  1484. Ref<Translation> tr = ResourceLoader::load(E);
  1485. if (tr.is_valid() && tr->get_locale() != "en") {
  1486. languages.insert(tr->get_locale());
  1487. }
  1488. }
  1489. for (const String &lang : languages) {
  1490. String fname = dest_dir + binary_name + "/" + lang + ".lproj";
  1491. tmp_app_path->make_dir_recursive(fname);
  1492. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1493. f->store_line("/* Localized versions of Info.plist keys */");
  1494. f->store_line("");
  1495. if (appnames.has(lang)) {
  1496. f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String() + "\";");
  1497. }
  1498. if (camera_usage_descriptions.has(lang)) {
  1499. f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String() + "\";");
  1500. }
  1501. if (microphone_usage_descriptions.has(lang)) {
  1502. f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String() + "\";");
  1503. }
  1504. if (photolibrary_usage_descriptions.has(lang)) {
  1505. f->store_line("NSPhotoLibraryUsageDescription = \"" + photolibrary_usage_descriptions[lang].operator String() + "\";");
  1506. }
  1507. }
  1508. }
  1509. // Copy project static libs to the project
  1510. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  1511. for (int i = 0; i < export_plugins.size(); i++) {
  1512. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  1513. for (int j = 0; j < project_static_libs.size(); j++) {
  1514. const String &static_lib_path = project_static_libs[j];
  1515. String dest_lib_file_path = dest_dir + static_lib_path.get_file();
  1516. Error lib_copy_err = tmp_app_path->copy(static_lib_path, dest_lib_file_path);
  1517. if (lib_copy_err != OK) {
  1518. ERR_PRINT("Can't copy '" + static_lib_path + "'.");
  1519. return lib_copy_err;
  1520. }
  1521. }
  1522. }
  1523. String iconset_dir = dest_dir + binary_name + "/Images.xcassets/AppIcon.appiconset/";
  1524. err = OK;
  1525. if (!tmp_app_path->dir_exists(iconset_dir)) {
  1526. err = tmp_app_path->make_dir_recursive(iconset_dir);
  1527. }
  1528. if (err) {
  1529. return err;
  1530. }
  1531. err = _export_icons(p_preset, iconset_dir);
  1532. if (err) {
  1533. return err;
  1534. }
  1535. {
  1536. bool use_storyboard = p_preset->get("storyboard/use_launch_screen_storyboard");
  1537. String launch_image_path = dest_dir + binary_name + "/Images.xcassets/LaunchImage.launchimage/";
  1538. String splash_image_path = dest_dir + binary_name + "/Images.xcassets/SplashImage.imageset/";
  1539. Ref<DirAccess> launch_screen_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1540. if (launch_screen_da.is_null()) {
  1541. return ERR_CANT_CREATE;
  1542. }
  1543. if (use_storyboard) {
  1544. print_line("Using Launch Storyboard");
  1545. if (launch_screen_da->change_dir(launch_image_path) == OK) {
  1546. launch_screen_da->erase_contents_recursive();
  1547. launch_screen_da->remove(launch_image_path);
  1548. }
  1549. err = _export_loading_screen_file(p_preset, splash_image_path);
  1550. } else {
  1551. print_line("Using Launch Images");
  1552. const String launch_screen_path = dest_dir + binary_name + "/Launch Screen.storyboard";
  1553. launch_screen_da->remove(launch_screen_path);
  1554. if (launch_screen_da->change_dir(splash_image_path) == OK) {
  1555. launch_screen_da->erase_contents_recursive();
  1556. launch_screen_da->remove(splash_image_path);
  1557. }
  1558. err = _export_loading_screen_images(p_preset, launch_image_path);
  1559. }
  1560. }
  1561. if (err) {
  1562. return err;
  1563. }
  1564. print_line("Exporting additional assets");
  1565. _export_additional_assets(dest_dir + binary_name, libraries, assets);
  1566. _add_assets_to_project(p_preset, project_file_data, assets);
  1567. String project_file_name = dest_dir + binary_name + ".xcodeproj/project.pbxproj";
  1568. {
  1569. Ref<FileAccess> f = FileAccess::open(project_file_name, FileAccess::WRITE);
  1570. if (f.is_null()) {
  1571. ERR_PRINT("Can't write '" + project_file_name + "'.");
  1572. return ERR_CANT_CREATE;
  1573. };
  1574. f->store_buffer(project_file_data.ptr(), project_file_data.size());
  1575. }
  1576. #ifdef MACOS_ENABLED
  1577. {
  1578. if (ep.step("Code-signing dylibs", 2)) {
  1579. return ERR_SKIP;
  1580. }
  1581. Ref<DirAccess> dylibs_dir = DirAccess::open(dest_dir + binary_name + "/dylibs");
  1582. ERR_FAIL_COND_V(dylibs_dir.is_null(), ERR_CANT_OPEN);
  1583. CodesignData codesign_data(p_preset, p_debug);
  1584. err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data);
  1585. if (err != OK) {
  1586. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  1587. return err;
  1588. }
  1589. }
  1590. if (ep.step("Making .xcarchive", 3)) {
  1591. return ERR_SKIP;
  1592. }
  1593. String archive_path = p_path.get_basename() + ".xcarchive";
  1594. List<String> archive_args;
  1595. archive_args.push_back("-project");
  1596. archive_args.push_back(dest_dir + binary_name + ".xcodeproj");
  1597. archive_args.push_back("-scheme");
  1598. archive_args.push_back(binary_name);
  1599. archive_args.push_back("-sdk");
  1600. if (p_simulator) {
  1601. archive_args.push_back("iphonesimulator");
  1602. } else {
  1603. archive_args.push_back("iphoneos");
  1604. }
  1605. archive_args.push_back("-configuration");
  1606. archive_args.push_back(p_debug ? "Debug" : "Release");
  1607. archive_args.push_back("-destination");
  1608. if (p_simulator) {
  1609. archive_args.push_back("generic/platform=iOS Simulator");
  1610. } else {
  1611. archive_args.push_back("generic/platform=iOS");
  1612. }
  1613. archive_args.push_back("archive");
  1614. archive_args.push_back("-allowProvisioningUpdates");
  1615. archive_args.push_back("-archivePath");
  1616. archive_args.push_back(archive_path);
  1617. String archive_str;
  1618. err = OS::get_singleton()->execute("xcodebuild", archive_args, &archive_str, nullptr, true);
  1619. ERR_FAIL_COND_V(err, err);
  1620. print_line("xcodebuild (.xcarchive):\n" + archive_str);
  1621. if (!archive_str.contains("** ARCHIVE SUCCEEDED **")) {
  1622. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR("Xcode project build failed, see editor log for details."));
  1623. return FAILED;
  1624. }
  1625. if (!p_skip_ipa) {
  1626. if (ep.step("Making .ipa", 4)) {
  1627. return ERR_SKIP;
  1628. }
  1629. List<String> export_args;
  1630. export_args.push_back("-exportArchive");
  1631. export_args.push_back("-archivePath");
  1632. export_args.push_back(archive_path);
  1633. export_args.push_back("-exportOptionsPlist");
  1634. export_args.push_back(dest_dir + binary_name + "/export_options.plist");
  1635. export_args.push_back("-allowProvisioningUpdates");
  1636. export_args.push_back("-exportPath");
  1637. export_args.push_back(dest_dir);
  1638. String export_str;
  1639. err = OS::get_singleton()->execute("xcodebuild", export_args, &export_str, nullptr, true);
  1640. ERR_FAIL_COND_V(err, err);
  1641. print_line("xcodebuild (.ipa):\n" + export_str);
  1642. if (!export_str.contains("** EXPORT SUCCEEDED **")) {
  1643. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR(".ipa export failed, see editor log for details."));
  1644. return FAILED;
  1645. }
  1646. }
  1647. #else
  1648. add_message(EXPORT_MESSAGE_WARNING, TTR("Xcode Build"), TTR(".ipa can only be built on macOS. Leaving Xcode project without building the package."));
  1649. #endif
  1650. return OK;
  1651. }
  1652. bool EditorExportPlatformIOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const {
  1653. String err;
  1654. bool valid = false;
  1655. #ifdef MODULE_MONO_ENABLED
  1656. err += TTR("Exporting to iOS is currently not supported in Godot 4 when using C#/.NET. Use Godot 3 to target iOS with C#/Mono instead.") + "\n";
  1657. err += TTR("If this project does not use C#, use a non-C# editor build to export the project.") + "\n";
  1658. // Don't check for additional errors, as this particular error cannot be resolved.
  1659. r_error = err;
  1660. return false;
  1661. #endif
  1662. // Look for export templates (first official, and if defined custom templates).
  1663. bool dvalid = exists_export_template("ios.zip", &err);
  1664. bool rvalid = dvalid; // Both in the same ZIP.
  1665. if (p_preset->get("custom_template/debug") != "") {
  1666. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  1667. if (!dvalid) {
  1668. err += TTR("Custom debug template not found.") + "\n";
  1669. }
  1670. }
  1671. if (p_preset->get("custom_template/release") != "") {
  1672. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  1673. if (!rvalid) {
  1674. err += TTR("Custom release template not found.") + "\n";
  1675. }
  1676. }
  1677. valid = dvalid || rvalid;
  1678. r_missing_templates = !valid;
  1679. if (!err.is_empty()) {
  1680. r_error = err;
  1681. }
  1682. return valid;
  1683. }
  1684. bool EditorExportPlatformIOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  1685. String err;
  1686. bool valid = true;
  1687. // Validate the project configuration.
  1688. List<ExportOption> options;
  1689. get_export_options(&options);
  1690. for (const EditorExportPlatform::ExportOption &E : options) {
  1691. if (get_export_option_visibility(p_preset.ptr(), E.option.name)) {
  1692. String warn = get_export_option_warning(p_preset.ptr(), E.option.name);
  1693. if (!warn.is_empty()) {
  1694. err += warn + "\n";
  1695. if (E.required) {
  1696. valid = false;
  1697. }
  1698. }
  1699. }
  1700. }
  1701. const String etc_error = test_etc2();
  1702. if (!etc_error.is_empty()) {
  1703. valid = false;
  1704. err += etc_error;
  1705. }
  1706. if (!err.is_empty()) {
  1707. r_error = err;
  1708. }
  1709. return valid;
  1710. }
  1711. int EditorExportPlatformIOS::get_options_count() const {
  1712. MutexLock lock(device_lock);
  1713. return devices.size();
  1714. }
  1715. String EditorExportPlatformIOS::get_options_tooltip() const {
  1716. return TTR("Select device from the list");
  1717. }
  1718. Ref<ImageTexture> EditorExportPlatformIOS::get_option_icon(int p_index) const {
  1719. MutexLock lock(device_lock);
  1720. Ref<ImageTexture> icon;
  1721. if (p_index >= 0 || p_index < devices.size()) {
  1722. Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
  1723. if (theme.is_valid()) {
  1724. if (devices[p_index].simulator) {
  1725. icon = theme->get_icon("IOSSimulator", "EditorIcons");
  1726. } else if (devices[p_index].wifi) {
  1727. icon = theme->get_icon("IOSDeviceWireless", "EditorIcons");
  1728. } else {
  1729. icon = theme->get_icon("IOSDeviceWired", "EditorIcons");
  1730. }
  1731. }
  1732. }
  1733. return icon;
  1734. }
  1735. String EditorExportPlatformIOS::get_option_label(int p_index) const {
  1736. ERR_FAIL_INDEX_V(p_index, devices.size(), "");
  1737. MutexLock lock(device_lock);
  1738. return devices[p_index].name;
  1739. }
  1740. String EditorExportPlatformIOS::get_option_tooltip(int p_index) const {
  1741. ERR_FAIL_INDEX_V(p_index, devices.size(), "");
  1742. MutexLock lock(device_lock);
  1743. return "UUID: " + devices[p_index].id;
  1744. }
  1745. bool EditorExportPlatformIOS::is_package_name_valid(const String &p_package, String *r_error) const {
  1746. String pname = p_package;
  1747. if (pname.length() == 0) {
  1748. if (r_error) {
  1749. *r_error = TTR("Identifier is missing.");
  1750. }
  1751. return false;
  1752. }
  1753. for (int i = 0; i < pname.length(); i++) {
  1754. char32_t c = pname[i];
  1755. if (!(is_ascii_alphanumeric_char(c) || c == '-' || c == '.')) {
  1756. if (r_error) {
  1757. *r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
  1758. }
  1759. return false;
  1760. }
  1761. }
  1762. return true;
  1763. }
  1764. #ifdef MACOS_ENABLED
  1765. void EditorExportPlatformIOS::_check_for_changes_poll_thread(void *ud) {
  1766. EditorExportPlatformIOS *ea = static_cast<EditorExportPlatformIOS *>(ud);
  1767. while (!ea->quit_request.is_set()) {
  1768. // Nothing to do if we already know the plugins have changed.
  1769. if (!ea->plugins_changed.is_set()) {
  1770. MutexLock lock(ea->plugins_lock);
  1771. Vector<PluginConfigIOS> loaded_plugins = get_plugins();
  1772. if (ea->plugins.size() != loaded_plugins.size()) {
  1773. ea->plugins_changed.set();
  1774. } else {
  1775. for (int i = 0; i < ea->plugins.size(); i++) {
  1776. if (ea->plugins[i].name != loaded_plugins[i].name || ea->plugins[i].last_updated != loaded_plugins[i].last_updated) {
  1777. ea->plugins_changed.set();
  1778. break;
  1779. }
  1780. }
  1781. }
  1782. }
  1783. // Check for devices updates.
  1784. Vector<Device> ldevices;
  1785. // Enum real devices.
  1786. String idepl = EDITOR_GET("export/ios/ios_deploy");
  1787. if (idepl.is_empty()) {
  1788. idepl = "ios-deploy";
  1789. }
  1790. {
  1791. String devices;
  1792. List<String> args;
  1793. args.push_back("-c");
  1794. args.push_back("-timeout");
  1795. args.push_back("1");
  1796. args.push_back("-j");
  1797. args.push_back("-u");
  1798. args.push_back("-I");
  1799. int ec = 0;
  1800. Error err = OS::get_singleton()->execute(idepl, args, &devices, &ec, true);
  1801. if (err == OK && ec == 0) {
  1802. Ref<JSON> json;
  1803. json.instantiate();
  1804. devices = "{ \"devices\":[" + devices.replace("}{", "},{") + "]}";
  1805. err = json->parse(devices);
  1806. if (err == OK) {
  1807. Dictionary data = json->get_data();
  1808. Array devices = data["devices"];
  1809. for (int i = 0; i < devices.size(); i++) {
  1810. Dictionary device_event = devices[i];
  1811. if (device_event["Event"] == "DeviceDetected") {
  1812. Dictionary device_info = device_event["Device"];
  1813. Device nd;
  1814. nd.id = device_info["DeviceIdentifier"];
  1815. nd.name = device_info["DeviceName"].operator String() + " (connected through " + device_event["Interface"].operator String() + ")";
  1816. nd.wifi = device_event["Interface"] == "WIFI";
  1817. nd.simulator = false;
  1818. ldevices.push_back(nd);
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }
  1824. // Enum simulators
  1825. if (FileAccess::exists("/usr/bin/xcrun") || FileAccess::exists("/bin/xcrun")) {
  1826. String devices;
  1827. List<String> args;
  1828. args.push_back("simctl");
  1829. args.push_back("list");
  1830. args.push_back("devices");
  1831. args.push_back("-j");
  1832. int ec = 0;
  1833. Error err = OS::get_singleton()->execute("xcrun", args, &devices, &ec, true);
  1834. if (err == OK && ec == 0) {
  1835. Ref<JSON> json;
  1836. json.instantiate();
  1837. err = json->parse(devices);
  1838. if (err == OK) {
  1839. Dictionary data = json->get_data();
  1840. Dictionary devices = data["devices"];
  1841. for (const Variant *key = devices.next(nullptr); key; key = devices.next(key)) {
  1842. Array os_devices = devices[*key];
  1843. for (int i = 0; i < os_devices.size(); i++) {
  1844. Dictionary device_info = os_devices[i];
  1845. if (device_info["isAvailable"].operator bool() && device_info["state"] == "Booted") {
  1846. Device nd;
  1847. nd.id = device_info["udid"];
  1848. nd.name = device_info["name"].operator String() + " (simulator)";
  1849. nd.simulator = true;
  1850. ldevices.push_back(nd);
  1851. }
  1852. }
  1853. }
  1854. }
  1855. }
  1856. }
  1857. // Update device list.
  1858. {
  1859. MutexLock lock(ea->device_lock);
  1860. bool different = false;
  1861. if (ea->devices.size() != ldevices.size()) {
  1862. different = true;
  1863. } else {
  1864. for (int i = 0; i < ea->devices.size(); i++) {
  1865. if (ea->devices[i].id != ldevices[i].id) {
  1866. different = true;
  1867. break;
  1868. }
  1869. }
  1870. }
  1871. if (different) {
  1872. ea->devices = ldevices;
  1873. ea->devices_changed.set();
  1874. }
  1875. }
  1876. uint64_t sleep = 200;
  1877. uint64_t wait = 3000000;
  1878. uint64_t time = OS::get_singleton()->get_ticks_usec();
  1879. while (OS::get_singleton()->get_ticks_usec() - time < wait) {
  1880. OS::get_singleton()->delay_usec(1000 * sleep);
  1881. if (ea->quit_request.is_set()) {
  1882. break;
  1883. }
  1884. }
  1885. }
  1886. }
  1887. #endif
  1888. Error EditorExportPlatformIOS::run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) {
  1889. #ifdef MACOS_ENABLED
  1890. ERR_FAIL_INDEX_V(p_device, devices.size(), ERR_INVALID_PARAMETER);
  1891. String can_export_error;
  1892. bool can_export_missing_templates;
  1893. if (!can_export(p_preset, can_export_error, can_export_missing_templates)) {
  1894. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), can_export_error);
  1895. return ERR_UNCONFIGURED;
  1896. }
  1897. MutexLock lock(device_lock);
  1898. EditorProgress ep("run", vformat(TTR("Running on %s"), devices[p_device].name), 3);
  1899. String id = "tmpexport." + uitos(OS::get_singleton()->get_unix_time());
  1900. Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1901. ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + EditorPaths::get_singleton()->get_cache_dir() + "'.");
  1902. filesystem_da->make_dir_recursive(EditorPaths::get_singleton()->get_cache_dir().path_join(id));
  1903. String tmp_export_path = EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.ipa");
  1904. #define CLEANUP_AND_RETURN(m_err) \
  1905. { \
  1906. if (filesystem_da->change_dir(EditorPaths::get_singleton()->get_cache_dir().path_join(id)) == OK) { \
  1907. filesystem_da->erase_contents_recursive(); \
  1908. filesystem_da->change_dir(".."); \
  1909. filesystem_da->remove(id); \
  1910. } \
  1911. return m_err; \
  1912. } \
  1913. ((void)0)
  1914. Device dev = devices[p_device];
  1915. // Export before sending to device.
  1916. Error err = _export_project_helper(p_preset, true, tmp_export_path, p_debug_flags, dev.simulator, true);
  1917. if (err != OK) {
  1918. CLEANUP_AND_RETURN(err);
  1919. }
  1920. Vector<String> cmd_args_list;
  1921. String host = EDITOR_GET("network/debug/remote_host");
  1922. int remote_port = (int)EDITOR_GET("network/debug/remote_port");
  1923. if (p_debug_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
  1924. host = "localhost";
  1925. }
  1926. if (p_debug_flags & DEBUG_FLAG_DUMB_CLIENT) {
  1927. int port = EDITOR_GET("filesystem/file_server/port");
  1928. String passwd = EDITOR_GET("filesystem/file_server/password");
  1929. cmd_args_list.push_back("--remote-fs");
  1930. cmd_args_list.push_back(host + ":" + itos(port));
  1931. if (!passwd.is_empty()) {
  1932. cmd_args_list.push_back("--remote-fs-password");
  1933. cmd_args_list.push_back(passwd);
  1934. }
  1935. }
  1936. if (p_debug_flags & DEBUG_FLAG_REMOTE_DEBUG) {
  1937. cmd_args_list.push_back("--remote-debug");
  1938. cmd_args_list.push_back(get_debug_protocol() + host + ":" + String::num(remote_port));
  1939. List<String> breakpoints;
  1940. ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
  1941. if (breakpoints.size()) {
  1942. cmd_args_list.push_back("--breakpoints");
  1943. String bpoints;
  1944. for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
  1945. bpoints += E->get().replace(" ", "%20");
  1946. if (E->next()) {
  1947. bpoints += ",";
  1948. }
  1949. }
  1950. cmd_args_list.push_back(bpoints);
  1951. }
  1952. }
  1953. if (p_debug_flags & DEBUG_FLAG_VIEW_COLLISIONS) {
  1954. cmd_args_list.push_back("--debug-collisions");
  1955. }
  1956. if (p_debug_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
  1957. cmd_args_list.push_back("--debug-navigation");
  1958. }
  1959. if (dev.simulator) {
  1960. // Deploy and run on simulator.
  1961. if (ep.step("Installing to simulator...", 3)) {
  1962. CLEANUP_AND_RETURN(ERR_SKIP);
  1963. } else {
  1964. List<String> args;
  1965. args.push_back("simctl");
  1966. args.push_back("install");
  1967. args.push_back(dev.id);
  1968. args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
  1969. String log;
  1970. int ec;
  1971. err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true);
  1972. if (err != OK) {
  1973. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start simctl executable."));
  1974. CLEANUP_AND_RETURN(err);
  1975. }
  1976. if (ec != 0) {
  1977. print_line("simctl install:\n" + log);
  1978. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation failed, see editor log for details."));
  1979. CLEANUP_AND_RETURN(ERR_UNCONFIGURED);
  1980. }
  1981. }
  1982. if (ep.step("Running on simulator...", 4)) {
  1983. CLEANUP_AND_RETURN(ERR_SKIP);
  1984. } else {
  1985. List<String> args;
  1986. args.push_back("simctl");
  1987. args.push_back("launch");
  1988. args.push_back(dev.id);
  1989. args.push_back(p_preset->get("application/bundle_identifier"));
  1990. for (const String &E : cmd_args_list) {
  1991. args.push_back(E);
  1992. }
  1993. String log;
  1994. int ec;
  1995. err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true);
  1996. if (err != OK) {
  1997. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start simctl executable."));
  1998. CLEANUP_AND_RETURN(err);
  1999. }
  2000. if (ec != 0) {
  2001. print_line("simctl launch:\n" + log);
  2002. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Running failed, see editor log for details."));
  2003. }
  2004. }
  2005. } else {
  2006. // Deploy and run on real device.
  2007. if (ep.step("Installing and running on device...", 4)) {
  2008. CLEANUP_AND_RETURN(ERR_SKIP);
  2009. } else {
  2010. List<String> args;
  2011. args.push_back("-u");
  2012. args.push_back("-I");
  2013. args.push_back("--id");
  2014. args.push_back(dev.id);
  2015. args.push_back("--justlaunch");
  2016. args.push_back("--bundle");
  2017. args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
  2018. String app_args;
  2019. for (const String &E : cmd_args_list) {
  2020. app_args += E + " ";
  2021. }
  2022. if (!app_args.is_empty()) {
  2023. args.push_back("--args");
  2024. args.push_back(app_args);
  2025. }
  2026. String idepl = EDITOR_GET("export/ios/ios_deploy");
  2027. if (idepl.is_empty()) {
  2028. idepl = "ios-deploy";
  2029. }
  2030. String log;
  2031. int ec;
  2032. err = OS::get_singleton()->execute(idepl, args, &log, &ec, true);
  2033. if (err != OK) {
  2034. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start ios-deploy executable."));
  2035. CLEANUP_AND_RETURN(err);
  2036. }
  2037. if (ec != 0) {
  2038. print_line("ios-deploy:\n" + log);
  2039. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation/running failed, see editor log for details."));
  2040. CLEANUP_AND_RETURN(ERR_UNCONFIGURED);
  2041. }
  2042. }
  2043. }
  2044. CLEANUP_AND_RETURN(OK);
  2045. #undef CLEANUP_AND_RETURN
  2046. #else
  2047. return ERR_UNCONFIGURED;
  2048. #endif
  2049. }
  2050. EditorExportPlatformIOS::EditorExportPlatformIOS() {
  2051. if (EditorNode::get_singleton()) {
  2052. #ifdef MODULE_SVG_ENABLED
  2053. Ref<Image> img = memnew(Image);
  2054. const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
  2055. ImageLoaderSVG::create_image_from_string(img, _ios_logo_svg, EDSCALE, upsample, false);
  2056. logo = ImageTexture::create_from_image(img);
  2057. ImageLoaderSVG::create_image_from_string(img, _ios_run_icon_svg, EDSCALE, upsample, false);
  2058. run_icon = ImageTexture::create_from_image(img);
  2059. #endif
  2060. plugins_changed.set();
  2061. devices_changed.set();
  2062. #ifdef MACOS_ENABLED
  2063. check_for_changes_thread.start(_check_for_changes_poll_thread, this);
  2064. #endif
  2065. }
  2066. }
  2067. EditorExportPlatformIOS::~EditorExportPlatformIOS() {
  2068. #ifdef MACOS_ENABLED
  2069. quit_request.set();
  2070. if (check_for_changes_thread.is_started()) {
  2071. check_for_changes_thread.wait_to_finish();
  2072. }
  2073. #endif
  2074. }