export_plugin.cpp 93 KB

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