export_plugin.cpp 76 KB

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