export_plugin.cpp 94 KB

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