export.cpp 40 KB

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