export_plugin.cpp 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444
  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. bool EditorExportPlatformIOS::_check_xcode_install() {
  1781. static bool xcode_found = false;
  1782. if (!xcode_found) {
  1783. String xcode_path;
  1784. List<String> args;
  1785. args.push_back("-p");
  1786. int ec = 0;
  1787. Error err = OS::get_singleton()->execute("xcode-select", args, &xcode_path, &ec, true);
  1788. if (err != OK || ec != 0) {
  1789. return false;
  1790. }
  1791. xcode_found = DirAccess::dir_exists_absolute(xcode_path.strip_edges());
  1792. }
  1793. return xcode_found;
  1794. }
  1795. void EditorExportPlatformIOS::_check_for_changes_poll_thread(void *ud) {
  1796. EditorExportPlatformIOS *ea = static_cast<EditorExportPlatformIOS *>(ud);
  1797. while (!ea->quit_request.is_set()) {
  1798. // Nothing to do if we already know the plugins have changed.
  1799. if (!ea->plugins_changed.is_set()) {
  1800. MutexLock lock(ea->plugins_lock);
  1801. Vector<PluginConfigIOS> loaded_plugins = get_plugins();
  1802. if (ea->plugins.size() != loaded_plugins.size()) {
  1803. ea->plugins_changed.set();
  1804. } else {
  1805. for (int i = 0; i < ea->plugins.size(); i++) {
  1806. if (ea->plugins[i].name != loaded_plugins[i].name || ea->plugins[i].last_updated != loaded_plugins[i].last_updated) {
  1807. ea->plugins_changed.set();
  1808. break;
  1809. }
  1810. }
  1811. }
  1812. }
  1813. // Check for devices updates.
  1814. Vector<Device> ldevices;
  1815. // Enum real devices.
  1816. String idepl = EDITOR_GET("export/ios/ios_deploy");
  1817. if (idepl.is_empty()) {
  1818. idepl = "ios-deploy";
  1819. }
  1820. {
  1821. String devices;
  1822. List<String> args;
  1823. args.push_back("-c");
  1824. args.push_back("-timeout");
  1825. args.push_back("1");
  1826. args.push_back("-j");
  1827. args.push_back("-u");
  1828. args.push_back("-I");
  1829. int ec = 0;
  1830. Error err = OS::get_singleton()->execute(idepl, args, &devices, &ec, true);
  1831. if (err == OK && ec == 0) {
  1832. Ref<JSON> json;
  1833. json.instantiate();
  1834. devices = "{ \"devices\":[" + devices.replace("}{", "},{") + "]}";
  1835. err = json->parse(devices);
  1836. if (err == OK) {
  1837. Dictionary data = json->get_data();
  1838. Array devices = data["devices"];
  1839. for (int i = 0; i < devices.size(); i++) {
  1840. Dictionary device_event = devices[i];
  1841. if (device_event["Event"] == "DeviceDetected") {
  1842. Dictionary device_info = device_event["Device"];
  1843. Device nd;
  1844. nd.id = device_info["DeviceIdentifier"];
  1845. nd.name = device_info["DeviceName"].operator String() + " (connected through " + device_event["Interface"].operator String() + ")";
  1846. nd.wifi = device_event["Interface"] == "WIFI";
  1847. nd.simulator = false;
  1848. ldevices.push_back(nd);
  1849. }
  1850. }
  1851. }
  1852. }
  1853. }
  1854. // Enum simulators
  1855. if (_check_xcode_install() && (FileAccess::exists("/usr/bin/xcrun") || FileAccess::exists("/bin/xcrun"))) {
  1856. String devices;
  1857. List<String> args;
  1858. args.push_back("simctl");
  1859. args.push_back("list");
  1860. args.push_back("devices");
  1861. args.push_back("-j");
  1862. int ec = 0;
  1863. Error err = OS::get_singleton()->execute("xcrun", args, &devices, &ec, true);
  1864. if (err == OK && ec == 0) {
  1865. Ref<JSON> json;
  1866. json.instantiate();
  1867. err = json->parse(devices);
  1868. if (err == OK) {
  1869. Dictionary data = json->get_data();
  1870. Dictionary devices = data["devices"];
  1871. for (const Variant *key = devices.next(nullptr); key; key = devices.next(key)) {
  1872. Array os_devices = devices[*key];
  1873. for (int i = 0; i < os_devices.size(); i++) {
  1874. Dictionary device_info = os_devices[i];
  1875. if (device_info["isAvailable"].operator bool() && device_info["state"] == "Booted") {
  1876. Device nd;
  1877. nd.id = device_info["udid"];
  1878. nd.name = device_info["name"].operator String() + " (simulator)";
  1879. nd.simulator = true;
  1880. ldevices.push_back(nd);
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. }
  1887. // Update device list.
  1888. {
  1889. MutexLock lock(ea->device_lock);
  1890. bool different = false;
  1891. if (ea->devices.size() != ldevices.size()) {
  1892. different = true;
  1893. } else {
  1894. for (int i = 0; i < ea->devices.size(); i++) {
  1895. if (ea->devices[i].id != ldevices[i].id) {
  1896. different = true;
  1897. break;
  1898. }
  1899. }
  1900. }
  1901. if (different) {
  1902. ea->devices = ldevices;
  1903. ea->devices_changed.set();
  1904. }
  1905. }
  1906. uint64_t sleep = 200;
  1907. uint64_t wait = 3000000;
  1908. uint64_t time = OS::get_singleton()->get_ticks_usec();
  1909. while (OS::get_singleton()->get_ticks_usec() - time < wait) {
  1910. OS::get_singleton()->delay_usec(1000 * sleep);
  1911. if (ea->quit_request.is_set()) {
  1912. break;
  1913. }
  1914. }
  1915. }
  1916. }
  1917. #endif
  1918. Error EditorExportPlatformIOS::run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) {
  1919. #ifdef MACOS_ENABLED
  1920. ERR_FAIL_INDEX_V(p_device, devices.size(), ERR_INVALID_PARAMETER);
  1921. String can_export_error;
  1922. bool can_export_missing_templates;
  1923. if (!can_export(p_preset, can_export_error, can_export_missing_templates)) {
  1924. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), can_export_error);
  1925. return ERR_UNCONFIGURED;
  1926. }
  1927. MutexLock lock(device_lock);
  1928. EditorProgress ep("run", vformat(TTR("Running on %s"), devices[p_device].name), 3);
  1929. String id = "tmpexport." + uitos(OS::get_singleton()->get_unix_time());
  1930. Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1931. ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + EditorPaths::get_singleton()->get_cache_dir() + "'.");
  1932. filesystem_da->make_dir_recursive(EditorPaths::get_singleton()->get_cache_dir().path_join(id));
  1933. String tmp_export_path = EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.ipa");
  1934. #define CLEANUP_AND_RETURN(m_err) \
  1935. { \
  1936. if (filesystem_da->change_dir(EditorPaths::get_singleton()->get_cache_dir().path_join(id)) == OK) { \
  1937. filesystem_da->erase_contents_recursive(); \
  1938. filesystem_da->change_dir(".."); \
  1939. filesystem_da->remove(id); \
  1940. } \
  1941. return m_err; \
  1942. } \
  1943. ((void)0)
  1944. Device dev = devices[p_device];
  1945. // Export before sending to device.
  1946. Error err = _export_project_helper(p_preset, true, tmp_export_path, p_debug_flags, dev.simulator, true);
  1947. if (err != OK) {
  1948. CLEANUP_AND_RETURN(err);
  1949. }
  1950. Vector<String> cmd_args_list;
  1951. String host = EDITOR_GET("network/debug/remote_host");
  1952. int remote_port = (int)EDITOR_GET("network/debug/remote_port");
  1953. if (p_debug_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
  1954. host = "localhost";
  1955. }
  1956. if (p_debug_flags & DEBUG_FLAG_DUMB_CLIENT) {
  1957. int port = EDITOR_GET("filesystem/file_server/port");
  1958. String passwd = EDITOR_GET("filesystem/file_server/password");
  1959. cmd_args_list.push_back("--remote-fs");
  1960. cmd_args_list.push_back(host + ":" + itos(port));
  1961. if (!passwd.is_empty()) {
  1962. cmd_args_list.push_back("--remote-fs-password");
  1963. cmd_args_list.push_back(passwd);
  1964. }
  1965. }
  1966. if (p_debug_flags & DEBUG_FLAG_REMOTE_DEBUG) {
  1967. cmd_args_list.push_back("--remote-debug");
  1968. cmd_args_list.push_back(get_debug_protocol() + host + ":" + String::num(remote_port));
  1969. List<String> breakpoints;
  1970. ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
  1971. if (breakpoints.size()) {
  1972. cmd_args_list.push_back("--breakpoints");
  1973. String bpoints;
  1974. for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
  1975. bpoints += E->get().replace(" ", "%20");
  1976. if (E->next()) {
  1977. bpoints += ",";
  1978. }
  1979. }
  1980. cmd_args_list.push_back(bpoints);
  1981. }
  1982. }
  1983. if (p_debug_flags & DEBUG_FLAG_VIEW_COLLISIONS) {
  1984. cmd_args_list.push_back("--debug-collisions");
  1985. }
  1986. if (p_debug_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
  1987. cmd_args_list.push_back("--debug-navigation");
  1988. }
  1989. if (dev.simulator) {
  1990. // Deploy and run on simulator.
  1991. if (ep.step("Installing to simulator...", 3)) {
  1992. CLEANUP_AND_RETURN(ERR_SKIP);
  1993. } else {
  1994. List<String> args;
  1995. args.push_back("simctl");
  1996. args.push_back("install");
  1997. args.push_back(dev.id);
  1998. args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
  1999. String log;
  2000. int ec;
  2001. err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true);
  2002. if (err != OK) {
  2003. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start simctl executable."));
  2004. CLEANUP_AND_RETURN(err);
  2005. }
  2006. if (ec != 0) {
  2007. print_line("simctl install:\n" + log);
  2008. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation failed, see editor log for details."));
  2009. CLEANUP_AND_RETURN(ERR_UNCONFIGURED);
  2010. }
  2011. }
  2012. if (ep.step("Running on simulator...", 4)) {
  2013. CLEANUP_AND_RETURN(ERR_SKIP);
  2014. } else {
  2015. List<String> args;
  2016. args.push_back("simctl");
  2017. args.push_back("launch");
  2018. args.push_back(dev.id);
  2019. args.push_back(p_preset->get("application/bundle_identifier"));
  2020. for (const String &E : cmd_args_list) {
  2021. args.push_back(E);
  2022. }
  2023. String log;
  2024. int ec;
  2025. err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true);
  2026. if (err != OK) {
  2027. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start simctl executable."));
  2028. CLEANUP_AND_RETURN(err);
  2029. }
  2030. if (ec != 0) {
  2031. print_line("simctl launch:\n" + log);
  2032. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Running failed, see editor log for details."));
  2033. }
  2034. }
  2035. } else {
  2036. // Deploy and run on real device.
  2037. if (ep.step("Installing and running on device...", 4)) {
  2038. CLEANUP_AND_RETURN(ERR_SKIP);
  2039. } else {
  2040. List<String> args;
  2041. args.push_back("-u");
  2042. args.push_back("-I");
  2043. args.push_back("--id");
  2044. args.push_back(dev.id);
  2045. args.push_back("--justlaunch");
  2046. args.push_back("--bundle");
  2047. args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
  2048. String app_args;
  2049. for (const String &E : cmd_args_list) {
  2050. app_args += E + " ";
  2051. }
  2052. if (!app_args.is_empty()) {
  2053. args.push_back("--args");
  2054. args.push_back(app_args);
  2055. }
  2056. String idepl = EDITOR_GET("export/ios/ios_deploy");
  2057. if (idepl.is_empty()) {
  2058. idepl = "ios-deploy";
  2059. }
  2060. String log;
  2061. int ec;
  2062. err = OS::get_singleton()->execute(idepl, args, &log, &ec, true);
  2063. if (err != OK) {
  2064. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start ios-deploy executable."));
  2065. CLEANUP_AND_RETURN(err);
  2066. }
  2067. if (ec != 0) {
  2068. print_line("ios-deploy:\n" + log);
  2069. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation/running failed, see editor log for details."));
  2070. CLEANUP_AND_RETURN(ERR_UNCONFIGURED);
  2071. }
  2072. }
  2073. }
  2074. CLEANUP_AND_RETURN(OK);
  2075. #undef CLEANUP_AND_RETURN
  2076. #else
  2077. return ERR_UNCONFIGURED;
  2078. #endif
  2079. }
  2080. EditorExportPlatformIOS::EditorExportPlatformIOS() {
  2081. if (EditorNode::get_singleton()) {
  2082. #ifdef MODULE_SVG_ENABLED
  2083. Ref<Image> img = memnew(Image);
  2084. const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
  2085. ImageLoaderSVG::create_image_from_string(img, _ios_logo_svg, EDSCALE, upsample, false);
  2086. logo = ImageTexture::create_from_image(img);
  2087. ImageLoaderSVG::create_image_from_string(img, _ios_run_icon_svg, EDSCALE, upsample, false);
  2088. run_icon = ImageTexture::create_from_image(img);
  2089. #endif
  2090. plugins_changed.set();
  2091. devices_changed.set();
  2092. #ifdef MACOS_ENABLED
  2093. check_for_changes_thread.start(_check_for_changes_poll_thread, this);
  2094. #endif
  2095. }
  2096. }
  2097. EditorExportPlatformIOS::~EditorExportPlatformIOS() {
  2098. #ifdef MACOS_ENABLED
  2099. quit_request.set();
  2100. if (check_for_changes_thread.is_started()) {
  2101. check_for_changes_thread.wait_to_finish();
  2102. }
  2103. #endif
  2104. }