export_plugin.cpp 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326
  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/io/plist.h"
  35. #include "core/string/translation.h"
  36. #include "editor/editor_node.h"
  37. #include "editor/editor_paths.h"
  38. #include "editor/editor_string_names.h"
  39. #include "editor/export/editor_export.h"
  40. #include "editor/export/lipo.h"
  41. #include "editor/export/macho.h"
  42. #include "editor/import/resource_importer_texture_settings.h"
  43. #include "editor/plugins/script_editor_plugin.h"
  44. #include "editor/themes/editor_scale.h"
  45. #include "modules/modules_enabled.gen.h" // For mono and svg.
  46. #ifdef MODULE_SVG_ENABLED
  47. #include "modules/svg/image_loader_svg.h"
  48. #endif
  49. void EditorExportPlatformIOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
  50. // Vulkan and OpenGL ES 3.0 both mandate ETC2 support.
  51. r_features->push_back("etc2");
  52. r_features->push_back("astc");
  53. Vector<String> architectures = _get_preset_architectures(p_preset);
  54. for (int i = 0; i < architectures.size(); ++i) {
  55. r_features->push_back(architectures[i]);
  56. }
  57. }
  58. Vector<EditorExportPlatformIOS::ExportArchitecture> EditorExportPlatformIOS::_get_supported_architectures() const {
  59. Vector<ExportArchitecture> archs;
  60. archs.push_back(ExportArchitecture("arm64", true));
  61. return archs;
  62. }
  63. struct IconInfo {
  64. const char *preset_key;
  65. const char *idiom;
  66. const char *export_name;
  67. const char *actual_size_side;
  68. const char *scale;
  69. const char *unscaled_size;
  70. const bool force_opaque;
  71. };
  72. static const IconInfo icon_infos[] = {
  73. // Settings on iPhone, iPad Pro, iPad, iPad mini
  74. { PNAME("icons/settings_58x58"), "universal", "Icon-58", "58", "2x", "29x29", false },
  75. { PNAME("icons/settings_87x87"), "universal", "Icon-87", "87", "3x", "29x29", false },
  76. // Notifications on iPhone, iPad Pro, iPad, iPad mini
  77. { PNAME("icons/notification_40x40"), "universal", "Icon-40", "40", "2x", "20x20", false },
  78. { PNAME("icons/notification_60x60"), "universal", "Icon-60", "60", "3x", "20x20", false },
  79. { PNAME("icons/notification_76x76"), "universal", "Icon-76", "76", "2x", "38x38", false },
  80. { PNAME("icons/notification_114x114"), "universal", "Icon-114", "114", "3x", "38x38", false },
  81. // Spotlight on iPhone, iPad Pro, iPad, iPad mini
  82. { PNAME("icons/spotlight_80x80"), "universal", "Icon-80", "80", "2x", "40x40", false },
  83. { PNAME("icons/spotlight_120x120"), "universal", "Icon-120", "120", "3x", "40x40", false },
  84. // Home Screen on iPhone
  85. { PNAME("icons/iphone_120x120"), "universal", "Icon-120-1", "120", "2x", "60x60", false },
  86. { PNAME("icons/iphone_180x180"), "universal", "Icon-180", "180", "3x", "60x60", false },
  87. // Home Screen on iPad Pro
  88. { PNAME("icons/ipad_167x167"), "universal", "Icon-167", "167", "2x", "83.5x83.5", false },
  89. // Home Screen on iPad, iPad mini
  90. { PNAME("icons/ipad_152x152"), "universal", "Icon-152", "152", "2x", "76x76", false },
  91. { PNAME("icons/ios_128x128"), "universal", "Icon-128", "128", "2x", "64x64", false },
  92. { PNAME("icons/ios_192x192"), "universal", "Icon-192", "192", "3x", "64x64", false },
  93. { PNAME("icons/ios_136x136"), "universal", "Icon-136", "136", "2x", "68x68", false },
  94. // App Store
  95. { PNAME("icons/app_store_1024x1024"), "universal", "Icon-1024", "1024", "1x", "1024x1024", true },
  96. };
  97. struct APIAccessInfo {
  98. String prop_name;
  99. String type_name;
  100. Vector<String> prop_flag_value;
  101. Vector<String> prop_flag_name;
  102. int default_value;
  103. };
  104. static const APIAccessInfo api_info[] = {
  105. { "file_timestamp",
  106. "NSPrivacyAccessedAPICategoryFileTimestamp",
  107. { "DDA9.1", "C617.1", "3B52.1" },
  108. { "Display to user on-device:", "Inside app or group container", "Files provided to app by user" },
  109. 3 },
  110. { "system_boot_time",
  111. "NSPrivacyAccessedAPICategorySystemBootTime",
  112. { "35F9.1", "8FFB.1", "3D61.1" },
  113. { "Measure time on-device", "Calculate absolute event timestamps", "User-initiated bug report" },
  114. 1 },
  115. { "disk_space",
  116. "NSPrivacyAccessedAPICategoryDiskSpace",
  117. { "E174.1", "85F4.1", "7D9E.1", "B728.1" },
  118. { "Write or delete file on-device", "Display to user on-device", "User-initiated bug report", "Health research app" },
  119. 3 },
  120. { "active_keyboard",
  121. "NSPrivacyAccessedAPICategoryActiveKeyboards",
  122. { "3EC4.1", "54BD.1" },
  123. { "Custom keyboard app on-device", "Customize UI on-device:2" },
  124. 0 },
  125. { "user_defaults",
  126. "NSPrivacyAccessedAPICategoryUserDefaults",
  127. { "1C8F.1", "AC6B.1", "CA92.1" },
  128. { "Access info from same App Group", "Access managed app configuration", "Access info from same app" },
  129. 0 }
  130. };
  131. struct DataCollectionInfo {
  132. String prop_name;
  133. String type_name;
  134. };
  135. static const DataCollectionInfo data_collect_type_info[] = {
  136. { "name", "NSPrivacyCollectedDataTypeName" },
  137. { "email_address", "NSPrivacyCollectedDataTypeEmailAddress" },
  138. { "phone_number", "NSPrivacyCollectedDataTypePhoneNumber" },
  139. { "physical_address", "NSPrivacyCollectedDataTypePhysicalAddress" },
  140. { "other_contact_info", "NSPrivacyCollectedDataTypeOtherUserContactInfo" },
  141. { "health", "NSPrivacyCollectedDataTypeHealth" },
  142. { "fitness", "NSPrivacyCollectedDataTypeFitness" },
  143. { "payment_info", "NSPrivacyCollectedDataTypePaymentInfo" },
  144. { "credit_info", "NSPrivacyCollectedDataTypeCreditInfo" },
  145. { "other_financial_info", "NSPrivacyCollectedDataTypeOtherFinancialInfo" },
  146. { "precise_location", "NSPrivacyCollectedDataTypePreciseLocation" },
  147. { "coarse_location", "NSPrivacyCollectedDataTypeCoarseLocation" },
  148. { "sensitive_info", "NSPrivacyCollectedDataTypeSensitiveInfo" },
  149. { "contacts", "NSPrivacyCollectedDataTypeContacts" },
  150. { "emails_or_text_messages", "NSPrivacyCollectedDataTypeEmailsOrTextMessages" },
  151. { "photos_or_videos", "NSPrivacyCollectedDataTypePhotosorVideos" },
  152. { "audio_data", "NSPrivacyCollectedDataTypeAudioData" },
  153. { "gameplay_content", "NSPrivacyCollectedDataTypeGameplayContent" },
  154. { "customer_support", "NSPrivacyCollectedDataTypeCustomerSupport" },
  155. { "other_user_content", "NSPrivacyCollectedDataTypeOtherUserContent" },
  156. { "browsing_history", "NSPrivacyCollectedDataTypeBrowsingHistory" },
  157. { "search_hhistory", "NSPrivacyCollectedDataTypeSearchHistory" },
  158. { "user_id", "NSPrivacyCollectedDataTypeUserID" },
  159. { "device_id", "NSPrivacyCollectedDataTypeDeviceID" },
  160. { "purchase_history", "NSPrivacyCollectedDataTypePurchaseHistory" },
  161. { "product_interaction", "NSPrivacyCollectedDataTypeProductInteraction" },
  162. { "advertising_data", "NSPrivacyCollectedDataTypeAdvertisingData" },
  163. { "other_usage_data", "NSPrivacyCollectedDataTypeOtherUsageData" },
  164. { "crash_data", "NSPrivacyCollectedDataTypeCrashData" },
  165. { "performance_data", "NSPrivacyCollectedDataTypePerformanceData" },
  166. { "other_diagnostic_data", "NSPrivacyCollectedDataTypeOtherDiagnosticData" },
  167. { "environment_scanning", "NSPrivacyCollectedDataTypeEnvironmentScanning" },
  168. { "hands", "NSPrivacyCollectedDataTypeHands" },
  169. { "head", "NSPrivacyCollectedDataTypeHead" },
  170. { "other_data_types", "NSPrivacyCollectedDataTypeOtherDataTypes" },
  171. };
  172. static const DataCollectionInfo data_collect_purpose_info[] = {
  173. { "Analytics", "NSPrivacyCollectedDataTypePurposeAnalytics" },
  174. { "App Functionality", "NSPrivacyCollectedDataTypePurposeAppFunctionality" },
  175. { "Developer Advertising", "NSPrivacyCollectedDataTypePurposeDeveloperAdvertising" },
  176. { "Third-party Advertising", "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising" },
  177. { "Product Personalization", "NSPrivacyCollectedDataTypePurposeProductPersonalization" },
  178. { "Other", "NSPrivacyCollectedDataTypePurposeOther" },
  179. };
  180. String EditorExportPlatformIOS::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const {
  181. if (p_preset) {
  182. if (p_name == "application/app_store_team_id") {
  183. String team_id = p_preset->get("application/app_store_team_id");
  184. if (team_id.is_empty()) {
  185. return TTR("App Store Team ID not specified.") + "\n";
  186. }
  187. } else if (p_name == "application/bundle_identifier") {
  188. String identifier = p_preset->get("application/bundle_identifier");
  189. String pn_err;
  190. if (!is_package_name_valid(identifier, &pn_err)) {
  191. return TTR("Invalid Identifier:") + " " + pn_err;
  192. }
  193. } else if (p_name == "privacy/file_timestamp_access_reasons") {
  194. int access = p_preset->get("privacy/file_timestamp_access_reasons");
  195. if (access == 0) {
  196. return TTR("At least one file timestamp access reason should be selected.");
  197. }
  198. } else if (p_name == "privacy/disk_space_access_reasons") {
  199. int access = p_preset->get("privacy/disk_space_access_reasons");
  200. if (access == 0) {
  201. return TTR("At least one disk space access reason should be selected.");
  202. }
  203. } else if (p_name == "privacy/system_boot_time_access_reasons") {
  204. int access = p_preset->get("privacy/system_boot_time_access_reasons");
  205. if (access == 0) {
  206. return TTR("At least one system boot time access reason should be selected.");
  207. }
  208. }
  209. }
  210. return String();
  211. }
  212. void EditorExportPlatformIOS::_notification(int p_what) {
  213. #ifdef MACOS_ENABLED
  214. if (p_what == NOTIFICATION_POSTINITIALIZE) {
  215. if (EditorExport::get_singleton()) {
  216. EditorExport::get_singleton()->connect_presets_runnable_updated(callable_mp(this, &EditorExportPlatformIOS::_update_preset_status));
  217. }
  218. }
  219. #endif
  220. }
  221. bool EditorExportPlatformIOS::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const {
  222. // Hide unsupported .NET embedding option.
  223. if (p_option == "dotnet/embed_build_outputs") {
  224. return false;
  225. }
  226. if (p_preset == nullptr) {
  227. return true;
  228. }
  229. bool advanced_options_enabled = p_preset->are_advanced_options_enabled();
  230. if (p_option.begins_with("privacy") || p_option == "application/generate_simulator_library_if_missing" || (p_option.begins_with("icons/") && !p_option.begins_with("icons/icon") && !p_option.begins_with("icons/app_store"))) {
  231. return advanced_options_enabled;
  232. }
  233. return true;
  234. }
  235. void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options) const {
  236. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  237. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  238. Vector<ExportArchitecture> architectures = _get_supported_architectures();
  239. for (int i = 0; i < architectures.size(); ++i) {
  240. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("architectures"), architectures[i].name)), architectures[i].is_default));
  241. }
  242. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_store_team_id"), "", false, true));
  243. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_debug", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
  244. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_debug", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Developer"), ""));
  245. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_debug", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 1));
  246. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_release", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
  247. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_release", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Distribution"), ""));
  248. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_release", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 0));
  249. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/targeted_device_family", PROPERTY_HINT_ENUM, "iPhone,iPad,iPhone & iPad"), 2));
  250. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "", false, true));
  251. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  252. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));
  253. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));
  254. // TODO(sgc): set to iOS 14.0 for Metal
  255. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_ios_version"), "12.0"));
  256. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/additional_plist_content", PROPERTY_HINT_MULTILINE_TEXT), ""));
  257. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
  258. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/export_project_only"), false));
  259. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/delete_old_export_files_unconditionally"), false));
  260. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/generate_simulator_library_if_missing"), true));
  261. Vector<PluginConfigIOS> found_plugins = get_plugins();
  262. for (int i = 0; i < found_plugins.size(); i++) {
  263. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("plugins"), found_plugins[i].name)), false));
  264. }
  265. HashSet<String> plist_keys;
  266. for (int i = 0; i < found_plugins.size(); i++) {
  267. // Editable plugin plist values
  268. PluginConfigIOS plugin = found_plugins[i];
  269. for (const KeyValue<String, PluginConfigIOS::PlistItem> &E : plugin.plist) {
  270. switch (E.value.type) {
  271. case PluginConfigIOS::PlistItemType::STRING_INPUT: {
  272. String preset_name = "plugins_plist/" + E.key;
  273. if (!plist_keys.has(preset_name)) {
  274. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, preset_name), E.value.value));
  275. plist_keys.insert(preset_name);
  276. }
  277. } break;
  278. default:
  279. continue;
  280. }
  281. }
  282. }
  283. plugins_changed.clear();
  284. plugins = found_plugins;
  285. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/access_wifi"), false));
  286. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/push_notifications"), false));
  287. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/performance_gaming_tier"), false));
  288. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/performance_a12"), false));
  289. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_files_app"), false));
  290. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_itunes_sharing"), false));
  291. 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"), ""));
  292. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  293. 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"), ""));
  294. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  295. 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"), ""));
  296. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photolibrary_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  297. for (uint64_t i = 0; i < sizeof(api_info) / sizeof(api_info[0]); ++i) {
  298. String prop_name = vformat("privacy/%s_access_reasons", api_info[i].prop_name);
  299. String hint;
  300. for (int j = 0; j < api_info[i].prop_flag_value.size(); j++) {
  301. if (j != 0) {
  302. hint += ",";
  303. }
  304. hint += vformat("%s - %s:%d", api_info[i].prop_flag_value[j], api_info[i].prop_flag_name[j], (1 << j));
  305. }
  306. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, prop_name, PROPERTY_HINT_FLAGS, hint), api_info[i].default_value));
  307. }
  308. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "privacy/tracking_enabled"), false));
  309. r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "privacy/tracking_domains"), Vector<String>()));
  310. {
  311. String hint;
  312. for (uint64_t i = 0; i < sizeof(data_collect_purpose_info) / sizeof(data_collect_purpose_info[0]); ++i) {
  313. if (i != 0) {
  314. hint += ",";
  315. }
  316. hint += vformat("%s:%d", data_collect_purpose_info[i].prop_name, (1 << i));
  317. }
  318. for (uint64_t i = 0; i < sizeof(data_collect_type_info) / sizeof(data_collect_type_info[0]); ++i) {
  319. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/collected", data_collect_type_info[i].prop_name)), false));
  320. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[i].prop_name)), false));
  321. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[i].prop_name)), false));
  322. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[i].prop_name), PROPERTY_HINT_FLAGS, hint), 0));
  323. }
  324. }
  325. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024", PROPERTY_HINT_FILE, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
  326. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_dark", PROPERTY_HINT_FILE, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
  327. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_tinted", PROPERTY_HINT_FILE, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
  328. HashSet<String> used_names;
  329. for (uint64_t i = 0; i < sizeof(icon_infos) / sizeof(icon_infos[0]); ++i) {
  330. if (!used_names.has(icon_infos[i].preset_key)) {
  331. used_names.insert(icon_infos[i].preset_key);
  332. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key), PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  333. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key) + "_dark", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  334. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key) + "_tinted", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  335. }
  336. }
  337. 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));
  338. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@2x", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  339. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@3x", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  340. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "storyboard/use_custom_bg_color"), false));
  341. r_options->push_back(ExportOption(PropertyInfo(Variant::COLOR, "storyboard/custom_bg_color"), Color()));
  342. }
  343. void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const IOSConfigData &p_config, bool p_debug) {
  344. static const String export_method_string[] = {
  345. "app-store",
  346. "development",
  347. "ad-hoc",
  348. "enterprise"
  349. };
  350. static const String storyboard_image_scale_mode[] = {
  351. "center",
  352. "scaleAspectFit",
  353. "scaleAspectFill",
  354. "scaleToFill"
  355. };
  356. 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");
  357. 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");
  358. 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" && dbg_sign_id != "iPhone Distribution");
  359. 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 Developer" && rel_sign_id != "iPhone Distribution");
  360. String str;
  361. String strnew;
  362. str.parse_utf8((const char *)pfile.ptr(), pfile.size());
  363. Vector<String> lines = str.split("\n");
  364. for (int i = 0; i < lines.size(); i++) {
  365. if (lines[i].contains("$binary")) {
  366. strnew += lines[i].replace("$binary", p_config.binary_name) + "\n";
  367. } else if (lines[i].contains("$modules_buildfile")) {
  368. strnew += lines[i].replace("$modules_buildfile", p_config.modules_buildfile) + "\n";
  369. } else if (lines[i].contains("$modules_fileref")) {
  370. strnew += lines[i].replace("$modules_fileref", p_config.modules_fileref) + "\n";
  371. } else if (lines[i].contains("$modules_buildphase")) {
  372. strnew += lines[i].replace("$modules_buildphase", p_config.modules_buildphase) + "\n";
  373. } else if (lines[i].contains("$modules_buildgrp")) {
  374. strnew += lines[i].replace("$modules_buildgrp", p_config.modules_buildgrp) + "\n";
  375. } else if (lines[i].contains("$name")) {
  376. strnew += lines[i].replace("$name", p_config.pkg_name) + "\n";
  377. } else if (lines[i].contains("$bundle_identifier")) {
  378. strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
  379. } else if (lines[i].contains("$short_version")) {
  380. strnew += lines[i].replace("$short_version", p_preset->get_version("application/short_version")) + "\n";
  381. } else if (lines[i].contains("$version")) {
  382. strnew += lines[i].replace("$version", p_preset->get_version("application/version")) + "\n";
  383. } else if (lines[i].contains("$min_version")) {
  384. strnew += lines[i].replace("$min_version", p_preset->get("application/min_ios_version")) + "\n";
  385. } else if (lines[i].contains("$signature")) {
  386. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  387. } else if (lines[i].contains("$team_id")) {
  388. strnew += lines[i].replace("$team_id", p_preset->get("application/app_store_team_id")) + "\n";
  389. } else if (lines[i].contains("$default_build_config")) {
  390. strnew += lines[i].replace("$default_build_config", p_debug ? "Debug" : "Release") + "\n";
  391. } else if (lines[i].contains("$export_method")) {
  392. int export_method = p_preset->get(p_debug ? "application/export_method_debug" : "application/export_method_release");
  393. strnew += lines[i].replace("$export_method", export_method_string[export_method]) + "\n";
  394. } else if (lines[i].contains("$provisioning_profile_uuid_release")) {
  395. strnew += lines[i].replace("$provisioning_profile_uuid_release", p_preset->get_or_env("application/provisioning_profile_uuid_release", ENV_IOS_PROFILE_UUID_RELEASE)) + "\n";
  396. } else if (lines[i].contains("$provisioning_profile_uuid_debug")) {
  397. strnew += lines[i].replace("$provisioning_profile_uuid_debug", p_preset->get_or_env("application/provisioning_profile_uuid_debug", ENV_IOS_PROFILE_UUID_DEBUG)) + "\n";
  398. } else if (lines[i].contains("$code_sign_style_debug")) {
  399. if (dbg_manual) {
  400. strnew += lines[i].replace("$code_sign_style_debug", "Manual") + "\n";
  401. } else {
  402. strnew += lines[i].replace("$code_sign_style_debug", "Automatic") + "\n";
  403. }
  404. } else if (lines[i].contains("$code_sign_style_release")) {
  405. if (rel_manual) {
  406. strnew += lines[i].replace("$code_sign_style_release", "Manual") + "\n";
  407. } else {
  408. strnew += lines[i].replace("$code_sign_style_release", "Automatic") + "\n";
  409. }
  410. } else if (lines[i].contains("$provisioning_profile_uuid")) {
  411. 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);
  412. strnew += lines[i].replace("$provisioning_profile_uuid", uuid) + "\n";
  413. } else if (lines[i].contains("$code_sign_identity_debug")) {
  414. strnew += lines[i].replace("$code_sign_identity_debug", dbg_sign_id) + "\n";
  415. } else if (lines[i].contains("$code_sign_identity_release")) {
  416. strnew += lines[i].replace("$code_sign_identity_release", rel_sign_id) + "\n";
  417. } else if (lines[i].contains("$additional_plist_content")) {
  418. strnew += lines[i].replace("$additional_plist_content", p_config.plist_content) + "\n";
  419. } else if (lines[i].contains("$godot_archs")) {
  420. strnew += lines[i].replace("$godot_archs", p_config.architectures) + "\n";
  421. } else if (lines[i].contains("$linker_flags")) {
  422. strnew += lines[i].replace("$linker_flags", p_config.linker_flags) + "\n";
  423. } else if (lines[i].contains("$targeted_device_family")) {
  424. String xcode_value;
  425. switch ((int)p_preset->get("application/targeted_device_family")) {
  426. case 0: // iPhone
  427. xcode_value = "1";
  428. break;
  429. case 1: // iPad
  430. xcode_value = "2";
  431. break;
  432. case 2: // iPhone & iPad
  433. xcode_value = "1,2";
  434. break;
  435. }
  436. strnew += lines[i].replace("$targeted_device_family", xcode_value) + "\n";
  437. } else if (lines[i].contains("$cpp_code")) {
  438. strnew += lines[i].replace("$cpp_code", p_config.cpp_code) + "\n";
  439. } else if (lines[i].contains("$docs_in_place")) {
  440. strnew += lines[i].replace("$docs_in_place", ((bool)p_preset->get("user_data/accessible_from_files_app")) ? "<true/>" : "<false/>") + "\n";
  441. } else if (lines[i].contains("$docs_sharing")) {
  442. strnew += lines[i].replace("$docs_sharing", ((bool)p_preset->get("user_data/accessible_from_itunes_sharing")) ? "<true/>" : "<false/>") + "\n";
  443. } else if (lines[i].contains("$entitlements_push_notifications")) {
  444. bool is_on = p_preset->get("capabilities/push_notifications");
  445. strnew += lines[i].replace("$entitlements_push_notifications", is_on ? "<key>aps-environment</key><string>development</string>" : "") + "\n";
  446. } else if (lines[i].contains("$required_device_capabilities")) {
  447. String capabilities;
  448. // I've removed armv7 as we can run on 64bit only devices
  449. // Note that capabilities listed here are requirements for the app to be installed.
  450. // They don't enable anything.
  451. Vector<String> capabilities_list = p_config.capabilities;
  452. if ((bool)p_preset->get("capabilities/access_wifi") && !capabilities_list.has("wifi")) {
  453. capabilities_list.push_back("wifi");
  454. }
  455. if ((bool)p_preset->get("capabilities/performance_gaming_tier") && !capabilities_list.has("iphone-performance-gaming-tier")) {
  456. capabilities_list.push_back("iphone-performance-gaming-tier");
  457. }
  458. if ((bool)p_preset->get("capabilities/performance_a12") && !capabilities_list.has("iphone-ipad-minimum-performance-a12")) {
  459. capabilities_list.push_back("iphone-ipad-minimum-performance-a12");
  460. }
  461. for (int idx = 0; idx < capabilities_list.size(); idx++) {
  462. capabilities += "<string>" + capabilities_list[idx] + "</string>\n";
  463. }
  464. strnew += lines[i].replace("$required_device_capabilities", capabilities);
  465. } else if (lines[i].contains("$interface_orientations")) {
  466. String orientations;
  467. const DisplayServer::ScreenOrientation screen_orientation =
  468. DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation")));
  469. switch (screen_orientation) {
  470. case DisplayServer::SCREEN_LANDSCAPE:
  471. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  472. break;
  473. case DisplayServer::SCREEN_PORTRAIT:
  474. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  475. break;
  476. case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
  477. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  478. break;
  479. case DisplayServer::SCREEN_REVERSE_PORTRAIT:
  480. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  481. break;
  482. case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
  483. // Allow both landscape orientations depending on sensor direction.
  484. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  485. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  486. break;
  487. case DisplayServer::SCREEN_SENSOR_PORTRAIT:
  488. // Allow both portrait orientations depending on sensor direction.
  489. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  490. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  491. break;
  492. case DisplayServer::SCREEN_SENSOR:
  493. // Allow all screen orientations depending on sensor direction.
  494. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  495. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  496. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  497. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  498. break;
  499. }
  500. strnew += lines[i].replace("$interface_orientations", orientations);
  501. } else if (lines[i].contains("$ipad_interface_orientations")) {
  502. String orientations;
  503. const DisplayServer::ScreenOrientation screen_orientation =
  504. DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation")));
  505. switch (screen_orientation) {
  506. case DisplayServer::SCREEN_LANDSCAPE:
  507. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  508. break;
  509. case DisplayServer::SCREEN_PORTRAIT:
  510. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  511. break;
  512. case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
  513. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  514. break;
  515. case DisplayServer::SCREEN_REVERSE_PORTRAIT:
  516. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  517. break;
  518. case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
  519. // Allow both landscape orientations depending on sensor direction.
  520. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  521. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  522. break;
  523. case DisplayServer::SCREEN_SENSOR_PORTRAIT:
  524. // Allow both portrait orientations depending on sensor direction.
  525. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  526. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  527. break;
  528. case DisplayServer::SCREEN_SENSOR:
  529. // Allow all screen orientations depending on sensor direction.
  530. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  531. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  532. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  533. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  534. break;
  535. }
  536. strnew += lines[i].replace("$ipad_interface_orientations", orientations);
  537. } else if (lines[i].contains("$camera_usage_description")) {
  538. String description = p_preset->get("privacy/camera_usage_description");
  539. strnew += lines[i].replace("$camera_usage_description", description) + "\n";
  540. } else if (lines[i].contains("$microphone_usage_description")) {
  541. String description = p_preset->get("privacy/microphone_usage_description");
  542. strnew += lines[i].replace("$microphone_usage_description", description) + "\n";
  543. } else if (lines[i].contains("$photolibrary_usage_description")) {
  544. String description = p_preset->get("privacy/photolibrary_usage_description");
  545. strnew += lines[i].replace("$photolibrary_usage_description", description) + "\n";
  546. } else if (lines[i].contains("$plist_launch_screen_name")) {
  547. String value = "<key>UILaunchStoryboardName</key>\n<string>Launch Screen</string>";
  548. strnew += lines[i].replace("$plist_launch_screen_name", value) + "\n";
  549. } else if (lines[i].contains("$pbx_launch_screen_file_reference")) {
  550. String value = "90DD2D9D24B36E8000717FE1 = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = \"Launch Screen.storyboard\"; sourceTree = \"<group>\"; };";
  551. strnew += lines[i].replace("$pbx_launch_screen_file_reference", value) + "\n";
  552. } else if (lines[i].contains("$pbx_launch_screen_copy_files")) {
  553. String value = "90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */,";
  554. strnew += lines[i].replace("$pbx_launch_screen_copy_files", value) + "\n";
  555. } else if (lines[i].contains("$pbx_launch_screen_build_phase")) {
  556. String value = "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */,";
  557. strnew += lines[i].replace("$pbx_launch_screen_build_phase", value) + "\n";
  558. } else if (lines[i].contains("$pbx_launch_screen_build_reference")) {
  559. String value = "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */; };";
  560. strnew += lines[i].replace("$pbx_launch_screen_build_reference", value) + "\n";
  561. #ifndef DISABLE_DEPRECATED
  562. } else if (lines[i].contains("$pbx_launch_image_usage_setting")) {
  563. strnew += lines[i].replace("$pbx_launch_image_usage_setting", "") + "\n";
  564. #endif
  565. } else if (lines[i].contains("$launch_screen_image_mode")) {
  566. int image_scale_mode = p_preset->get("storyboard/image_scale_mode");
  567. String value;
  568. switch (image_scale_mode) {
  569. case 0: {
  570. String logo_path = GLOBAL_GET("application/boot_splash/image");
  571. bool is_on = GLOBAL_GET("application/boot_splash/fullsize");
  572. // If custom logo is not specified, Godot does not scale default one, so we should do the same.
  573. value = (is_on && logo_path.length() > 0) ? "scaleAspectFit" : "center";
  574. } break;
  575. default: {
  576. value = storyboard_image_scale_mode[image_scale_mode - 1];
  577. }
  578. }
  579. strnew += lines[i].replace("$launch_screen_image_mode", value) + "\n";
  580. } else if (lines[i].contains("$launch_screen_background_color")) {
  581. bool use_custom = p_preset->get("storyboard/use_custom_bg_color");
  582. Color color = use_custom ? p_preset->get("storyboard/custom_bg_color") : GLOBAL_GET("application/boot_splash/bg_color");
  583. const String value_format = "red=\"$red\" green=\"$green\" blue=\"$blue\" alpha=\"$alpha\"";
  584. Dictionary value_dictionary;
  585. value_dictionary["red"] = color.r;
  586. value_dictionary["green"] = color.g;
  587. value_dictionary["blue"] = color.b;
  588. value_dictionary["alpha"] = color.a;
  589. String value = value_format.format(value_dictionary, "$_");
  590. strnew += lines[i].replace("$launch_screen_background_color", value) + "\n";
  591. } else if (lines[i].contains("$pbx_locale_file_reference")) {
  592. String locale_files;
  593. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  594. if (translations.size() > 0) {
  595. HashSet<String> languages;
  596. for (const String &E : translations) {
  597. Ref<Translation> tr = ResourceLoader::load(E);
  598. if (tr.is_valid() && tr->get_locale() != "en") {
  599. languages.insert(tr->get_locale());
  600. }
  601. }
  602. int index = 0;
  603. for (const String &lang : languages) {
  604. 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";
  605. index++;
  606. }
  607. }
  608. strnew += lines[i].replace("$pbx_locale_file_reference", locale_files);
  609. } else if (lines[i].contains("$pbx_locale_build_reference")) {
  610. String locale_files;
  611. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  612. if (translations.size() > 0) {
  613. HashSet<String> languages;
  614. for (const String &E : translations) {
  615. Ref<Translation> tr = ResourceLoader::load(E);
  616. if (tr.is_valid() && tr->get_locale() != "en") {
  617. languages.insert(tr->get_locale());
  618. }
  619. }
  620. int index = 0;
  621. for (const String &lang : languages) {
  622. locale_files += "D0BCFE4518AEBDA2004A" + itos(index).pad_zeros(4) + " /* " + lang + " */,\n";
  623. index++;
  624. }
  625. }
  626. strnew += lines[i].replace("$pbx_locale_build_reference", locale_files);
  627. } else if (lines[i].contains("$swift_runtime_migration")) {
  628. String value = !p_config.use_swift_runtime ? "" : "LastSwiftMigration = 1250;";
  629. strnew += lines[i].replace("$swift_runtime_migration", value) + "\n";
  630. } else if (lines[i].contains("$swift_runtime_build_settings")) {
  631. String value = !p_config.use_swift_runtime ? "" : R"(
  632. CLANG_ENABLE_MODULES = YES;
  633. SWIFT_OBJC_BRIDGING_HEADER = "$binary/dummy.h";
  634. SWIFT_VERSION = 5.0;
  635. )";
  636. value = value.replace("$binary", p_config.binary_name);
  637. strnew += lines[i].replace("$swift_runtime_build_settings", value) + "\n";
  638. } else if (lines[i].contains("$swift_runtime_fileref")) {
  639. String value = !p_config.use_swift_runtime ? "" : R"(
  640. 90B4C2AA2680BC560039117A /* dummy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "dummy.h"; sourceTree = "<group>"; };
  641. 90B4C2B52680C7E90039117A /* dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "dummy.swift"; sourceTree = "<group>"; };
  642. )";
  643. strnew += lines[i].replace("$swift_runtime_fileref", value) + "\n";
  644. } else if (lines[i].contains("$swift_runtime_binary_files")) {
  645. String value = !p_config.use_swift_runtime ? "" : R"(
  646. 90B4C2AA2680BC560039117A /* dummy.h */,
  647. 90B4C2B52680C7E90039117A /* dummy.swift */,
  648. )";
  649. strnew += lines[i].replace("$swift_runtime_binary_files", value) + "\n";
  650. } else if (lines[i].contains("$swift_runtime_buildfile")) {
  651. String value = !p_config.use_swift_runtime ? "" : "90B4C2B62680C7E90039117A /* dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B4C2B52680C7E90039117A /* dummy.swift */; };";
  652. strnew += lines[i].replace("$swift_runtime_buildfile", value) + "\n";
  653. } else if (lines[i].contains("$swift_runtime_build_phase")) {
  654. String value = !p_config.use_swift_runtime ? "" : "90B4C2B62680C7E90039117A /* dummy.swift */,";
  655. strnew += lines[i].replace("$swift_runtime_build_phase", value) + "\n";
  656. } else if (lines[i].contains("$priv_collection")) {
  657. bool section_opened = false;
  658. for (uint64_t j = 0; j < sizeof(data_collect_type_info) / sizeof(data_collect_type_info[0]); ++j) {
  659. bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name));
  660. bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name));
  661. bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name));
  662. int purposes = p_preset->get(vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[j].prop_name));
  663. if (data_collected) {
  664. if (!section_opened) {
  665. section_opened = true;
  666. strnew += "\t<key>NSPrivacyCollectedDataTypes</key>\n";
  667. strnew += "\t<array>\n";
  668. }
  669. strnew += "\t\t<dict>\n";
  670. strnew += "\t\t\t<key>NSPrivacyCollectedDataType</key>\n";
  671. strnew += vformat("\t\t\t<string>%s</string>\n", data_collect_type_info[j].type_name);
  672. strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeLinked</key>\n";
  673. if (linked) {
  674. strnew += "\t\t\t\t<true/>\n";
  675. } else {
  676. strnew += "\t\t\t\t<false/>\n";
  677. }
  678. strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeTracking</key>\n";
  679. if (tracking) {
  680. strnew += "\t\t\t\t<true/>\n";
  681. } else {
  682. strnew += "\t\t\t\t<false/>\n";
  683. }
  684. if (purposes != 0) {
  685. strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n";
  686. strnew += "\t\t\t\t<array>\n";
  687. for (uint64_t k = 0; k < sizeof(data_collect_purpose_info) / sizeof(data_collect_purpose_info[0]); ++k) {
  688. if (purposes & (1 << k)) {
  689. strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name);
  690. }
  691. }
  692. strnew += "\t\t\t\t</array>\n";
  693. }
  694. strnew += "\t\t\t</dict>\n";
  695. }
  696. }
  697. if (section_opened) {
  698. strnew += "\t</array>\n";
  699. }
  700. } else if (lines[i].contains("$priv_tracking")) {
  701. bool tracking = p_preset->get("privacy/tracking_enabled");
  702. strnew += "\t<key>NSPrivacyTracking</key>\n";
  703. if (tracking) {
  704. strnew += "\t<true/>\n";
  705. } else {
  706. strnew += "\t<false/>\n";
  707. }
  708. Vector<String> tracking_domains = p_preset->get("privacy/tracking_domains");
  709. if (!tracking_domains.is_empty()) {
  710. strnew += "\t<key>NSPrivacyTrackingDomains</key>\n";
  711. strnew += "\t<array>\n";
  712. for (const String &E : tracking_domains) {
  713. strnew += "\t\t<string>" + E + "</string>\n";
  714. }
  715. strnew += "\t</array>\n";
  716. }
  717. } else if (lines[i].contains("$priv_api_types")) {
  718. strnew += "\t<array>\n";
  719. for (uint64_t j = 0; j < sizeof(api_info) / sizeof(api_info[0]); ++j) {
  720. int api_access = p_preset->get(vformat("privacy/%s_access_reasons", api_info[j].prop_name));
  721. if (api_access != 0) {
  722. strnew += "\t\t<dict>\n";
  723. strnew += "\t\t\t<key>NSPrivacyAccessedAPITypeReasons</key>\n";
  724. strnew += "\t\t\t<array>\n";
  725. for (int k = 0; k < api_info[j].prop_flag_value.size(); k++) {
  726. if (api_access & (1 << k)) {
  727. strnew += vformat("\t\t\t\t<string>%s</string>\n", api_info[j].prop_flag_value[k]);
  728. }
  729. }
  730. strnew += "\t\t\t</array>\n";
  731. strnew += "\t\t\t<key>NSPrivacyAccessedAPIType</key>\n";
  732. strnew += vformat("\t\t\t<string>%s</string>\n", api_info[j].type_name);
  733. strnew += "\t\t</dict>\n";
  734. }
  735. }
  736. strnew += "\t</array>\n";
  737. } else {
  738. strnew += lines[i] + "\n";
  739. }
  740. }
  741. // !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...
  742. // should apply the same fix in our macOS export.
  743. CharString cs = strnew.utf8();
  744. pfile.resize(cs.size() - 1);
  745. for (int i = 0; i < cs.size() - 1; i++) {
  746. pfile.write[i] = cs[i];
  747. }
  748. }
  749. String EditorExportPlatformIOS::_get_additional_plist_content() {
  750. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  751. String result;
  752. for (int i = 0; i < export_plugins.size(); ++i) {
  753. result += export_plugins[i]->get_ios_plist_content();
  754. }
  755. return result;
  756. }
  757. String EditorExportPlatformIOS::_get_linker_flags() {
  758. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  759. String result;
  760. for (int i = 0; i < export_plugins.size(); ++i) {
  761. String flags = export_plugins[i]->get_ios_linker_flags();
  762. if (flags.length() == 0) {
  763. continue;
  764. }
  765. if (result.length() > 0) {
  766. result += ' ';
  767. }
  768. result += flags;
  769. }
  770. // the flags will be enclosed in quotes, so need to escape them
  771. return result.replace("\"", "\\\"");
  772. }
  773. String EditorExportPlatformIOS::_get_cpp_code() {
  774. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  775. String result;
  776. for (int i = 0; i < export_plugins.size(); ++i) {
  777. result += export_plugins[i]->get_ios_cpp_code();
  778. }
  779. return result;
  780. }
  781. void EditorExportPlatformIOS::_blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot) {
  782. ERR_FAIL_COND(p_dst.is_null());
  783. ERR_FAIL_COND(p_src.is_null());
  784. int sw = p_rot ? p_src->get_height() : p_src->get_width();
  785. int sh = p_rot ? p_src->get_width() : p_src->get_height();
  786. int x_pos = (p_dst->get_width() - sw) / 2;
  787. int y_pos = (p_dst->get_height() - sh) / 2;
  788. int xs = (x_pos >= 0) ? 0 : -x_pos;
  789. int ys = (y_pos >= 0) ? 0 : -y_pos;
  790. if (sw + x_pos > p_dst->get_width()) {
  791. sw = p_dst->get_width() - x_pos;
  792. }
  793. if (sh + y_pos > p_dst->get_height()) {
  794. sh = p_dst->get_height() - y_pos;
  795. }
  796. for (int y = ys; y < sh; y++) {
  797. for (int x = xs; x < sw; x++) {
  798. Color sc = p_rot ? p_src->get_pixel(p_src->get_width() - y - 1, x) : p_src->get_pixel(x, y);
  799. Color dc = p_dst->get_pixel(x_pos + x, y_pos + y);
  800. dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r);
  801. dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g);
  802. dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b);
  803. dc.a = (double)(sc.a + dc.a * (1.0 - sc.a));
  804. p_dst->set_pixel(x_pos + x, y_pos + y, dc);
  805. }
  806. }
  807. }
  808. Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
  809. String json_description = "{\"images\":[";
  810. String sizes;
  811. Ref<DirAccess> da = DirAccess::open(p_iconset_dir);
  812. if (da.is_null()) {
  813. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not open a directory at path \"%s\"."), p_iconset_dir));
  814. return ERR_CANT_OPEN;
  815. }
  816. Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color");
  817. enum IconColorMode {
  818. ICON_NORMAL,
  819. ICON_DARK,
  820. ICON_TINTED,
  821. ICON_MAX,
  822. };
  823. bool first_icon = true;
  824. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  825. for (int color_mode = ICON_NORMAL; color_mode < ICON_MAX; color_mode++) {
  826. IconInfo info = icon_infos[i];
  827. int side_size = String(info.actual_size_side).to_int();
  828. String key = info.preset_key;
  829. String exp_name = info.export_name;
  830. if (color_mode == ICON_DARK) {
  831. key += "_dark";
  832. exp_name += "_dark";
  833. } else if (color_mode == ICON_TINTED) {
  834. key += "_tinted";
  835. exp_name += "_tinted";
  836. }
  837. exp_name += ".png";
  838. String icon_path = p_preset->get(key);
  839. bool resize_waning = true;
  840. if (icon_path.is_empty()) {
  841. // Load and resize base icon.
  842. key = "icons/icon_1024x1024";
  843. if (color_mode == ICON_DARK) {
  844. key += "_dark";
  845. } else if (color_mode == ICON_TINTED) {
  846. key += "_tinted";
  847. }
  848. icon_path = p_preset->get(key);
  849. resize_waning = false;
  850. }
  851. if (icon_path.is_empty()) {
  852. if (color_mode != ICON_NORMAL) {
  853. continue;
  854. }
  855. // Resize main app icon.
  856. icon_path = GLOBAL_GET("application/config/icon");
  857. Ref<Image> img = memnew(Image);
  858. Error err = ImageLoader::load_image(icon_path, img);
  859. if (err != OK) {
  860. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
  861. return ERR_UNCONFIGURED;
  862. } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
  863. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  864. Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
  865. new_img->fill(boot_bg_color);
  866. _blend_and_rotate(new_img, img, false);
  867. err = new_img->save_png(p_iconset_dir + exp_name);
  868. } else {
  869. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  870. err = img->save_png(p_iconset_dir + exp_name);
  871. }
  872. if (err) {
  873. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
  874. return err;
  875. }
  876. } else {
  877. // Load custom icon and resize if required.
  878. Ref<Image> img = memnew(Image);
  879. Error err = ImageLoader::load_image(icon_path, img);
  880. if (err != OK) {
  881. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
  882. return ERR_UNCONFIGURED;
  883. } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
  884. if (resize_waning) {
  885. add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
  886. }
  887. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  888. Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
  889. new_img->fill(boot_bg_color);
  890. _blend_and_rotate(new_img, img, false);
  891. err = new_img->save_png(p_iconset_dir + exp_name);
  892. } else if (img->get_width() != side_size || img->get_height() != side_size) {
  893. if (resize_waning) {
  894. 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)));
  895. }
  896. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  897. err = img->save_png(p_iconset_dir + exp_name);
  898. } else if (!icon_path.ends_with(".png")) {
  899. err = img->save_png(p_iconset_dir + exp_name);
  900. } else {
  901. err = da->copy(icon_path, p_iconset_dir + exp_name);
  902. }
  903. if (err) {
  904. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
  905. return err;
  906. }
  907. }
  908. sizes += String(info.actual_size_side) + "\n";
  909. if (first_icon) {
  910. first_icon = false;
  911. } else {
  912. json_description += ",";
  913. }
  914. json_description += String("{");
  915. if (color_mode != ICON_NORMAL) {
  916. json_description += String("\"appearances\":[{");
  917. json_description += String("\"appearance\":\"luminosity\",");
  918. if (color_mode == ICON_DARK) {
  919. json_description += String("\"value\":\"dark\"");
  920. } else if (color_mode == ICON_TINTED) {
  921. json_description += String("\"value\":\"tinted\"");
  922. }
  923. json_description += String("}],");
  924. }
  925. json_description += String("\"idiom\":") + "\"" + info.idiom + "\",";
  926. json_description += String("\"platform\":\"ios\",");
  927. json_description += String("\"size\":") + "\"" + info.unscaled_size + "\",";
  928. if (String(info.scale) != "1x") {
  929. json_description += String("\"scale\":") + "\"" + info.scale + "\",";
  930. }
  931. json_description += String("\"filename\":") + "\"" + exp_name + "\"";
  932. json_description += String("}");
  933. }
  934. }
  935. json_description += "],\"info\":{\"author\":\"xcode\",\"version\":1}}";
  936. Ref<FileAccess> json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
  937. if (json_file.is_null()) {
  938. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), p_iconset_dir + "Contents.json"));
  939. return ERR_CANT_CREATE;
  940. }
  941. CharString json_utf8 = json_description.utf8();
  942. json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length());
  943. Ref<FileAccess> sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE);
  944. if (sizes_file.is_null()) {
  945. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), p_iconset_dir + "sizes"));
  946. return ERR_CANT_CREATE;
  947. }
  948. CharString sizes_utf8 = sizes.utf8();
  949. sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length());
  950. return OK;
  951. }
  952. Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  953. const String custom_launch_image_2x = p_preset->get("storyboard/custom_image@2x");
  954. const String custom_launch_image_3x = p_preset->get("storyboard/custom_image@3x");
  955. if (custom_launch_image_2x.length() > 0 && custom_launch_image_3x.length() > 0) {
  956. Ref<Image> image;
  957. String image_path = p_dest_dir.path_join("[email protected]");
  958. image.instantiate();
  959. Error err = ImageLoader::load_image(custom_launch_image_2x, image);
  960. if (err) {
  961. image.unref();
  962. return err;
  963. }
  964. if (image->save_png(image_path) != OK) {
  965. return ERR_FILE_CANT_WRITE;
  966. }
  967. image.unref();
  968. image_path = p_dest_dir.path_join("[email protected]");
  969. image.instantiate();
  970. err = ImageLoader::load_image(custom_launch_image_3x, image);
  971. if (err) {
  972. image.unref();
  973. return err;
  974. }
  975. if (image->save_png(image_path) != OK) {
  976. return ERR_FILE_CANT_WRITE;
  977. }
  978. } else {
  979. Ref<Image> splash;
  980. const String splash_path = GLOBAL_GET("application/boot_splash/image");
  981. if (!splash_path.is_empty()) {
  982. splash.instantiate();
  983. const Error err = ImageLoader::load_image(splash_path, splash);
  984. if (err) {
  985. splash.unref();
  986. }
  987. }
  988. if (splash.is_null()) {
  989. splash = Ref<Image>(memnew(Image(boot_splash_png)));
  990. }
  991. // Using same image for both @2x and @3x
  992. // because Godot's own boot logo uses single image for all resolutions.
  993. // Also not using @1x image, because devices using this image variant
  994. // are not supported by iOS 9, which is minimal target.
  995. const String splash_png_path_2x = p_dest_dir.path_join("[email protected]");
  996. const String splash_png_path_3x = p_dest_dir.path_join("[email protected]");
  997. if (splash->save_png(splash_png_path_2x) != OK) {
  998. return ERR_FILE_CANT_WRITE;
  999. }
  1000. if (splash->save_png(splash_png_path_3x) != OK) {
  1001. return ERR_FILE_CANT_WRITE;
  1002. }
  1003. }
  1004. return OK;
  1005. }
  1006. Error EditorExportPlatformIOS::_walk_dir_recursive(Ref<DirAccess> &p_da, FileHandler p_handler, void *p_userdata) {
  1007. Vector<String> dirs;
  1008. String current_dir = p_da->get_current_dir();
  1009. p_da->list_dir_begin();
  1010. String path = p_da->get_next();
  1011. while (!path.is_empty()) {
  1012. if (p_da->current_is_dir()) {
  1013. if (path != "." && path != "..") {
  1014. dirs.push_back(path);
  1015. }
  1016. } else {
  1017. Error err = p_handler(current_dir.path_join(path), p_userdata);
  1018. if (err) {
  1019. p_da->list_dir_end();
  1020. return err;
  1021. }
  1022. }
  1023. path = p_da->get_next();
  1024. }
  1025. p_da->list_dir_end();
  1026. for (int i = 0; i < dirs.size(); ++i) {
  1027. p_da->change_dir(dirs[i]);
  1028. Error err = _walk_dir_recursive(p_da, p_handler, p_userdata);
  1029. p_da->change_dir("..");
  1030. if (err) {
  1031. return err;
  1032. }
  1033. }
  1034. return OK;
  1035. }
  1036. struct CodesignData {
  1037. const Ref<EditorExportPreset> &preset;
  1038. bool debug = false;
  1039. CodesignData(const Ref<EditorExportPreset> &p_preset, bool p_debug) :
  1040. preset(p_preset),
  1041. debug(p_debug) {
  1042. }
  1043. };
  1044. Error EditorExportPlatformIOS::_codesign(String p_file, void *p_userdata) {
  1045. if (p_file.ends_with(".dylib")) {
  1046. CodesignData *data = static_cast<CodesignData *>(p_userdata);
  1047. print_line(String("Signing ") + p_file);
  1048. String sign_id;
  1049. if (data->debug) {
  1050. sign_id = data->preset->get("application/code_sign_identity_debug").operator String().is_empty() ? "iPhone Developer" : data->preset->get("application/code_sign_identity_debug");
  1051. } else {
  1052. sign_id = data->preset->get("application/code_sign_identity_release").operator String().is_empty() ? "iPhone Distribution" : data->preset->get("application/code_sign_identity_release");
  1053. }
  1054. List<String> codesign_args;
  1055. codesign_args.push_back("-f");
  1056. codesign_args.push_back("-s");
  1057. codesign_args.push_back(sign_id);
  1058. codesign_args.push_back(p_file);
  1059. String str;
  1060. Error err = OS::get_singleton()->execute("codesign", codesign_args, &str, nullptr, true);
  1061. print_verbose("codesign (" + p_file + "):\n" + str);
  1062. return err;
  1063. }
  1064. return OK;
  1065. }
  1066. struct PbxId {
  1067. private:
  1068. static char _hex_char(uint8_t four_bits) {
  1069. if (four_bits < 10) {
  1070. return ('0' + four_bits);
  1071. }
  1072. return 'A' + (four_bits - 10);
  1073. }
  1074. static String _hex_pad(uint32_t num) {
  1075. Vector<char> ret;
  1076. ret.resize(sizeof(num) * 2);
  1077. for (uint64_t i = 0; i < sizeof(num) * 2; ++i) {
  1078. uint8_t four_bits = (num >> (sizeof(num) * 8 - (i + 1) * 4)) & 0xF;
  1079. ret.write[i] = _hex_char(four_bits);
  1080. }
  1081. return String::utf8(ret.ptr(), ret.size());
  1082. }
  1083. public:
  1084. uint32_t high_bits;
  1085. uint32_t mid_bits;
  1086. uint32_t low_bits;
  1087. String str() const {
  1088. return _hex_pad(high_bits) + _hex_pad(mid_bits) + _hex_pad(low_bits);
  1089. }
  1090. PbxId &operator++() {
  1091. low_bits++;
  1092. if (!low_bits) {
  1093. mid_bits++;
  1094. if (!mid_bits) {
  1095. high_bits++;
  1096. }
  1097. }
  1098. return *this;
  1099. }
  1100. };
  1101. struct ExportLibsData {
  1102. Vector<String> lib_paths;
  1103. String dest_dir;
  1104. };
  1105. bool EditorExportPlatformIOS::_archive_has_arm64(const String &p_path, uint32_t *r_cputype, uint32_t *r_cpusubtype) const {
  1106. bool has_arm64_image = false;
  1107. if (FileAccess::exists(p_path)) {
  1108. if (LipO::is_lipo(p_path)) {
  1109. // LipO.
  1110. Ref<LipO> lipo;
  1111. lipo.instantiate();
  1112. if (lipo->open_file(p_path)) {
  1113. for (int i = 0; i < lipo->get_arch_count(); i++) {
  1114. if (lipo->get_arch_cputype(i) == 0x100000c && lipo->get_arch_cpusubtype(i) == 0) {
  1115. has_arm64_image = true;
  1116. break;
  1117. }
  1118. }
  1119. }
  1120. lipo->close();
  1121. } else {
  1122. // Single architecture archive.
  1123. Ref<FileAccess> sim_f = FileAccess::open(p_path, FileAccess::READ);
  1124. if (sim_f.is_valid()) {
  1125. char magic[9] = {};
  1126. sim_f->get_buffer((uint8_t *)&magic[0], 8);
  1127. if (String(magic) == String("!<arch>\n")) {
  1128. while (!sim_f->eof_reached()) {
  1129. // Read file metadata.
  1130. char name_short[17] = {};
  1131. char size_short[11] = {};
  1132. sim_f->get_buffer((uint8_t *)&name_short[0], 16);
  1133. sim_f->seek(sim_f->get_position() + 12 + 6 + 6 + 8); // Skip modification time, owner ID, group ID, file mode.
  1134. sim_f->get_buffer((uint8_t *)&size_short[0], 10);
  1135. sim_f->seek(sim_f->get_position() + 2); // Skip end marker.
  1136. int64_t file_size = String(size_short).to_int();
  1137. int64_t next_off = sim_f->get_position() + file_size;
  1138. String name = String(name_short); // Skip extended name.
  1139. if (name.is_empty() || file_size == 0) {
  1140. break;
  1141. }
  1142. if (name.begins_with("#1/")) {
  1143. int64_t name_len = String(name_short).replace("#1/", "").to_int();
  1144. sim_f->seek(sim_f->get_position() + name_len);
  1145. }
  1146. // Read file content.
  1147. uint32_t obj_magic = sim_f->get_32();
  1148. bool swap = (obj_magic == 0xcffaedfe || obj_magic == 0xcefaedfe);
  1149. if (obj_magic == 0xcefaedfe || obj_magic == 0xfeedface || obj_magic == 0xcffaedfe || obj_magic == 0xfeedfacf) {
  1150. uint32_t cputype = sim_f->get_32();
  1151. uint32_t cpusubtype = sim_f->get_32();
  1152. if (swap) {
  1153. cputype = BSWAP32(cputype);
  1154. cpusubtype = BSWAP32(cpusubtype);
  1155. }
  1156. if (r_cputype) {
  1157. *r_cputype = cputype;
  1158. }
  1159. if (r_cpusubtype) {
  1160. *r_cpusubtype = cpusubtype;
  1161. }
  1162. if (cputype == 0x100000c && cpusubtype == 0) {
  1163. has_arm64_image = true;
  1164. }
  1165. break;
  1166. }
  1167. sim_f->seek(next_off);
  1168. }
  1169. }
  1170. sim_f->close();
  1171. }
  1172. }
  1173. }
  1174. return has_arm64_image;
  1175. }
  1176. int EditorExportPlatformIOS::_archive_convert_to_simulator(const String &p_path) const {
  1177. int commands_patched = 0;
  1178. Ref<FileAccess> sim_f = FileAccess::open(p_path, FileAccess::READ_WRITE);
  1179. if (sim_f.is_valid()) {
  1180. char magic[9] = {};
  1181. sim_f->get_buffer((uint8_t *)&magic[0], 8);
  1182. if (String(magic) == String("!<arch>\n")) {
  1183. while (!sim_f->eof_reached()) {
  1184. // Read file metadata.
  1185. char name_short[17] = {};
  1186. char size_short[11] = {};
  1187. sim_f->get_buffer((uint8_t *)&name_short[0], 16);
  1188. sim_f->seek(sim_f->get_position() + 12 + 6 + 6 + 8); // Skip modification time, owner ID, group ID, file mode.
  1189. sim_f->get_buffer((uint8_t *)&size_short[0], 10);
  1190. sim_f->seek(sim_f->get_position() + 2); // Skip end marker.
  1191. int64_t file_size = String(size_short).to_int();
  1192. int64_t next_off = sim_f->get_position() + file_size;
  1193. String name = String(name_short); // Skip extended name.
  1194. if (name.is_empty() || file_size == 0) {
  1195. break;
  1196. }
  1197. if (name.begins_with("#1/")) {
  1198. int64_t name_len = String(name_short).replace("#1/", "").to_int();
  1199. sim_f->seek(sim_f->get_position() + name_len);
  1200. }
  1201. // Read file content.
  1202. uint32_t obj_magic = sim_f->get_32();
  1203. bool swap = (obj_magic == 0xcffaedfe || obj_magic == 0xcefaedfe);
  1204. if (obj_magic == 0xcefaedfe || obj_magic == 0xfeedface || obj_magic == 0xcffaedfe || obj_magic == 0xfeedfacf) {
  1205. uint32_t cputype = sim_f->get_32();
  1206. uint32_t cpusubtype = sim_f->get_32();
  1207. uint32_t filetype = sim_f->get_32();
  1208. uint32_t ncmds = sim_f->get_32();
  1209. sim_f->get_32(); // Commands total size.
  1210. sim_f->get_32(); // Commands flags.
  1211. if (obj_magic == 0xcffaedfe || obj_magic == 0xfeedfacf) {
  1212. sim_f->get_32(); // Reserved, 64-bit only.
  1213. }
  1214. if (swap) {
  1215. ncmds = BSWAP32(ncmds);
  1216. cputype = BSWAP32(cputype);
  1217. cpusubtype = BSWAP32(cpusubtype);
  1218. filetype = BSWAP32(filetype);
  1219. }
  1220. if (cputype == 0x100000C && cpusubtype == 0 && filetype == 1) {
  1221. // ARM64, object file.
  1222. for (uint32_t i = 0; i < ncmds; i++) {
  1223. int64_t cmdofs = sim_f->get_position();
  1224. uint32_t cmdid = sim_f->get_32();
  1225. uint32_t cmdsize = sim_f->get_32();
  1226. if (swap) {
  1227. cmdid = BSWAP32(cmdid);
  1228. cmdsize = BSWAP32(cmdsize);
  1229. }
  1230. if (cmdid == MachO::LoadCommandID::LC_BUILD_VERSION) {
  1231. int64_t platform = sim_f->get_32();
  1232. if (swap) {
  1233. platform = BSWAP32(platform);
  1234. }
  1235. if (platform == MachO::PlatformID::PLATFORM_IOS) {
  1236. sim_f->seek(cmdofs + 4 + 4);
  1237. uint32_t new_id = MachO::PlatformID::PLATFORM_IOSSIMULATOR;
  1238. if (swap) {
  1239. new_id = BSWAP32(new_id);
  1240. }
  1241. sim_f->store_32(new_id);
  1242. commands_patched++;
  1243. }
  1244. }
  1245. sim_f->seek(cmdofs + cmdsize);
  1246. }
  1247. }
  1248. }
  1249. sim_f->seek(next_off);
  1250. }
  1251. }
  1252. sim_f->close();
  1253. }
  1254. return commands_patched;
  1255. }
  1256. void EditorExportPlatformIOS::_check_xcframework_content(const String &p_path, int &r_total_libs, int &r_static_libs, int &r_dylibs, int &r_frameworks) const {
  1257. Ref<PList> plist;
  1258. plist.instantiate();
  1259. plist->load_file(p_path.path_join("Info.plist"));
  1260. Ref<PListNode> root_node = plist->get_root();
  1261. if (root_node.is_null()) {
  1262. return;
  1263. }
  1264. Dictionary root = root_node->get_value();
  1265. if (!root.has("AvailableLibraries")) {
  1266. return;
  1267. }
  1268. Ref<PListNode> libs_node = root["AvailableLibraries"];
  1269. if (libs_node.is_null()) {
  1270. return;
  1271. }
  1272. Array libs = libs_node->get_value();
  1273. r_total_libs = libs.size();
  1274. for (int j = 0; j < libs.size(); j++) {
  1275. Ref<PListNode> lib_node = libs[j];
  1276. if (lib_node.is_null()) {
  1277. return;
  1278. }
  1279. Dictionary lib = lib_node->get_value();
  1280. if (lib.has("BinaryPath")) {
  1281. Ref<PListNode> path_node = lib["BinaryPath"];
  1282. if (path_node.is_valid()) {
  1283. String path = path_node->get_value();
  1284. if (path.ends_with(".a")) {
  1285. r_static_libs++;
  1286. }
  1287. if (path.ends_with(".dylib")) {
  1288. r_dylibs++;
  1289. }
  1290. if (path.ends_with(".framework")) {
  1291. r_frameworks++;
  1292. }
  1293. }
  1294. }
  1295. }
  1296. }
  1297. Error EditorExportPlatformIOS::_convert_to_framework(const String &p_source, const String &p_destination, const String &p_id) const {
  1298. print_line("Converting to .framework", p_source, " -> ", p_destination);
  1299. Ref<DirAccess> da = DirAccess::create_for_path(p_source);
  1300. if (da.is_null()) {
  1301. return ERR_CANT_OPEN;
  1302. }
  1303. Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1304. if (filesystem_da.is_null()) {
  1305. return ERR_CANT_OPEN;
  1306. }
  1307. if (!filesystem_da->dir_exists(p_destination)) {
  1308. Error make_dir_err = filesystem_da->make_dir_recursive(p_destination);
  1309. if (make_dir_err) {
  1310. return make_dir_err;
  1311. }
  1312. }
  1313. String asset = p_source.ends_with("/") ? p_source.left(p_source.length() - 1) : p_source;
  1314. if (asset.ends_with(".xcframework")) {
  1315. Ref<PList> plist;
  1316. plist.instantiate();
  1317. plist->load_file(p_source.path_join("Info.plist"));
  1318. Ref<PListNode> root_node = plist->get_root();
  1319. if (root_node.is_null()) {
  1320. return ERR_CANT_OPEN;
  1321. }
  1322. Dictionary root = root_node->get_value();
  1323. if (!root.has("AvailableLibraries")) {
  1324. return ERR_CANT_OPEN;
  1325. }
  1326. Ref<PListNode> libs_node = root["AvailableLibraries"];
  1327. if (libs_node.is_null()) {
  1328. return ERR_CANT_OPEN;
  1329. }
  1330. Array libs = libs_node->get_value();
  1331. for (int j = 0; j < libs.size(); j++) {
  1332. Ref<PListNode> lib_node = libs[j];
  1333. if (lib_node.is_null()) {
  1334. return ERR_CANT_OPEN;
  1335. }
  1336. Dictionary lib = lib_node->get_value();
  1337. if (lib.has("BinaryPath") && lib.has("LibraryPath") && lib.has("LibraryIdentifier")) {
  1338. Ref<PListNode> bpath_node = lib["BinaryPath"];
  1339. Ref<PListNode> lpath_node = lib["LibraryPath"];
  1340. Ref<PListNode> lid_node = lib["LibraryIdentifier"];
  1341. if (bpath_node.is_valid() && lpath_node.is_valid() && lid_node.is_valid()) {
  1342. String binary_path = bpath_node->get_value();
  1343. String library_identifier = lid_node->get_value();
  1344. String file_name = binary_path.get_basename().get_file();
  1345. String framework_name = file_name + ".framework";
  1346. bpath_node->data_string = framework_name.utf8();
  1347. lpath_node->data_string = framework_name.utf8();
  1348. if (!filesystem_da->dir_exists(p_destination.path_join(library_identifier))) {
  1349. filesystem_da->make_dir_recursive(p_destination.path_join(library_identifier));
  1350. }
  1351. _convert_to_framework(p_source.path_join(library_identifier).path_join(binary_path), p_destination.path_join(library_identifier).path_join(framework_name), p_id);
  1352. if (lib.has("DebugSymbolsPath")) {
  1353. Ref<PListNode> dpath_node = lib["DebugSymbolsPath"];
  1354. if (dpath_node.is_valid()) {
  1355. String dpath = dpath_node->get_value();
  1356. if (da->dir_exists(p_source.path_join(library_identifier).path_join(dpath))) {
  1357. da->copy_dir(p_source.path_join(library_identifier).path_join(dpath), p_destination.path_join(library_identifier).path_join("dSYMs"));
  1358. }
  1359. }
  1360. }
  1361. }
  1362. }
  1363. }
  1364. String info_plist = plist->save_text();
  1365. Ref<FileAccess> f = FileAccess::open(p_destination.path_join("Info.plist"), FileAccess::WRITE);
  1366. if (f.is_valid()) {
  1367. f->store_string(info_plist);
  1368. }
  1369. } else {
  1370. String file_name = p_destination.get_basename().get_file();
  1371. String framework_name = file_name + ".framework";
  1372. da->copy(p_source, p_destination.path_join(file_name));
  1373. // Performing `install_name_tool -id @rpath/{name}.framework/{name} ./{name}` on dylib
  1374. {
  1375. List<String> install_name_args;
  1376. install_name_args.push_back("-id");
  1377. install_name_args.push_back(String("@rpath").path_join(framework_name).path_join(file_name));
  1378. install_name_args.push_back(p_destination.path_join(file_name));
  1379. OS::get_singleton()->execute("install_name_tool", install_name_args);
  1380. }
  1381. // Creating Info.plist
  1382. {
  1383. String lib_clean_name = file_name;
  1384. for (int i = 0; i < lib_clean_name.length(); i++) {
  1385. if (!is_ascii_alphanumeric_char(lib_clean_name[i]) && lib_clean_name[i] != '.' && lib_clean_name[i] != '-') {
  1386. lib_clean_name[i] = '-';
  1387. }
  1388. }
  1389. String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1390. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  1391. "<plist version=\"1.0\">\n"
  1392. " <dict>\n"
  1393. " <key>CFBundleShortVersionString</key>\n"
  1394. " <string>1.0</string>\n"
  1395. " <key>CFBundleIdentifier</key>\n"
  1396. " <string>$id.framework.$cl_name</string>\n"
  1397. " <key>CFBundleName</key>\n"
  1398. " <string>$name</string>\n"
  1399. " <key>CFBundleExecutable</key>\n"
  1400. " <string>$name</string>\n"
  1401. " <key>DTPlatformName</key>\n"
  1402. " <string>iphoneos</string>\n"
  1403. " <key>CFBundleInfoDictionaryVersion</key>\n"
  1404. " <string>6.0</string>\n"
  1405. " <key>CFBundleVersion</key>\n"
  1406. " <string>1</string>\n"
  1407. " <key>CFBundlePackageType</key>\n"
  1408. " <string>FMWK</string>\n"
  1409. " <key>MinimumOSVersion</key>\n"
  1410. " <string>12.0</string>\n"
  1411. " </dict>\n"
  1412. "</plist>";
  1413. String info_plist = info_plist_format.replace("$id", p_id).replace("$name", file_name).replace("$cl_name", lib_clean_name);
  1414. Ref<FileAccess> f = FileAccess::open(p_destination.path_join("Info.plist"), FileAccess::WRITE);
  1415. if (f.is_valid()) {
  1416. f->store_string(info_plist);
  1417. }
  1418. }
  1419. }
  1420. return OK;
  1421. }
  1422. void EditorExportPlatformIOS::_add_assets_to_project(const String &p_out_dir, const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets) {
  1423. // that is just a random number, we just need Godot IDs not to clash with
  1424. // existing IDs in the project.
  1425. PbxId current_id = { 0x58938401, 0, 0 };
  1426. String pbx_files;
  1427. String pbx_frameworks_build;
  1428. String pbx_frameworks_refs;
  1429. String pbx_resources_build;
  1430. String pbx_resources_refs;
  1431. String pbx_embeded_frameworks;
  1432. const String file_info_format = String("$build_id = {isa = PBXBuildFile; fileRef = $ref_id; };\n") +
  1433. "$ref_id = {isa = PBXFileReference; lastKnownFileType = $file_type; name = \"$name\"; path = \"$file_path\"; sourceTree = \"<group>\"; };\n";
  1434. for (int i = 0; i < p_additional_assets.size(); ++i) {
  1435. String additional_asset_info_format = file_info_format;
  1436. String build_id = (++current_id).str();
  1437. String ref_id = (++current_id).str();
  1438. String framework_id = "";
  1439. const IOSExportAsset &asset = p_additional_assets[i];
  1440. String type;
  1441. if (asset.exported_path.ends_with(".framework")) {
  1442. if (asset.should_embed) {
  1443. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  1444. framework_id = (++current_id).str();
  1445. pbx_embeded_frameworks += framework_id + ",\n";
  1446. }
  1447. type = "wrapper.framework";
  1448. } else if (asset.exported_path.ends_with(".xcframework")) {
  1449. int total_libs = 0;
  1450. int static_libs = 0;
  1451. int dylibs = 0;
  1452. int frameworks = 0;
  1453. _check_xcframework_content(p_out_dir.path_join(asset.exported_path), total_libs, static_libs, dylibs, frameworks);
  1454. if (asset.should_embed && static_libs != total_libs) {
  1455. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  1456. framework_id = (++current_id).str();
  1457. pbx_embeded_frameworks += framework_id + ",\n";
  1458. }
  1459. type = "wrapper.xcframework";
  1460. } else if (asset.exported_path.ends_with(".dylib")) {
  1461. type = "compiled.mach-o.dylib";
  1462. } else if (asset.exported_path.ends_with(".a")) {
  1463. type = "archive.ar";
  1464. } else {
  1465. type = "file";
  1466. }
  1467. String &pbx_build = asset.is_framework ? pbx_frameworks_build : pbx_resources_build;
  1468. String &pbx_refs = asset.is_framework ? pbx_frameworks_refs : pbx_resources_refs;
  1469. if (pbx_build.length() > 0) {
  1470. pbx_build += ",\n";
  1471. pbx_refs += ",\n";
  1472. }
  1473. pbx_build += build_id;
  1474. pbx_refs += ref_id;
  1475. Dictionary format_dict;
  1476. format_dict["build_id"] = build_id;
  1477. format_dict["ref_id"] = ref_id;
  1478. format_dict["name"] = asset.exported_path.get_file();
  1479. format_dict["file_path"] = asset.exported_path;
  1480. format_dict["file_type"] = type;
  1481. if (framework_id.length() > 0) {
  1482. format_dict["framework_id"] = framework_id;
  1483. }
  1484. pbx_files += additional_asset_info_format.format(format_dict, "$_");
  1485. }
  1486. // Note, frameworks like gamekit are always included in our project.pbxprof file
  1487. // even if turned off in capabilities.
  1488. String str = String::utf8((const char *)p_project_data.ptr(), p_project_data.size());
  1489. str = str.replace("$additional_pbx_files", pbx_files);
  1490. str = str.replace("$additional_pbx_frameworks_build", pbx_frameworks_build);
  1491. str = str.replace("$additional_pbx_frameworks_refs", pbx_frameworks_refs);
  1492. str = str.replace("$additional_pbx_resources_build", pbx_resources_build);
  1493. str = str.replace("$additional_pbx_resources_refs", pbx_resources_refs);
  1494. str = str.replace("$pbx_embeded_frameworks", pbx_embeded_frameworks);
  1495. CharString cs = str.utf8();
  1496. p_project_data.resize(cs.size() - 1);
  1497. for (int i = 0; i < cs.size() - 1; i++) {
  1498. p_project_data.write[i] = cs[i];
  1499. }
  1500. }
  1501. Error EditorExportPlatformIOS::_copy_asset(const Ref<EditorExportPreset> &p_preset, 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) {
  1502. String binary_name = p_out_dir.get_file().get_basename();
  1503. Ref<DirAccess> da = DirAccess::create_for_path(p_asset);
  1504. if (da.is_null()) {
  1505. ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't open directory: " + p_asset + ".");
  1506. }
  1507. bool file_exists = da->file_exists(p_asset);
  1508. bool dir_exists = da->dir_exists(p_asset);
  1509. if (!file_exists && !dir_exists) {
  1510. return ERR_FILE_NOT_FOUND;
  1511. }
  1512. String base_dir = p_asset.get_base_dir().replace("res://", "").replace(".godot/mono/temp/bin/", "");
  1513. String asset = p_asset.ends_with("/") ? p_asset.left(p_asset.length() - 1) : p_asset;
  1514. String destination_dir;
  1515. String destination;
  1516. String asset_path;
  1517. Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1518. ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_out_dir + "'.");
  1519. if (p_is_framework && asset.ends_with(".dylib")) {
  1520. // For iOS we need to turn .dylib into .framework
  1521. // to be able to send application to AppStore
  1522. asset_path = String("dylibs").path_join(base_dir);
  1523. String file_name;
  1524. if (!p_custom_file_name) {
  1525. file_name = p_asset.get_basename().get_file();
  1526. } else {
  1527. file_name = *p_custom_file_name;
  1528. }
  1529. String framework_name = file_name + ".framework";
  1530. asset_path = asset_path.path_join(framework_name);
  1531. destination_dir = p_out_dir.path_join(asset_path);
  1532. destination = destination_dir;
  1533. // Convert to framework and copy.
  1534. Error err = _convert_to_framework(p_asset, destination, p_preset->get("application/bundle_identifier"));
  1535. if (err) {
  1536. return err;
  1537. }
  1538. } else if (p_is_framework && asset.ends_with(".xcframework")) {
  1539. // For iOS we need to turn .dylib inside .xcframework
  1540. // into .framework to be able to send application to AppStore
  1541. int total_libs = 0;
  1542. int static_libs = 0;
  1543. int dylibs = 0;
  1544. int frameworks = 0;
  1545. _check_xcframework_content(p_asset, total_libs, static_libs, dylibs, frameworks);
  1546. asset_path = String("dylibs").path_join(base_dir);
  1547. String file_name;
  1548. if (!p_custom_file_name) {
  1549. file_name = p_asset.get_file();
  1550. } else {
  1551. file_name = *p_custom_file_name;
  1552. }
  1553. asset_path = asset_path.path_join(file_name);
  1554. destination_dir = p_out_dir.path_join(asset_path);
  1555. destination = destination_dir;
  1556. if (dylibs > 0) {
  1557. // Convert to framework and copy.
  1558. Error err = _convert_to_framework(p_asset, destination, p_preset->get("application/bundle_identifier"));
  1559. if (err) {
  1560. return err;
  1561. }
  1562. } else {
  1563. // Copy as is.
  1564. if (!filesystem_da->dir_exists(destination_dir)) {
  1565. Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir);
  1566. if (make_dir_err) {
  1567. return make_dir_err;
  1568. }
  1569. }
  1570. Error err = dir_exists ? da->copy_dir(p_asset, destination) : da->copy(p_asset, destination);
  1571. if (err) {
  1572. return err;
  1573. }
  1574. }
  1575. } else if (p_is_framework && asset.ends_with(".framework")) {
  1576. // Framework.
  1577. asset_path = String("dylibs").path_join(base_dir);
  1578. String file_name;
  1579. if (!p_custom_file_name) {
  1580. file_name = p_asset.get_file();
  1581. } else {
  1582. file_name = *p_custom_file_name;
  1583. }
  1584. asset_path = asset_path.path_join(file_name);
  1585. destination_dir = p_out_dir.path_join(asset_path);
  1586. destination = destination_dir;
  1587. // Copy as is.
  1588. if (!filesystem_da->dir_exists(destination_dir)) {
  1589. Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir);
  1590. if (make_dir_err) {
  1591. return make_dir_err;
  1592. }
  1593. }
  1594. Error err = dir_exists ? da->copy_dir(p_asset, destination) : da->copy(p_asset, destination);
  1595. if (err) {
  1596. return err;
  1597. }
  1598. } else {
  1599. // Unknown resource.
  1600. asset_path = base_dir;
  1601. String file_name;
  1602. if (!p_custom_file_name) {
  1603. file_name = p_asset.get_file();
  1604. } else {
  1605. file_name = *p_custom_file_name;
  1606. }
  1607. destination_dir = p_out_dir.path_join(asset_path);
  1608. asset_path = asset_path.path_join(file_name);
  1609. destination = p_out_dir.path_join(asset_path);
  1610. // Copy as is.
  1611. if (!filesystem_da->dir_exists(destination_dir)) {
  1612. Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir);
  1613. if (make_dir_err) {
  1614. return make_dir_err;
  1615. }
  1616. }
  1617. Error err = dir_exists ? da->copy_dir(p_asset, destination) : da->copy(p_asset, destination);
  1618. if (err) {
  1619. return err;
  1620. }
  1621. }
  1622. if (asset_path.ends_with("/")) {
  1623. asset_path = asset_path.left(asset_path.length() - 1);
  1624. }
  1625. IOSExportAsset exported_asset = { binary_name.path_join(asset_path), p_is_framework, p_should_embed };
  1626. r_exported_assets.push_back(exported_asset);
  1627. return OK;
  1628. }
  1629. Error EditorExportPlatformIOS::_export_additional_assets(const Ref<EditorExportPreset> &p_preset, const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, bool p_should_embed, Vector<IOSExportAsset> &r_exported_assets) {
  1630. for (int f_idx = 0; f_idx < p_assets.size(); ++f_idx) {
  1631. const String &asset = p_assets[f_idx];
  1632. if (asset.begins_with("res://")) {
  1633. Error err = _copy_asset(p_preset, p_out_dir, asset, nullptr, p_is_framework, p_should_embed, r_exported_assets);
  1634. ERR_FAIL_COND_V(err != OK, err);
  1635. } else if (asset.is_absolute_path() && ProjectSettings::get_singleton()->localize_path(asset).begins_with("res://")) {
  1636. Error err = _copy_asset(p_preset, p_out_dir, ProjectSettings::get_singleton()->localize_path(asset), nullptr, p_is_framework, p_should_embed, r_exported_assets);
  1637. ERR_FAIL_COND_V(err != OK, err);
  1638. } else {
  1639. // either SDK-builtin or already a part of the export template
  1640. IOSExportAsset exported_asset = { asset, p_is_framework, p_should_embed };
  1641. r_exported_assets.push_back(exported_asset);
  1642. }
  1643. }
  1644. return OK;
  1645. }
  1646. Error EditorExportPlatformIOS::_export_additional_assets(const Ref<EditorExportPreset> &p_preset, const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets) {
  1647. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  1648. for (int i = 0; i < export_plugins.size(); i++) {
  1649. Vector<String> linked_frameworks = export_plugins[i]->get_ios_frameworks();
  1650. Error err = _export_additional_assets(p_preset, p_out_dir, linked_frameworks, true, false, r_exported_assets);
  1651. ERR_FAIL_COND_V(err, err);
  1652. Vector<String> embedded_frameworks = export_plugins[i]->get_ios_embedded_frameworks();
  1653. err = _export_additional_assets(p_preset, p_out_dir, embedded_frameworks, true, true, r_exported_assets);
  1654. ERR_FAIL_COND_V(err, err);
  1655. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  1656. for (int j = 0; j < project_static_libs.size(); j++) {
  1657. project_static_libs.write[j] = project_static_libs[j].get_file(); // Only the file name as it's copied to the project
  1658. }
  1659. err = _export_additional_assets(p_preset, p_out_dir, project_static_libs, true, false, r_exported_assets);
  1660. ERR_FAIL_COND_V(err, err);
  1661. Vector<String> ios_bundle_files = export_plugins[i]->get_ios_bundle_files();
  1662. err = _export_additional_assets(p_preset, p_out_dir, ios_bundle_files, false, false, r_exported_assets);
  1663. ERR_FAIL_COND_V(err, err);
  1664. }
  1665. Vector<String> library_paths;
  1666. for (int i = 0; i < p_libraries.size(); ++i) {
  1667. library_paths.push_back(p_libraries[i].path);
  1668. }
  1669. Error err = _export_additional_assets(p_preset, p_out_dir, library_paths, true, true, r_exported_assets);
  1670. ERR_FAIL_COND_V(err, err);
  1671. return OK;
  1672. }
  1673. Vector<String> EditorExportPlatformIOS::_get_preset_architectures(const Ref<EditorExportPreset> &p_preset) const {
  1674. Vector<ExportArchitecture> all_archs = _get_supported_architectures();
  1675. Vector<String> enabled_archs;
  1676. for (int i = 0; i < all_archs.size(); ++i) {
  1677. bool is_enabled = p_preset->get("architectures/" + all_archs[i].name);
  1678. if (is_enabled) {
  1679. enabled_archs.push_back(all_archs[i].name);
  1680. }
  1681. }
  1682. return enabled_archs;
  1683. }
  1684. 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) {
  1685. String plugin_definition_cpp_code;
  1686. String plugin_initialization_cpp_code;
  1687. String plugin_deinitialization_cpp_code;
  1688. Vector<String> plugin_linked_dependencies;
  1689. Vector<String> plugin_embedded_dependencies;
  1690. Vector<String> plugin_files;
  1691. Vector<PluginConfigIOS> enabled_plugins = get_enabled_plugins(p_preset);
  1692. Vector<String> added_linked_dependenciy_names;
  1693. Vector<String> added_embedded_dependenciy_names;
  1694. HashMap<String, String> plist_values;
  1695. HashSet<String> plugin_linker_flags;
  1696. Error err;
  1697. for (int i = 0; i < enabled_plugins.size(); i++) {
  1698. PluginConfigIOS plugin = enabled_plugins[i];
  1699. // Export plugin binary.
  1700. String plugin_main_binary = PluginConfigIOS::get_plugin_main_binary(plugin, p_debug);
  1701. String plugin_binary_result_file = plugin.binary.get_file();
  1702. // We shouldn't embed .xcframework that contains static libraries.
  1703. // Static libraries are not embedded anyway.
  1704. err = _copy_asset(p_preset, dest_dir, plugin_main_binary, &plugin_binary_result_file, true, false, r_exported_assets);
  1705. ERR_FAIL_COND_V(err != OK, err);
  1706. // Adding dependencies.
  1707. // Use separate container for names to check for duplicates.
  1708. for (int j = 0; j < plugin.linked_dependencies.size(); j++) {
  1709. String dependency = plugin.linked_dependencies[j];
  1710. String name = dependency.get_file();
  1711. if (added_linked_dependenciy_names.has(name)) {
  1712. continue;
  1713. }
  1714. added_linked_dependenciy_names.push_back(name);
  1715. plugin_linked_dependencies.push_back(dependency);
  1716. }
  1717. for (int j = 0; j < plugin.system_dependencies.size(); j++) {
  1718. String dependency = plugin.system_dependencies[j];
  1719. String name = dependency.get_file();
  1720. if (added_linked_dependenciy_names.has(name)) {
  1721. continue;
  1722. }
  1723. added_linked_dependenciy_names.push_back(name);
  1724. plugin_linked_dependencies.push_back(dependency);
  1725. }
  1726. for (int j = 0; j < plugin.embedded_dependencies.size(); j++) {
  1727. String dependency = plugin.embedded_dependencies[j];
  1728. String name = dependency.get_file();
  1729. if (added_embedded_dependenciy_names.has(name)) {
  1730. continue;
  1731. }
  1732. added_embedded_dependenciy_names.push_back(name);
  1733. plugin_embedded_dependencies.push_back(dependency);
  1734. }
  1735. plugin_files.append_array(plugin.files_to_copy);
  1736. // Capabilities
  1737. // Also checking for duplicates.
  1738. for (int j = 0; j < plugin.capabilities.size(); j++) {
  1739. String capability = plugin.capabilities[j];
  1740. if (p_config_data.capabilities.has(capability)) {
  1741. continue;
  1742. }
  1743. p_config_data.capabilities.push_back(capability);
  1744. }
  1745. // Linker flags
  1746. // Checking duplicates
  1747. for (int j = 0; j < plugin.linker_flags.size(); j++) {
  1748. String linker_flag = plugin.linker_flags[j];
  1749. plugin_linker_flags.insert(linker_flag);
  1750. }
  1751. // Plist
  1752. // Using hash map container to remove duplicates
  1753. for (const KeyValue<String, PluginConfigIOS::PlistItem> &E : plugin.plist) {
  1754. String key = E.key;
  1755. const PluginConfigIOS::PlistItem &item = E.value;
  1756. String value;
  1757. switch (item.type) {
  1758. case PluginConfigIOS::PlistItemType::STRING_INPUT: {
  1759. String preset_name = "plugins_plist/" + key;
  1760. String input_value = p_preset->get(preset_name);
  1761. value = "<string>" + input_value + "</string>";
  1762. } break;
  1763. default:
  1764. value = item.value;
  1765. break;
  1766. }
  1767. if (key.is_empty() || value.is_empty()) {
  1768. continue;
  1769. }
  1770. String plist_key = "<key>" + key + "</key>";
  1771. plist_values[plist_key] = value;
  1772. }
  1773. // CPP Code
  1774. String definition_comment = "// Plugin: " + plugin.name + "\n";
  1775. String initialization_method = plugin.initialization_method + "();\n";
  1776. String deinitialization_method = plugin.deinitialization_method + "();\n";
  1777. plugin_definition_cpp_code += definition_comment +
  1778. "extern void " + initialization_method +
  1779. "extern void " + deinitialization_method + "\n";
  1780. plugin_initialization_cpp_code += "\t" + initialization_method;
  1781. plugin_deinitialization_cpp_code += "\t" + deinitialization_method;
  1782. if (plugin.use_swift_runtime) {
  1783. p_config_data.use_swift_runtime = true;
  1784. }
  1785. }
  1786. // Updating `Info.plist`
  1787. {
  1788. for (const KeyValue<String, String> &E : plist_values) {
  1789. String key = E.key;
  1790. String value = E.value;
  1791. if (key.is_empty() || value.is_empty()) {
  1792. continue;
  1793. }
  1794. p_config_data.plist_content += key + value + "\n";
  1795. }
  1796. }
  1797. // Export files
  1798. {
  1799. // Export linked plugin dependency
  1800. err = _export_additional_assets(p_preset, dest_dir, plugin_linked_dependencies, true, false, r_exported_assets);
  1801. ERR_FAIL_COND_V(err != OK, err);
  1802. // Export embedded plugin dependency
  1803. err = _export_additional_assets(p_preset, dest_dir, plugin_embedded_dependencies, true, true, r_exported_assets);
  1804. ERR_FAIL_COND_V(err != OK, err);
  1805. // Export plugin files
  1806. err = _export_additional_assets(p_preset, dest_dir, plugin_files, false, false, r_exported_assets);
  1807. ERR_FAIL_COND_V(err != OK, err);
  1808. }
  1809. // Update CPP
  1810. {
  1811. Dictionary plugin_format;
  1812. plugin_format["definition"] = plugin_definition_cpp_code;
  1813. plugin_format["initialization"] = plugin_initialization_cpp_code;
  1814. plugin_format["deinitialization"] = plugin_deinitialization_cpp_code;
  1815. String plugin_cpp_code = "\n// Godot Plugins\n"
  1816. "void godot_ios_plugins_initialize();\n"
  1817. "void godot_ios_plugins_deinitialize();\n"
  1818. "// Exported Plugins\n\n"
  1819. "$definition"
  1820. "// Use Plugins\n"
  1821. "void godot_ios_plugins_initialize() {\n"
  1822. "$initialization"
  1823. "}\n\n"
  1824. "void godot_ios_plugins_deinitialize() {\n"
  1825. "$deinitialization"
  1826. "}\n";
  1827. p_config_data.cpp_code += plugin_cpp_code.format(plugin_format, "$_");
  1828. }
  1829. // Update Linker Flag Values
  1830. {
  1831. String result_linker_flags = " ";
  1832. for (const String &E : plugin_linker_flags) {
  1833. const String &flag = E;
  1834. if (flag.length() == 0) {
  1835. continue;
  1836. }
  1837. if (result_linker_flags.length() > 0) {
  1838. result_linker_flags += ' ';
  1839. }
  1840. result_linker_flags += flag;
  1841. }
  1842. result_linker_flags = result_linker_flags.replace("\"", "\\\"");
  1843. p_config_data.linker_flags += result_linker_flags;
  1844. }
  1845. return OK;
  1846. }
  1847. Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) {
  1848. return _export_project_helper(p_preset, p_debug, p_path, p_flags, false, false);
  1849. }
  1850. Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags, bool p_simulator, bool p_oneclick) {
  1851. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  1852. const String dest_dir = p_path.get_base_dir() + "/";
  1853. const String binary_name = p_path.get_file().get_basename();
  1854. const String binary_dir = dest_dir + binary_name;
  1855. if (!DirAccess::exists(dest_dir)) {
  1856. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Target folder does not exist or is inaccessible: \"%s\""), dest_dir));
  1857. return ERR_FILE_BAD_PATH;
  1858. }
  1859. bool export_project_only = p_preset->get("application/export_project_only");
  1860. if (p_oneclick) {
  1861. export_project_only = false; // Skip for one-click deploy.
  1862. }
  1863. EditorProgress ep("export", export_project_only ? TTR("Exporting for iOS (Project Files Only)") : TTR("Exporting for iOS"), export_project_only ? 2 : 5, true);
  1864. String team_id = p_preset->get("application/app_store_team_id");
  1865. ERR_FAIL_COND_V_MSG(team_id.length() == 0, ERR_CANT_OPEN, "App Store Team ID not specified - cannot configure the project.");
  1866. String src_pkg_name;
  1867. if (p_debug) {
  1868. src_pkg_name = p_preset->get("custom_template/debug");
  1869. } else {
  1870. src_pkg_name = p_preset->get("custom_template/release");
  1871. }
  1872. if (src_pkg_name.is_empty()) {
  1873. String err;
  1874. src_pkg_name = find_export_template("ios.zip", &err);
  1875. if (src_pkg_name.is_empty()) {
  1876. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found."));
  1877. return ERR_FILE_NOT_FOUND;
  1878. }
  1879. }
  1880. {
  1881. bool delete_old = p_preset->get("application/delete_old_export_files_unconditionally");
  1882. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1883. if (da.is_valid()) {
  1884. String current_dir = da->get_current_dir();
  1885. // Remove leftovers from last export so they don't interfere in case some files are no longer needed.
  1886. if (da->change_dir(binary_dir + ".xcodeproj") == OK) {
  1887. // Check directory content before deleting.
  1888. int expected_files = 0;
  1889. int total_files = 0;
  1890. if (!delete_old) {
  1891. da->list_dir_begin();
  1892. for (String n = da->get_next(); !n.is_empty(); n = da->get_next()) {
  1893. if (!n.begins_with(".")) { // Ignore ".", ".." and hidden files.
  1894. if (da->current_is_dir()) {
  1895. if (n == "xcshareddata" || n == "project.xcworkspace") {
  1896. expected_files++;
  1897. }
  1898. } else {
  1899. if (n == "project.pbxproj") {
  1900. expected_files++;
  1901. }
  1902. }
  1903. total_files++;
  1904. }
  1905. }
  1906. da->list_dir_end();
  1907. }
  1908. if ((total_files == 0) || (expected_files >= Math::floor(total_files * 0.8))) {
  1909. da->erase_contents_recursive();
  1910. } else {
  1911. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Unexpected files found in the export destination directory \"%s.xcodeproj\", delete it manually or select another destination."), binary_dir));
  1912. return ERR_CANT_CREATE;
  1913. }
  1914. }
  1915. da->change_dir(current_dir);
  1916. if (da->change_dir(binary_dir) == OK) {
  1917. // Check directory content before deleting.
  1918. int expected_files = 0;
  1919. int total_files = 0;
  1920. if (!delete_old) {
  1921. da->list_dir_begin();
  1922. for (String n = da->get_next(); !n.is_empty(); n = da->get_next()) {
  1923. if (!n.begins_with(".")) { // Ignore ".", ".." and hidden files.
  1924. if (da->current_is_dir()) {
  1925. if (n == "dylibs" || n == "Images.xcassets" || n.ends_with(".lproj") || n == "godot-publish-dotnet" || n.ends_with(".xcframework") || n.ends_with(".framework")) {
  1926. expected_files++;
  1927. }
  1928. } else {
  1929. if (n == binary_name + "-Info.plist" || n == binary_name + ".entitlements" || n == "Launch Screen.storyboard" || n == "export_options.plist" || n.begins_with("dummy.") || n.ends_with(".gdip")) {
  1930. expected_files++;
  1931. }
  1932. }
  1933. total_files++;
  1934. }
  1935. }
  1936. da->list_dir_end();
  1937. }
  1938. if ((total_files == 0) || (expected_files >= Math::floor(total_files * 0.8))) {
  1939. da->erase_contents_recursive();
  1940. } else {
  1941. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Unexpected files found in the export destination directory \"%s\", delete it manually or select another destination."), binary_dir));
  1942. return ERR_CANT_CREATE;
  1943. }
  1944. }
  1945. da->change_dir(current_dir);
  1946. if (!da->dir_exists(binary_dir)) {
  1947. Error err = da->make_dir(binary_dir);
  1948. if (err != OK) {
  1949. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Failed to create the directory: \"%s\""), binary_dir));
  1950. return err;
  1951. }
  1952. }
  1953. }
  1954. }
  1955. if (ep.step("Making .pck", 0)) {
  1956. return ERR_SKIP;
  1957. }
  1958. String pack_path = binary_dir + ".pck";
  1959. Vector<SharedObject> libraries;
  1960. Error err = save_pack(p_preset, p_debug, pack_path, &libraries);
  1961. if (err) {
  1962. // Message is supplied by the subroutine method.
  1963. return err;
  1964. }
  1965. if (ep.step("Extracting and configuring Xcode project", 1)) {
  1966. return ERR_SKIP;
  1967. }
  1968. String library_to_use = "libgodot.ios." + String(p_debug ? "debug" : "release") + ".xcframework";
  1969. print_line("Static framework: " + library_to_use);
  1970. String pkg_name;
  1971. if (String(GLOBAL_GET("application/config/name")) != "") {
  1972. pkg_name = String(GLOBAL_GET("application/config/name"));
  1973. } else {
  1974. pkg_name = "Unnamed";
  1975. }
  1976. bool found_library = false;
  1977. const String project_file = "godot_ios.xcodeproj/project.pbxproj";
  1978. HashSet<String> files_to_parse;
  1979. files_to_parse.insert("godot_ios/godot_ios-Info.plist");
  1980. files_to_parse.insert(project_file);
  1981. files_to_parse.insert("godot_ios/export_options.plist");
  1982. files_to_parse.insert("godot_ios/dummy.cpp");
  1983. files_to_parse.insert("godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata");
  1984. files_to_parse.insert("godot_ios.xcodeproj/xcshareddata/xcschemes/godot_ios.xcscheme");
  1985. files_to_parse.insert("godot_ios/godot_ios.entitlements");
  1986. files_to_parse.insert("godot_ios/Launch Screen.storyboard");
  1987. files_to_parse.insert("PrivacyInfo.xcprivacy");
  1988. IOSConfigData config_data = {
  1989. pkg_name,
  1990. binary_name,
  1991. _get_additional_plist_content(),
  1992. String(" ").join(_get_preset_architectures(p_preset)),
  1993. _get_linker_flags(),
  1994. _get_cpp_code(),
  1995. "",
  1996. "",
  1997. "",
  1998. "",
  1999. Vector<String>(),
  2000. false
  2001. };
  2002. config_data.plist_content += p_preset->get("application/additional_plist_content").operator String() + "\n";
  2003. Vector<IOSExportAsset> assets;
  2004. Ref<DirAccess> tmp_app_path = DirAccess::create_for_path(dest_dir);
  2005. if (tmp_app_path.is_null()) {
  2006. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not create and open the directory: \"%s\""), dest_dir));
  2007. return ERR_CANT_CREATE;
  2008. }
  2009. print_line("Unzipping...");
  2010. Ref<FileAccess> io_fa;
  2011. zlib_filefunc_def io = zipio_create_io(&io_fa);
  2012. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  2013. if (!src_pkg_zip) {
  2014. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Could not open export template (not a zip file?): \"%s\".", src_pkg_name));
  2015. return ERR_CANT_OPEN;
  2016. }
  2017. err = _export_ios_plugins(p_preset, config_data, binary_dir, assets, p_debug);
  2018. if (err != OK) {
  2019. // TODO: Improve error reporting by using `add_message` throughout all methods called via `_export_ios_plugins`.
  2020. // For now a generic top level message would be fine, but we're ought to use proper reporting here instead of
  2021. // just fail macros and non-descriptive error return values.
  2022. add_message(EXPORT_MESSAGE_ERROR, TTR("iOS Plugins"), vformat(TTR("Failed to export iOS plugins with code %d. Please check the output log."), err));
  2023. return err;
  2024. }
  2025. //export rest of the files
  2026. int ret = unzGoToFirstFile(src_pkg_zip);
  2027. Vector<uint8_t> project_file_data;
  2028. while (ret == UNZ_OK) {
  2029. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  2030. bool is_execute = false;
  2031. #endif
  2032. //get filename
  2033. unz_file_info info;
  2034. char fname[16384];
  2035. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  2036. if (ret != UNZ_OK) {
  2037. break;
  2038. }
  2039. String file = String::utf8(fname);
  2040. print_line("READ: " + file);
  2041. Vector<uint8_t> data;
  2042. data.resize(info.uncompressed_size);
  2043. //read
  2044. unzOpenCurrentFile(src_pkg_zip);
  2045. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  2046. unzCloseCurrentFile(src_pkg_zip);
  2047. //write
  2048. if (files_to_parse.has(file)) {
  2049. _fix_config_file(p_preset, data, config_data, p_debug);
  2050. } else if (file.begins_with("libgodot.ios")) {
  2051. if (!file.begins_with(library_to_use) || file.ends_with(String("/empty"))) {
  2052. ret = unzGoToNextFile(src_pkg_zip);
  2053. continue; //ignore!
  2054. }
  2055. found_library = true;
  2056. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  2057. is_execute = true;
  2058. #endif
  2059. file = file.replace(library_to_use, binary_name + ".xcframework");
  2060. }
  2061. if (file == project_file) {
  2062. project_file_data = data;
  2063. }
  2064. ///@TODO need to parse logo files
  2065. if (data.size() > 0) {
  2066. file = file.replace("godot_ios", binary_name);
  2067. print_line("ADDING: " + file + " size: " + itos(data.size()));
  2068. /* write it into our folder structure */
  2069. file = dest_dir + file;
  2070. /* make sure this folder exists */
  2071. String dir_name = file.get_base_dir();
  2072. if (!tmp_app_path->dir_exists(dir_name)) {
  2073. print_line("Creating " + dir_name);
  2074. Error dir_err = tmp_app_path->make_dir_recursive(dir_name);
  2075. if (dir_err) {
  2076. unzClose(src_pkg_zip);
  2077. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create a directory at path \"%s\"."), dir_name));
  2078. return ERR_CANT_CREATE;
  2079. }
  2080. }
  2081. /* write the file */
  2082. {
  2083. Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);
  2084. if (f.is_null()) {
  2085. unzClose(src_pkg_zip);
  2086. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write to a file at path \"%s\"."), file));
  2087. return ERR_CANT_CREATE;
  2088. };
  2089. f->store_buffer(data.ptr(), data.size());
  2090. }
  2091. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  2092. if (is_execute) {
  2093. // we need execute rights on this file
  2094. chmod(file.utf8().get_data(), 0755);
  2095. }
  2096. #endif
  2097. }
  2098. ret = unzGoToNextFile(src_pkg_zip);
  2099. }
  2100. // We're done with our source zip.
  2101. unzClose(src_pkg_zip);
  2102. if (!found_library) {
  2103. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Requested template library '%s' not found. It might be missing from your template archive."), library_to_use));
  2104. return ERR_FILE_NOT_FOUND;
  2105. }
  2106. // Check and generate missing ARM64 simulator library.
  2107. if (p_preset->get("application/generate_simulator_library_if_missing").operator bool()) {
  2108. String sim_lib_path = dest_dir + String(binary_name + ".xcframework").path_join("ios-arm64_x86_64-simulator").path_join("libgodot.a");
  2109. String dev_lib_path = dest_dir + String(binary_name + ".xcframework").path_join("ios-arm64").path_join("libgodot.a");
  2110. String tmp_lib_path = EditorPaths::get_singleton()->get_cache_dir().path_join(binary_name + "_lipo_");
  2111. uint32_t cputype = 0;
  2112. uint32_t cpusubtype = 0;
  2113. if (!_archive_has_arm64(sim_lib_path, &cputype, &cpusubtype) && _archive_has_arm64(dev_lib_path) && FileAccess::exists(dev_lib_path)) {
  2114. add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("ARM64 simulator library, generating from device library."));
  2115. Vector<String> tmp_lib_files;
  2116. Vector<Vector2i> tmp_lib_cputypes;
  2117. // Extract/copy simulator lib.
  2118. if (FileAccess::exists(sim_lib_path)) {
  2119. if (LipO::is_lipo(sim_lib_path)) {
  2120. Ref<LipO> lipo;
  2121. lipo.instantiate();
  2122. if (lipo->open_file(sim_lib_path)) {
  2123. for (int i = 0; i < lipo->get_arch_count(); i++) {
  2124. const String &f_name = tmp_lib_path + itos(tmp_lib_files.size());
  2125. lipo->extract_arch(i, f_name);
  2126. tmp_lib_files.push_back(f_name);
  2127. tmp_lib_cputypes.push_back(Vector2i(lipo->get_arch_cputype(i), lipo->get_arch_cpusubtype(i)));
  2128. }
  2129. }
  2130. } else {
  2131. const String &f_name = tmp_lib_path + itos(tmp_lib_files.size());
  2132. tmp_app_path->copy(sim_lib_path, f_name);
  2133. tmp_lib_files.push_back(f_name);
  2134. tmp_lib_cputypes.push_back(Vector2i(cputype, cpusubtype));
  2135. }
  2136. }
  2137. // Copy device lib.
  2138. if (LipO::is_lipo(dev_lib_path)) {
  2139. Ref<LipO> lipo;
  2140. lipo.instantiate();
  2141. if (lipo->open_file(dev_lib_path)) {
  2142. for (int i = 0; i < lipo->get_arch_count(); i++) {
  2143. if (lipo->get_arch_cputype(i) == 0x100000c && lipo->get_arch_cpusubtype(i) == 0) {
  2144. const String &f_name = tmp_lib_path + itos(tmp_lib_files.size());
  2145. lipo->extract_arch(i, f_name);
  2146. tmp_lib_files.push_back(f_name);
  2147. tmp_lib_cputypes.push_back(Vector2i(0x100000c, 0)); // ARM64.
  2148. break;
  2149. }
  2150. }
  2151. }
  2152. } else {
  2153. const String &f_name = tmp_lib_path + itos(tmp_lib_files.size());
  2154. tmp_app_path->copy(dev_lib_path, f_name);
  2155. tmp_lib_files.push_back(f_name);
  2156. tmp_lib_cputypes.push_back(Vector2i(0x100000c, 0)); // ARM64.
  2157. }
  2158. // Patch device lib.
  2159. int patch_count = _archive_convert_to_simulator(tmp_lib_path + itos(tmp_lib_files.size() - 1));
  2160. if (patch_count == 0) {
  2161. add_message(EXPORT_MESSAGE_WARNING, TTR("Export"), TTR("Unable to generate ARM64 simulator library."));
  2162. } else {
  2163. // Repack.
  2164. Ref<LipO> lipo;
  2165. lipo.instantiate();
  2166. lipo->create_file(sim_lib_path, tmp_lib_files, tmp_lib_cputypes);
  2167. }
  2168. // Cleanup.
  2169. for (const String &E : tmp_lib_files) {
  2170. tmp_app_path->remove(E);
  2171. }
  2172. }
  2173. }
  2174. // Generate translations files.
  2175. Dictionary appnames = GLOBAL_GET("application/config/name_localized");
  2176. Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");
  2177. Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");
  2178. Dictionary photolibrary_usage_descriptions = p_preset->get("privacy/photolibrary_usage_description_localized");
  2179. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  2180. if (translations.size() > 0) {
  2181. {
  2182. String fname = binary_dir + "/en.lproj";
  2183. tmp_app_path->make_dir_recursive(fname);
  2184. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  2185. f->store_line("/* Localized versions of Info.plist keys */");
  2186. f->store_line("");
  2187. f->store_line("CFBundleDisplayName = \"" + GLOBAL_GET("application/config/name").operator String() + "\";");
  2188. f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String() + "\";");
  2189. f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String() + "\";");
  2190. f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photolibrary_usage_description").operator String() + "\";");
  2191. }
  2192. HashSet<String> languages;
  2193. for (const String &E : translations) {
  2194. Ref<Translation> tr = ResourceLoader::load(E);
  2195. if (tr.is_valid() && tr->get_locale() != "en") {
  2196. languages.insert(tr->get_locale());
  2197. }
  2198. }
  2199. for (const String &lang : languages) {
  2200. String fname = binary_dir + "/" + lang + ".lproj";
  2201. tmp_app_path->make_dir_recursive(fname);
  2202. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  2203. f->store_line("/* Localized versions of Info.plist keys */");
  2204. f->store_line("");
  2205. if (appnames.has(lang)) {
  2206. f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String() + "\";");
  2207. }
  2208. if (camera_usage_descriptions.has(lang)) {
  2209. f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String() + "\";");
  2210. }
  2211. if (microphone_usage_descriptions.has(lang)) {
  2212. f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String() + "\";");
  2213. }
  2214. if (photolibrary_usage_descriptions.has(lang)) {
  2215. f->store_line("NSPhotoLibraryUsageDescription = \"" + photolibrary_usage_descriptions[lang].operator String() + "\";");
  2216. }
  2217. }
  2218. }
  2219. // Copy project static libs to the project
  2220. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  2221. for (int i = 0; i < export_plugins.size(); i++) {
  2222. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  2223. for (int j = 0; j < project_static_libs.size(); j++) {
  2224. const String &static_lib_path = project_static_libs[j];
  2225. String dest_lib_file_path = dest_dir + static_lib_path.get_file();
  2226. Error lib_copy_err = tmp_app_path->copy(static_lib_path, dest_lib_file_path);
  2227. if (lib_copy_err != OK) {
  2228. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not copy a file at path \"%s\" to \"%s\"."), static_lib_path, dest_lib_file_path));
  2229. return lib_copy_err;
  2230. }
  2231. }
  2232. }
  2233. String iconset_dir = binary_dir + "/Images.xcassets/AppIcon.appiconset/";
  2234. err = OK;
  2235. if (!tmp_app_path->dir_exists(iconset_dir)) {
  2236. err = tmp_app_path->make_dir_recursive(iconset_dir);
  2237. }
  2238. if (err != OK) {
  2239. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create a directory at path \"%s\"."), iconset_dir));
  2240. return err;
  2241. }
  2242. err = _export_icons(p_preset, iconset_dir);
  2243. if (err != OK) {
  2244. // Message is supplied by the subroutine method.
  2245. return err;
  2246. }
  2247. {
  2248. String splash_image_path = binary_dir + "/Images.xcassets/SplashImage.imageset/";
  2249. Ref<DirAccess> launch_screen_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  2250. if (launch_screen_da.is_null()) {
  2251. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Could not access the filesystem."));
  2252. return ERR_CANT_CREATE;
  2253. }
  2254. print_line("Exporting launch screen storyboard");
  2255. err = _export_loading_screen_file(p_preset, splash_image_path);
  2256. if (err != OK) {
  2257. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Failed to create a file at path \"%s\" with code %d."), splash_image_path, err));
  2258. }
  2259. }
  2260. if (err != OK) {
  2261. return err;
  2262. }
  2263. print_line("Exporting additional assets");
  2264. _export_additional_assets(p_preset, binary_dir, libraries, assets);
  2265. _add_assets_to_project(dest_dir, p_preset, project_file_data, assets);
  2266. String project_file_name = binary_dir + ".xcodeproj/project.pbxproj";
  2267. {
  2268. Ref<FileAccess> f = FileAccess::open(project_file_name, FileAccess::WRITE);
  2269. if (f.is_null()) {
  2270. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write to a file at path \"%s\"."), project_file_name));
  2271. return ERR_CANT_CREATE;
  2272. };
  2273. f->store_buffer(project_file_data.ptr(), project_file_data.size());
  2274. }
  2275. #ifdef MACOS_ENABLED
  2276. {
  2277. if (ep.step("Code-signing dylibs", 2)) {
  2278. return ERR_SKIP;
  2279. }
  2280. Ref<DirAccess> dylibs_dir = DirAccess::open(binary_dir + "/dylibs");
  2281. ERR_FAIL_COND_V(dylibs_dir.is_null(), ERR_CANT_OPEN);
  2282. CodesignData codesign_data(p_preset, p_debug);
  2283. err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data);
  2284. if (err != OK) {
  2285. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  2286. return err;
  2287. }
  2288. }
  2289. if (export_project_only) {
  2290. return OK;
  2291. }
  2292. if (ep.step("Making .xcarchive", 3)) {
  2293. return ERR_SKIP;
  2294. }
  2295. String archive_path = p_path.get_basename() + ".xcarchive";
  2296. List<String> archive_args;
  2297. archive_args.push_back("-project");
  2298. archive_args.push_back(binary_dir + ".xcodeproj");
  2299. archive_args.push_back("-scheme");
  2300. archive_args.push_back(binary_name);
  2301. archive_args.push_back("-sdk");
  2302. if (p_simulator) {
  2303. archive_args.push_back("iphonesimulator");
  2304. } else {
  2305. archive_args.push_back("iphoneos");
  2306. }
  2307. archive_args.push_back("-configuration");
  2308. archive_args.push_back(p_debug ? "Debug" : "Release");
  2309. archive_args.push_back("-destination");
  2310. if (p_simulator) {
  2311. archive_args.push_back("generic/platform=iOS Simulator");
  2312. } else {
  2313. archive_args.push_back("generic/platform=iOS");
  2314. }
  2315. archive_args.push_back("archive");
  2316. archive_args.push_back("-allowProvisioningUpdates");
  2317. archive_args.push_back("-archivePath");
  2318. archive_args.push_back(archive_path);
  2319. String archive_str;
  2320. err = OS::get_singleton()->execute("xcodebuild", archive_args, &archive_str, nullptr, true);
  2321. if (err != OK) {
  2322. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), vformat(TTR("Failed to run xcodebuild with code %d"), err));
  2323. return err;
  2324. }
  2325. print_line("xcodebuild (.xcarchive):\n" + archive_str);
  2326. if (!archive_str.contains("** ARCHIVE SUCCEEDED **")) {
  2327. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR("Xcode project build failed, see editor log for details."));
  2328. return FAILED;
  2329. }
  2330. if (!p_oneclick) {
  2331. if (ep.step("Making .ipa", 4)) {
  2332. return ERR_SKIP;
  2333. }
  2334. List<String> export_args;
  2335. export_args.push_back("-exportArchive");
  2336. export_args.push_back("-archivePath");
  2337. export_args.push_back(archive_path);
  2338. export_args.push_back("-exportOptionsPlist");
  2339. export_args.push_back(binary_dir + "/export_options.plist");
  2340. export_args.push_back("-allowProvisioningUpdates");
  2341. export_args.push_back("-exportPath");
  2342. export_args.push_back(dest_dir);
  2343. String export_str;
  2344. err = OS::get_singleton()->execute("xcodebuild", export_args, &export_str, nullptr, true);
  2345. if (err != OK) {
  2346. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), vformat(TTR("Failed to run xcodebuild with code %d"), err));
  2347. return err;
  2348. }
  2349. print_line("xcodebuild (.ipa):\n" + export_str);
  2350. if (!export_str.contains("** EXPORT SUCCEEDED **")) {
  2351. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR(".ipa export failed, see editor log for details."));
  2352. return FAILED;
  2353. }
  2354. }
  2355. #else
  2356. add_message(EXPORT_MESSAGE_WARNING, TTR("Xcode Build"), TTR(".ipa can only be built on macOS. Leaving Xcode project without building the package."));
  2357. #endif
  2358. return OK;
  2359. }
  2360. bool EditorExportPlatformIOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const {
  2361. #if defined(MODULE_MONO_ENABLED) && !defined(MACOS_ENABLED)
  2362. // TODO: Remove this restriction when we don't rely on macOS tools to package up the native libraries anymore.
  2363. r_error += TTR("Exporting to iOS when using C#/.NET is experimental and requires macOS.") + "\n";
  2364. return false;
  2365. #else
  2366. String err;
  2367. bool valid = false;
  2368. #if defined(MODULE_MONO_ENABLED)
  2369. // iOS export is still a work in progress, keep a message as a warning.
  2370. err += TTR("Exporting to iOS when using C#/.NET is experimental.") + "\n";
  2371. #endif
  2372. // Look for export templates (first official, and if defined custom templates).
  2373. bool dvalid = exists_export_template("ios.zip", &err);
  2374. bool rvalid = dvalid; // Both in the same ZIP.
  2375. if (p_preset->get("custom_template/debug") != "") {
  2376. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  2377. if (!dvalid) {
  2378. err += TTR("Custom debug template not found.") + "\n";
  2379. }
  2380. }
  2381. if (p_preset->get("custom_template/release") != "") {
  2382. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  2383. if (!rvalid) {
  2384. err += TTR("Custom release template not found.") + "\n";
  2385. }
  2386. }
  2387. valid = dvalid || rvalid;
  2388. r_missing_templates = !valid;
  2389. const String &additional_plist_content = p_preset->get("application/additional_plist_content");
  2390. if (!additional_plist_content.is_empty()) {
  2391. const String &plist = vformat("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2392. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
  2393. "<plist version=\"1.0\">"
  2394. "<dict>\n"
  2395. "%s\n"
  2396. "</dict>\n"
  2397. "</plist>\n",
  2398. additional_plist_content);
  2399. String plist_err;
  2400. Ref<PList> plist_parser;
  2401. plist_parser.instantiate();
  2402. if (!plist_parser->load_string(plist, plist_err)) {
  2403. err += TTR("Invalid additional PList content: ") + plist_err + "\n";
  2404. valid = false;
  2405. }
  2406. }
  2407. if (GLOBAL_GET("rendering/rendering_device/driver.ios") == "metal") {
  2408. float version = p_preset->get("application/min_ios_version").operator String().to_float();
  2409. if (version < 14.0) {
  2410. err += TTR("Metal renderer require iOS 14+.") + "\n";
  2411. }
  2412. }
  2413. if (!err.is_empty()) {
  2414. r_error = err;
  2415. }
  2416. return valid;
  2417. #endif // !(MODULE_MONO_ENABLED && !MACOS_ENABLED)
  2418. }
  2419. bool EditorExportPlatformIOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  2420. String err;
  2421. bool valid = true;
  2422. // Validate the project configuration.
  2423. List<ExportOption> options;
  2424. get_export_options(&options);
  2425. for (const EditorExportPlatform::ExportOption &E : options) {
  2426. if (get_export_option_visibility(p_preset.ptr(), E.option.name)) {
  2427. String warn = get_export_option_warning(p_preset.ptr(), E.option.name);
  2428. if (!warn.is_empty()) {
  2429. err += warn + "\n";
  2430. if (E.required) {
  2431. valid = false;
  2432. }
  2433. }
  2434. }
  2435. }
  2436. if (!ResourceImporterTextureSettings::should_import_etc2_astc()) {
  2437. valid = false;
  2438. }
  2439. if (!err.is_empty()) {
  2440. r_error = err;
  2441. }
  2442. return valid;
  2443. }
  2444. int EditorExportPlatformIOS::get_options_count() const {
  2445. MutexLock lock(device_lock);
  2446. return devices.size();
  2447. }
  2448. String EditorExportPlatformIOS::get_options_tooltip() const {
  2449. return TTR("Select device from the list");
  2450. }
  2451. Ref<ImageTexture> EditorExportPlatformIOS::get_option_icon(int p_index) const {
  2452. MutexLock lock(device_lock);
  2453. Ref<ImageTexture> icon;
  2454. if (p_index >= 0 || p_index < devices.size()) {
  2455. Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
  2456. if (theme.is_valid()) {
  2457. if (devices[p_index].simulator) {
  2458. icon = theme->get_icon("IOSSimulator", EditorStringName(EditorIcons));
  2459. } else if (devices[p_index].wifi) {
  2460. icon = theme->get_icon("IOSDeviceWireless", EditorStringName(EditorIcons));
  2461. } else {
  2462. icon = theme->get_icon("IOSDeviceWired", EditorStringName(EditorIcons));
  2463. }
  2464. }
  2465. }
  2466. return icon;
  2467. }
  2468. String EditorExportPlatformIOS::get_option_label(int p_index) const {
  2469. ERR_FAIL_INDEX_V(p_index, devices.size(), "");
  2470. MutexLock lock(device_lock);
  2471. return devices[p_index].name;
  2472. }
  2473. String EditorExportPlatformIOS::get_option_tooltip(int p_index) const {
  2474. ERR_FAIL_INDEX_V(p_index, devices.size(), "");
  2475. MutexLock lock(device_lock);
  2476. return "UUID: " + devices[p_index].id;
  2477. }
  2478. bool EditorExportPlatformIOS::is_package_name_valid(const String &p_package, String *r_error) const {
  2479. String pname = p_package;
  2480. if (pname.length() == 0) {
  2481. if (r_error) {
  2482. *r_error = TTR("Identifier is missing.");
  2483. }
  2484. return false;
  2485. }
  2486. for (int i = 0; i < pname.length(); i++) {
  2487. char32_t c = pname[i];
  2488. if (!(is_ascii_alphanumeric_char(c) || c == '-' || c == '.')) {
  2489. if (r_error) {
  2490. *r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
  2491. }
  2492. return false;
  2493. }
  2494. }
  2495. return true;
  2496. }
  2497. #ifdef MACOS_ENABLED
  2498. bool EditorExportPlatformIOS::_check_xcode_install() {
  2499. static bool xcode_found = false;
  2500. if (!xcode_found) {
  2501. Vector<String> mdfind_paths;
  2502. List<String> mdfind_args;
  2503. mdfind_args.push_back("kMDItemCFBundleIdentifier=com.apple.dt.Xcode");
  2504. String output;
  2505. Error err = OS::get_singleton()->execute("mdfind", mdfind_args, &output);
  2506. if (err == OK) {
  2507. mdfind_paths = output.split("\n");
  2508. }
  2509. for (const String &found_path : mdfind_paths) {
  2510. xcode_found = !found_path.is_empty() && DirAccess::dir_exists_absolute(found_path.strip_edges());
  2511. if (xcode_found) {
  2512. break;
  2513. }
  2514. }
  2515. }
  2516. return xcode_found;
  2517. }
  2518. void EditorExportPlatformIOS::_check_for_changes_poll_thread(void *ud) {
  2519. EditorExportPlatformIOS *ea = static_cast<EditorExportPlatformIOS *>(ud);
  2520. while (!ea->quit_request.is_set()) {
  2521. // Nothing to do if we already know the plugins have changed.
  2522. if (!ea->plugins_changed.is_set()) {
  2523. MutexLock lock(ea->plugins_lock);
  2524. Vector<PluginConfigIOS> loaded_plugins = get_plugins();
  2525. if (ea->plugins.size() != loaded_plugins.size()) {
  2526. ea->plugins_changed.set();
  2527. } else {
  2528. for (int i = 0; i < ea->plugins.size(); i++) {
  2529. if (ea->plugins[i].name != loaded_plugins[i].name || ea->plugins[i].last_updated != loaded_plugins[i].last_updated) {
  2530. ea->plugins_changed.set();
  2531. break;
  2532. }
  2533. }
  2534. }
  2535. }
  2536. // Check for devices updates.
  2537. Vector<Device> ldevices;
  2538. // Enum real devices (via ios_deploy, pre Xcode 15).
  2539. String idepl = EDITOR_GET("export/ios/ios_deploy");
  2540. if (ea->has_runnable_preset.is_set() && !idepl.is_empty()) {
  2541. String devices;
  2542. List<String> args;
  2543. args.push_back("-c");
  2544. args.push_back("-timeout");
  2545. args.push_back("1");
  2546. args.push_back("-j");
  2547. args.push_back("-u");
  2548. args.push_back("-I");
  2549. int ec = 0;
  2550. Error err = OS::get_singleton()->execute(idepl, args, &devices, &ec, true);
  2551. if (err == OK && ec == 0) {
  2552. Ref<JSON> json;
  2553. json.instantiate();
  2554. devices = "{ \"devices\":[" + devices.replace("}{", "},{") + "]}";
  2555. err = json->parse(devices);
  2556. if (err == OK) {
  2557. Dictionary data = json->get_data();
  2558. Array devices = data["devices"];
  2559. for (int i = 0; i < devices.size(); i++) {
  2560. Dictionary device_event = devices[i];
  2561. if (device_event["Event"] == "DeviceDetected") {
  2562. Dictionary device_info = device_event["Device"];
  2563. Device nd;
  2564. nd.id = device_info["DeviceIdentifier"];
  2565. nd.name = device_info["DeviceName"].operator String() + " (ios_deploy, " + ((device_event["Interface"] == "WIFI") ? "network" : "wired") + ")";
  2566. nd.wifi = device_event["Interface"] == "WIFI";
  2567. nd.use_ios_deploy = true;
  2568. nd.simulator = false;
  2569. ldevices.push_back(nd);
  2570. }
  2571. }
  2572. }
  2573. }
  2574. }
  2575. // Enum simulators.
  2576. if (ea->has_runnable_preset.is_set() && _check_xcode_install() && (FileAccess::exists("/usr/bin/xcrun") || FileAccess::exists("/bin/xcrun"))) {
  2577. {
  2578. String devices;
  2579. List<String> args;
  2580. args.push_back("devicectl");
  2581. args.push_back("list");
  2582. args.push_back("devices");
  2583. args.push_back("-j");
  2584. args.push_back("-");
  2585. args.push_back("-q");
  2586. int ec = 0;
  2587. Error err = OS::get_singleton()->execute("xcrun", args, &devices, &ec, true);
  2588. if (err == OK && ec == 0) {
  2589. Ref<JSON> json;
  2590. json.instantiate();
  2591. err = json->parse(devices);
  2592. if (err == OK) {
  2593. const Dictionary &data = json->get_data();
  2594. const Dictionary &result = data["result"];
  2595. const Array &devices = result["devices"];
  2596. for (int i = 0; i < devices.size(); i++) {
  2597. const Dictionary &device_info = devices[i];
  2598. const Dictionary &conn_props = device_info["connectionProperties"];
  2599. const Dictionary &dev_props = device_info["deviceProperties"];
  2600. if (conn_props["pairingState"] == "paired" && dev_props["developerModeStatus"] == "enabled") {
  2601. Device nd;
  2602. nd.id = device_info["identifier"];
  2603. nd.name = dev_props["name"].operator String() + " (devicectl, " + ((conn_props["transportType"] == "localNetwork") ? "network" : "wired") + ")";
  2604. nd.wifi = conn_props["transportType"] == "localNetwork";
  2605. nd.simulator = false;
  2606. ldevices.push_back(nd);
  2607. }
  2608. }
  2609. }
  2610. }
  2611. }
  2612. // Enum simulators.
  2613. if (ea->has_runnable_preset.is_set()) {
  2614. String devices;
  2615. List<String> args;
  2616. args.push_back("simctl");
  2617. args.push_back("list");
  2618. args.push_back("devices");
  2619. args.push_back("-j");
  2620. int ec = 0;
  2621. Error err = OS::get_singleton()->execute("xcrun", args, &devices, &ec, true);
  2622. if (err == OK && ec == 0) {
  2623. Ref<JSON> json;
  2624. json.instantiate();
  2625. err = json->parse(devices);
  2626. if (err == OK) {
  2627. const Dictionary &data = json->get_data();
  2628. const Dictionary &devices = data["devices"];
  2629. for (const Variant *key = devices.next(nullptr); key; key = devices.next(key)) {
  2630. const Array &os_devices = devices[*key];
  2631. for (int i = 0; i < os_devices.size(); i++) {
  2632. const Dictionary &device_info = os_devices[i];
  2633. if (device_info["isAvailable"].operator bool() && device_info["state"] == "Booted") {
  2634. Device nd;
  2635. nd.id = device_info["udid"];
  2636. nd.name = device_info["name"].operator String() + " (simulator)";
  2637. nd.simulator = true;
  2638. ldevices.push_back(nd);
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. }
  2645. }
  2646. // Update device list.
  2647. {
  2648. MutexLock lock(ea->device_lock);
  2649. bool different = false;
  2650. if (ea->devices.size() != ldevices.size()) {
  2651. different = true;
  2652. } else {
  2653. for (int i = 0; i < ea->devices.size(); i++) {
  2654. if (ea->devices[i].id != ldevices[i].id) {
  2655. different = true;
  2656. break;
  2657. }
  2658. }
  2659. }
  2660. if (different) {
  2661. ea->devices = ldevices;
  2662. ea->devices_changed.set();
  2663. }
  2664. }
  2665. uint64_t sleep = 200;
  2666. uint64_t wait = 3000000;
  2667. uint64_t time = OS::get_singleton()->get_ticks_usec();
  2668. while (OS::get_singleton()->get_ticks_usec() - time < wait) {
  2669. OS::get_singleton()->delay_usec(1000 * sleep);
  2670. if (ea->quit_request.is_set()) {
  2671. break;
  2672. }
  2673. }
  2674. }
  2675. }
  2676. void EditorExportPlatformIOS::_update_preset_status() {
  2677. const int preset_count = EditorExport::get_singleton()->get_export_preset_count();
  2678. bool has_runnable = false;
  2679. for (int i = 0; i < preset_count; i++) {
  2680. const Ref<EditorExportPreset> &preset = EditorExport::get_singleton()->get_export_preset(i);
  2681. if (preset->get_platform() == this && preset->is_runnable()) {
  2682. has_runnable = true;
  2683. break;
  2684. }
  2685. }
  2686. if (has_runnable) {
  2687. has_runnable_preset.set();
  2688. } else {
  2689. has_runnable_preset.clear();
  2690. }
  2691. devices_changed.set();
  2692. }
  2693. #endif
  2694. Error EditorExportPlatformIOS::run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) {
  2695. #ifdef MACOS_ENABLED
  2696. ERR_FAIL_INDEX_V(p_device, devices.size(), ERR_INVALID_PARAMETER);
  2697. String can_export_error;
  2698. bool can_export_missing_templates;
  2699. if (!can_export(p_preset, can_export_error, can_export_missing_templates)) {
  2700. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), can_export_error);
  2701. return ERR_UNCONFIGURED;
  2702. }
  2703. MutexLock lock(device_lock);
  2704. EditorProgress ep("run", vformat(TTR("Running on %s"), devices[p_device].name), 3);
  2705. String id = "tmpexport." + uitos(OS::get_singleton()->get_unix_time());
  2706. Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  2707. ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + EditorPaths::get_singleton()->get_cache_dir() + "'.");
  2708. filesystem_da->make_dir_recursive(EditorPaths::get_singleton()->get_cache_dir().path_join(id));
  2709. String tmp_export_path = EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.ipa");
  2710. #define CLEANUP_AND_RETURN(m_err) \
  2711. { \
  2712. if (filesystem_da->change_dir(EditorPaths::get_singleton()->get_cache_dir().path_join(id)) == OK) { \
  2713. filesystem_da->erase_contents_recursive(); \
  2714. filesystem_da->change_dir(".."); \
  2715. filesystem_da->remove(id); \
  2716. } \
  2717. return m_err; \
  2718. } \
  2719. ((void)0)
  2720. Device dev = devices[p_device];
  2721. // Export before sending to device.
  2722. Error err = _export_project_helper(p_preset, true, tmp_export_path, p_debug_flags, dev.simulator, true);
  2723. if (err != OK) {
  2724. CLEANUP_AND_RETURN(err);
  2725. }
  2726. Vector<String> cmd_args_list;
  2727. String host = EDITOR_GET("network/debug/remote_host");
  2728. int remote_port = (int)EDITOR_GET("network/debug/remote_port");
  2729. if (p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST)) {
  2730. host = "localhost";
  2731. }
  2732. if (p_debug_flags.has_flag(DEBUG_FLAG_DUMB_CLIENT)) {
  2733. int port = EDITOR_GET("filesystem/file_server/port");
  2734. String passwd = EDITOR_GET("filesystem/file_server/password");
  2735. cmd_args_list.push_back("--remote-fs");
  2736. cmd_args_list.push_back(host + ":" + itos(port));
  2737. if (!passwd.is_empty()) {
  2738. cmd_args_list.push_back("--remote-fs-password");
  2739. cmd_args_list.push_back(passwd);
  2740. }
  2741. }
  2742. if (p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG)) {
  2743. cmd_args_list.push_back("--remote-debug");
  2744. cmd_args_list.push_back(get_debug_protocol() + host + ":" + String::num(remote_port));
  2745. List<String> breakpoints;
  2746. ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
  2747. if (breakpoints.size()) {
  2748. cmd_args_list.push_back("--breakpoints");
  2749. String bpoints;
  2750. for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
  2751. bpoints += E->get().replace(" ", "%20");
  2752. if (E->next()) {
  2753. bpoints += ",";
  2754. }
  2755. }
  2756. cmd_args_list.push_back(bpoints);
  2757. }
  2758. }
  2759. if (p_debug_flags.has_flag(DEBUG_FLAG_VIEW_COLLISIONS)) {
  2760. cmd_args_list.push_back("--debug-collisions");
  2761. }
  2762. if (p_debug_flags.has_flag(DEBUG_FLAG_VIEW_NAVIGATION)) {
  2763. cmd_args_list.push_back("--debug-navigation");
  2764. }
  2765. if (dev.simulator) {
  2766. // Deploy and run on simulator.
  2767. if (ep.step("Installing to simulator...", 3)) {
  2768. CLEANUP_AND_RETURN(ERR_SKIP);
  2769. } else {
  2770. List<String> args;
  2771. args.push_back("simctl");
  2772. args.push_back("install");
  2773. args.push_back(dev.id);
  2774. args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
  2775. String log;
  2776. int ec;
  2777. err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true);
  2778. if (err != OK) {
  2779. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start simctl executable."));
  2780. CLEANUP_AND_RETURN(err);
  2781. }
  2782. if (ec != 0) {
  2783. print_line("simctl install:\n" + log);
  2784. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation failed, see editor log for details."));
  2785. CLEANUP_AND_RETURN(ERR_UNCONFIGURED);
  2786. }
  2787. }
  2788. if (ep.step("Running on simulator...", 4)) {
  2789. CLEANUP_AND_RETURN(ERR_SKIP);
  2790. } else {
  2791. List<String> args;
  2792. args.push_back("simctl");
  2793. args.push_back("launch");
  2794. args.push_back("--terminate-running-process");
  2795. args.push_back(dev.id);
  2796. args.push_back(p_preset->get("application/bundle_identifier"));
  2797. for (const String &E : cmd_args_list) {
  2798. args.push_back(E);
  2799. }
  2800. String log;
  2801. int ec;
  2802. err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true);
  2803. if (err != OK) {
  2804. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start simctl executable."));
  2805. CLEANUP_AND_RETURN(err);
  2806. }
  2807. if (ec != 0) {
  2808. print_line("simctl launch:\n" + log);
  2809. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Running failed, see editor log for details."));
  2810. }
  2811. }
  2812. } else if (dev.use_ios_deploy) {
  2813. // Deploy and run on real device (via ios-deploy).
  2814. if (ep.step("Installing and running on device...", 4)) {
  2815. CLEANUP_AND_RETURN(ERR_SKIP);
  2816. } else {
  2817. List<String> args;
  2818. args.push_back("-u");
  2819. args.push_back("-I");
  2820. args.push_back("--id");
  2821. args.push_back(dev.id);
  2822. args.push_back("--justlaunch");
  2823. args.push_back("--bundle");
  2824. args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
  2825. String app_args;
  2826. for (const String &E : cmd_args_list) {
  2827. app_args += E + " ";
  2828. }
  2829. if (!app_args.is_empty()) {
  2830. args.push_back("--args");
  2831. args.push_back(app_args);
  2832. }
  2833. String idepl = EDITOR_GET("export/ios/ios_deploy");
  2834. if (idepl.is_empty()) {
  2835. idepl = "ios-deploy";
  2836. }
  2837. String log;
  2838. int ec;
  2839. err = OS::get_singleton()->execute(idepl, args, &log, &ec, true);
  2840. if (err != OK) {
  2841. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start ios-deploy executable."));
  2842. CLEANUP_AND_RETURN(err);
  2843. }
  2844. if (ec != 0) {
  2845. print_line("ios-deploy:\n" + log);
  2846. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation/running failed, see editor log for details."));
  2847. CLEANUP_AND_RETURN(ERR_UNCONFIGURED);
  2848. }
  2849. }
  2850. } else {
  2851. // Deploy and run on real device.
  2852. if (ep.step("Installing to device...", 3)) {
  2853. CLEANUP_AND_RETURN(ERR_SKIP);
  2854. } else {
  2855. List<String> args;
  2856. args.push_back("devicectl");
  2857. args.push_back("device");
  2858. args.push_back("install");
  2859. args.push_back("app");
  2860. args.push_back("-d");
  2861. args.push_back(dev.id);
  2862. args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
  2863. String log;
  2864. int ec;
  2865. err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true);
  2866. if (err != OK) {
  2867. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start device executable."));
  2868. CLEANUP_AND_RETURN(err);
  2869. }
  2870. if (ec != 0) {
  2871. print_line("device install:\n" + log);
  2872. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation failed, see editor log for details."));
  2873. CLEANUP_AND_RETURN(ERR_UNCONFIGURED);
  2874. }
  2875. }
  2876. if (ep.step("Running on device...", 4)) {
  2877. CLEANUP_AND_RETURN(ERR_SKIP);
  2878. } else {
  2879. List<String> args;
  2880. args.push_back("devicectl");
  2881. args.push_back("device");
  2882. args.push_back("process");
  2883. args.push_back("launch");
  2884. args.push_back("--terminate-existing");
  2885. args.push_back("-d");
  2886. args.push_back(dev.id);
  2887. args.push_back(p_preset->get("application/bundle_identifier"));
  2888. for (const String &E : cmd_args_list) {
  2889. args.push_back(E);
  2890. }
  2891. String log;
  2892. int ec;
  2893. err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true);
  2894. if (err != OK) {
  2895. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start devicectl executable."));
  2896. CLEANUP_AND_RETURN(err);
  2897. }
  2898. if (ec != 0) {
  2899. print_line("devicectl launch:\n" + log);
  2900. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Running failed, see editor log for details."));
  2901. }
  2902. }
  2903. }
  2904. CLEANUP_AND_RETURN(OK);
  2905. #undef CLEANUP_AND_RETURN
  2906. #else
  2907. return ERR_UNCONFIGURED;
  2908. #endif
  2909. }
  2910. EditorExportPlatformIOS::EditorExportPlatformIOS() {
  2911. if (EditorNode::get_singleton()) {
  2912. #ifdef MODULE_SVG_ENABLED
  2913. Ref<Image> img = memnew(Image);
  2914. const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
  2915. ImageLoaderSVG::create_image_from_string(img, _ios_logo_svg, EDSCALE, upsample, false);
  2916. logo = ImageTexture::create_from_image(img);
  2917. ImageLoaderSVG::create_image_from_string(img, _ios_run_icon_svg, EDSCALE, upsample, false);
  2918. run_icon = ImageTexture::create_from_image(img);
  2919. #endif
  2920. plugins_changed.set();
  2921. devices_changed.set();
  2922. #ifdef MACOS_ENABLED
  2923. _update_preset_status();
  2924. check_for_changes_thread.start(_check_for_changes_poll_thread, this);
  2925. #endif
  2926. }
  2927. }
  2928. EditorExportPlatformIOS::~EditorExportPlatformIOS() {
  2929. #ifdef MACOS_ENABLED
  2930. quit_request.set();
  2931. if (check_for_changes_thread.is_started()) {
  2932. check_for_changes_thread.wait_to_finish();
  2933. }
  2934. #endif
  2935. }