export_plugin.cpp 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916
  1. /*************************************************************************/
  2. /* export_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 "core/string/translation.h"
  32. #include "editor/editor_node.h"
  33. void EditorExportPlatformIOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
  34. String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name");
  35. // Vulkan and OpenGL ES 3.0 both mandate ETC2 support.
  36. r_features->push_back("etc2");
  37. Vector<String> architectures = _get_preset_architectures(p_preset);
  38. for (int i = 0; i < architectures.size(); ++i) {
  39. r_features->push_back(architectures[i]);
  40. }
  41. }
  42. Vector<EditorExportPlatformIOS::ExportArchitecture> EditorExportPlatformIOS::_get_supported_architectures() const {
  43. Vector<ExportArchitecture> archs;
  44. archs.push_back(ExportArchitecture("arm64", true));
  45. return archs;
  46. }
  47. struct LoadingScreenInfo {
  48. const char *preset_key;
  49. const char *export_name;
  50. int width = 0;
  51. int height = 0;
  52. bool rotate = false;
  53. };
  54. static const LoadingScreenInfo loading_screen_infos[] = {
  55. { PNAME("landscape_launch_screens/iphone_2436x1125"), "Default-Landscape-X.png", 2436, 1125, false },
  56. { PNAME("landscape_launch_screens/iphone_2208x1242"), "[email protected]", 2208, 1242, false },
  57. { PNAME("landscape_launch_screens/ipad_1024x768"), "Default-Landscape.png", 1024, 768, false },
  58. { PNAME("landscape_launch_screens/ipad_2048x1536"), "[email protected]", 2048, 1536, false },
  59. { PNAME("portrait_launch_screens/iphone_640x960"), "[email protected]", 640, 960, true },
  60. { PNAME("portrait_launch_screens/iphone_640x1136"), "[email protected]", 640, 1136, true },
  61. { PNAME("portrait_launch_screens/iphone_750x1334"), "[email protected]", 750, 1334, true },
  62. { PNAME("portrait_launch_screens/iphone_1125x2436"), "Default-Portrait-X.png", 1125, 2436, true },
  63. { PNAME("portrait_launch_screens/ipad_768x1024"), "Default-Portrait.png", 768, 1024, true },
  64. { PNAME("portrait_launch_screens/ipad_1536x2048"), "[email protected]", 1536, 2048, true },
  65. { PNAME("portrait_launch_screens/iphone_1242x2208"), "[email protected]", 1242, 2208, true }
  66. };
  67. void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options) {
  68. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  69. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  70. Vector<ExportArchitecture> architectures = _get_supported_architectures();
  71. for (int i = 0; i < architectures.size(); ++i) {
  72. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("architectures"), architectures[i].name)), architectures[i].is_default));
  73. }
  74. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_store_team_id"), ""));
  75. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_debug"), ""));
  76. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_debug", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Developer"), ""));
  77. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_debug", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 1));
  78. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_release"), ""));
  79. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_release", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Distribution"), ""));
  80. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_release", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 0));
  81. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/targeted_device_family", PROPERTY_HINT_ENUM, "iPhone,iPad,iPhone & iPad"), 2));
  82. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), ""));
  83. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  84. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
  85. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
  86. Vector<PluginConfigIOS> found_plugins = get_plugins();
  87. for (int i = 0; i < found_plugins.size(); i++) {
  88. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("plugins"), found_plugins[i].name)), false));
  89. }
  90. HashSet<String> plist_keys;
  91. for (int i = 0; i < found_plugins.size(); i++) {
  92. // Editable plugin plist values
  93. PluginConfigIOS plugin = found_plugins[i];
  94. for (const KeyValue<String, PluginConfigIOS::PlistItem> &E : plugin.plist) {
  95. switch (E.value.type) {
  96. case PluginConfigIOS::PlistItemType::STRING_INPUT: {
  97. String preset_name = "plugins_plist/" + E.key;
  98. if (!plist_keys.has(preset_name)) {
  99. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, preset_name), E.value.value));
  100. plist_keys.insert(preset_name);
  101. }
  102. } break;
  103. default:
  104. continue;
  105. }
  106. }
  107. }
  108. plugins_changed.clear();
  109. plugins = found_plugins;
  110. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/access_wifi"), false));
  111. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/push_notifications"), false));
  112. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_files_app"), false));
  113. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_itunes_sharing"), false));
  114. 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"), ""));
  115. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  116. 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"), ""));
  117. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  118. 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"), ""));
  119. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photolibrary_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  120. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/iphone_120x120", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), "")); // Home screen on iPhone/iPod Touch with Retina display
  121. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/iphone_180x180", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), "")); // Home screen on iPhone with Retina HD display
  122. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/ipad_76x76", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), "")); // Home screen on iPad
  123. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/ipad_152x152", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), "")); // Home screen on iPad with Retina display
  124. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/ipad_167x167", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), "")); // Home screen on iPad Pro
  125. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/app_store_1024x1024", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), "")); // App Store
  126. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/spotlight_40x40", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), "")); // Spotlight
  127. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/spotlight_80x80", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), "")); // Spotlight on devices with Retina display
  128. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "storyboard/use_launch_screen_storyboard"), false));
  129. 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));
  130. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@2x", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  131. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@3x", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  132. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "storyboard/use_custom_bg_color"), false));
  133. r_options->push_back(ExportOption(PropertyInfo(Variant::COLOR, "storyboard/custom_bg_color"), Color()));
  134. for (uint64_t i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  135. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, loading_screen_infos[i].preset_key, PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  136. }
  137. }
  138. void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const IOSConfigData &p_config, bool p_debug) {
  139. static const String export_method_string[] = {
  140. "app-store",
  141. "development",
  142. "ad-hoc",
  143. "enterprise"
  144. };
  145. static const String storyboard_image_scale_mode[] = {
  146. "center",
  147. "scaleAspectFit",
  148. "scaleAspectFill",
  149. "scaleToFill"
  150. };
  151. 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");
  152. 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");
  153. bool dbg_manual = !p_preset->get("application/provisioning_profile_uuid_debug").operator String().is_empty() || (dbg_sign_id != "iPhone Developer");
  154. bool rel_manual = !p_preset->get("application/provisioning_profile_uuid_release").operator String().is_empty() || (rel_sign_id != "iPhone Distribution");
  155. String str;
  156. String strnew;
  157. str.parse_utf8((const char *)pfile.ptr(), pfile.size());
  158. Vector<String> lines = str.split("\n");
  159. for (int i = 0; i < lines.size(); i++) {
  160. if (lines[i].find("$binary") != -1) {
  161. strnew += lines[i].replace("$binary", p_config.binary_name) + "\n";
  162. } else if (lines[i].find("$modules_buildfile") != -1) {
  163. strnew += lines[i].replace("$modules_buildfile", p_config.modules_buildfile) + "\n";
  164. } else if (lines[i].find("$modules_fileref") != -1) {
  165. strnew += lines[i].replace("$modules_fileref", p_config.modules_fileref) + "\n";
  166. } else if (lines[i].find("$modules_buildphase") != -1) {
  167. strnew += lines[i].replace("$modules_buildphase", p_config.modules_buildphase) + "\n";
  168. } else if (lines[i].find("$modules_buildgrp") != -1) {
  169. strnew += lines[i].replace("$modules_buildgrp", p_config.modules_buildgrp) + "\n";
  170. } else if (lines[i].find("$name") != -1) {
  171. strnew += lines[i].replace("$name", p_config.pkg_name) + "\n";
  172. } else if (lines[i].find("$bundle_identifier") != -1) {
  173. strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
  174. } else if (lines[i].find("$short_version") != -1) {
  175. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  176. } else if (lines[i].find("$version") != -1) {
  177. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  178. } else if (lines[i].find("$signature") != -1) {
  179. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  180. } else if (lines[i].find("$team_id") != -1) {
  181. strnew += lines[i].replace("$team_id", p_preset->get("application/app_store_team_id")) + "\n";
  182. } else if (lines[i].find("$default_build_config") != -1) {
  183. strnew += lines[i].replace("$default_build_config", p_debug ? "Debug" : "Release") + "\n";
  184. } else if (lines[i].find("$export_method") != -1) {
  185. int export_method = p_preset->get(p_debug ? "application/export_method_debug" : "application/export_method_release");
  186. strnew += lines[i].replace("$export_method", export_method_string[export_method]) + "\n";
  187. } else if (lines[i].find("$provisioning_profile_uuid_release") != -1) {
  188. strnew += lines[i].replace("$provisioning_profile_uuid_release", p_preset->get("application/provisioning_profile_uuid_release")) + "\n";
  189. } else if (lines[i].find("$provisioning_profile_uuid_debug") != -1) {
  190. strnew += lines[i].replace("$provisioning_profile_uuid_debug", p_preset->get("application/provisioning_profile_uuid_debug")) + "\n";
  191. } else if (lines[i].find("$code_sign_style_debug") != -1) {
  192. if (dbg_manual) {
  193. strnew += lines[i].replace("$code_sign_style_debug", "Manual") + "\n";
  194. } else {
  195. strnew += lines[i].replace("$code_sign_style_debug", "Automatic") + "\n";
  196. }
  197. } else if (lines[i].find("$code_sign_style_release") != -1) {
  198. if (rel_manual) {
  199. strnew += lines[i].replace("$code_sign_style_release", "Manual") + "\n";
  200. } else {
  201. strnew += lines[i].replace("$code_sign_style_release", "Automatic") + "\n";
  202. }
  203. } else if (lines[i].find("$provisioning_profile_uuid") != -1) {
  204. String uuid = p_debug ? p_preset->get("application/provisioning_profile_uuid_debug") : p_preset->get("application/provisioning_profile_uuid_release");
  205. strnew += lines[i].replace("$provisioning_profile_uuid", uuid) + "\n";
  206. } else if (lines[i].find("$code_sign_identity_debug") != -1) {
  207. strnew += lines[i].replace("$code_sign_identity_debug", dbg_sign_id) + "\n";
  208. } else if (lines[i].find("$code_sign_identity_release") != -1) {
  209. strnew += lines[i].replace("$code_sign_identity_release", rel_sign_id) + "\n";
  210. } else if (lines[i].find("$additional_plist_content") != -1) {
  211. strnew += lines[i].replace("$additional_plist_content", p_config.plist_content) + "\n";
  212. } else if (lines[i].find("$godot_archs") != -1) {
  213. strnew += lines[i].replace("$godot_archs", p_config.architectures) + "\n";
  214. } else if (lines[i].find("$linker_flags") != -1) {
  215. strnew += lines[i].replace("$linker_flags", p_config.linker_flags) + "\n";
  216. } else if (lines[i].find("$targeted_device_family") != -1) {
  217. String xcode_value;
  218. switch ((int)p_preset->get("application/targeted_device_family")) {
  219. case 0: // iPhone
  220. xcode_value = "1";
  221. break;
  222. case 1: // iPad
  223. xcode_value = "2";
  224. break;
  225. case 2: // iPhone & iPad
  226. xcode_value = "1,2";
  227. break;
  228. }
  229. strnew += lines[i].replace("$targeted_device_family", xcode_value) + "\n";
  230. } else if (lines[i].find("$cpp_code") != -1) {
  231. strnew += lines[i].replace("$cpp_code", p_config.cpp_code) + "\n";
  232. } else if (lines[i].find("$docs_in_place") != -1) {
  233. strnew += lines[i].replace("$docs_in_place", ((bool)p_preset->get("user_data/accessible_from_files_app")) ? "<true/>" : "<false/>") + "\n";
  234. } else if (lines[i].find("$docs_sharing") != -1) {
  235. strnew += lines[i].replace("$docs_sharing", ((bool)p_preset->get("user_data/accessible_from_itunes_sharing")) ? "<true/>" : "<false/>") + "\n";
  236. } else if (lines[i].find("$entitlements_push_notifications") != -1) {
  237. bool is_on = p_preset->get("capabilities/push_notifications");
  238. strnew += lines[i].replace("$entitlements_push_notifications", is_on ? "<key>aps-environment</key><string>development</string>" : "") + "\n";
  239. } else if (lines[i].find("$required_device_capabilities") != -1) {
  240. String capabilities;
  241. // I've removed armv7 as we can run on 64bit only devices
  242. // Note that capabilities listed here are requirements for the app to be installed.
  243. // They don't enable anything.
  244. Vector<String> capabilities_list = p_config.capabilities;
  245. if ((bool)p_preset->get("capabilities/access_wifi") && !capabilities_list.has("wifi")) {
  246. capabilities_list.push_back("wifi");
  247. }
  248. for (int idx = 0; idx < capabilities_list.size(); idx++) {
  249. capabilities += "<string>" + capabilities_list[idx] + "</string>\n";
  250. }
  251. strnew += lines[i].replace("$required_device_capabilities", capabilities);
  252. } else if (lines[i].find("$interface_orientations") != -1) {
  253. String orientations;
  254. const DisplayServer::ScreenOrientation screen_orientation =
  255. DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation")));
  256. switch (screen_orientation) {
  257. case DisplayServer::SCREEN_LANDSCAPE:
  258. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  259. break;
  260. case DisplayServer::SCREEN_PORTRAIT:
  261. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  262. break;
  263. case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
  264. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  265. break;
  266. case DisplayServer::SCREEN_REVERSE_PORTRAIT:
  267. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  268. break;
  269. case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
  270. // Allow both landscape orientations depending on sensor direction.
  271. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  272. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  273. break;
  274. case DisplayServer::SCREEN_SENSOR_PORTRAIT:
  275. // Allow both portrait orientations depending on sensor direction.
  276. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  277. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  278. break;
  279. case DisplayServer::SCREEN_SENSOR:
  280. // Allow all screen orientations depending on sensor direction.
  281. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  282. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  283. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  284. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  285. break;
  286. }
  287. strnew += lines[i].replace("$interface_orientations", orientations);
  288. } else if (lines[i].find("$camera_usage_description") != -1) {
  289. String description = p_preset->get("privacy/camera_usage_description");
  290. strnew += lines[i].replace("$camera_usage_description", description) + "\n";
  291. } else if (lines[i].find("$microphone_usage_description") != -1) {
  292. String description = p_preset->get("privacy/microphone_usage_description");
  293. strnew += lines[i].replace("$microphone_usage_description", description) + "\n";
  294. } else if (lines[i].find("$photolibrary_usage_description") != -1) {
  295. String description = p_preset->get("privacy/photolibrary_usage_description");
  296. strnew += lines[i].replace("$photolibrary_usage_description", description) + "\n";
  297. } else if (lines[i].find("$plist_launch_screen_name") != -1) {
  298. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  299. String value = is_on ? "<key>UILaunchStoryboardName</key>\n<string>Launch Screen</string>" : "";
  300. strnew += lines[i].replace("$plist_launch_screen_name", value) + "\n";
  301. } else if (lines[i].find("$pbx_launch_screen_file_reference") != -1) {
  302. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  303. String value = is_on ? "90DD2D9D24B36E8000717FE1 = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = \"Launch Screen.storyboard\"; sourceTree = \"<group>\"; };" : "";
  304. strnew += lines[i].replace("$pbx_launch_screen_file_reference", value) + "\n";
  305. } else if (lines[i].find("$pbx_launch_screen_copy_files") != -1) {
  306. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  307. String value = is_on ? "90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */," : "";
  308. strnew += lines[i].replace("$pbx_launch_screen_copy_files", value) + "\n";
  309. } else if (lines[i].find("$pbx_launch_screen_build_phase") != -1) {
  310. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  311. String value = is_on ? "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */," : "";
  312. strnew += lines[i].replace("$pbx_launch_screen_build_phase", value) + "\n";
  313. } else if (lines[i].find("$pbx_launch_screen_build_reference") != -1) {
  314. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  315. String value = is_on ? "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */; };" : "";
  316. strnew += lines[i].replace("$pbx_launch_screen_build_reference", value) + "\n";
  317. } else if (lines[i].find("$pbx_launch_image_usage_setting") != -1) {
  318. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  319. String value = is_on ? "" : "ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;";
  320. strnew += lines[i].replace("$pbx_launch_image_usage_setting", value) + "\n";
  321. } else if (lines[i].find("$launch_screen_image_mode") != -1) {
  322. int image_scale_mode = p_preset->get("storyboard/image_scale_mode");
  323. String value;
  324. switch (image_scale_mode) {
  325. case 0: {
  326. String logo_path = ProjectSettings::get_singleton()->get("application/boot_splash/image");
  327. bool is_on = ProjectSettings::get_singleton()->get("application/boot_splash/fullsize");
  328. // If custom logo is not specified, Godot does not scale default one, so we should do the same.
  329. value = (is_on && logo_path.length() > 0) ? "scaleAspectFit" : "center";
  330. } break;
  331. default: {
  332. value = storyboard_image_scale_mode[image_scale_mode - 1];
  333. }
  334. }
  335. strnew += lines[i].replace("$launch_screen_image_mode", value) + "\n";
  336. } else if (lines[i].find("$launch_screen_background_color") != -1) {
  337. bool use_custom = p_preset->get("storyboard/use_custom_bg_color");
  338. Color color = use_custom ? p_preset->get("storyboard/custom_bg_color") : ProjectSettings::get_singleton()->get("application/boot_splash/bg_color");
  339. const String value_format = "red=\"$red\" green=\"$green\" blue=\"$blue\" alpha=\"$alpha\"";
  340. Dictionary value_dictionary;
  341. value_dictionary["red"] = color.r;
  342. value_dictionary["green"] = color.g;
  343. value_dictionary["blue"] = color.b;
  344. value_dictionary["alpha"] = color.a;
  345. String value = value_format.format(value_dictionary, "$_");
  346. strnew += lines[i].replace("$launch_screen_background_color", value) + "\n";
  347. } else if (lines[i].find("$pbx_locale_file_reference") != -1) {
  348. String locale_files;
  349. Vector<String> translations = ProjectSettings::get_singleton()->get("internationalization/locale/translations");
  350. if (translations.size() > 0) {
  351. HashSet<String> languages;
  352. for (const String &E : translations) {
  353. Ref<Translation> tr = ResourceLoader::load(E);
  354. if (tr.is_valid() && tr->get_locale() != "en") {
  355. languages.insert(tr->get_locale());
  356. }
  357. }
  358. int index = 0;
  359. for (const String &lang : languages) {
  360. 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";
  361. index++;
  362. }
  363. }
  364. strnew += lines[i].replace("$pbx_locale_file_reference", locale_files);
  365. } else if (lines[i].find("$pbx_locale_build_reference") != -1) {
  366. String locale_files;
  367. Vector<String> translations = ProjectSettings::get_singleton()->get("internationalization/locale/translations");
  368. if (translations.size() > 0) {
  369. HashSet<String> languages;
  370. for (const String &E : translations) {
  371. Ref<Translation> tr = ResourceLoader::load(E);
  372. if (tr.is_valid() && tr->get_locale() != "en") {
  373. languages.insert(tr->get_locale());
  374. }
  375. }
  376. int index = 0;
  377. for (const String &lang : languages) {
  378. locale_files += "D0BCFE4518AEBDA2004A" + itos(index).pad_zeros(4) + " /* " + lang + " */,\n";
  379. index++;
  380. }
  381. }
  382. strnew += lines[i].replace("$pbx_locale_build_reference", locale_files);
  383. } else if (lines[i].find("$swift_runtime_migration") != -1) {
  384. String value = !p_config.use_swift_runtime ? "" : "LastSwiftMigration = 1250;";
  385. strnew += lines[i].replace("$swift_runtime_migration", value) + "\n";
  386. } else if (lines[i].find("$swift_runtime_build_settings") != -1) {
  387. String value = !p_config.use_swift_runtime ? "" : R"(
  388. CLANG_ENABLE_MODULES = YES;
  389. SWIFT_OBJC_BRIDGING_HEADER = "$binary/dummy.h";
  390. SWIFT_VERSION = 5.0;
  391. )";
  392. value = value.replace("$binary", p_config.binary_name);
  393. strnew += lines[i].replace("$swift_runtime_build_settings", value) + "\n";
  394. } else if (lines[i].find("$swift_runtime_fileref") != -1) {
  395. String value = !p_config.use_swift_runtime ? "" : R"(
  396. 90B4C2AA2680BC560039117A /* dummy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "dummy.h"; sourceTree = "<group>"; };
  397. 90B4C2B52680C7E90039117A /* dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "dummy.swift"; sourceTree = "<group>"; };
  398. )";
  399. strnew += lines[i].replace("$swift_runtime_fileref", value) + "\n";
  400. } else if (lines[i].find("$swift_runtime_binary_files") != -1) {
  401. String value = !p_config.use_swift_runtime ? "" : R"(
  402. 90B4C2AA2680BC560039117A /* dummy.h */,
  403. 90B4C2B52680C7E90039117A /* dummy.swift */,
  404. )";
  405. strnew += lines[i].replace("$swift_runtime_binary_files", value) + "\n";
  406. } else if (lines[i].find("$swift_runtime_buildfile") != -1) {
  407. String value = !p_config.use_swift_runtime ? "" : "90B4C2B62680C7E90039117A /* dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B4C2B52680C7E90039117A /* dummy.swift */; };";
  408. strnew += lines[i].replace("$swift_runtime_buildfile", value) + "\n";
  409. } else if (lines[i].find("$swift_runtime_build_phase") != -1) {
  410. String value = !p_config.use_swift_runtime ? "" : "90B4C2B62680C7E90039117A /* dummy.swift */,";
  411. strnew += lines[i].replace("$swift_runtime_build_phase", value) + "\n";
  412. } else {
  413. strnew += lines[i] + "\n";
  414. }
  415. }
  416. // !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...
  417. // should apply the same fix in our macOS export.
  418. CharString cs = strnew.utf8();
  419. pfile.resize(cs.size() - 1);
  420. for (int i = 0; i < cs.size() - 1; i++) {
  421. pfile.write[i] = cs[i];
  422. }
  423. }
  424. String EditorExportPlatformIOS::_get_additional_plist_content() {
  425. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  426. String result;
  427. for (int i = 0; i < export_plugins.size(); ++i) {
  428. result += export_plugins[i]->get_ios_plist_content();
  429. }
  430. return result;
  431. }
  432. String EditorExportPlatformIOS::_get_linker_flags() {
  433. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  434. String result;
  435. for (int i = 0; i < export_plugins.size(); ++i) {
  436. String flags = export_plugins[i]->get_ios_linker_flags();
  437. if (flags.length() == 0) {
  438. continue;
  439. }
  440. if (result.length() > 0) {
  441. result += ' ';
  442. }
  443. result += flags;
  444. }
  445. // the flags will be enclosed in quotes, so need to escape them
  446. return result.replace("\"", "\\\"");
  447. }
  448. String EditorExportPlatformIOS::_get_cpp_code() {
  449. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  450. String result;
  451. for (int i = 0; i < export_plugins.size(); ++i) {
  452. result += export_plugins[i]->get_ios_cpp_code();
  453. }
  454. return result;
  455. }
  456. void EditorExportPlatformIOS::_blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot) {
  457. ERR_FAIL_COND(p_dst.is_null());
  458. ERR_FAIL_COND(p_src.is_null());
  459. int sw = p_rot ? p_src->get_height() : p_src->get_width();
  460. int sh = p_rot ? p_src->get_width() : p_src->get_height();
  461. int x_pos = (p_dst->get_width() - sw) / 2;
  462. int y_pos = (p_dst->get_height() - sh) / 2;
  463. int xs = (x_pos >= 0) ? 0 : -x_pos;
  464. int ys = (y_pos >= 0) ? 0 : -y_pos;
  465. if (sw + x_pos > p_dst->get_width()) {
  466. sw = p_dst->get_width() - x_pos;
  467. }
  468. if (sh + y_pos > p_dst->get_height()) {
  469. sh = p_dst->get_height() - y_pos;
  470. }
  471. for (int y = ys; y < sh; y++) {
  472. for (int x = xs; x < sw; x++) {
  473. Color sc = p_rot ? p_src->get_pixel(p_src->get_width() - y - 1, x) : p_src->get_pixel(x, y);
  474. Color dc = p_dst->get_pixel(x_pos + x, y_pos + y);
  475. dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r);
  476. dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g);
  477. dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b);
  478. dc.a = (double)(sc.a + dc.a * (1.0 - sc.a));
  479. p_dst->set_pixel(x_pos + x, y_pos + y, dc);
  480. }
  481. }
  482. }
  483. struct IconInfo {
  484. const char *preset_key;
  485. const char *idiom;
  486. const char *export_name;
  487. const char *actual_size_side;
  488. const char *scale;
  489. const char *unscaled_size;
  490. const bool force_opaque;
  491. };
  492. static const IconInfo icon_infos[] = {
  493. // Home screen on iPhone
  494. { "icons/iphone_120x120", "iphone", "Icon-120.png", "120", "2x", "60x60", false },
  495. { "icons/iphone_120x120", "iphone", "Icon-120.png", "120", "3x", "40x40", false },
  496. { "icons/iphone_180x180", "iphone", "Icon-180.png", "180", "3x", "60x60", false },
  497. // Home screen on iPad
  498. { "icons/ipad_76x76", "ipad", "Icon-76.png", "76", "1x", "76x76", false },
  499. { "icons/ipad_152x152", "ipad", "Icon-152.png", "152", "2x", "76x76", false },
  500. { "icons/ipad_167x167", "ipad", "Icon-167.png", "167", "2x", "83.5x83.5", false },
  501. // App Store
  502. { "icons/app_store_1024x1024", "ios-marketing", "Icon-1024.png", "1024", "1x", "1024x1024", true },
  503. // Spotlight
  504. { "icons/spotlight_40x40", "ipad", "Icon-40.png", "40", "1x", "40x40", false },
  505. { "icons/spotlight_80x80", "iphone", "Icon-80.png", "80", "2x", "40x40", false },
  506. { "icons/spotlight_80x80", "ipad", "Icon-80.png", "80", "2x", "40x40", false }
  507. };
  508. Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
  509. String json_description = "{\"images\":[";
  510. String sizes;
  511. Ref<DirAccess> da = DirAccess::open(p_iconset_dir);
  512. ERR_FAIL_COND_V_MSG(da.is_null(), ERR_CANT_OPEN, "Cannot open directory '" + p_iconset_dir + "'.");
  513. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  514. IconInfo info = icon_infos[i];
  515. int side_size = String(info.actual_size_side).to_int();
  516. String icon_path = p_preset->get(info.preset_key);
  517. if (icon_path.length() == 0) {
  518. // Resize main app icon
  519. icon_path = ProjectSettings::get_singleton()->get("application/config/icon");
  520. Ref<Image> img = memnew(Image);
  521. Error err = ImageLoader::load_image(icon_path, img);
  522. if (err != OK) {
  523. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
  524. return ERR_UNCONFIGURED;
  525. }
  526. if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
  527. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
  528. return ERR_UNCONFIGURED;
  529. }
  530. img->resize(side_size, side_size);
  531. err = img->save_png(p_iconset_dir + info.export_name);
  532. if (err) {
  533. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
  534. return err;
  535. }
  536. } else {
  537. // Load custom icon and resize if required
  538. Ref<Image> img = memnew(Image);
  539. Error err = ImageLoader::load_image(icon_path, img);
  540. if (err != OK) {
  541. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
  542. return ERR_UNCONFIGURED;
  543. }
  544. if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
  545. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
  546. return ERR_UNCONFIGURED;
  547. }
  548. if (img->get_width() != side_size || img->get_height() != side_size) {
  549. 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)));
  550. img->resize(side_size, side_size);
  551. err = img->save_png(p_iconset_dir + info.export_name);
  552. } else {
  553. err = da->copy(icon_path, p_iconset_dir + info.export_name);
  554. }
  555. if (err) {
  556. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
  557. return err;
  558. }
  559. }
  560. sizes += String(info.actual_size_side) + "\n";
  561. if (i > 0) {
  562. json_description += ",";
  563. }
  564. json_description += String("{");
  565. json_description += String("\"idiom\":") + "\"" + info.idiom + "\",";
  566. json_description += String("\"size\":") + "\"" + info.unscaled_size + "\",";
  567. json_description += String("\"scale\":") + "\"" + info.scale + "\",";
  568. json_description += String("\"filename\":") + "\"" + info.export_name + "\"";
  569. json_description += String("}");
  570. }
  571. json_description += "]}";
  572. Ref<FileAccess> json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
  573. ERR_FAIL_COND_V(json_file.is_null(), ERR_CANT_CREATE);
  574. CharString json_utf8 = json_description.utf8();
  575. json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length());
  576. Ref<FileAccess> sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE);
  577. ERR_FAIL_COND_V(sizes_file.is_null(), ERR_CANT_CREATE);
  578. CharString sizes_utf8 = sizes.utf8();
  579. sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length());
  580. return OK;
  581. }
  582. Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  583. const String custom_launch_image_2x = p_preset->get("storyboard/custom_image@2x");
  584. const String custom_launch_image_3x = p_preset->get("storyboard/custom_image@3x");
  585. if (custom_launch_image_2x.length() > 0 && custom_launch_image_3x.length() > 0) {
  586. Ref<Image> image;
  587. String image_path = p_dest_dir.path_join("[email protected]");
  588. image.instantiate();
  589. Error err = image->load(custom_launch_image_2x);
  590. if (err) {
  591. image.unref();
  592. return err;
  593. }
  594. if (image->save_png(image_path) != OK) {
  595. return ERR_FILE_CANT_WRITE;
  596. }
  597. image.unref();
  598. image_path = p_dest_dir.path_join("[email protected]");
  599. image.instantiate();
  600. err = image->load(custom_launch_image_3x);
  601. if (err) {
  602. image.unref();
  603. return err;
  604. }
  605. if (image->save_png(image_path) != OK) {
  606. return ERR_FILE_CANT_WRITE;
  607. }
  608. } else {
  609. Ref<Image> splash;
  610. const String splash_path = ProjectSettings::get_singleton()->get("application/boot_splash/image");
  611. if (!splash_path.is_empty()) {
  612. splash.instantiate();
  613. const Error err = splash->load(splash_path);
  614. if (err) {
  615. splash.unref();
  616. }
  617. }
  618. if (splash.is_null()) {
  619. splash = Ref<Image>(memnew(Image(boot_splash_png)));
  620. }
  621. // Using same image for both @2x and @3x
  622. // because Godot's own boot logo uses single image for all resolutions.
  623. // Also not using @1x image, because devices using this image variant
  624. // are not supported by iOS 9, which is minimal target.
  625. const String splash_png_path_2x = p_dest_dir.path_join("[email protected]");
  626. const String splash_png_path_3x = p_dest_dir.path_join("[email protected]");
  627. if (splash->save_png(splash_png_path_2x) != OK) {
  628. return ERR_FILE_CANT_WRITE;
  629. }
  630. if (splash->save_png(splash_png_path_3x) != OK) {
  631. return ERR_FILE_CANT_WRITE;
  632. }
  633. }
  634. return OK;
  635. }
  636. Error EditorExportPlatformIOS::_export_loading_screen_images(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  637. Ref<DirAccess> da = DirAccess::open(p_dest_dir);
  638. ERR_FAIL_COND_V_MSG(da.is_null(), ERR_CANT_OPEN, "Cannot open directory '" + p_dest_dir + "'.");
  639. for (uint64_t i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  640. LoadingScreenInfo info = loading_screen_infos[i];
  641. String loading_screen_file = p_preset->get(info.preset_key);
  642. Color boot_bg_color = ProjectSettings::get_singleton()->get("application/boot_splash/bg_color");
  643. String boot_logo_path = ProjectSettings::get_singleton()->get("application/boot_splash/image");
  644. bool boot_logo_scale = ProjectSettings::get_singleton()->get("application/boot_splash/fullsize");
  645. if (loading_screen_file.size() > 0) {
  646. // Load custom loading screens, and resize if required.
  647. Ref<Image> img = memnew(Image);
  648. Error err = ImageLoader::load_image(loading_screen_file, img);
  649. if (err != OK) {
  650. ERR_PRINT("Invalid loading screen (" + String(info.preset_key) + "): '" + loading_screen_file + "'.");
  651. return ERR_UNCONFIGURED;
  652. }
  653. if (img->get_width() != info.width || img->get_height() != info.height) {
  654. 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) + ".");
  655. float aspect_ratio = (float)img->get_width() / (float)img->get_height();
  656. if (boot_logo_scale) {
  657. if (info.height * aspect_ratio <= info.width) {
  658. img->resize(info.height * aspect_ratio, info.height);
  659. } else {
  660. img->resize(info.width, info.width / aspect_ratio);
  661. }
  662. }
  663. Ref<Image> new_img = memnew(Image);
  664. new_img->create(info.width, info.height, false, Image::FORMAT_RGBA8);
  665. new_img->fill(boot_bg_color);
  666. _blend_and_rotate(new_img, img, false);
  667. err = new_img->save_png(p_dest_dir + info.export_name);
  668. } else {
  669. err = da->copy(loading_screen_file, p_dest_dir + info.export_name);
  670. }
  671. if (err) {
  672. String err_str = String("Failed to export loading screen (") + info.preset_key + ") from path '" + loading_screen_file + "'.";
  673. ERR_PRINT(err_str.utf8().get_data());
  674. return err;
  675. }
  676. } else {
  677. // Generate loading screen from the splash screen
  678. Ref<Image> img = memnew(Image);
  679. img->create(info.width, info.height, false, Image::FORMAT_RGBA8);
  680. img->fill(boot_bg_color);
  681. Ref<Image> img_bs;
  682. if (boot_logo_path.length() > 0) {
  683. img_bs = Ref<Image>(memnew(Image));
  684. ImageLoader::load_image(boot_logo_path, img_bs);
  685. }
  686. if (!img_bs.is_valid()) {
  687. img_bs = Ref<Image>(memnew(Image(boot_splash_png)));
  688. }
  689. if (img_bs.is_valid()) {
  690. float aspect_ratio = (float)img_bs->get_width() / (float)img_bs->get_height();
  691. if (info.rotate) {
  692. if (boot_logo_scale) {
  693. if (info.width * aspect_ratio <= info.height) {
  694. img_bs->resize(info.width * aspect_ratio, info.width);
  695. } else {
  696. img_bs->resize(info.height, info.height / aspect_ratio);
  697. }
  698. }
  699. } else {
  700. if (boot_logo_scale) {
  701. if (info.height * aspect_ratio <= info.width) {
  702. img_bs->resize(info.height * aspect_ratio, info.height);
  703. } else {
  704. img_bs->resize(info.width, info.width / aspect_ratio);
  705. }
  706. }
  707. }
  708. _blend_and_rotate(img, img_bs, info.rotate);
  709. }
  710. Error err = img->save_png(p_dest_dir + info.export_name);
  711. if (err) {
  712. String err_str = String("Failed to export loading screen (") + info.preset_key + ") from splash screen.";
  713. WARN_PRINT(err_str.utf8().get_data());
  714. }
  715. }
  716. }
  717. return OK;
  718. }
  719. Error EditorExportPlatformIOS::_walk_dir_recursive(Ref<DirAccess> &p_da, FileHandler p_handler, void *p_userdata) {
  720. Vector<String> dirs;
  721. String current_dir = p_da->get_current_dir();
  722. p_da->list_dir_begin();
  723. String path = p_da->get_next();
  724. while (!path.is_empty()) {
  725. if (p_da->current_is_dir()) {
  726. if (path != "." && path != "..") {
  727. dirs.push_back(path);
  728. }
  729. } else {
  730. Error err = p_handler(current_dir.path_join(path), p_userdata);
  731. if (err) {
  732. p_da->list_dir_end();
  733. return err;
  734. }
  735. }
  736. path = p_da->get_next();
  737. }
  738. p_da->list_dir_end();
  739. for (int i = 0; i < dirs.size(); ++i) {
  740. String dir = dirs[i];
  741. p_da->change_dir(dir);
  742. Error err = _walk_dir_recursive(p_da, p_handler, p_userdata);
  743. p_da->change_dir("..");
  744. if (err) {
  745. return err;
  746. }
  747. }
  748. return OK;
  749. }
  750. struct CodesignData {
  751. const Ref<EditorExportPreset> &preset;
  752. bool debug = false;
  753. CodesignData(const Ref<EditorExportPreset> &p_preset, bool p_debug) :
  754. preset(p_preset),
  755. debug(p_debug) {
  756. }
  757. };
  758. Error EditorExportPlatformIOS::_codesign(String p_file, void *p_userdata) {
  759. if (p_file.ends_with(".dylib")) {
  760. CodesignData *data = static_cast<CodesignData *>(p_userdata);
  761. print_line(String("Signing ") + p_file);
  762. String sign_id;
  763. if (data->debug) {
  764. sign_id = data->preset->get("application/code_sign_identity_debug").operator String().is_empty() ? "iPhone Developer" : data->preset->get("application/code_sign_identity_debug");
  765. } else {
  766. sign_id = data->preset->get("application/code_sign_identity_release").operator String().is_empty() ? "iPhone Distribution" : data->preset->get("application/code_sign_identity_release");
  767. }
  768. List<String> codesign_args;
  769. codesign_args.push_back("-f");
  770. codesign_args.push_back("-s");
  771. codesign_args.push_back(sign_id);
  772. codesign_args.push_back(p_file);
  773. String str;
  774. Error err = OS::get_singleton()->execute("codesign", codesign_args, &str, nullptr, true);
  775. print_verbose("codesign (" + p_file + "):\n" + str);
  776. return err;
  777. }
  778. return OK;
  779. }
  780. struct PbxId {
  781. private:
  782. static char _hex_char(uint8_t four_bits) {
  783. if (four_bits < 10) {
  784. return ('0' + four_bits);
  785. }
  786. return 'A' + (four_bits - 10);
  787. }
  788. static String _hex_pad(uint32_t num) {
  789. Vector<char> ret;
  790. ret.resize(sizeof(num) * 2);
  791. for (uint64_t i = 0; i < sizeof(num) * 2; ++i) {
  792. uint8_t four_bits = (num >> (sizeof(num) * 8 - (i + 1) * 4)) & 0xF;
  793. ret.write[i] = _hex_char(four_bits);
  794. }
  795. return String::utf8(ret.ptr(), ret.size());
  796. }
  797. public:
  798. uint32_t high_bits;
  799. uint32_t mid_bits;
  800. uint32_t low_bits;
  801. String str() const {
  802. return _hex_pad(high_bits) + _hex_pad(mid_bits) + _hex_pad(low_bits);
  803. }
  804. PbxId &operator++() {
  805. low_bits++;
  806. if (!low_bits) {
  807. mid_bits++;
  808. if (!mid_bits) {
  809. high_bits++;
  810. }
  811. }
  812. return *this;
  813. }
  814. };
  815. struct ExportLibsData {
  816. Vector<String> lib_paths;
  817. String dest_dir;
  818. };
  819. void EditorExportPlatformIOS::_add_assets_to_project(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets) {
  820. // that is just a random number, we just need Godot IDs not to clash with
  821. // existing IDs in the project.
  822. PbxId current_id = { 0x58938401, 0, 0 };
  823. String pbx_files;
  824. String pbx_frameworks_build;
  825. String pbx_frameworks_refs;
  826. String pbx_resources_build;
  827. String pbx_resources_refs;
  828. String pbx_embeded_frameworks;
  829. const String file_info_format = String("$build_id = {isa = PBXBuildFile; fileRef = $ref_id; };\n") +
  830. "$ref_id = {isa = PBXFileReference; lastKnownFileType = $file_type; name = \"$name\"; path = \"$file_path\"; sourceTree = \"<group>\"; };\n";
  831. for (int i = 0; i < p_additional_assets.size(); ++i) {
  832. String additional_asset_info_format = file_info_format;
  833. String build_id = (++current_id).str();
  834. String ref_id = (++current_id).str();
  835. String framework_id = "";
  836. const IOSExportAsset &asset = p_additional_assets[i];
  837. String type;
  838. if (asset.exported_path.ends_with(".framework")) {
  839. if (asset.should_embed) {
  840. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  841. framework_id = (++current_id).str();
  842. pbx_embeded_frameworks += framework_id + ",\n";
  843. }
  844. type = "wrapper.framework";
  845. } else if (asset.exported_path.ends_with(".xcframework")) {
  846. if (asset.should_embed) {
  847. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  848. framework_id = (++current_id).str();
  849. pbx_embeded_frameworks += framework_id + ",\n";
  850. }
  851. type = "wrapper.xcframework";
  852. } else if (asset.exported_path.ends_with(".dylib")) {
  853. type = "compiled.mach-o.dylib";
  854. } else if (asset.exported_path.ends_with(".a")) {
  855. type = "archive.ar";
  856. } else {
  857. type = "file";
  858. }
  859. String &pbx_build = asset.is_framework ? pbx_frameworks_build : pbx_resources_build;
  860. String &pbx_refs = asset.is_framework ? pbx_frameworks_refs : pbx_resources_refs;
  861. if (pbx_build.length() > 0) {
  862. pbx_build += ",\n";
  863. pbx_refs += ",\n";
  864. }
  865. pbx_build += build_id;
  866. pbx_refs += ref_id;
  867. Dictionary format_dict;
  868. format_dict["build_id"] = build_id;
  869. format_dict["ref_id"] = ref_id;
  870. format_dict["name"] = asset.exported_path.get_file();
  871. format_dict["file_path"] = asset.exported_path;
  872. format_dict["file_type"] = type;
  873. if (framework_id.length() > 0) {
  874. format_dict["framework_id"] = framework_id;
  875. }
  876. pbx_files += additional_asset_info_format.format(format_dict, "$_");
  877. }
  878. // Note, frameworks like gamekit are always included in our project.pbxprof file
  879. // even if turned off in capabilities.
  880. String str = String::utf8((const char *)p_project_data.ptr(), p_project_data.size());
  881. str = str.replace("$additional_pbx_files", pbx_files);
  882. str = str.replace("$additional_pbx_frameworks_build", pbx_frameworks_build);
  883. str = str.replace("$additional_pbx_frameworks_refs", pbx_frameworks_refs);
  884. str = str.replace("$additional_pbx_resources_build", pbx_resources_build);
  885. str = str.replace("$additional_pbx_resources_refs", pbx_resources_refs);
  886. str = str.replace("$pbx_embeded_frameworks", pbx_embeded_frameworks);
  887. CharString cs = str.utf8();
  888. p_project_data.resize(cs.size() - 1);
  889. for (int i = 0; i < cs.size() - 1; i++) {
  890. p_project_data.write[i] = cs[i];
  891. }
  892. }
  893. 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) {
  894. String binary_name = p_out_dir.get_file().get_basename();
  895. Ref<DirAccess> da = DirAccess::create_for_path(p_asset);
  896. if (da.is_null()) {
  897. ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't create directory: " + p_asset + ".");
  898. }
  899. bool file_exists = da->file_exists(p_asset);
  900. bool dir_exists = da->dir_exists(p_asset);
  901. if (!file_exists && !dir_exists) {
  902. return ERR_FILE_NOT_FOUND;
  903. }
  904. String base_dir = p_asset.get_base_dir().replace("res://", "");
  905. String destination_dir;
  906. String destination;
  907. String asset_path;
  908. bool create_framework = false;
  909. if (p_is_framework && p_asset.ends_with(".dylib")) {
  910. // For iOS we need to turn .dylib into .framework
  911. // to be able to send application to AppStore
  912. asset_path = String("dylibs").path_join(base_dir);
  913. String file_name;
  914. if (!p_custom_file_name) {
  915. file_name = p_asset.get_basename().get_file();
  916. } else {
  917. file_name = *p_custom_file_name;
  918. }
  919. String framework_name = file_name + ".framework";
  920. asset_path = asset_path.path_join(framework_name);
  921. destination_dir = p_out_dir.path_join(asset_path);
  922. destination = destination_dir.path_join(file_name);
  923. create_framework = true;
  924. } else if (p_is_framework && (p_asset.ends_with(".framework") || p_asset.ends_with(".xcframework"))) {
  925. asset_path = String("dylibs").path_join(base_dir);
  926. String file_name;
  927. if (!p_custom_file_name) {
  928. file_name = p_asset.get_file();
  929. } else {
  930. file_name = *p_custom_file_name;
  931. }
  932. asset_path = asset_path.path_join(file_name);
  933. destination_dir = p_out_dir.path_join(asset_path);
  934. destination = destination_dir;
  935. } else {
  936. asset_path = base_dir;
  937. String file_name;
  938. if (!p_custom_file_name) {
  939. file_name = p_asset.get_file();
  940. } else {
  941. file_name = *p_custom_file_name;
  942. }
  943. destination_dir = p_out_dir.path_join(asset_path);
  944. asset_path = asset_path.path_join(file_name);
  945. destination = p_out_dir.path_join(asset_path);
  946. }
  947. Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  948. ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_out_dir + "'.");
  949. if (!filesystem_da->dir_exists(destination_dir)) {
  950. Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir);
  951. if (make_dir_err) {
  952. return make_dir_err;
  953. }
  954. }
  955. Error err = dir_exists ? da->copy_dir(p_asset, destination) : da->copy(p_asset, destination);
  956. if (err) {
  957. return err;
  958. }
  959. IOSExportAsset exported_asset = { binary_name.path_join(asset_path), p_is_framework, p_should_embed };
  960. r_exported_assets.push_back(exported_asset);
  961. if (create_framework) {
  962. String file_name;
  963. if (!p_custom_file_name) {
  964. file_name = p_asset.get_basename().get_file();
  965. } else {
  966. file_name = *p_custom_file_name;
  967. }
  968. String framework_name = file_name + ".framework";
  969. // Performing `install_name_tool -id @rpath/{name}.framework/{name} ./{name}` on dylib
  970. {
  971. List<String> install_name_args;
  972. install_name_args.push_back("-id");
  973. install_name_args.push_back(String("@rpath").path_join(framework_name).path_join(file_name));
  974. install_name_args.push_back(destination);
  975. OS::get_singleton()->execute("install_name_tool", install_name_args);
  976. }
  977. // Creating Info.plist
  978. {
  979. String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  980. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  981. "<plist version=\"1.0\">\n"
  982. "<dict>\n"
  983. "<key>CFBundleShortVersionString</key>\n"
  984. "<string>1.0</string>\n"
  985. "<key>CFBundleIdentifier</key>\n"
  986. "<string>com.gdnative.framework.$name</string>\n"
  987. "<key>CFBundleName</key>\n"
  988. "<string>$name</string>\n"
  989. "<key>CFBundleExecutable</key>\n"
  990. "<string>$name</string>\n"
  991. "<key>DTPlatformName</key>\n"
  992. "<string>iphoneos</string>\n"
  993. "<key>CFBundleInfoDictionaryVersion</key>\n"
  994. "<string>6.0</string>\n"
  995. "<key>CFBundleVersion</key>\n"
  996. "<string>1</string>\n"
  997. "<key>CFBundlePackageType</key>\n"
  998. "<string>FMWK</string>\n"
  999. "<key>MinimumOSVersion</key>\n"
  1000. "<string>10.0</string>\n"
  1001. "</dict>\n"
  1002. "</plist>";
  1003. String info_plist = info_plist_format.replace("$name", file_name);
  1004. Ref<FileAccess> f = FileAccess::open(destination_dir.path_join("Info.plist"), FileAccess::WRITE);
  1005. if (f.is_valid()) {
  1006. f->store_string(info_plist);
  1007. }
  1008. }
  1009. }
  1010. return OK;
  1011. }
  1012. 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) {
  1013. for (int f_idx = 0; f_idx < p_assets.size(); ++f_idx) {
  1014. String asset = p_assets[f_idx];
  1015. if (!asset.begins_with("res://")) {
  1016. // either SDK-builtin or already a part of the export template
  1017. IOSExportAsset exported_asset = { asset, p_is_framework, p_should_embed };
  1018. r_exported_assets.push_back(exported_asset);
  1019. } else {
  1020. Error err = _copy_asset(p_out_dir, asset, nullptr, p_is_framework, p_should_embed, r_exported_assets);
  1021. ERR_FAIL_COND_V(err, err);
  1022. }
  1023. }
  1024. return OK;
  1025. }
  1026. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets) {
  1027. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  1028. for (int i = 0; i < export_plugins.size(); i++) {
  1029. Vector<String> linked_frameworks = export_plugins[i]->get_ios_frameworks();
  1030. Error err = _export_additional_assets(p_out_dir, linked_frameworks, true, false, r_exported_assets);
  1031. ERR_FAIL_COND_V(err, err);
  1032. Vector<String> embedded_frameworks = export_plugins[i]->get_ios_embedded_frameworks();
  1033. err = _export_additional_assets(p_out_dir, embedded_frameworks, true, true, r_exported_assets);
  1034. ERR_FAIL_COND_V(err, err);
  1035. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  1036. for (int j = 0; j < project_static_libs.size(); j++) {
  1037. project_static_libs.write[j] = project_static_libs[j].get_file(); // Only the file name as it's copied to the project
  1038. }
  1039. err = _export_additional_assets(p_out_dir, project_static_libs, true, false, r_exported_assets);
  1040. ERR_FAIL_COND_V(err, err);
  1041. Vector<String> ios_bundle_files = export_plugins[i]->get_ios_bundle_files();
  1042. err = _export_additional_assets(p_out_dir, ios_bundle_files, false, false, r_exported_assets);
  1043. ERR_FAIL_COND_V(err, err);
  1044. }
  1045. Vector<String> library_paths;
  1046. for (int i = 0; i < p_libraries.size(); ++i) {
  1047. library_paths.push_back(p_libraries[i].path);
  1048. }
  1049. Error err = _export_additional_assets(p_out_dir, library_paths, true, true, r_exported_assets);
  1050. ERR_FAIL_COND_V(err, err);
  1051. return OK;
  1052. }
  1053. Vector<String> EditorExportPlatformIOS::_get_preset_architectures(const Ref<EditorExportPreset> &p_preset) const {
  1054. Vector<ExportArchitecture> all_archs = _get_supported_architectures();
  1055. Vector<String> enabled_archs;
  1056. for (int i = 0; i < all_archs.size(); ++i) {
  1057. bool is_enabled = p_preset->get("architectures/" + all_archs[i].name);
  1058. if (is_enabled) {
  1059. enabled_archs.push_back(all_archs[i].name);
  1060. }
  1061. }
  1062. return enabled_archs;
  1063. }
  1064. 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) {
  1065. String plugin_definition_cpp_code;
  1066. String plugin_initialization_cpp_code;
  1067. String plugin_deinitialization_cpp_code;
  1068. Vector<String> plugin_linked_dependencies;
  1069. Vector<String> plugin_embedded_dependencies;
  1070. Vector<String> plugin_files;
  1071. Vector<PluginConfigIOS> enabled_plugins = get_enabled_plugins(p_preset);
  1072. Vector<String> added_linked_dependenciy_names;
  1073. Vector<String> added_embedded_dependenciy_names;
  1074. HashMap<String, String> plist_values;
  1075. HashSet<String> plugin_linker_flags;
  1076. Error err;
  1077. for (int i = 0; i < enabled_plugins.size(); i++) {
  1078. PluginConfigIOS plugin = enabled_plugins[i];
  1079. // Export plugin binary.
  1080. String plugin_main_binary = PluginConfigIOS::get_plugin_main_binary(plugin, p_debug);
  1081. String plugin_binary_result_file = plugin.binary.get_file();
  1082. // We shouldn't embed .xcframework that contains static libraries.
  1083. // Static libraries are not embedded anyway.
  1084. err = _copy_asset(dest_dir, plugin_main_binary, &plugin_binary_result_file, true, false, r_exported_assets);
  1085. ERR_FAIL_COND_V(err, err);
  1086. // Adding dependencies.
  1087. // Use separate container for names to check for duplicates.
  1088. for (int j = 0; j < plugin.linked_dependencies.size(); j++) {
  1089. String dependency = plugin.linked_dependencies[j];
  1090. String name = dependency.get_file();
  1091. if (added_linked_dependenciy_names.has(name)) {
  1092. continue;
  1093. }
  1094. added_linked_dependenciy_names.push_back(name);
  1095. plugin_linked_dependencies.push_back(dependency);
  1096. }
  1097. for (int j = 0; j < plugin.system_dependencies.size(); j++) {
  1098. String dependency = plugin.system_dependencies[j];
  1099. String name = dependency.get_file();
  1100. if (added_linked_dependenciy_names.has(name)) {
  1101. continue;
  1102. }
  1103. added_linked_dependenciy_names.push_back(name);
  1104. plugin_linked_dependencies.push_back(dependency);
  1105. }
  1106. for (int j = 0; j < plugin.embedded_dependencies.size(); j++) {
  1107. String dependency = plugin.embedded_dependencies[j];
  1108. String name = dependency.get_file();
  1109. if (added_embedded_dependenciy_names.has(name)) {
  1110. continue;
  1111. }
  1112. added_embedded_dependenciy_names.push_back(name);
  1113. plugin_embedded_dependencies.push_back(dependency);
  1114. }
  1115. plugin_files.append_array(plugin.files_to_copy);
  1116. // Capabilities
  1117. // Also checking for duplicates.
  1118. for (int j = 0; j < plugin.capabilities.size(); j++) {
  1119. String capability = plugin.capabilities[j];
  1120. if (p_config_data.capabilities.has(capability)) {
  1121. continue;
  1122. }
  1123. p_config_data.capabilities.push_back(capability);
  1124. }
  1125. // Linker flags
  1126. // Checking duplicates
  1127. for (int j = 0; j < plugin.linker_flags.size(); j++) {
  1128. String linker_flag = plugin.linker_flags[j];
  1129. plugin_linker_flags.insert(linker_flag);
  1130. }
  1131. // Plist
  1132. // Using hash map container to remove duplicates
  1133. for (const KeyValue<String, PluginConfigIOS::PlistItem> &E : plugin.plist) {
  1134. String key = E.key;
  1135. const PluginConfigIOS::PlistItem &item = E.value;
  1136. String value;
  1137. switch (item.type) {
  1138. case PluginConfigIOS::PlistItemType::STRING_INPUT: {
  1139. String preset_name = "plugins_plist/" + key;
  1140. String input_value = p_preset->get(preset_name);
  1141. value = "<string>" + input_value + "</string>";
  1142. } break;
  1143. default:
  1144. value = item.value;
  1145. break;
  1146. }
  1147. if (key.is_empty() || value.is_empty()) {
  1148. continue;
  1149. }
  1150. String plist_key = "<key>" + key + "</key>";
  1151. plist_values[plist_key] = value;
  1152. }
  1153. // CPP Code
  1154. String definition_comment = "// Plugin: " + plugin.name + "\n";
  1155. String initialization_method = plugin.initialization_method + "();\n";
  1156. String deinitialization_method = plugin.deinitialization_method + "();\n";
  1157. plugin_definition_cpp_code += definition_comment +
  1158. "extern void " + initialization_method +
  1159. "extern void " + deinitialization_method + "\n";
  1160. plugin_initialization_cpp_code += "\t" + initialization_method;
  1161. plugin_deinitialization_cpp_code += "\t" + deinitialization_method;
  1162. if (plugin.use_swift_runtime) {
  1163. p_config_data.use_swift_runtime = true;
  1164. }
  1165. }
  1166. // Updating `Info.plist`
  1167. {
  1168. for (const KeyValue<String, String> &E : plist_values) {
  1169. String key = E.key;
  1170. String value = E.value;
  1171. if (key.is_empty() || value.is_empty()) {
  1172. continue;
  1173. }
  1174. p_config_data.plist_content += key + value + "\n";
  1175. }
  1176. }
  1177. // Export files
  1178. {
  1179. // Export linked plugin dependency
  1180. err = _export_additional_assets(dest_dir, plugin_linked_dependencies, true, false, r_exported_assets);
  1181. ERR_FAIL_COND_V(err, err);
  1182. // Export embedded plugin dependency
  1183. err = _export_additional_assets(dest_dir, plugin_embedded_dependencies, true, true, r_exported_assets);
  1184. ERR_FAIL_COND_V(err, err);
  1185. // Export plugin files
  1186. err = _export_additional_assets(dest_dir, plugin_files, false, false, r_exported_assets);
  1187. ERR_FAIL_COND_V(err, err);
  1188. }
  1189. // Update CPP
  1190. {
  1191. Dictionary plugin_format;
  1192. plugin_format["definition"] = plugin_definition_cpp_code;
  1193. plugin_format["initialization"] = plugin_initialization_cpp_code;
  1194. plugin_format["deinitialization"] = plugin_deinitialization_cpp_code;
  1195. String plugin_cpp_code = "\n// Godot Plugins\n"
  1196. "void godot_ios_plugins_initialize();\n"
  1197. "void godot_ios_plugins_deinitialize();\n"
  1198. "// Exported Plugins\n\n"
  1199. "$definition"
  1200. "// Use Plugins\n"
  1201. "void godot_ios_plugins_initialize() {\n"
  1202. "$initialization"
  1203. "}\n\n"
  1204. "void godot_ios_plugins_deinitialize() {\n"
  1205. "$deinitialization"
  1206. "}\n";
  1207. p_config_data.cpp_code += plugin_cpp_code.format(plugin_format, "$_");
  1208. }
  1209. // Update Linker Flag Values
  1210. {
  1211. String result_linker_flags = " ";
  1212. for (const String &E : plugin_linker_flags) {
  1213. const String &flag = E;
  1214. if (flag.length() == 0) {
  1215. continue;
  1216. }
  1217. if (result_linker_flags.length() > 0) {
  1218. result_linker_flags += ' ';
  1219. }
  1220. result_linker_flags += flag;
  1221. }
  1222. result_linker_flags = result_linker_flags.replace("\"", "\\\"");
  1223. p_config_data.linker_flags += result_linker_flags;
  1224. }
  1225. return OK;
  1226. }
  1227. Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  1228. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  1229. String src_pkg_name;
  1230. String dest_dir = p_path.get_base_dir() + "/";
  1231. String binary_name = p_path.get_file().get_basename();
  1232. EditorProgress ep("export", "Exporting for iOS", 5, true);
  1233. String team_id = p_preset->get("application/app_store_team_id");
  1234. ERR_FAIL_COND_V_MSG(team_id.length() == 0, ERR_CANT_OPEN, "App Store Team ID not specified - cannot configure the project.");
  1235. if (p_debug) {
  1236. src_pkg_name = p_preset->get("custom_template/debug");
  1237. } else {
  1238. src_pkg_name = p_preset->get("custom_template/release");
  1239. }
  1240. if (src_pkg_name.is_empty()) {
  1241. String err;
  1242. src_pkg_name = find_export_template("ios.zip", &err);
  1243. if (src_pkg_name.is_empty()) {
  1244. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found."));
  1245. return ERR_FILE_NOT_FOUND;
  1246. }
  1247. }
  1248. if (!DirAccess::exists(dest_dir)) {
  1249. return ERR_FILE_BAD_PATH;
  1250. }
  1251. {
  1252. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1253. if (da.is_valid()) {
  1254. String current_dir = da->get_current_dir();
  1255. // remove leftovers from last export so they don't interfere
  1256. // in case some files are no longer needed
  1257. if (da->change_dir(dest_dir + binary_name + ".xcodeproj") == OK) {
  1258. da->erase_contents_recursive();
  1259. }
  1260. if (da->change_dir(dest_dir + binary_name) == OK) {
  1261. da->erase_contents_recursive();
  1262. }
  1263. da->change_dir(current_dir);
  1264. if (!da->dir_exists(dest_dir + binary_name)) {
  1265. Error err = da->make_dir(dest_dir + binary_name);
  1266. if (err) {
  1267. return err;
  1268. }
  1269. }
  1270. }
  1271. }
  1272. if (ep.step("Making .pck", 0)) {
  1273. return ERR_SKIP;
  1274. }
  1275. String pack_path = dest_dir + binary_name + ".pck";
  1276. Vector<SharedObject> libraries;
  1277. Error err = save_pack(p_preset, p_debug, pack_path, &libraries);
  1278. if (err) {
  1279. return err;
  1280. }
  1281. if (ep.step("Extracting and configuring Xcode project", 1)) {
  1282. return ERR_SKIP;
  1283. }
  1284. String library_to_use = "libgodot.ios." + String(p_debug ? "debug" : "release") + ".xcframework";
  1285. print_line("Static framework: " + library_to_use);
  1286. String pkg_name;
  1287. if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") {
  1288. pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
  1289. } else {
  1290. pkg_name = "Unnamed";
  1291. }
  1292. bool found_library = false;
  1293. const String project_file = "godot_ios.xcodeproj/project.pbxproj";
  1294. HashSet<String> files_to_parse;
  1295. files_to_parse.insert("godot_ios/godot_ios-Info.plist");
  1296. files_to_parse.insert(project_file);
  1297. files_to_parse.insert("godot_ios/export_options.plist");
  1298. files_to_parse.insert("godot_ios/dummy.cpp");
  1299. files_to_parse.insert("godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata");
  1300. files_to_parse.insert("godot_ios.xcodeproj/xcshareddata/xcschemes/godot_ios.xcscheme");
  1301. files_to_parse.insert("godot_ios/godot_ios.entitlements");
  1302. files_to_parse.insert("godot_ios/Launch Screen.storyboard");
  1303. IOSConfigData config_data = {
  1304. pkg_name,
  1305. binary_name,
  1306. _get_additional_plist_content(),
  1307. String(" ").join(_get_preset_architectures(p_preset)),
  1308. _get_linker_flags(),
  1309. _get_cpp_code(),
  1310. "",
  1311. "",
  1312. "",
  1313. "",
  1314. Vector<String>(),
  1315. false
  1316. };
  1317. Vector<IOSExportAsset> assets;
  1318. Ref<DirAccess> tmp_app_path = DirAccess::create_for_path(dest_dir);
  1319. ERR_FAIL_COND_V(tmp_app_path.is_null(), ERR_CANT_CREATE);
  1320. print_line("Unzipping...");
  1321. Ref<FileAccess> io_fa;
  1322. zlib_filefunc_def io = zipio_create_io(&io_fa);
  1323. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  1324. if (!src_pkg_zip) {
  1325. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Could not open export template (not a zip file?): \"%s\".", src_pkg_name));
  1326. return ERR_CANT_OPEN;
  1327. }
  1328. err = _export_ios_plugins(p_preset, config_data, dest_dir + binary_name, assets, p_debug);
  1329. ERR_FAIL_COND_V(err, err);
  1330. //export rest of the files
  1331. int ret = unzGoToFirstFile(src_pkg_zip);
  1332. Vector<uint8_t> project_file_data;
  1333. while (ret == UNZ_OK) {
  1334. #if defined(MACOS_ENABLED) || defined(X11_ENABLED)
  1335. bool is_execute = false;
  1336. #endif
  1337. //get filename
  1338. unz_file_info info;
  1339. char fname[16384];
  1340. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  1341. if (ret != UNZ_OK) {
  1342. break;
  1343. }
  1344. String file = String::utf8(fname);
  1345. print_line("READ: " + file);
  1346. Vector<uint8_t> data;
  1347. data.resize(info.uncompressed_size);
  1348. //read
  1349. unzOpenCurrentFile(src_pkg_zip);
  1350. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  1351. unzCloseCurrentFile(src_pkg_zip);
  1352. //write
  1353. if (files_to_parse.has(file)) {
  1354. _fix_config_file(p_preset, data, config_data, p_debug);
  1355. } else if (file.begins_with("libgodot.ios")) {
  1356. if (!file.begins_with(library_to_use) || file.ends_with(String("/empty"))) {
  1357. ret = unzGoToNextFile(src_pkg_zip);
  1358. continue; //ignore!
  1359. }
  1360. found_library = true;
  1361. #if defined(MACOS_ENABLED) || defined(X11_ENABLED)
  1362. is_execute = true;
  1363. #endif
  1364. file = file.replace(library_to_use, binary_name + ".xcframework");
  1365. }
  1366. if (file == project_file) {
  1367. project_file_data = data;
  1368. }
  1369. ///@TODO need to parse logo files
  1370. if (data.size() > 0) {
  1371. file = file.replace("godot_ios", binary_name);
  1372. print_line("ADDING: " + file + " size: " + itos(data.size()));
  1373. /* write it into our folder structure */
  1374. file = dest_dir + file;
  1375. /* make sure this folder exists */
  1376. String dir_name = file.get_base_dir();
  1377. if (!tmp_app_path->dir_exists(dir_name)) {
  1378. print_line("Creating " + dir_name);
  1379. Error dir_err = tmp_app_path->make_dir_recursive(dir_name);
  1380. if (dir_err) {
  1381. ERR_PRINT("Can't create '" + dir_name + "'.");
  1382. unzClose(src_pkg_zip);
  1383. return ERR_CANT_CREATE;
  1384. }
  1385. }
  1386. /* write the file */
  1387. {
  1388. Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);
  1389. if (f.is_null()) {
  1390. ERR_PRINT("Can't write '" + file + "'.");
  1391. unzClose(src_pkg_zip);
  1392. return ERR_CANT_CREATE;
  1393. };
  1394. f->store_buffer(data.ptr(), data.size());
  1395. }
  1396. #if defined(MACOS_ENABLED) || defined(X11_ENABLED)
  1397. if (is_execute) {
  1398. // we need execute rights on this file
  1399. chmod(file.utf8().get_data(), 0755);
  1400. }
  1401. #endif
  1402. }
  1403. ret = unzGoToNextFile(src_pkg_zip);
  1404. }
  1405. /* we're done with our source zip */
  1406. unzClose(src_pkg_zip);
  1407. if (!found_library) {
  1408. ERR_PRINT("Requested template library '" + library_to_use + "' not found. It might be missing from your template archive.");
  1409. return ERR_FILE_NOT_FOUND;
  1410. }
  1411. Dictionary appnames = ProjectSettings::get_singleton()->get("application/config/name_localized");
  1412. Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");
  1413. Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");
  1414. Dictionary photolibrary_usage_descriptions = p_preset->get("privacy/photolibrary_usage_description_localized");
  1415. Vector<String> translations = ProjectSettings::get_singleton()->get("internationalization/locale/translations");
  1416. if (translations.size() > 0) {
  1417. {
  1418. String fname = dest_dir + binary_name + "/en.lproj";
  1419. tmp_app_path->make_dir_recursive(fname);
  1420. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1421. f->store_line("/* Localized versions of Info.plist keys */");
  1422. f->store_line("");
  1423. f->store_line("CFBundleDisplayName = \"" + ProjectSettings::get_singleton()->get("application/config/name").operator String() + "\";");
  1424. f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String() + "\";");
  1425. f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String() + "\";");
  1426. f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photolibrary_usage_description").operator String() + "\";");
  1427. }
  1428. HashSet<String> languages;
  1429. for (const String &E : translations) {
  1430. Ref<Translation> tr = ResourceLoader::load(E);
  1431. if (tr.is_valid() && tr->get_locale() != "en") {
  1432. languages.insert(tr->get_locale());
  1433. }
  1434. }
  1435. for (const String &lang : languages) {
  1436. String fname = dest_dir + binary_name + "/" + lang + ".lproj";
  1437. tmp_app_path->make_dir_recursive(fname);
  1438. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1439. f->store_line("/* Localized versions of Info.plist keys */");
  1440. f->store_line("");
  1441. if (appnames.has(lang)) {
  1442. f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String() + "\";");
  1443. }
  1444. if (camera_usage_descriptions.has(lang)) {
  1445. f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String() + "\";");
  1446. }
  1447. if (microphone_usage_descriptions.has(lang)) {
  1448. f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String() + "\";");
  1449. }
  1450. if (photolibrary_usage_descriptions.has(lang)) {
  1451. f->store_line("NSPhotoLibraryUsageDescription = \"" + photolibrary_usage_descriptions[lang].operator String() + "\";");
  1452. }
  1453. }
  1454. }
  1455. // Copy project static libs to the project
  1456. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  1457. for (int i = 0; i < export_plugins.size(); i++) {
  1458. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  1459. for (int j = 0; j < project_static_libs.size(); j++) {
  1460. const String &static_lib_path = project_static_libs[j];
  1461. String dest_lib_file_path = dest_dir + static_lib_path.get_file();
  1462. Error lib_copy_err = tmp_app_path->copy(static_lib_path, dest_lib_file_path);
  1463. if (lib_copy_err != OK) {
  1464. ERR_PRINT("Can't copy '" + static_lib_path + "'.");
  1465. return lib_copy_err;
  1466. }
  1467. }
  1468. }
  1469. String iconset_dir = dest_dir + binary_name + "/Images.xcassets/AppIcon.appiconset/";
  1470. err = OK;
  1471. if (!tmp_app_path->dir_exists(iconset_dir)) {
  1472. err = tmp_app_path->make_dir_recursive(iconset_dir);
  1473. }
  1474. if (err) {
  1475. return err;
  1476. }
  1477. err = _export_icons(p_preset, iconset_dir);
  1478. if (err) {
  1479. return err;
  1480. }
  1481. {
  1482. bool use_storyboard = p_preset->get("storyboard/use_launch_screen_storyboard");
  1483. String launch_image_path = dest_dir + binary_name + "/Images.xcassets/LaunchImage.launchimage/";
  1484. String splash_image_path = dest_dir + binary_name + "/Images.xcassets/SplashImage.imageset/";
  1485. Ref<DirAccess> launch_screen_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1486. if (launch_screen_da.is_null()) {
  1487. return ERR_CANT_CREATE;
  1488. }
  1489. if (use_storyboard) {
  1490. print_line("Using Launch Storyboard");
  1491. if (launch_screen_da->change_dir(launch_image_path) == OK) {
  1492. launch_screen_da->erase_contents_recursive();
  1493. launch_screen_da->remove(launch_image_path);
  1494. }
  1495. err = _export_loading_screen_file(p_preset, splash_image_path);
  1496. } else {
  1497. print_line("Using Launch Images");
  1498. const String launch_screen_path = dest_dir + binary_name + "/Launch Screen.storyboard";
  1499. launch_screen_da->remove(launch_screen_path);
  1500. if (launch_screen_da->change_dir(splash_image_path) == OK) {
  1501. launch_screen_da->erase_contents_recursive();
  1502. launch_screen_da->remove(splash_image_path);
  1503. }
  1504. err = _export_loading_screen_images(p_preset, launch_image_path);
  1505. }
  1506. }
  1507. if (err) {
  1508. return err;
  1509. }
  1510. print_line("Exporting additional assets");
  1511. _export_additional_assets(dest_dir + binary_name, libraries, assets);
  1512. _add_assets_to_project(p_preset, project_file_data, assets);
  1513. String project_file_name = dest_dir + binary_name + ".xcodeproj/project.pbxproj";
  1514. {
  1515. Ref<FileAccess> f = FileAccess::open(project_file_name, FileAccess::WRITE);
  1516. if (f.is_null()) {
  1517. ERR_PRINT("Can't write '" + project_file_name + "'.");
  1518. return ERR_CANT_CREATE;
  1519. };
  1520. f->store_buffer(project_file_data.ptr(), project_file_data.size());
  1521. }
  1522. #ifdef MACOS_ENABLED
  1523. {
  1524. if (ep.step("Code-signing dylibs", 2)) {
  1525. return ERR_SKIP;
  1526. }
  1527. Ref<DirAccess> dylibs_dir = DirAccess::open(dest_dir + binary_name + "/dylibs");
  1528. ERR_FAIL_COND_V(dylibs_dir.is_null(), ERR_CANT_OPEN);
  1529. CodesignData codesign_data(p_preset, p_debug);
  1530. err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data);
  1531. ERR_FAIL_COND_V(err, err);
  1532. }
  1533. if (ep.step("Making .xcarchive", 3)) {
  1534. return ERR_SKIP;
  1535. }
  1536. String archive_path = p_path.get_basename() + ".xcarchive";
  1537. List<String> archive_args;
  1538. archive_args.push_back("-project");
  1539. archive_args.push_back(dest_dir + binary_name + ".xcodeproj");
  1540. archive_args.push_back("-scheme");
  1541. archive_args.push_back(binary_name);
  1542. archive_args.push_back("-sdk");
  1543. archive_args.push_back("iphoneos");
  1544. archive_args.push_back("-configuration");
  1545. archive_args.push_back(p_debug ? "Debug" : "Release");
  1546. archive_args.push_back("-destination");
  1547. archive_args.push_back("generic/platform=iOS");
  1548. archive_args.push_back("archive");
  1549. archive_args.push_back("-allowProvisioningUpdates");
  1550. archive_args.push_back("-archivePath");
  1551. archive_args.push_back(archive_path);
  1552. String archive_str;
  1553. err = OS::get_singleton()->execute("xcodebuild", archive_args, &archive_str, nullptr, true);
  1554. ERR_FAIL_COND_V(err, err);
  1555. print_line("xcodebuild (.xcarchive):\n" + archive_str);
  1556. if (ep.step("Making .ipa", 4)) {
  1557. return ERR_SKIP;
  1558. }
  1559. List<String> export_args;
  1560. export_args.push_back("-exportArchive");
  1561. export_args.push_back("-archivePath");
  1562. export_args.push_back(archive_path);
  1563. export_args.push_back("-exportOptionsPlist");
  1564. export_args.push_back(dest_dir + binary_name + "/export_options.plist");
  1565. export_args.push_back("-allowProvisioningUpdates");
  1566. export_args.push_back("-exportPath");
  1567. export_args.push_back(dest_dir);
  1568. String export_str;
  1569. err = OS::get_singleton()->execute("xcodebuild", export_args, &export_str, nullptr, true);
  1570. ERR_FAIL_COND_V(err, err);
  1571. print_line("xcodebuild (.ipa):\n" + export_str);
  1572. #else
  1573. print_line(".ipa can only be built on macOS. Leaving Xcode project without building the package.");
  1574. #endif
  1575. return OK;
  1576. }
  1577. bool EditorExportPlatformIOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  1578. String err;
  1579. bool valid = false;
  1580. // Look for export templates (first official, and if defined custom templates).
  1581. bool dvalid = exists_export_template("ios.zip", &err);
  1582. bool rvalid = dvalid; // Both in the same ZIP.
  1583. if (p_preset->get("custom_template/debug") != "") {
  1584. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  1585. if (!dvalid) {
  1586. err += TTR("Custom debug template not found.") + "\n";
  1587. }
  1588. }
  1589. if (p_preset->get("custom_template/release") != "") {
  1590. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  1591. if (!rvalid) {
  1592. err += TTR("Custom release template not found.") + "\n";
  1593. }
  1594. }
  1595. valid = dvalid || rvalid;
  1596. r_missing_templates = !valid;
  1597. if (!err.is_empty()) {
  1598. r_error = err;
  1599. }
  1600. return valid;
  1601. }
  1602. bool EditorExportPlatformIOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  1603. String err;
  1604. bool valid = true;
  1605. // Validate the project configuration.
  1606. String team_id = p_preset->get("application/app_store_team_id");
  1607. if (team_id.length() == 0) {
  1608. err += TTR("App Store Team ID not specified - cannot configure the project.") + "\n";
  1609. valid = false;
  1610. }
  1611. String identifier = p_preset->get("application/bundle_identifier");
  1612. String pn_err;
  1613. if (!is_package_name_valid(identifier, &pn_err)) {
  1614. err += TTR("Invalid Identifier:") + " " + pn_err + "\n";
  1615. valid = false;
  1616. }
  1617. const String etc_error = test_etc2();
  1618. if (!etc_error.is_empty()) {
  1619. valid = false;
  1620. err += etc_error;
  1621. }
  1622. if (!err.is_empty()) {
  1623. r_error = err;
  1624. }
  1625. return valid;
  1626. }
  1627. EditorExportPlatformIOS::EditorExportPlatformIOS() {
  1628. logo = ImageTexture::create_from_image(memnew(Image(_ios_logo)));
  1629. plugins_changed.set();
  1630. #ifndef ANDROID_ENABLED
  1631. check_for_changes_thread.start(_check_for_changes_poll_thread, this);
  1632. #endif
  1633. }
  1634. EditorExportPlatformIOS::~EditorExportPlatformIOS() {
  1635. #ifndef ANDROID_ENABLED
  1636. quit_request.set();
  1637. check_for_changes_thread.wait_to_finish();
  1638. #endif
  1639. }