export_plugin.cpp 93 KB

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