export_plugin.cpp 60 KB

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