export_plugin.cpp 68 KB

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