export_plugin.cpp 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  1. /*************************************************************************/
  2. /* export_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. void EditorExportPlatformOSX::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
  32. if (p_preset->get("texture_format/s3tc")) {
  33. r_features->push_back("s3tc");
  34. }
  35. if (p_preset->get("texture_format/etc")) {
  36. r_features->push_back("etc");
  37. }
  38. if (p_preset->get("texture_format/etc2")) {
  39. r_features->push_back("etc2");
  40. }
  41. r_features->push_back("64");
  42. }
  43. void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) {
  44. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  45. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  46. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
  47. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/info"), "Made with Godot Engine"));
  48. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.png,*.icns"), ""));
  49. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), ""));
  50. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  51. 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"));
  52. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
  53. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
  54. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
  55. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), false));
  56. 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"), ""));
  57. 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"), ""));
  58. #ifdef OSX_ENABLED
  59. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/enable"), true));
  60. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), ""));
  61. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/timestamp"), true));
  62. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/hardened_runtime"), true));
  63. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/replace_existing_signature"), true));
  64. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/custom_file", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), ""));
  65. if (!Engine::get_singleton()->has_singleton("GodotSharp")) {
  66. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  67. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false));
  68. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false));
  69. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false));
  70. }
  71. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/disable_library_validation"), false));
  72. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/audio_input"), false));
  73. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/camera"), false));
  74. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/location"), false));
  75. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/address_book"), false));
  76. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/calendars"), false));
  77. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/photos_library"), false));
  78. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/apple_events"), false));
  79. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/debugging"), false));
  80. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/enabled"), false));
  81. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_server"), false));
  82. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_client"), false));
  83. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_usb"), false));
  84. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_bluetooth"), false));
  85. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_downloads", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  86. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_pictures", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  87. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_music", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  88. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_movies", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  89. r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));
  90. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "notarization/enable"), false));
  91. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple ID email"), ""));
  92. 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"), ""));
  93. 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"), ""));
  94. #endif
  95. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
  96. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
  97. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
  98. }
  99. void _rgba8_to_packbits_encode(int p_ch, int p_size, Vector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {
  100. int src_len = p_size * p_size;
  101. Vector<uint8_t> result;
  102. result.resize(src_len * 1.25); //temp vector for rle encoded data, make it 25% larger for worst case scenario
  103. int res_size = 0;
  104. uint8_t buf[128];
  105. int buf_size = 0;
  106. int i = 0;
  107. while (i < src_len) {
  108. uint8_t cur = p_source.ptr()[i * 4 + p_ch];
  109. if (i < src_len - 2) {
  110. if ((p_source.ptr()[(i + 1) * 4 + p_ch] == cur) && (p_source.ptr()[(i + 2) * 4 + p_ch] == cur)) {
  111. if (buf_size > 0) {
  112. result.write[res_size++] = (uint8_t)(buf_size - 1);
  113. memcpy(&result.write[res_size], &buf, buf_size);
  114. res_size += buf_size;
  115. buf_size = 0;
  116. }
  117. uint8_t lim = i + 130 >= src_len ? src_len - i - 1 : 130;
  118. bool hit_lim = true;
  119. for (int j = 3; j <= lim; j++) {
  120. if (p_source.ptr()[(i + j) * 4 + p_ch] != cur) {
  121. hit_lim = false;
  122. i = i + j - 1;
  123. result.write[res_size++] = (uint8_t)(j - 3 + 0x80);
  124. result.write[res_size++] = cur;
  125. break;
  126. }
  127. }
  128. if (hit_lim) {
  129. result.write[res_size++] = (uint8_t)(lim - 3 + 0x80);
  130. result.write[res_size++] = cur;
  131. i = i + lim;
  132. }
  133. } else {
  134. buf[buf_size++] = cur;
  135. if (buf_size == 128) {
  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. }
  142. } else {
  143. buf[buf_size++] = cur;
  144. result.write[res_size++] = (uint8_t)(buf_size - 1);
  145. memcpy(&result.write[res_size], &buf, buf_size);
  146. res_size += buf_size;
  147. buf_size = 0;
  148. }
  149. i++;
  150. }
  151. int ofs = p_dest.size();
  152. p_dest.resize(p_dest.size() + res_size);
  153. memcpy(&p_dest.write[ofs], result.ptr(), res_size);
  154. }
  155. void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {
  156. Ref<ImageTexture> it = memnew(ImageTexture);
  157. Vector<uint8_t> data;
  158. data.resize(8);
  159. data.write[0] = 'i';
  160. data.write[1] = 'c';
  161. data.write[2] = 'n';
  162. data.write[3] = 's';
  163. struct MacOSIconInfo {
  164. const char *name;
  165. const char *mask_name;
  166. bool is_png;
  167. int size;
  168. };
  169. static const MacOSIconInfo icon_infos[] = {
  170. { "ic10", "", true, 1024 }, //1024×1024 32-bit PNG and 512×512@2x 32-bit "retina" PNG
  171. { "ic09", "", true, 512 }, //512×512 32-bit PNG
  172. { "ic14", "", true, 512 }, //256×256@2x 32-bit "retina" PNG
  173. { "ic08", "", true, 256 }, //256×256 32-bit PNG
  174. { "ic13", "", true, 256 }, //128×128@2x 32-bit "retina" PNG
  175. { "ic07", "", true, 128 }, //128×128 32-bit PNG
  176. { "ic12", "", true, 64 }, //32×32@2× 32-bit "retina" PNG
  177. { "ic11", "", true, 32 }, //16×16@2× 32-bit "retina" PNG
  178. { "il32", "l8mk", false, 32 }, //32×32 24-bit RLE + 8-bit uncompressed mask
  179. { "is32", "s8mk", false, 16 } //16×16 24-bit RLE + 8-bit uncompressed mask
  180. };
  181. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  182. 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?
  183. copy->convert(Image::FORMAT_RGBA8);
  184. copy->resize(icon_infos[i].size, icon_infos[i].size);
  185. if (icon_infos[i].is_png) {
  186. // Encode PNG icon.
  187. it->create_from_image(copy);
  188. String path = EditorPaths::get_singleton()->get_cache_dir().plus_file("icon.png");
  189. ResourceSaver::save(path, it);
  190. FileAccess *f = FileAccess::open(path, FileAccess::READ);
  191. if (!f) {
  192. // Clean up generated file.
  193. DirAccess::remove_file_or_error(path);
  194. ERR_FAIL();
  195. }
  196. int ofs = data.size();
  197. uint64_t len = f->get_length();
  198. data.resize(data.size() + len + 8);
  199. f->get_buffer(&data.write[ofs + 8], len);
  200. memdelete(f);
  201. len += 8;
  202. len = BSWAP32(len);
  203. memcpy(&data.write[ofs], icon_infos[i].name, 4);
  204. encode_uint32(len, &data.write[ofs + 4]);
  205. // Clean up generated file.
  206. DirAccess::remove_file_or_error(path);
  207. } else {
  208. Vector<uint8_t> src_data = copy->get_data();
  209. //encode 24bit RGB RLE icon
  210. {
  211. int ofs = data.size();
  212. data.resize(data.size() + 8);
  213. _rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data); // encode R
  214. _rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data); // encode G
  215. _rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data); // encode B
  216. int len = data.size() - ofs;
  217. len = BSWAP32(len);
  218. memcpy(&data.write[ofs], icon_infos[i].name, 4);
  219. encode_uint32(len, &data.write[ofs + 4]);
  220. }
  221. //encode 8bit mask uncompressed icon
  222. {
  223. int ofs = data.size();
  224. int len = copy->get_width() * copy->get_height();
  225. data.resize(data.size() + len + 8);
  226. for (int j = 0; j < len; j++) {
  227. data.write[ofs + 8 + j] = src_data.ptr()[j * 4 + 3];
  228. }
  229. len += 8;
  230. len = BSWAP32(len);
  231. memcpy(&data.write[ofs], icon_infos[i].mask_name, 4);
  232. encode_uint32(len, &data.write[ofs + 4]);
  233. }
  234. }
  235. }
  236. uint32_t total_len = data.size();
  237. total_len = BSWAP32(total_len);
  238. encode_uint32(total_len, &data.write[4]);
  239. p_data = data;
  240. }
  241. void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary) {
  242. String str;
  243. String strnew;
  244. str.parse_utf8((const char *)plist.ptr(), plist.size());
  245. Vector<String> lines = str.split("\n");
  246. for (int i = 0; i < lines.size(); i++) {
  247. if (lines[i].find("$binary") != -1) {
  248. strnew += lines[i].replace("$binary", p_binary) + "\n";
  249. } else if (lines[i].find("$name") != -1) {
  250. strnew += lines[i].replace("$name", p_binary) + "\n";
  251. } else if (lines[i].find("$info") != -1) {
  252. strnew += lines[i].replace("$info", p_preset->get("application/info")) + "\n";
  253. } else if (lines[i].find("$bundle_identifier") != -1) {
  254. strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
  255. } else if (lines[i].find("$short_version") != -1) {
  256. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  257. } else if (lines[i].find("$version") != -1) {
  258. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  259. } else if (lines[i].find("$signature") != -1) {
  260. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  261. } else if (lines[i].find("$app_category") != -1) {
  262. String cat = p_preset->get("application/app_category");
  263. strnew += lines[i].replace("$app_category", cat.to_lower()) + "\n";
  264. } else if (lines[i].find("$copyright") != -1) {
  265. strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
  266. } else if (lines[i].find("$highres") != -1) {
  267. strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "<true/>" : "<false/>") + "\n";
  268. } else if (lines[i].find("$camera_usage_description") != -1) {
  269. String description = p_preset->get("privacy/camera_usage_description");
  270. strnew += lines[i].replace("$camera_usage_description", description) + "\n";
  271. } else if (lines[i].find("$microphone_usage_description") != -1) {
  272. String description = p_preset->get("privacy/microphone_usage_description");
  273. strnew += lines[i].replace("$microphone_usage_description", description) + "\n";
  274. } else {
  275. strnew += lines[i] + "\n";
  276. }
  277. }
  278. CharString cs = strnew.utf8();
  279. plist.resize(cs.size() - 1);
  280. for (int i = 0; i < cs.size() - 1; i++) {
  281. plist.write[i] = cs[i];
  282. }
  283. }
  284. /**
  285. If we're running the OSX version of the Godot editor we'll:
  286. - export our application bundle to a temporary folder
  287. - attempt to code sign it
  288. - and then wrap it up in a DMG
  289. **/
  290. Error EditorExportPlatformOSX::_notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
  291. #ifdef OSX_ENABLED
  292. List<String> args;
  293. args.push_back("altool");
  294. args.push_back("--notarize-app");
  295. args.push_back("--primary-bundle-id");
  296. args.push_back(p_preset->get("application/bundle_identifier"));
  297. args.push_back("--username");
  298. args.push_back(p_preset->get("notarization/apple_id_name"));
  299. args.push_back("--password");
  300. args.push_back(p_preset->get("notarization/apple_id_password"));
  301. args.push_back("--type");
  302. args.push_back("osx");
  303. if (p_preset->get("notarization/apple_team_id")) {
  304. args.push_back("--asc-provider");
  305. args.push_back(p_preset->get("notarization/apple_team_id"));
  306. }
  307. args.push_back("--file");
  308. args.push_back(p_path);
  309. String str;
  310. Error err = OS::get_singleton()->execute("xcrun", args, &str, nullptr, true);
  311. ERR_FAIL_COND_V(err != OK, err);
  312. print_line("altool (" + p_path + "):\n" + str);
  313. if (str.find("RequestUUID") == -1) {
  314. EditorNode::add_io_error("altool: " + str);
  315. return FAILED;
  316. } else {
  317. print_line("Note: The notarization process generally takes less than an hour. When the process is completed, you'll receive an email.");
  318. print_line(" You can check progress manually by opening a Terminal and running the following command:");
  319. print_line(" \"xcrun altool --notarization-history 0 -u <your email> -p <app-specific pwd>\"");
  320. }
  321. #endif
  322. return OK;
  323. }
  324. Error EditorExportPlatformOSX::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path) {
  325. #ifdef OSX_ENABLED
  326. List<String> args;
  327. if (p_preset->get("codesign/timestamp")) {
  328. args.push_back("--timestamp");
  329. }
  330. if (p_preset->get("codesign/hardened_runtime")) {
  331. args.push_back("--options");
  332. args.push_back("runtime");
  333. }
  334. if (p_path.get_extension() != "dmg") {
  335. args.push_back("--entitlements");
  336. args.push_back(p_ent_path);
  337. }
  338. PackedStringArray user_args = p_preset->get("codesign/custom_options");
  339. for (int i = 0; i < user_args.size(); i++) {
  340. String user_arg = user_args[i].strip_edges();
  341. if (!user_arg.is_empty()) {
  342. args.push_back(user_arg);
  343. }
  344. }
  345. args.push_back("-s");
  346. if (p_preset->get("codesign/identity") == "") {
  347. args.push_back("-");
  348. } else {
  349. args.push_back(p_preset->get("codesign/identity"));
  350. }
  351. args.push_back("-v"); /* provide some more feedback */
  352. if (p_preset->get("codesign/replace_existing_signature")) {
  353. args.push_back("-f");
  354. }
  355. args.push_back(p_path);
  356. String str;
  357. Error err = OS::get_singleton()->execute("codesign", args, &str, nullptr, true);
  358. ERR_FAIL_COND_V(err != OK, err);
  359. print_line("codesign (" + p_path + "):\n" + str);
  360. if (str.find("no identity found") != -1) {
  361. EditorNode::add_io_error("codesign: no identity found");
  362. return FAILED;
  363. }
  364. if ((str.find("unrecognized blob type") != -1) || (str.find("cannot read entitlement data") != -1)) {
  365. EditorNode::add_io_error("codesign: invalid entitlements file");
  366. return FAILED;
  367. }
  368. #endif
  369. return OK;
  370. }
  371. Error EditorExportPlatformOSX::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {
  372. List<String> args;
  373. if (FileAccess::exists(p_dmg_path)) {
  374. OS::get_singleton()->move_to_trash(p_dmg_path);
  375. }
  376. args.push_back("create");
  377. args.push_back(p_dmg_path);
  378. args.push_back("-volname");
  379. args.push_back(p_pkg_name);
  380. args.push_back("-fs");
  381. args.push_back("HFS+");
  382. args.push_back("-srcfolder");
  383. args.push_back(p_app_path_name);
  384. String str;
  385. Error err = OS::get_singleton()->execute("hdiutil", args, &str, nullptr, true);
  386. ERR_FAIL_COND_V(err != OK, err);
  387. print_line("hdiutil returned: " + str);
  388. if (str.find("create failed") != -1) {
  389. if (str.find("File exists") != -1) {
  390. EditorNode::add_io_error("hdiutil: create failed - file exists");
  391. } else {
  392. EditorNode::add_io_error("hdiutil: create failed");
  393. }
  394. return FAILED;
  395. }
  396. return OK;
  397. }
  398. Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  399. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  400. String src_pkg_name;
  401. EditorProgress ep("export", "Exporting for OSX", 3, true);
  402. if (p_debug) {
  403. src_pkg_name = p_preset->get("custom_template/debug");
  404. } else {
  405. src_pkg_name = p_preset->get("custom_template/release");
  406. }
  407. if (src_pkg_name == "") {
  408. String err;
  409. src_pkg_name = find_export_template("osx.zip", &err);
  410. if (src_pkg_name == "") {
  411. EditorNode::add_io_error(err);
  412. return ERR_FILE_NOT_FOUND;
  413. }
  414. }
  415. if (!DirAccess::exists(p_path.get_base_dir())) {
  416. return ERR_FILE_BAD_PATH;
  417. }
  418. FileAccess *src_f = nullptr;
  419. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  420. if (ep.step("Creating app", 0)) {
  421. return ERR_SKIP;
  422. }
  423. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  424. if (!src_pkg_zip) {
  425. EditorNode::add_io_error("Could not find template app to export:\n" + src_pkg_name);
  426. return ERR_FILE_NOT_FOUND;
  427. }
  428. int ret = unzGoToFirstFile(src_pkg_zip);
  429. String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + ".64";
  430. String pkg_name;
  431. if (p_preset->get("application/name") != "") {
  432. pkg_name = p_preset->get("application/name"); // app_name
  433. } else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") {
  434. pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
  435. } else {
  436. pkg_name = "Unnamed";
  437. }
  438. pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
  439. String export_format = use_dmg() && p_path.ends_with("dmg") ? "dmg" : "zip";
  440. // Create our application bundle.
  441. String tmp_app_dir_name = pkg_name + ".app";
  442. String tmp_app_path_name = EditorPaths::get_singleton()->get_cache_dir().plus_file(tmp_app_dir_name);
  443. print_line("Exporting to " + tmp_app_path_name);
  444. Error err = OK;
  445. DirAccessRef tmp_app_dir = DirAccess::create_for_path(tmp_app_path_name);
  446. if (!tmp_app_dir) {
  447. err = ERR_CANT_CREATE;
  448. }
  449. // Create our folder structure.
  450. if (err == OK) {
  451. print_line("Creating " + tmp_app_path_name + "/Contents/MacOS");
  452. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
  453. }
  454. if (err == OK) {
  455. print_line("Creating " + tmp_app_path_name + "/Contents/Frameworks");
  456. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");
  457. }
  458. if (err == OK) {
  459. print_line("Creating " + tmp_app_path_name + "/Contents/Resources");
  460. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
  461. }
  462. // Now process our template.
  463. bool found_binary = false;
  464. int total_size = 0;
  465. Vector<String> dylibs_found;
  466. while (ret == UNZ_OK && err == OK) {
  467. bool is_execute = false;
  468. // Get filename.
  469. unz_file_info info;
  470. char fname[16384];
  471. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  472. String file = fname;
  473. Vector<uint8_t> data;
  474. data.resize(info.uncompressed_size);
  475. // Read.
  476. unzOpenCurrentFile(src_pkg_zip);
  477. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  478. unzCloseCurrentFile(src_pkg_zip);
  479. // Write.
  480. file = file.replace_first("osx_template.app/", "");
  481. if (file == "Contents/Info.plist") {
  482. _fix_plist(p_preset, data, pkg_name);
  483. }
  484. if (file.begins_with("Contents/MacOS/godot_")) {
  485. if (file != "Contents/MacOS/" + binary_to_use) {
  486. ret = unzGoToNextFile(src_pkg_zip);
  487. continue; // skip
  488. }
  489. found_binary = true;
  490. is_execute = true;
  491. file = "Contents/MacOS/" + pkg_name;
  492. }
  493. if (file == "Contents/Resources/icon.icns") {
  494. // See if there is an icon.
  495. String iconpath;
  496. if (p_preset->get("application/icon") != "") {
  497. iconpath = p_preset->get("application/icon");
  498. } else {
  499. iconpath = ProjectSettings::get_singleton()->get("application/config/icon");
  500. }
  501. if (iconpath != "") {
  502. if (iconpath.get_extension() == "icns") {
  503. FileAccess *icon = FileAccess::open(iconpath, FileAccess::READ);
  504. if (icon) {
  505. data.resize(icon->get_length());
  506. icon->get_buffer(&data.write[0], icon->get_length());
  507. icon->close();
  508. memdelete(icon);
  509. }
  510. } else {
  511. Ref<Image> icon;
  512. icon.instantiate();
  513. icon->load(iconpath);
  514. if (!icon->is_empty()) {
  515. _make_icon(icon, data);
  516. }
  517. }
  518. }
  519. }
  520. if (data.size() > 0) {
  521. if (file.find("/data.mono.osx.64.release_debug/") != -1) {
  522. if (!p_debug) {
  523. ret = unzGoToNextFile(src_pkg_zip);
  524. continue; // skip
  525. }
  526. file = file.replace("/data.mono.osx.64.release_debug/", "/GodotSharp/");
  527. }
  528. if (file.find("/data.mono.osx.64.release/") != -1) {
  529. if (p_debug) {
  530. ret = unzGoToNextFile(src_pkg_zip);
  531. continue; // skip
  532. }
  533. file = file.replace("/data.mono.osx.64.release/", "/GodotSharp/");
  534. }
  535. if (file.ends_with(".dylib")) {
  536. dylibs_found.push_back(file);
  537. }
  538. print_line("ADDING: " + file + " size: " + itos(data.size()));
  539. total_size += data.size();
  540. // Write it into our application bundle.
  541. file = tmp_app_path_name.plus_file(file);
  542. if (err == OK) {
  543. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  544. }
  545. if (err == OK) {
  546. FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
  547. if (f) {
  548. f->store_buffer(data.ptr(), data.size());
  549. f->close();
  550. if (is_execute) {
  551. // chmod with 0755 if the file is executable.
  552. FileAccess::set_unix_permissions(file, 0755);
  553. }
  554. memdelete(f);
  555. } else {
  556. err = ERR_CANT_CREATE;
  557. }
  558. }
  559. }
  560. ret = unzGoToNextFile(src_pkg_zip);
  561. }
  562. // We're done with our source zip.
  563. unzClose(src_pkg_zip);
  564. if (!found_binary) {
  565. ERR_PRINT("Requested template binary '" + binary_to_use + "' not found. It might be missing from your template archive.");
  566. err = ERR_FILE_NOT_FOUND;
  567. }
  568. if (err == OK) {
  569. if (ep.step("Making PKG", 1)) {
  570. return ERR_SKIP;
  571. }
  572. String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
  573. Vector<SharedObject> shared_objects;
  574. err = save_pack(p_preset, pack_path, &shared_objects);
  575. // See if we can code sign our new package.
  576. bool sign_enabled = p_preset->get("codesign/enable");
  577. String ent_path = p_preset->get("codesign/entitlements/custom_file");
  578. if (sign_enabled && (ent_path == "")) {
  579. ent_path = EditorPaths::get_singleton()->get_cache_dir().plus_file(pkg_name + ".entitlements");
  580. FileAccess *ent_f = FileAccess::open(ent_path, FileAccess::WRITE);
  581. if (ent_f) {
  582. ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  583. ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  584. ent_f->store_line("<plist version=\"1.0\">");
  585. ent_f->store_line("<dict>");
  586. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  587. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  588. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  589. ent_f->store_line("<true/>");
  590. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  591. ent_f->store_line("<true/>");
  592. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  593. ent_f->store_line("<true/>");
  594. } else {
  595. if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) {
  596. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  597. ent_f->store_line("<true/>");
  598. }
  599. if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) {
  600. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  601. ent_f->store_line("<true/>");
  602. }
  603. if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) {
  604. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  605. ent_f->store_line("<true/>");
  606. }
  607. }
  608. if ((bool)p_preset->get("codesign/entitlements/disable_library_validation")) {
  609. ent_f->store_line("<key>com.apple.security.cs.disable-library-validation</key>");
  610. ent_f->store_line("<true/>");
  611. }
  612. if ((bool)p_preset->get("codesign/entitlements/audio_input")) {
  613. ent_f->store_line("<key>com.apple.security.device.audio-input</key>");
  614. ent_f->store_line("<true/>");
  615. }
  616. if ((bool)p_preset->get("codesign/entitlements/camera")) {
  617. ent_f->store_line("<key>com.apple.security.device.camera</key>");
  618. ent_f->store_line("<true/>");
  619. }
  620. if ((bool)p_preset->get("codesign/entitlements/location")) {
  621. ent_f->store_line("<key>com.apple.security.personal-information.location</key>");
  622. ent_f->store_line("<true/>");
  623. }
  624. if ((bool)p_preset->get("codesign/entitlements/address_book")) {
  625. ent_f->store_line("<key>com.apple.security.personal-information.addressbook</key>");
  626. ent_f->store_line("<true/>");
  627. }
  628. if ((bool)p_preset->get("codesign/entitlements/calendars")) {
  629. ent_f->store_line("<key>com.apple.security.personal-information.calendars</key>");
  630. ent_f->store_line("<true/>");
  631. }
  632. if ((bool)p_preset->get("codesign/entitlements/photos_library")) {
  633. ent_f->store_line("<key>com.apple.security.personal-information.photos-library</key>");
  634. ent_f->store_line("<true/>");
  635. }
  636. if ((bool)p_preset->get("codesign/entitlements/apple_events")) {
  637. ent_f->store_line("<key>com.apple.security.automation.apple-events</key>");
  638. ent_f->store_line("<true/>");
  639. }
  640. if ((bool)p_preset->get("codesign/entitlements/debugging")) {
  641. ent_f->store_line("<key>com.apple.security.get-task-allow</key>");
  642. ent_f->store_line("<true/>");
  643. }
  644. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/enabled")) {
  645. ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
  646. ent_f->store_line("<true/>");
  647. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_server")) {
  648. ent_f->store_line("<key>com.apple.security.network.server</key>");
  649. ent_f->store_line("<true/>");
  650. }
  651. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_client")) {
  652. ent_f->store_line("<key>com.apple.security.network.client</key>");
  653. ent_f->store_line("<true/>");
  654. }
  655. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_usb")) {
  656. ent_f->store_line("<key>com.apple.security.device.usb</key>");
  657. ent_f->store_line("<true/>");
  658. }
  659. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_bluetooth")) {
  660. ent_f->store_line("<key>com.apple.security.device.bluetooth</key>");
  661. ent_f->store_line("<true/>");
  662. }
  663. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 1) {
  664. ent_f->store_line("<key>com.apple.security.files.downloads.read-only</key>");
  665. ent_f->store_line("<true/>");
  666. }
  667. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 2) {
  668. ent_f->store_line("<key>com.apple.security.files.downloads.read-write</key>");
  669. ent_f->store_line("<true/>");
  670. }
  671. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 1) {
  672. ent_f->store_line("<key>com.apple.security.files.pictures.read-only</key>");
  673. ent_f->store_line("<true/>");
  674. }
  675. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 2) {
  676. ent_f->store_line("<key>com.apple.security.files.pictures.read-write</key>");
  677. ent_f->store_line("<true/>");
  678. }
  679. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 1) {
  680. ent_f->store_line("<key>com.apple.security.files.music.read-only</key>");
  681. ent_f->store_line("<true/>");
  682. }
  683. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 2) {
  684. ent_f->store_line("<key>com.apple.security.files.music.read-write</key>");
  685. ent_f->store_line("<true/>");
  686. }
  687. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 1) {
  688. ent_f->store_line("<key>com.apple.security.files.movies.read-only</key>");
  689. ent_f->store_line("<true/>");
  690. }
  691. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 2) {
  692. ent_f->store_line("<key>com.apple.security.files.movies.read-write</key>");
  693. ent_f->store_line("<true/>");
  694. }
  695. }
  696. ent_f->store_line("</dict>");
  697. ent_f->store_line("</plist>");
  698. ent_f->close();
  699. memdelete(ent_f);
  700. } else {
  701. err = ERR_CANT_CREATE;
  702. }
  703. }
  704. if (err == OK) {
  705. DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  706. for (int i = 0; i < shared_objects.size(); i++) {
  707. String src_path = ProjectSettings::get_singleton()->globalize_path(shared_objects[i].path);
  708. if (da->dir_exists(src_path)) {
  709. #ifndef UNIX_ENABLED
  710. WARN_PRINT("Relative symlinks are not supported, exported " + src_path.get_file() + " might be broken!");
  711. #endif
  712. print_verbose("export framework: " + src_path + " -> " + tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file());
  713. err = da->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file());
  714. if (err == OK) {
  715. err = da->copy_dir(src_path, tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file(), -1, true);
  716. }
  717. } else {
  718. print_verbose("export dylib: " + src_path + " -> " + tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file());
  719. err = da->copy(src_path, tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file());
  720. }
  721. if (err == OK && sign_enabled) {
  722. err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file(), ent_path);
  723. }
  724. }
  725. memdelete(da);
  726. }
  727. if (sign_enabled) {
  728. for (int i = 0; i < dylibs_found.size(); i++) {
  729. if (err == OK) {
  730. err = _code_sign(p_preset, tmp_app_path_name + "/" + dylibs_found[i], ent_path);
  731. }
  732. }
  733. }
  734. if (err == OK && sign_enabled) {
  735. if (ep.step("Code signing bundle", 2)) {
  736. return ERR_SKIP;
  737. }
  738. err = _code_sign(p_preset, tmp_app_path_name + "/Contents/MacOS/" + pkg_name, ent_path);
  739. }
  740. if (export_format == "dmg") {
  741. // Create a DMG.
  742. if (err == OK) {
  743. if (ep.step("Making DMG", 3)) {
  744. return ERR_SKIP;
  745. }
  746. err = _create_dmg(p_path, pkg_name, tmp_app_path_name);
  747. }
  748. // Sign DMG.
  749. if (err == OK && sign_enabled) {
  750. if (ep.step("Code signing DMG", 3)) {
  751. return ERR_SKIP;
  752. }
  753. err = _code_sign(p_preset, p_path, ent_path);
  754. }
  755. } else {
  756. // Create ZIP.
  757. if (err == OK) {
  758. if (ep.step("Making ZIP", 3)) {
  759. return ERR_SKIP;
  760. }
  761. if (FileAccess::exists(p_path)) {
  762. OS::get_singleton()->move_to_trash(p_path);
  763. }
  764. FileAccess *dst_f = nullptr;
  765. zlib_filefunc_def io_dst = zipio_create_io_from_file(&dst_f);
  766. zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
  767. _zip_folder_recursive(zip, EditorPaths::get_singleton()->get_cache_dir(), pkg_name + ".app", pkg_name);
  768. zipClose(zip, nullptr);
  769. }
  770. }
  771. bool noto_enabled = p_preset->get("notarization/enable");
  772. if (err == OK && noto_enabled) {
  773. if (ep.step("Sending archive for notarization", 4)) {
  774. return ERR_SKIP;
  775. }
  776. err = _notarize(p_preset, p_path);
  777. }
  778. // Clean up temporary .app dir.
  779. tmp_app_dir->change_dir(tmp_app_path_name);
  780. tmp_app_dir->erase_contents_recursive();
  781. tmp_app_dir->change_dir("..");
  782. tmp_app_dir->remove(tmp_app_dir_name);
  783. }
  784. return err;
  785. }
  786. void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name) {
  787. String dir = p_root_path.plus_file(p_folder);
  788. DirAccess *da = DirAccess::open(dir);
  789. da->list_dir_begin();
  790. String f;
  791. while ((f = da->get_next()) != "") {
  792. if (f == "." || f == "..") {
  793. continue;
  794. }
  795. if (da->is_link(f)) {
  796. OS::Time time = OS::get_singleton()->get_time();
  797. OS::Date date = OS::get_singleton()->get_date();
  798. zip_fileinfo zipfi;
  799. zipfi.tmz_date.tm_hour = time.hour;
  800. zipfi.tmz_date.tm_mday = date.day;
  801. zipfi.tmz_date.tm_min = time.minute;
  802. 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/
  803. zipfi.tmz_date.tm_sec = time.second;
  804. zipfi.tmz_date.tm_year = date.year;
  805. zipfi.dosDate = 0;
  806. // 0120000: symbolic link type
  807. // 0000755: permissions rwxr-xr-x
  808. // 0000644: permissions rw-r--r--
  809. uint32_t _mode = 0120644;
  810. zipfi.external_fa = (_mode << 16L) | !(_mode & 0200);
  811. zipfi.internal_fa = 0;
  812. zipOpenNewFileInZip4(p_zip,
  813. p_folder.plus_file(f).utf8().get_data(),
  814. &zipfi,
  815. nullptr,
  816. 0,
  817. nullptr,
  818. 0,
  819. nullptr,
  820. Z_DEFLATED,
  821. Z_DEFAULT_COMPRESSION,
  822. 0,
  823. -MAX_WBITS,
  824. DEF_MEM_LEVEL,
  825. Z_DEFAULT_STRATEGY,
  826. nullptr,
  827. 0,
  828. 0x0314, // "version made by", 0x03 - Unix, 0x14 - ZIP specification version 2.0, required to store Unix file permissions
  829. 0);
  830. String target = da->read_link(f);
  831. zipWriteInFileInZip(p_zip, target.utf8().get_data(), target.utf8().size());
  832. zipCloseFileInZip(p_zip);
  833. } else if (da->current_is_dir()) {
  834. _zip_folder_recursive(p_zip, p_root_path, p_folder.plus_file(f), p_pkg_name);
  835. } else {
  836. bool is_executable = (p_folder.ends_with("MacOS") && (f == p_pkg_name));
  837. OS::Time time = OS::get_singleton()->get_time();
  838. OS::Date date = OS::get_singleton()->get_date();
  839. zip_fileinfo zipfi;
  840. zipfi.tmz_date.tm_hour = time.hour;
  841. zipfi.tmz_date.tm_mday = date.day;
  842. zipfi.tmz_date.tm_min = time.minute;
  843. 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/
  844. zipfi.tmz_date.tm_sec = time.second;
  845. zipfi.tmz_date.tm_year = date.year;
  846. zipfi.dosDate = 0;
  847. // 0100000: regular file type
  848. // 0000755: permissions rwxr-xr-x
  849. // 0000644: permissions rw-r--r--
  850. uint32_t _mode = (is_executable ? 0100755 : 0100644);
  851. zipfi.external_fa = (_mode << 16L) | !(_mode & 0200);
  852. zipfi.internal_fa = 0;
  853. zipOpenNewFileInZip4(p_zip,
  854. p_folder.plus_file(f).utf8().get_data(),
  855. &zipfi,
  856. nullptr,
  857. 0,
  858. nullptr,
  859. 0,
  860. nullptr,
  861. Z_DEFLATED,
  862. Z_DEFAULT_COMPRESSION,
  863. 0,
  864. -MAX_WBITS,
  865. DEF_MEM_LEVEL,
  866. Z_DEFAULT_STRATEGY,
  867. nullptr,
  868. 0,
  869. 0x0314, // "version made by", 0x03 - Unix, 0x14 - ZIP specification version 2.0, required to store Unix file permissions
  870. 0);
  871. Vector<uint8_t> array = FileAccess::get_file_as_array(dir.plus_file(f));
  872. zipWriteInFileInZip(p_zip, array.ptr(), array.size());
  873. zipCloseFileInZip(p_zip);
  874. }
  875. }
  876. da->list_dir_end();
  877. memdelete(da);
  878. }
  879. bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  880. String err;
  881. bool valid = false;
  882. // Look for export templates (first official, and if defined custom templates).
  883. bool dvalid = exists_export_template("osx.zip", &err);
  884. bool rvalid = dvalid; // Both in the same ZIP.
  885. if (p_preset->get("custom_template/debug") != "") {
  886. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  887. if (!dvalid) {
  888. err += TTR("Custom debug template not found.") + "\n";
  889. }
  890. }
  891. if (p_preset->get("custom_template/release") != "") {
  892. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  893. if (!rvalid) {
  894. err += TTR("Custom release template not found.") + "\n";
  895. }
  896. }
  897. valid = dvalid || rvalid;
  898. r_missing_templates = !valid;
  899. String identifier = p_preset->get("application/bundle_identifier");
  900. String pn_err;
  901. if (!is_package_name_valid(identifier, &pn_err)) {
  902. err += TTR("Invalid bundle identifier:") + " " + pn_err + "\n";
  903. valid = false;
  904. }
  905. bool sign_enabled = p_preset->get("codesign/enable");
  906. bool noto_enabled = p_preset->get("notarization/enable");
  907. if (noto_enabled) {
  908. if (!sign_enabled) {
  909. err += TTR("Notarization: code signing required.") + "\n";
  910. valid = false;
  911. }
  912. bool hr_enabled = p_preset->get("codesign/hardened_runtime");
  913. if (!hr_enabled) {
  914. err += TTR("Notarization: hardened runtime required.") + "\n";
  915. valid = false;
  916. }
  917. if (p_preset->get("notarization/apple_id_name") == "") {
  918. err += TTR("Notarization: Apple ID name not specified.") + "\n";
  919. valid = false;
  920. }
  921. if (p_preset->get("notarization/apple_id_password") == "") {
  922. err += TTR("Notarization: Apple ID password not specified.") + "\n";
  923. valid = false;
  924. }
  925. }
  926. if (!err.is_empty()) {
  927. r_error = err;
  928. }
  929. return valid;
  930. }
  931. EditorExportPlatformOSX::EditorExportPlatformOSX() {
  932. Ref<Image> img = memnew(Image(_osx_logo));
  933. logo.instantiate();
  934. logo->create_from_image(img);
  935. }
  936. EditorExportPlatformOSX::~EditorExportPlatformOSX() {
  937. }