export_plugin.cpp 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  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 "modules/modules_enabled.gen.h" // For regex.
  31. #include "codesign.h"
  32. #include "export_plugin.h"
  33. void EditorExportPlatformOSX::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
  34. if (p_preset->get("texture_format/s3tc")) {
  35. r_features->push_back("s3tc");
  36. }
  37. if (p_preset->get("texture_format/etc")) {
  38. r_features->push_back("etc");
  39. }
  40. if (p_preset->get("texture_format/etc2")) {
  41. r_features->push_back("etc2");
  42. }
  43. r_features->push_back("64");
  44. }
  45. void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) {
  46. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  47. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  48. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
  49. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/info"), "Made with Godot Engine"));
  50. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.png,*.icns"), ""));
  51. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), ""));
  52. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  53. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_category", PROPERTY_HINT_ENUM, "Business,Developer-tools,Education,Entertainment,Finance,Games,Action-games,Adventure-games,Arcade-games,Board-games,Card-games,Casino-games,Dice-games,Educational-games,Family-games,Kids-games,Music-games,Puzzle-games,Racing-games,Role-playing-games,Simulation-games,Sports-games,Strategy-games,Trivia-games,Word-games,Graphics-design,Healthcare-fitness,Lifestyle,Medical,Music,News,Photography,Productivity,Reference,Social-networking,Sports,Travel,Utilities,Video,Weather"), "Games"));
  54. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
  55. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
  56. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
  57. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), false));
  58. 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"), ""));
  59. 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"), ""));
  60. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/location_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the location information"), ""));
  61. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/address_book_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the address book"), ""));
  62. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/calendar_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the calendar"), ""));
  63. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/photos_library_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the photo library"), ""));
  64. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/desktop_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Desktop folder"), ""));
  65. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/documents_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Documents folder"), ""));
  66. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/downloads_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Downloads folder"), ""));
  67. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/network_volumes_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use network volumes"), ""));
  68. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/removable_volumes_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use removable volumes"), ""));
  69. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/enable"), true));
  70. #ifdef OSX_ENABLED
  71. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), ""));
  72. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/timestamp"), true));
  73. #endif
  74. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/replace_existing_signature"), true));
  75. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/hardened_runtime"), true));
  76. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/custom_file", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), ""));
  77. if (!Engine::get_singleton()->has_singleton("GodotSharp")) {
  78. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  79. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false));
  80. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false));
  81. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false));
  82. }
  83. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/disable_library_validation"), false));
  84. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/audio_input"), false));
  85. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/camera"), false));
  86. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/location"), false));
  87. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/address_book"), false));
  88. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/calendars"), false));
  89. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/photos_library"), false));
  90. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/apple_events"), false));
  91. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/debugging"), false));
  92. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/enabled"), false));
  93. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_server"), false));
  94. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_client"), false));
  95. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_usb"), false));
  96. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_bluetooth"), false));
  97. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_downloads", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  98. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_pictures", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  99. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_music", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  100. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_movies", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  101. r_options->push_back(ExportOption(PropertyInfo(Variant::ARRAY, "codesign/entitlements/app_sandbox/helper_executables", PROPERTY_HINT_ARRAY_TYPE, itos(Variant::STRING) + "/" + itos(PROPERTY_HINT_GLOBAL_FILE) + ":"), Array()));
  102. #ifdef OSX_ENABLED
  103. r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));
  104. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "notarization/enable"), false));
  105. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple ID email"), ""));
  106. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_password", PROPERTY_HINT_PLACEHOLDER_TEXT, "Enable two-factor authentication and provide app-specific password"), ""));
  107. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_team_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide team ID if your Apple ID belongs to multiple teams"), ""));
  108. #endif
  109. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
  110. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
  111. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
  112. }
  113. void _rgba8_to_packbits_encode(int p_ch, int p_size, Vector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {
  114. int src_len = p_size * p_size;
  115. Vector<uint8_t> result;
  116. result.resize(src_len * 1.25); //temp vector for rle encoded data, make it 25% larger for worst case scenario
  117. int res_size = 0;
  118. uint8_t buf[128];
  119. int buf_size = 0;
  120. int i = 0;
  121. while (i < src_len) {
  122. uint8_t cur = p_source.ptr()[i * 4 + p_ch];
  123. if (i < src_len - 2) {
  124. if ((p_source.ptr()[(i + 1) * 4 + p_ch] == cur) && (p_source.ptr()[(i + 2) * 4 + p_ch] == cur)) {
  125. if (buf_size > 0) {
  126. result.write[res_size++] = (uint8_t)(buf_size - 1);
  127. memcpy(&result.write[res_size], &buf, buf_size);
  128. res_size += buf_size;
  129. buf_size = 0;
  130. }
  131. uint8_t lim = i + 130 >= src_len ? src_len - i - 1 : 130;
  132. bool hit_lim = true;
  133. for (int j = 3; j <= lim; j++) {
  134. if (p_source.ptr()[(i + j) * 4 + p_ch] != cur) {
  135. hit_lim = false;
  136. i = i + j - 1;
  137. result.write[res_size++] = (uint8_t)(j - 3 + 0x80);
  138. result.write[res_size++] = cur;
  139. break;
  140. }
  141. }
  142. if (hit_lim) {
  143. result.write[res_size++] = (uint8_t)(lim - 3 + 0x80);
  144. result.write[res_size++] = cur;
  145. i = i + lim;
  146. }
  147. } else {
  148. buf[buf_size++] = cur;
  149. if (buf_size == 128) {
  150. result.write[res_size++] = (uint8_t)(buf_size - 1);
  151. memcpy(&result.write[res_size], &buf, buf_size);
  152. res_size += buf_size;
  153. buf_size = 0;
  154. }
  155. }
  156. } else {
  157. buf[buf_size++] = cur;
  158. result.write[res_size++] = (uint8_t)(buf_size - 1);
  159. memcpy(&result.write[res_size], &buf, buf_size);
  160. res_size += buf_size;
  161. buf_size = 0;
  162. }
  163. i++;
  164. }
  165. int ofs = p_dest.size();
  166. p_dest.resize(p_dest.size() + res_size);
  167. memcpy(&p_dest.write[ofs], result.ptr(), res_size);
  168. }
  169. void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {
  170. Ref<ImageTexture> it = memnew(ImageTexture);
  171. Vector<uint8_t> data;
  172. data.resize(8);
  173. data.write[0] = 'i';
  174. data.write[1] = 'c';
  175. data.write[2] = 'n';
  176. data.write[3] = 's';
  177. struct MacOSIconInfo {
  178. const char *name;
  179. const char *mask_name;
  180. bool is_png;
  181. int size;
  182. };
  183. static const MacOSIconInfo icon_infos[] = {
  184. { "ic10", "", true, 1024 }, //1024×1024 32-bit PNG and 512×512@2x 32-bit "retina" PNG
  185. { "ic09", "", true, 512 }, //512×512 32-bit PNG
  186. { "ic14", "", true, 512 }, //256×256@2x 32-bit "retina" PNG
  187. { "ic08", "", true, 256 }, //256×256 32-bit PNG
  188. { "ic13", "", true, 256 }, //128×128@2x 32-bit "retina" PNG
  189. { "ic07", "", true, 128 }, //128×128 32-bit PNG
  190. { "ic12", "", true, 64 }, //32×32@2× 32-bit "retina" PNG
  191. { "ic11", "", true, 32 }, //16×16@2× 32-bit "retina" PNG
  192. { "il32", "l8mk", false, 32 }, //32×32 24-bit RLE + 8-bit uncompressed mask
  193. { "is32", "s8mk", false, 16 } //16×16 24-bit RLE + 8-bit uncompressed mask
  194. };
  195. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  196. Ref<Image> copy = p_icon; // does this make sense? doesn't this just increase the reference count instead of making a copy? Do we even need a copy?
  197. copy->convert(Image::FORMAT_RGBA8);
  198. copy->resize(icon_infos[i].size, icon_infos[i].size);
  199. if (icon_infos[i].is_png) {
  200. // Encode PNG icon.
  201. it->create_from_image(copy);
  202. String path = EditorPaths::get_singleton()->get_cache_dir().plus_file("icon.png");
  203. ResourceSaver::save(path, it);
  204. FileAccess *f = FileAccess::open(path, FileAccess::READ);
  205. if (!f) {
  206. // Clean up generated file.
  207. DirAccess::remove_file_or_error(path);
  208. ERR_FAIL();
  209. }
  210. int ofs = data.size();
  211. uint64_t len = f->get_length();
  212. data.resize(data.size() + len + 8);
  213. f->get_buffer(&data.write[ofs + 8], len);
  214. memdelete(f);
  215. len += 8;
  216. len = BSWAP32(len);
  217. memcpy(&data.write[ofs], icon_infos[i].name, 4);
  218. encode_uint32(len, &data.write[ofs + 4]);
  219. // Clean up generated file.
  220. DirAccess::remove_file_or_error(path);
  221. } else {
  222. Vector<uint8_t> src_data = copy->get_data();
  223. //encode 24bit RGB RLE icon
  224. {
  225. int ofs = data.size();
  226. data.resize(data.size() + 8);
  227. _rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data); // encode R
  228. _rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data); // encode G
  229. _rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data); // encode B
  230. int len = data.size() - ofs;
  231. len = BSWAP32(len);
  232. memcpy(&data.write[ofs], icon_infos[i].name, 4);
  233. encode_uint32(len, &data.write[ofs + 4]);
  234. }
  235. //encode 8bit mask uncompressed icon
  236. {
  237. int ofs = data.size();
  238. int len = copy->get_width() * copy->get_height();
  239. data.resize(data.size() + len + 8);
  240. for (int j = 0; j < len; j++) {
  241. data.write[ofs + 8 + j] = src_data.ptr()[j * 4 + 3];
  242. }
  243. len += 8;
  244. len = BSWAP32(len);
  245. memcpy(&data.write[ofs], icon_infos[i].mask_name, 4);
  246. encode_uint32(len, &data.write[ofs + 4]);
  247. }
  248. }
  249. }
  250. uint32_t total_len = data.size();
  251. total_len = BSWAP32(total_len);
  252. encode_uint32(total_len, &data.write[4]);
  253. p_data = data;
  254. }
  255. void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary) {
  256. String str;
  257. String strnew;
  258. str.parse_utf8((const char *)plist.ptr(), plist.size());
  259. Vector<String> lines = str.split("\n");
  260. for (int i = 0; i < lines.size(); i++) {
  261. if (lines[i].find("$binary") != -1) {
  262. strnew += lines[i].replace("$binary", p_binary) + "\n";
  263. } else if (lines[i].find("$name") != -1) {
  264. strnew += lines[i].replace("$name", p_binary) + "\n";
  265. } else if (lines[i].find("$info") != -1) {
  266. strnew += lines[i].replace("$info", p_preset->get("application/info")) + "\n";
  267. } else if (lines[i].find("$bundle_identifier") != -1) {
  268. strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
  269. } else if (lines[i].find("$short_version") != -1) {
  270. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  271. } else if (lines[i].find("$version") != -1) {
  272. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  273. } else if (lines[i].find("$signature") != -1) {
  274. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  275. } else if (lines[i].find("$app_category") != -1) {
  276. String cat = p_preset->get("application/app_category");
  277. strnew += lines[i].replace("$app_category", cat.to_lower()) + "\n";
  278. } else if (lines[i].find("$copyright") != -1) {
  279. strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
  280. } else if (lines[i].find("$highres") != -1) {
  281. strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "\t<true/>" : "\t<false/>") + "\n";
  282. } else if (lines[i].find("$usage_descriptions") != -1) {
  283. String descriptions;
  284. if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
  285. descriptions += "\t<key>NSMicrophoneUsageDescription</key>\n";
  286. descriptions += "\t<string>" + (String)p_preset->get("privacy/microphone_usage_description") + "</string>\n";
  287. }
  288. if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
  289. descriptions += "\t<key>NSCameraUsageDescription</key>\n";
  290. descriptions += "\t<string>" + (String)p_preset->get("privacy/camera_usage_description") + "</string>\n";
  291. }
  292. if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
  293. descriptions += "\t<key>NSLocationUsageDescription</key>\n";
  294. descriptions += "\t<string>" + (String)p_preset->get("privacy/location_usage_description") + "</string>\n";
  295. }
  296. if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
  297. descriptions += "\t<key>NSContactsUsageDescription</key>\n";
  298. descriptions += "\t<string>" + (String)p_preset->get("privacy/address_book_usage_description") + "</string>\n";
  299. }
  300. if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
  301. descriptions += "\t<key>NSCalendarsUsageDescription</key>\n";
  302. descriptions += "\t<string>" + (String)p_preset->get("privacy/calendar_usage_description") + "</string>\n";
  303. }
  304. if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
  305. descriptions += "\t<key>NSPhotoLibraryUsageDescription</key>\n";
  306. descriptions += "\t<string>" + (String)p_preset->get("privacy/photos_library_usage_description") + "</string>\n";
  307. }
  308. if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {
  309. descriptions += "\t<key>NSDesktopFolderUsageDescription</key>\n";
  310. descriptions += "\t<string>" + (String)p_preset->get("privacy/desktop_folder_usage_description") + "</string>\n";
  311. }
  312. if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {
  313. descriptions += "\t<key>NSDocumentsFolderUsageDescription</key>\n";
  314. descriptions += "\t<string>" + (String)p_preset->get("privacy/documents_folder_usage_description") + "</string>\n";
  315. }
  316. if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {
  317. descriptions += "\t<key>NSDownloadsFolderUsageDescription</key>\n";
  318. descriptions += "\t<string>" + (String)p_preset->get("privacy/downloads_folder_usage_description") + "</string>\n";
  319. }
  320. if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {
  321. descriptions += "\t<key>NSNetworkVolumesUsageDescription</key>\n";
  322. descriptions += "\t<string>" + (String)p_preset->get("privacy/network_volumes_usage_description") + "</string>\n";
  323. }
  324. if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {
  325. descriptions += "\t<key>NSRemovableVolumesUsageDescription</key>\n";
  326. descriptions += "\t<string>" + (String)p_preset->get("privacy/removable_volumes_usage_description") + "</string>\n";
  327. }
  328. if (!descriptions.is_empty()) {
  329. strnew += lines[i].replace("$usage_descriptions", descriptions);
  330. }
  331. } else {
  332. strnew += lines[i] + "\n";
  333. }
  334. }
  335. CharString cs = strnew.utf8();
  336. plist.resize(cs.size() - 1);
  337. for (int i = 0; i < cs.size() - 1; i++) {
  338. plist.write[i] = cs[i];
  339. }
  340. }
  341. /**
  342. * If we're running the OSX version of the Godot editor we'll:
  343. * - export our application bundle to a temporary folder
  344. * - attempt to code sign it
  345. * - and then wrap it up in a DMG
  346. */
  347. Error EditorExportPlatformOSX::_notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
  348. #ifdef OSX_ENABLED
  349. List<String> args;
  350. args.push_back("altool");
  351. args.push_back("--notarize-app");
  352. args.push_back("--primary-bundle-id");
  353. args.push_back(p_preset->get("application/bundle_identifier"));
  354. args.push_back("--username");
  355. args.push_back(p_preset->get("notarization/apple_id_name"));
  356. args.push_back("--password");
  357. args.push_back(p_preset->get("notarization/apple_id_password"));
  358. args.push_back("--type");
  359. args.push_back("osx");
  360. if (p_preset->get("notarization/apple_team_id")) {
  361. args.push_back("--asc-provider");
  362. args.push_back(p_preset->get("notarization/apple_team_id"));
  363. }
  364. args.push_back("--file");
  365. args.push_back(p_path);
  366. String str;
  367. Error err = OS::get_singleton()->execute("xcrun", args, &str, nullptr, true);
  368. ERR_FAIL_COND_V(err != OK, err);
  369. print_verbose("altool (" + p_path + "):\n" + str);
  370. if (str.find("RequestUUID") == -1) {
  371. EditorNode::add_io_error("altool: " + str);
  372. return FAILED;
  373. } else {
  374. print_line(TTR("Note: The notarization process generally takes less than an hour. When the process is completed, you'll receive an email."));
  375. print_line(" " + TTR("You can check progress manually by opening a Terminal and running the following command:"));
  376. print_line(" \"xcrun altool --notarization-history 0 -u <your email> -p <app-specific pwd>\"");
  377. print_line(" " + TTR("Run the following command to staple notarization ticket to the exported application (optional):"));
  378. print_line(" \"xcrun stapler staple <app path>\"");
  379. }
  380. #endif
  381. return OK;
  382. }
  383. Error EditorExportPlatformOSX::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path) {
  384. bool force_builtin_codesign = EditorSettings::get_singleton()->get("export/macos/force_builtin_codesign");
  385. bool ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  386. if ((!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) || force_builtin_codesign) {
  387. print_verbose("using built-in codesign...");
  388. #ifdef MODULE_REGEX_ENABLED
  389. if (p_preset->get("codesign/timestamp")) {
  390. WARN_PRINT("Timestamping is not compatible with ad-hoc signature, and was disabled!");
  391. }
  392. if (p_preset->get("codesign/hardened_runtime")) {
  393. WARN_PRINT("Hardened Runtime is not compatible with ad-hoc signature, and was disabled!");
  394. }
  395. String error_msg;
  396. Error err = CodeSign::codesign(false, p_preset->get("codesign/replace_existing_signature"), p_path, p_ent_path, error_msg);
  397. if (err != OK) {
  398. EditorNode::add_io_error("Built-in CodeSign: " + error_msg);
  399. return FAILED;
  400. }
  401. #else
  402. ERR_FAIL_V_MSG(FAILED, "Built-in CodeSign require regex module");
  403. #endif
  404. return OK;
  405. } else {
  406. print_verbose("using external codesign...");
  407. List<String> args;
  408. if (p_preset->get("codesign/timestamp")) {
  409. if (ad_hoc) {
  410. WARN_PRINT("Timestamping is not compatible with ad-hoc signature, and was disabled!");
  411. } else {
  412. args.push_back("--timestamp");
  413. }
  414. }
  415. if (p_preset->get("codesign/hardened_runtime")) {
  416. if (ad_hoc) {
  417. WARN_PRINT("Hardened Runtime is not compatible with ad-hoc signature, and was disabled!");
  418. } else {
  419. args.push_back("--options");
  420. args.push_back("runtime");
  421. }
  422. }
  423. if (p_path.get_extension() != "dmg") {
  424. args.push_back("--entitlements");
  425. args.push_back(p_ent_path);
  426. }
  427. PackedStringArray user_args = p_preset->get("codesign/custom_options");
  428. for (int i = 0; i < user_args.size(); i++) {
  429. String user_arg = user_args[i].strip_edges();
  430. if (!user_arg.is_empty()) {
  431. args.push_back(user_arg);
  432. }
  433. }
  434. args.push_back("-s");
  435. if (ad_hoc) {
  436. args.push_back("-");
  437. } else {
  438. args.push_back(p_preset->get("codesign/identity"));
  439. }
  440. args.push_back("-v"); /* provide some more feedback */
  441. if (p_preset->get("codesign/replace_existing_signature")) {
  442. args.push_back("-f");
  443. }
  444. args.push_back(p_path);
  445. String str;
  446. Error err = OS::get_singleton()->execute("codesign", args, &str, nullptr, true);
  447. ERR_FAIL_COND_V(err != OK, err);
  448. print_verbose("codesign (" + p_path + "):\n" + str);
  449. if (str.find("no identity found") != -1) {
  450. EditorNode::add_io_error("CodeSign: " + TTR("No identity found."));
  451. return FAILED;
  452. }
  453. if ((str.find("unrecognized blob type") != -1) || (str.find("cannot read entitlement data") != -1)) {
  454. EditorNode::add_io_error("CodeSign: " + TTR("Invalid entitlements file."));
  455. return FAILED;
  456. }
  457. return OK;
  458. }
  459. }
  460. Error EditorExportPlatformOSX::_code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path,
  461. const String &p_ent_path, bool p_should_error_on_non_code) {
  462. #ifdef OSX_ENABLED
  463. static Vector<String> extensions_to_sign;
  464. if (extensions_to_sign.is_empty()) {
  465. extensions_to_sign.push_back("dylib");
  466. extensions_to_sign.push_back("framework");
  467. }
  468. Error dir_access_error;
  469. DirAccessRef dir_access{ DirAccess::open(p_path, &dir_access_error) };
  470. if (dir_access_error != OK) {
  471. return dir_access_error;
  472. }
  473. dir_access->list_dir_begin();
  474. String current_file{ dir_access->get_next() };
  475. while (!current_file.is_empty()) {
  476. String current_file_path{ p_path.plus_file(current_file) };
  477. if (current_file == ".." || current_file == ".") {
  478. current_file = dir_access->get_next();
  479. continue;
  480. }
  481. if (extensions_to_sign.find(current_file.get_extension()) > -1) {
  482. Error code_sign_error{ _code_sign(p_preset, current_file_path, p_ent_path) };
  483. if (code_sign_error != OK) {
  484. return code_sign_error;
  485. }
  486. } else if (dir_access->current_is_dir()) {
  487. Error code_sign_error{ _code_sign_directory(p_preset, current_file_path, p_ent_path, p_should_error_on_non_code) };
  488. if (code_sign_error != OK) {
  489. return code_sign_error;
  490. }
  491. } else if (p_should_error_on_non_code) {
  492. ERR_PRINT(vformat("Cannot sign file %s.", current_file));
  493. return Error::FAILED;
  494. }
  495. current_file = dir_access->get_next();
  496. }
  497. #endif
  498. return OK;
  499. }
  500. Error EditorExportPlatformOSX::_copy_and_sign_files(DirAccessRef &dir_access, const String &p_src_path,
  501. const String &p_in_app_path, bool p_sign_enabled,
  502. const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,
  503. bool p_should_error_on_non_code_sign) {
  504. Error err{ OK };
  505. if (dir_access->dir_exists(p_src_path)) {
  506. #ifndef UNIX_ENABLED
  507. WARN_PRINT("Relative symlinks are not supported, exported " + p_src_path.get_file() + " might be broken!");
  508. #endif
  509. print_verbose("export framework: " + p_src_path + " -> " + p_in_app_path);
  510. err = dir_access->make_dir_recursive(p_in_app_path);
  511. if (err == OK) {
  512. err = dir_access->copy_dir(p_src_path, p_in_app_path, -1, true);
  513. }
  514. } else {
  515. print_verbose("export dylib: " + p_src_path + " -> " + p_in_app_path);
  516. err = dir_access->copy(p_src_path, p_in_app_path);
  517. }
  518. if (err == OK && p_sign_enabled) {
  519. if (dir_access->dir_exists(p_src_path) && p_src_path.get_extension().is_empty()) {
  520. // If it is a directory, find and sign all dynamic libraries.
  521. err = _code_sign_directory(p_preset, p_in_app_path, p_ent_path, p_should_error_on_non_code_sign);
  522. } else {
  523. err = _code_sign(p_preset, p_in_app_path, p_ent_path);
  524. }
  525. }
  526. return err;
  527. }
  528. Error EditorExportPlatformOSX::_export_osx_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin,
  529. const String &p_app_path_name, DirAccessRef &dir_access,
  530. bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,
  531. const String &p_ent_path) {
  532. Error error{ OK };
  533. const Vector<String> &osx_plugins{ p_editor_export_plugin->get_osx_plugin_files() };
  534. for (int i = 0; i < osx_plugins.size(); ++i) {
  535. String src_path{ ProjectSettings::get_singleton()->globalize_path(osx_plugins[i]) };
  536. String path_in_app{ p_app_path_name + "/Contents/PlugIns/" + src_path.get_file() };
  537. error = _copy_and_sign_files(dir_access, src_path, path_in_app, p_sign_enabled, p_preset, p_ent_path, false);
  538. if (error != OK) {
  539. break;
  540. }
  541. }
  542. return error;
  543. }
  544. Error EditorExportPlatformOSX::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {
  545. List<String> args;
  546. if (FileAccess::exists(p_dmg_path)) {
  547. OS::get_singleton()->move_to_trash(p_dmg_path);
  548. }
  549. args.push_back("create");
  550. args.push_back(p_dmg_path);
  551. args.push_back("-volname");
  552. args.push_back(p_pkg_name);
  553. args.push_back("-fs");
  554. args.push_back("HFS+");
  555. args.push_back("-srcfolder");
  556. args.push_back(p_app_path_name);
  557. String str;
  558. Error err = OS::get_singleton()->execute("hdiutil", args, &str, nullptr, true);
  559. ERR_FAIL_COND_V(err != OK, err);
  560. print_verbose("hdiutil returned: " + str);
  561. if (str.find("create failed") != -1) {
  562. if (str.find("File exists") != -1) {
  563. EditorNode::add_io_error("hdiutil: " + TTR("DMG creation failed, file already exists."));
  564. } else {
  565. EditorNode::add_io_error("hdiutil: " + TTR("DMG create failed."));
  566. }
  567. return FAILED;
  568. }
  569. return OK;
  570. }
  571. Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  572. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  573. String src_pkg_name;
  574. EditorProgress ep("export", "Exporting for OSX", 3, true);
  575. if (p_debug) {
  576. src_pkg_name = p_preset->get("custom_template/debug");
  577. } else {
  578. src_pkg_name = p_preset->get("custom_template/release");
  579. }
  580. if (src_pkg_name.is_empty()) {
  581. String err;
  582. src_pkg_name = find_export_template("osx.zip", &err);
  583. if (src_pkg_name.is_empty()) {
  584. EditorNode::add_io_error(err);
  585. return ERR_FILE_NOT_FOUND;
  586. }
  587. }
  588. if (!DirAccess::exists(p_path.get_base_dir())) {
  589. return ERR_FILE_BAD_PATH;
  590. }
  591. FileAccess *src_f = nullptr;
  592. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  593. if (ep.step(TTR("Creating app bundle"), 0)) {
  594. return ERR_SKIP;
  595. }
  596. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  597. if (!src_pkg_zip) {
  598. EditorNode::add_io_error(TTR("Could not find template app to export:") + "\n" + src_pkg_name);
  599. return ERR_FILE_NOT_FOUND;
  600. }
  601. int ret = unzGoToFirstFile(src_pkg_zip);
  602. String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + ".64";
  603. String pkg_name;
  604. if (p_preset->get("application/name") != "") {
  605. pkg_name = p_preset->get("application/name"); // app_name
  606. } else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") {
  607. pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
  608. } else {
  609. pkg_name = "Unnamed";
  610. }
  611. pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
  612. String export_format;
  613. if (use_dmg() && p_path.ends_with("dmg")) {
  614. export_format = "dmg";
  615. } else if (p_path.ends_with("zip")) {
  616. export_format = "zip";
  617. } else if (p_path.ends_with("app")) {
  618. export_format = "app";
  619. } else {
  620. EditorNode::add_io_error("Invalid export format");
  621. return ERR_CANT_CREATE;
  622. }
  623. // Create our application bundle.
  624. String tmp_app_dir_name = pkg_name + ".app";
  625. String tmp_app_path_name;
  626. if (export_format == "app") {
  627. tmp_app_path_name = p_path;
  628. } else {
  629. tmp_app_path_name = EditorPaths::get_singleton()->get_cache_dir().plus_file(tmp_app_dir_name);
  630. }
  631. print_verbose("Exporting to " + tmp_app_path_name);
  632. Error err = OK;
  633. DirAccessRef tmp_app_dir = DirAccess::create_for_path(tmp_app_path_name);
  634. if (!tmp_app_dir) {
  635. err = ERR_CANT_CREATE;
  636. }
  637. if (DirAccess::exists(tmp_app_dir_name)) {
  638. if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) {
  639. tmp_app_dir->erase_contents_recursive();
  640. }
  641. }
  642. Array helpers = p_preset->get("codesign/entitlements/app_sandbox/helper_executables");
  643. // Create our folder structure.
  644. if (err == OK) {
  645. print_verbose("Creating " + tmp_app_path_name + "/Contents/MacOS");
  646. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
  647. }
  648. if (err == OK) {
  649. print_verbose("Creating " + tmp_app_path_name + "/Contents/Frameworks");
  650. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");
  651. }
  652. if ((err == OK) && helpers.size() > 0) {
  653. print_line("Creating " + tmp_app_path_name + "/Contents/Helpers");
  654. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Helpers");
  655. }
  656. if (err == OK) {
  657. print_verbose("Creating " + tmp_app_path_name + "/Contents/Resources");
  658. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
  659. }
  660. // Now process our template.
  661. bool found_binary = false;
  662. Vector<String> dylibs_found;
  663. while (ret == UNZ_OK && err == OK) {
  664. bool is_execute = false;
  665. // Get filename.
  666. unz_file_info info;
  667. char fname[16384];
  668. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  669. String file = String::utf8(fname);
  670. Vector<uint8_t> data;
  671. data.resize(info.uncompressed_size);
  672. // Read.
  673. unzOpenCurrentFile(src_pkg_zip);
  674. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  675. unzCloseCurrentFile(src_pkg_zip);
  676. // Write.
  677. file = file.replace_first("osx_template.app/", "");
  678. if (((info.external_fa >> 16L) & 0120000) == 0120000) {
  679. #ifndef UNIX_ENABLED
  680. WARN_PRINT(vformat("Relative symlinks are not supported on this OS, exported project might be broken!"));
  681. #endif
  682. // Handle symlinks in the archive.
  683. file = tmp_app_path_name.plus_file(file);
  684. if (err == OK) {
  685. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  686. }
  687. if (err == OK) {
  688. String lnk_data = String::utf8((const char *)data.ptr(), data.size());
  689. err = tmp_app_dir->create_link(lnk_data, file);
  690. print_verbose(vformat("ADDING SYMLINK %s => %s\n", file, lnk_data));
  691. }
  692. ret = unzGoToNextFile(src_pkg_zip);
  693. continue; // next
  694. }
  695. if (file == "Contents/Info.plist") {
  696. _fix_plist(p_preset, data, pkg_name);
  697. }
  698. if (file.begins_with("Contents/MacOS/godot_")) {
  699. if (file != "Contents/MacOS/" + binary_to_use) {
  700. ret = unzGoToNextFile(src_pkg_zip);
  701. continue; // skip
  702. }
  703. found_binary = true;
  704. is_execute = true;
  705. file = "Contents/MacOS/" + pkg_name;
  706. }
  707. if (file == "Contents/Resources/icon.icns") {
  708. // See if there is an icon.
  709. String iconpath;
  710. if (p_preset->get("application/icon") != "") {
  711. iconpath = p_preset->get("application/icon");
  712. } else {
  713. iconpath = ProjectSettings::get_singleton()->get("application/config/icon");
  714. }
  715. if (!iconpath.is_empty()) {
  716. if (iconpath.get_extension() == "icns") {
  717. FileAccess *icon = FileAccess::open(iconpath, FileAccess::READ);
  718. if (icon) {
  719. data.resize(icon->get_length());
  720. icon->get_buffer(&data.write[0], icon->get_length());
  721. icon->close();
  722. memdelete(icon);
  723. }
  724. } else {
  725. Ref<Image> icon;
  726. icon.instantiate();
  727. icon->load(iconpath);
  728. if (!icon->is_empty()) {
  729. _make_icon(icon, data);
  730. }
  731. }
  732. }
  733. }
  734. if (data.size() > 0) {
  735. if (file.find("/data.mono.osx.64.release_debug/") != -1) {
  736. if (!p_debug) {
  737. ret = unzGoToNextFile(src_pkg_zip);
  738. continue; // skip
  739. }
  740. file = file.replace("/data.mono.osx.64.release_debug/", "/GodotSharp/");
  741. }
  742. if (file.find("/data.mono.osx.64.release/") != -1) {
  743. if (p_debug) {
  744. ret = unzGoToNextFile(src_pkg_zip);
  745. continue; // skip
  746. }
  747. file = file.replace("/data.mono.osx.64.release/", "/GodotSharp/");
  748. }
  749. if (file.ends_with(".dylib")) {
  750. dylibs_found.push_back(file);
  751. }
  752. print_verbose("ADDING: " + file + " size: " + itos(data.size()));
  753. // Write it into our application bundle.
  754. file = tmp_app_path_name.plus_file(file);
  755. if (err == OK) {
  756. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  757. }
  758. if (err == OK) {
  759. FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
  760. if (f) {
  761. f->store_buffer(data.ptr(), data.size());
  762. f->close();
  763. if (is_execute) {
  764. // chmod with 0755 if the file is executable.
  765. FileAccess::set_unix_permissions(file, 0755);
  766. }
  767. memdelete(f);
  768. } else {
  769. err = ERR_CANT_CREATE;
  770. }
  771. }
  772. }
  773. ret = unzGoToNextFile(src_pkg_zip);
  774. }
  775. // We're done with our source zip.
  776. unzClose(src_pkg_zip);
  777. if (!found_binary) {
  778. ERR_PRINT(vformat("Requested template binary '%s' not found. It might be missing from your template archive.", binary_to_use));
  779. err = ERR_FILE_NOT_FOUND;
  780. }
  781. if (err == OK) {
  782. if (ep.step(TTR("Making PKG"), 1)) {
  783. return ERR_SKIP;
  784. }
  785. String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
  786. Vector<SharedObject> shared_objects;
  787. err = save_pack(p_preset, pack_path, &shared_objects);
  788. // See if we can code sign our new package.
  789. bool sign_enabled = p_preset->get("codesign/enable");
  790. String ent_path = p_preset->get("codesign/entitlements/custom_file");
  791. String hlp_ent_path = EditorPaths::get_singleton()->get_cache_dir().plus_file(pkg_name + "_helper.entitlements");
  792. if (sign_enabled && (ent_path.is_empty())) {
  793. ent_path = EditorPaths::get_singleton()->get_cache_dir().plus_file(pkg_name + ".entitlements");
  794. FileAccess *ent_f = FileAccess::open(ent_path, FileAccess::WRITE);
  795. if (ent_f) {
  796. ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  797. ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  798. ent_f->store_line("<plist version=\"1.0\">");
  799. ent_f->store_line("<dict>");
  800. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  801. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  802. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  803. ent_f->store_line("<true/>");
  804. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  805. ent_f->store_line("<true/>");
  806. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  807. ent_f->store_line("<true/>");
  808. } else {
  809. if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) {
  810. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  811. ent_f->store_line("<true/>");
  812. }
  813. if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) {
  814. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  815. ent_f->store_line("<true/>");
  816. }
  817. if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) {
  818. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  819. ent_f->store_line("<true/>");
  820. }
  821. }
  822. if ((bool)p_preset->get("codesign/entitlements/disable_library_validation")) {
  823. ent_f->store_line("<key>com.apple.security.cs.disable-library-validation</key>");
  824. ent_f->store_line("<true/>");
  825. }
  826. if ((bool)p_preset->get("codesign/entitlements/audio_input")) {
  827. ent_f->store_line("<key>com.apple.security.device.audio-input</key>");
  828. ent_f->store_line("<true/>");
  829. }
  830. if ((bool)p_preset->get("codesign/entitlements/camera")) {
  831. ent_f->store_line("<key>com.apple.security.device.camera</key>");
  832. ent_f->store_line("<true/>");
  833. }
  834. if ((bool)p_preset->get("codesign/entitlements/location")) {
  835. ent_f->store_line("<key>com.apple.security.personal-information.location</key>");
  836. ent_f->store_line("<true/>");
  837. }
  838. if ((bool)p_preset->get("codesign/entitlements/address_book")) {
  839. ent_f->store_line("<key>com.apple.security.personal-information.addressbook</key>");
  840. ent_f->store_line("<true/>");
  841. }
  842. if ((bool)p_preset->get("codesign/entitlements/calendars")) {
  843. ent_f->store_line("<key>com.apple.security.personal-information.calendars</key>");
  844. ent_f->store_line("<true/>");
  845. }
  846. if ((bool)p_preset->get("codesign/entitlements/photos_library")) {
  847. ent_f->store_line("<key>com.apple.security.personal-information.photos-library</key>");
  848. ent_f->store_line("<true/>");
  849. }
  850. if ((bool)p_preset->get("codesign/entitlements/apple_events")) {
  851. ent_f->store_line("<key>com.apple.security.automation.apple-events</key>");
  852. ent_f->store_line("<true/>");
  853. }
  854. if ((bool)p_preset->get("codesign/entitlements/debugging")) {
  855. ent_f->store_line("<key>com.apple.security.get-task-allow</key>");
  856. ent_f->store_line("<true/>");
  857. }
  858. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/enabled")) {
  859. ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
  860. ent_f->store_line("<true/>");
  861. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_server")) {
  862. ent_f->store_line("<key>com.apple.security.network.server</key>");
  863. ent_f->store_line("<true/>");
  864. }
  865. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_client")) {
  866. ent_f->store_line("<key>com.apple.security.network.client</key>");
  867. ent_f->store_line("<true/>");
  868. }
  869. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_usb")) {
  870. ent_f->store_line("<key>com.apple.security.device.usb</key>");
  871. ent_f->store_line("<true/>");
  872. }
  873. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_bluetooth")) {
  874. ent_f->store_line("<key>com.apple.security.device.bluetooth</key>");
  875. ent_f->store_line("<true/>");
  876. }
  877. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 1) {
  878. ent_f->store_line("<key>com.apple.security.files.downloads.read-only</key>");
  879. ent_f->store_line("<true/>");
  880. }
  881. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 2) {
  882. ent_f->store_line("<key>com.apple.security.files.downloads.read-write</key>");
  883. ent_f->store_line("<true/>");
  884. }
  885. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 1) {
  886. ent_f->store_line("<key>com.apple.security.files.pictures.read-only</key>");
  887. ent_f->store_line("<true/>");
  888. }
  889. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 2) {
  890. ent_f->store_line("<key>com.apple.security.files.pictures.read-write</key>");
  891. ent_f->store_line("<true/>");
  892. }
  893. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 1) {
  894. ent_f->store_line("<key>com.apple.security.files.music.read-only</key>");
  895. ent_f->store_line("<true/>");
  896. }
  897. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 2) {
  898. ent_f->store_line("<key>com.apple.security.files.music.read-write</key>");
  899. ent_f->store_line("<true/>");
  900. }
  901. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 1) {
  902. ent_f->store_line("<key>com.apple.security.files.movies.read-only</key>");
  903. ent_f->store_line("<true/>");
  904. }
  905. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 2) {
  906. ent_f->store_line("<key>com.apple.security.files.movies.read-write</key>");
  907. ent_f->store_line("<true/>");
  908. }
  909. }
  910. ent_f->store_line("</dict>");
  911. ent_f->store_line("</plist>");
  912. ent_f->close();
  913. memdelete(ent_f);
  914. } else {
  915. err = ERR_CANT_CREATE;
  916. }
  917. if ((err == OK) && helpers.size() > 0) {
  918. ent_f = FileAccess::open(hlp_ent_path, FileAccess::WRITE);
  919. if (ent_f) {
  920. ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  921. ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  922. ent_f->store_line("<plist version=\"1.0\">");
  923. ent_f->store_line("<dict>");
  924. ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
  925. ent_f->store_line("<true/>");
  926. ent_f->store_line("<key>com.apple.security.inherit</key>");
  927. ent_f->store_line("<true/>");
  928. ent_f->store_line("</dict>");
  929. ent_f->store_line("</plist>");
  930. ent_f->close();
  931. memdelete(ent_f);
  932. } else {
  933. err = ERR_CANT_CREATE;
  934. }
  935. }
  936. }
  937. if ((err == OK) && helpers.size() > 0) {
  938. DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  939. for (int i = 0; i < helpers.size(); i++) {
  940. String hlp_path = helpers[i];
  941. err = da->copy(hlp_path, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file());
  942. if (err == OK && sign_enabled) {
  943. err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), hlp_ent_path);
  944. }
  945. FileAccess::set_unix_permissions(tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), 0755);
  946. }
  947. }
  948. bool ad_hoc = true;
  949. if (err == OK) {
  950. #ifdef OSX_ENABLED
  951. String sign_identity = p_preset->get("codesign/identity");
  952. #else
  953. String sign_identity = "-";
  954. #endif
  955. ad_hoc = (sign_identity == "" || sign_identity == "-");
  956. bool lib_validation = p_preset->get("codesign/entitlements/disable_library_validation");
  957. if ((!dylibs_found.is_empty() || !shared_objects.is_empty()) && sign_enabled && ad_hoc && !lib_validation) {
  958. ERR_PRINT("Application with an ad-hoc signature require 'Disable Library Validation' entitlement to load dynamic libraries.");
  959. err = ERR_CANT_CREATE;
  960. }
  961. }
  962. if (err == OK) {
  963. DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  964. for (int i = 0; i < shared_objects.size(); i++) {
  965. String src_path = ProjectSettings::get_singleton()->globalize_path(shared_objects[i].path);
  966. String path_in_app{ tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file() };
  967. err = _copy_and_sign_files(da, src_path, path_in_app, sign_enabled, p_preset, ent_path, true);
  968. if (err != OK) {
  969. break;
  970. }
  971. }
  972. Vector<Ref<EditorExportPlugin>> export_plugins{ EditorExport::get_singleton()->get_export_plugins() };
  973. for (int i = 0; i < export_plugins.size(); ++i) {
  974. err = _export_osx_plugins_for(export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path);
  975. if (err != OK) {
  976. break;
  977. }
  978. }
  979. }
  980. if (sign_enabled) {
  981. for (int i = 0; i < dylibs_found.size(); i++) {
  982. if (err == OK) {
  983. err = _code_sign(p_preset, tmp_app_path_name + "/" + dylibs_found[i], ent_path);
  984. }
  985. }
  986. }
  987. if (err == OK && sign_enabled) {
  988. if (ep.step(TTR("Code signing bundle"), 2)) {
  989. return ERR_SKIP;
  990. }
  991. err = _code_sign(p_preset, tmp_app_path_name, ent_path);
  992. }
  993. if (export_format == "dmg") {
  994. // Create a DMG.
  995. if (err == OK) {
  996. if (ep.step(TTR("Making DMG"), 3)) {
  997. return ERR_SKIP;
  998. }
  999. err = _create_dmg(p_path, pkg_name, tmp_app_path_name);
  1000. }
  1001. // Sign DMG.
  1002. if (err == OK && sign_enabled && !ad_hoc) {
  1003. if (ep.step(TTR("Code signing DMG"), 3)) {
  1004. return ERR_SKIP;
  1005. }
  1006. err = _code_sign(p_preset, p_path, ent_path);
  1007. }
  1008. } else if (export_format == "zip") {
  1009. // Create ZIP.
  1010. if (err == OK) {
  1011. if (ep.step(TTR("Making ZIP"), 3)) {
  1012. return ERR_SKIP;
  1013. }
  1014. if (FileAccess::exists(p_path)) {
  1015. OS::get_singleton()->move_to_trash(p_path);
  1016. }
  1017. FileAccess *dst_f = nullptr;
  1018. zlib_filefunc_def io_dst = zipio_create_io_from_file(&dst_f);
  1019. zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
  1020. _zip_folder_recursive(zip, EditorPaths::get_singleton()->get_cache_dir(), pkg_name + ".app", pkg_name);
  1021. zipClose(zip, nullptr);
  1022. }
  1023. }
  1024. bool noto_enabled = p_preset->get("notarization/enable");
  1025. if (err == OK && noto_enabled) {
  1026. if (export_format == "app") {
  1027. WARN_PRINT("Notarization require app to be archived first, select DMG or ZIP export format instead.");
  1028. } else {
  1029. if (ep.step(TTR("Sending archive for notarization"), 4)) {
  1030. return ERR_SKIP;
  1031. }
  1032. err = _notarize(p_preset, p_path);
  1033. }
  1034. }
  1035. // Clean up temporary entitlements files.
  1036. DirAccess::remove_file_or_error(hlp_ent_path);
  1037. // Clean up temporary .app dir and generated entitlements.
  1038. if ((String)(p_preset->get("codesign/entitlements/custom_file")) == "") {
  1039. tmp_app_dir->remove(ent_path);
  1040. }
  1041. if (export_format != "app") {
  1042. if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) {
  1043. tmp_app_dir->erase_contents_recursive();
  1044. tmp_app_dir->change_dir("..");
  1045. tmp_app_dir->remove(tmp_app_dir_name);
  1046. }
  1047. }
  1048. }
  1049. return err;
  1050. }
  1051. void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name) {
  1052. String dir = p_root_path.plus_file(p_folder);
  1053. DirAccessRef da = DirAccess::open(dir);
  1054. da->list_dir_begin();
  1055. String f = da->get_next();
  1056. while (!f.is_empty()) {
  1057. if (f == "." || f == "..") {
  1058. f = da->get_next();
  1059. continue;
  1060. }
  1061. if (da->is_link(f)) {
  1062. OS::Time time = OS::get_singleton()->get_time();
  1063. OS::Date date = OS::get_singleton()->get_date();
  1064. zip_fileinfo zipfi;
  1065. zipfi.tmz_date.tm_hour = time.hour;
  1066. zipfi.tmz_date.tm_mday = date.day;
  1067. zipfi.tmz_date.tm_min = time.minute;
  1068. zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, https://www.cplusplus.com/reference/ctime/tm/
  1069. zipfi.tmz_date.tm_sec = time.second;
  1070. zipfi.tmz_date.tm_year = date.year;
  1071. zipfi.dosDate = 0;
  1072. // 0120000: symbolic link type
  1073. // 0000755: permissions rwxr-xr-x
  1074. // 0000644: permissions rw-r--r--
  1075. uint32_t _mode = 0120644;
  1076. zipfi.external_fa = (_mode << 16L) | !(_mode & 0200);
  1077. zipfi.internal_fa = 0;
  1078. zipOpenNewFileInZip4(p_zip,
  1079. p_folder.plus_file(f).utf8().get_data(),
  1080. &zipfi,
  1081. nullptr,
  1082. 0,
  1083. nullptr,
  1084. 0,
  1085. nullptr,
  1086. Z_DEFLATED,
  1087. Z_DEFAULT_COMPRESSION,
  1088. 0,
  1089. -MAX_WBITS,
  1090. DEF_MEM_LEVEL,
  1091. Z_DEFAULT_STRATEGY,
  1092. nullptr,
  1093. 0,
  1094. 0x0314, // "version made by", 0x03 - Unix, 0x14 - ZIP specification version 2.0, required to store Unix file permissions
  1095. 0);
  1096. String target = da->read_link(f);
  1097. zipWriteInFileInZip(p_zip, target.utf8().get_data(), target.utf8().size());
  1098. zipCloseFileInZip(p_zip);
  1099. } else if (da->current_is_dir()) {
  1100. _zip_folder_recursive(p_zip, p_root_path, p_folder.plus_file(f), p_pkg_name);
  1101. } else {
  1102. bool is_executable = (p_folder.ends_with("MacOS") && (f == p_pkg_name)) || p_folder.ends_with("Helpers");
  1103. OS::Time time = OS::get_singleton()->get_time();
  1104. OS::Date date = OS::get_singleton()->get_date();
  1105. zip_fileinfo zipfi;
  1106. zipfi.tmz_date.tm_hour = time.hour;
  1107. zipfi.tmz_date.tm_mday = date.day;
  1108. zipfi.tmz_date.tm_min = time.minute;
  1109. zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, https://www.cplusplus.com/reference/ctime/tm/
  1110. zipfi.tmz_date.tm_sec = time.second;
  1111. zipfi.tmz_date.tm_year = date.year;
  1112. zipfi.dosDate = 0;
  1113. // 0100000: regular file type
  1114. // 0000755: permissions rwxr-xr-x
  1115. // 0000644: permissions rw-r--r--
  1116. uint32_t _mode = (is_executable ? 0100755 : 0100644);
  1117. zipfi.external_fa = (_mode << 16L) | !(_mode & 0200);
  1118. zipfi.internal_fa = 0;
  1119. zipOpenNewFileInZip4(p_zip,
  1120. p_folder.plus_file(f).utf8().get_data(),
  1121. &zipfi,
  1122. nullptr,
  1123. 0,
  1124. nullptr,
  1125. 0,
  1126. nullptr,
  1127. Z_DEFLATED,
  1128. Z_DEFAULT_COMPRESSION,
  1129. 0,
  1130. -MAX_WBITS,
  1131. DEF_MEM_LEVEL,
  1132. Z_DEFAULT_STRATEGY,
  1133. nullptr,
  1134. 0,
  1135. 0x0314, // "version made by", 0x03 - Unix, 0x14 - ZIP specification version 2.0, required to store Unix file permissions
  1136. 0);
  1137. FileAccessRef fa = FileAccess::open(dir.plus_file(f), FileAccess::READ);
  1138. if (!fa) {
  1139. ERR_FAIL_MSG(vformat("Can't open file to read from path \"%s\".", dir.plus_file(f)));
  1140. }
  1141. const int bufsize = 16384;
  1142. uint8_t buf[bufsize];
  1143. while (true) {
  1144. uint64_t got = fa->get_buffer(buf, bufsize);
  1145. if (got == 0) {
  1146. break;
  1147. }
  1148. zipWriteInFileInZip(p_zip, buf, got);
  1149. }
  1150. zipCloseFileInZip(p_zip);
  1151. }
  1152. f = da->get_next();
  1153. }
  1154. da->list_dir_end();
  1155. }
  1156. bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  1157. String err;
  1158. bool valid = false;
  1159. // Look for export templates (custom templates).
  1160. bool dvalid = false;
  1161. bool rvalid = false;
  1162. if (p_preset->get("custom_template/debug") != "") {
  1163. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  1164. if (!dvalid) {
  1165. err += TTR("Custom debug template not found.") + "\n";
  1166. }
  1167. }
  1168. if (p_preset->get("custom_template/release") != "") {
  1169. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  1170. if (!rvalid) {
  1171. err += TTR("Custom release template not found.") + "\n";
  1172. }
  1173. }
  1174. // Look for export templates (official templates, check only is custom templates are not set).
  1175. if (!dvalid || !rvalid) {
  1176. dvalid = exists_export_template("osx.zip", &err);
  1177. rvalid = dvalid; // Both in the same ZIP.
  1178. }
  1179. valid = dvalid || rvalid;
  1180. r_missing_templates = !valid;
  1181. String identifier = p_preset->get("application/bundle_identifier");
  1182. String pn_err;
  1183. if (!is_package_name_valid(identifier, &pn_err)) {
  1184. err += TTR("Invalid bundle identifier:") + " " + pn_err + "\n";
  1185. valid = false;
  1186. }
  1187. bool sign_enabled = p_preset->get("codesign/enable");
  1188. bool noto_enabled = p_preset->get("notarization/enable");
  1189. bool ad_hoc = ((p_preset->get("codesign/identity") == "") || (p_preset->get("codesign/identity") == "-"));
  1190. #ifdef OSX_ENABLED
  1191. if (!ad_hoc && (bool)EditorSettings::get_singleton()->get("export/macos/force_builtin_codesign")) {
  1192. err += TTR("Warning: Built-in \"codesign\" is selected in the Editor Settings. Code signing is limited to ad-hoc signature only.") + "\n";
  1193. }
  1194. if (!ad_hoc && !FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {
  1195. err += TTR("Warning: Xcode command line tools are not installed, using built-in \"codesign\". Code signing is limited to ad-hoc signature only.") + "\n";
  1196. }
  1197. #endif
  1198. if (noto_enabled) {
  1199. if (ad_hoc) {
  1200. err += TTR("Notarization: Notarization with the ad-hoc signature is not supported.") + "\n";
  1201. valid = false;
  1202. }
  1203. if (!sign_enabled) {
  1204. err += TTR("Notarization: Code signing is required for notarization.") + "\n";
  1205. valid = false;
  1206. }
  1207. if (!(bool)p_preset->get("codesign/hardened_runtime")) {
  1208. err += TTR("Notarization: Hardened runtime is required for notarization.") + "\n";
  1209. valid = false;
  1210. }
  1211. if (!(bool)p_preset->get("codesign/timestamp")) {
  1212. err += TTR("Notarization: Timestamping is required for notarization.") + "\n";
  1213. valid = false;
  1214. }
  1215. if (p_preset->get("notarization/apple_id_name") == "") {
  1216. err += TTR("Notarization: Apple ID name not specified.") + "\n";
  1217. valid = false;
  1218. }
  1219. if (p_preset->get("notarization/apple_id_password") == "") {
  1220. err += TTR("Notarization: Apple ID password not specified.") + "\n";
  1221. valid = false;
  1222. }
  1223. } else {
  1224. #ifdef OSX_ENABLED
  1225. err += TTR("Warning: Notarization is disabled. Exported project will be blocked by Gatekeeper, if it's downloaded from an unknown source.") + "\n";
  1226. #else
  1227. err += TTR("Warning: Notarization is not supported on this OS. Exported project will be blocked by Gatekeeper, if it's downloaded from an unknown source.") + "\n";
  1228. #endif
  1229. if (!sign_enabled) {
  1230. err += TTR("Code signing is disabled. Exported project will not run on Macs with enabled Gatekeeper and Apple Silicon powered Macs.") + "\n";
  1231. } else {
  1232. if ((bool)p_preset->get("codesign/hardened_runtime") && ad_hoc) {
  1233. err += TTR("Hardened Runtime is not compatible with ad-hoc signature, and will be disabled!") + "\n";
  1234. }
  1235. if ((bool)p_preset->get("codesign/timestamp") && ad_hoc) {
  1236. err += TTR("Timestamping is not compatible with ad-hoc signature, and will be disabled!") + "\n";
  1237. }
  1238. }
  1239. }
  1240. if (sign_enabled) {
  1241. if ((bool)p_preset->get("codesign/entitlements/audio_input") && ((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
  1242. err += TTR("Privacy: Microphone access is enabled, but usage description is not specified.") + "\n";
  1243. valid = false;
  1244. }
  1245. if ((bool)p_preset->get("codesign/entitlements/camera") && ((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
  1246. err += TTR("Privacy: Camera access is enabled, but usage description is not specified.") + "\n";
  1247. valid = false;
  1248. }
  1249. if ((bool)p_preset->get("codesign/entitlements/location") && ((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
  1250. err += TTR("Privacy: Location information access is enabled, but usage description is not specified.") + "\n";
  1251. valid = false;
  1252. }
  1253. if ((bool)p_preset->get("codesign/entitlements/address_book") && ((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
  1254. err += TTR("Privacy: Address book access is enabled, but usage description is not specified.") + "\n";
  1255. valid = false;
  1256. }
  1257. if ((bool)p_preset->get("codesign/entitlements/calendars") && ((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
  1258. err += TTR("Privacy: Calendar access is enabled, but usage description is not specified.") + "\n";
  1259. valid = false;
  1260. }
  1261. if ((bool)p_preset->get("codesign/entitlements/photos_library") && ((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
  1262. err += TTR("Privacy: Photo library access is enabled, but usage description is not specified.") + "\n";
  1263. valid = false;
  1264. }
  1265. }
  1266. if (!err.is_empty()) {
  1267. r_error = err;
  1268. }
  1269. return valid;
  1270. }
  1271. EditorExportPlatformOSX::EditorExportPlatformOSX() {
  1272. Ref<Image> img = memnew(Image(_osx_logo));
  1273. logo.instantiate();
  1274. logo->create_from_image(img);
  1275. }
  1276. EditorExportPlatformOSX::~EditorExportPlatformOSX() {
  1277. }