export.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*************************************************************************/
  2. /* export.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 "editor/editor_import_export.h"
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_settings.h"
  34. #include "globals.h"
  35. #include "io/marshalls.h"
  36. #include "io/resource_saver.h"
  37. #include "io/zip_io.h"
  38. #include "os/file_access.h"
  39. #include "os/os.h"
  40. #include "platform/osx/logo.gen.h"
  41. #include "string.h"
  42. #include "version.h"
  43. class EditorExportPlatformOSX : public EditorExportPlatform {
  44. OBJ_TYPE(EditorExportPlatformOSX, EditorExportPlatform);
  45. String custom_release_package;
  46. String custom_debug_package;
  47. enum BitsMode {
  48. BITS_FAT,
  49. BITS_64,
  50. BITS_32
  51. };
  52. int version_code;
  53. String app_name;
  54. String info;
  55. String icon;
  56. String identifier;
  57. String short_version;
  58. String version;
  59. String signature;
  60. String copyright;
  61. String identity;
  62. String entitlements;
  63. BitsMode bits_mode;
  64. bool high_resolution;
  65. Ref<ImageTexture> logo;
  66. void _fix_plist(Vector<uint8_t> &plist, const String &p_binary);
  67. void _make_icon(const Image &p_icon, Vector<uint8_t> &data);
  68. Error _code_sign(const String &p_path);
  69. Error _create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name);
  70. #ifdef OSX_ENABLED
  71. bool use_codesign() const { return true; }
  72. bool use_dmg() const { return true; }
  73. #else
  74. bool use_codesign() const { return false; }
  75. bool use_dmg() const { return false; }
  76. #endif
  77. protected:
  78. bool _set(const StringName &p_name, const Variant &p_value);
  79. bool _get(const StringName &p_name, Variant &r_ret) const;
  80. void _get_property_list(List<PropertyInfo> *p_list) const;
  81. public:
  82. virtual String get_name() const { return "Mac OSX"; }
  83. virtual ImageCompression get_image_compression() const { return IMAGE_COMPRESSION_BC; }
  84. virtual Ref<Texture> get_logo() const { return logo; }
  85. virtual bool poll_devices() { return false; }
  86. virtual int get_device_count() const { return 0; }
  87. virtual String get_device_name(int p_device) const { return String(); }
  88. virtual String get_device_info(int p_device) const { return String(); }
  89. virtual Error run(int p_device, int p_flags = 0);
  90. virtual bool requires_password(bool p_debug) const { return false; }
  91. virtual String get_binary_extension() const { return use_dmg() ? "dmg" : "zip"; }
  92. virtual Error export_project(const String &p_path, bool p_debug, int p_flags = 0);
  93. virtual bool can_export(String *r_error = NULL) const;
  94. EditorExportPlatformOSX();
  95. ~EditorExportPlatformOSX();
  96. };
  97. bool EditorExportPlatformOSX::_set(const StringName &p_name, const Variant &p_value) {
  98. String n = p_name;
  99. if (n == "custom_package/debug")
  100. custom_debug_package = p_value;
  101. else if (n == "custom_package/release")
  102. custom_release_package = p_value;
  103. else if (n == "application/name")
  104. app_name = p_value;
  105. else if (n == "application/info")
  106. info = p_value;
  107. else if (n == "application/icon")
  108. icon = p_value;
  109. else if (n == "application/identifier")
  110. identifier = p_value;
  111. else if (n == "application/signature")
  112. signature = p_value;
  113. else if (n == "application/short_version")
  114. short_version = p_value;
  115. else if (n == "application/version")
  116. version = p_value;
  117. else if (n == "application/copyright")
  118. copyright = p_value;
  119. else if (n == "application/bits_mode")
  120. bits_mode = BitsMode(int(p_value));
  121. else if (n == "display/high_res")
  122. high_resolution = p_value;
  123. else if (n == "codesign/identity")
  124. identity = p_value;
  125. else if (n == "codesign/entitlements")
  126. entitlements = p_value;
  127. else
  128. return false;
  129. return true;
  130. }
  131. bool EditorExportPlatformOSX::_get(const StringName &p_name, Variant &r_ret) const {
  132. String n = p_name;
  133. if (n == "custom_package/debug")
  134. r_ret = custom_debug_package;
  135. else if (n == "custom_package/release")
  136. r_ret = custom_release_package;
  137. else if (n == "application/name")
  138. r_ret = app_name;
  139. else if (n == "application/info")
  140. r_ret = info;
  141. else if (n == "application/icon")
  142. r_ret = icon;
  143. else if (n == "application/identifier")
  144. r_ret = identifier;
  145. else if (n == "application/signature")
  146. r_ret = signature;
  147. else if (n == "application/short_version")
  148. r_ret = short_version;
  149. else if (n == "application/version")
  150. r_ret = version;
  151. else if (n == "application/copyright")
  152. r_ret = copyright;
  153. else if (n == "application/bits_mode")
  154. r_ret = bits_mode;
  155. else if (n == "display/high_res")
  156. r_ret = high_resolution;
  157. else if (n == "codesign/identity")
  158. r_ret = identity;
  159. else if (n == "codesign/entitlements")
  160. r_ret = entitlements;
  161. else
  162. return false;
  163. return true;
  164. }
  165. void EditorExportPlatformOSX::_get_property_list(List<PropertyInfo> *p_list) const {
  166. p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "zip"));
  167. p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "zip"));
  168. p_list->push_back(PropertyInfo(Variant::STRING, "application/name"));
  169. p_list->push_back(PropertyInfo(Variant::STRING, "application/info"));
  170. p_list->push_back(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "png"));
  171. p_list->push_back(PropertyInfo(Variant::STRING, "application/identifier"));
  172. p_list->push_back(PropertyInfo(Variant::STRING, "application/signature"));
  173. p_list->push_back(PropertyInfo(Variant::STRING, "application/short_version"));
  174. p_list->push_back(PropertyInfo(Variant::STRING, "application/version"));
  175. p_list->push_back(PropertyInfo(Variant::STRING, "application/copyright"));
  176. p_list->push_back(PropertyInfo(Variant::INT, "application/bits_mode", PROPERTY_HINT_ENUM, "Fat (32 & 64 bits),64 bits,32 bits"));
  177. p_list->push_back(PropertyInfo(Variant::BOOL, "display/high_res"));
  178. p_list->push_back(PropertyInfo(Variant::STRING, "codesign/identity"));
  179. p_list->push_back(PropertyInfo(Variant::STRING, "codesign/entitlements"));
  180. }
  181. void EditorExportPlatformOSX::_make_icon(const Image &p_icon, Vector<uint8_t> &icon) {
  182. Ref<ImageTexture> it = memnew(ImageTexture);
  183. int size = 512;
  184. Vector<uint8_t> data;
  185. data.resize(8);
  186. data[0] = 'i';
  187. data[1] = 'c';
  188. data[2] = 'n';
  189. data[3] = 's';
  190. const char *name[] = { "ic09", "ic08", "ic07", "icp6", "icp5", "icp4" };
  191. int index = 0;
  192. while (size >= 16) {
  193. Image copy = p_icon;
  194. copy.convert(Image::FORMAT_RGBA);
  195. copy.resize(size, size);
  196. it->create_from_image(copy);
  197. String path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/icon.png";
  198. ResourceSaver::save(path, it);
  199. FileAccess *f = FileAccess::open(path, FileAccess::READ);
  200. ERR_FAIL_COND(!f);
  201. int ofs = data.size();
  202. uint32_t len = f->get_len();
  203. data.resize(data.size() + len + 8);
  204. f->get_buffer(&data[ofs + 8], len);
  205. memdelete(f);
  206. len += 8;
  207. len = BSWAP32(len);
  208. copymem(&data[ofs], name[index], 4);
  209. encode_uint32(len, &data[ofs + 4]);
  210. index++;
  211. size /= 2;
  212. }
  213. uint32_t total_len = data.size();
  214. total_len = BSWAP32(total_len);
  215. encode_uint32(total_len, &data[4]);
  216. icon = data;
  217. }
  218. void EditorExportPlatformOSX::_fix_plist(Vector<uint8_t> &plist, const String &p_binary) {
  219. String str;
  220. String strnew;
  221. str.parse_utf8((const char *)plist.ptr(), plist.size());
  222. Vector<String> lines = str.split("\n");
  223. for (int i = 0; i < lines.size(); i++) {
  224. if (lines[i].find("$binary") != -1) {
  225. strnew += lines[i].replace("$binary", p_binary) + "\n";
  226. } else if (lines[i].find("$name") != -1) {
  227. strnew += lines[i].replace("$name", p_binary) + "\n";
  228. } else if (lines[i].find("$info") != -1) {
  229. strnew += lines[i].replace("$info", info) + "\n";
  230. } else if (lines[i].find("$identifier") != -1) {
  231. strnew += lines[i].replace("$identifier", identifier) + "\n";
  232. } else if (lines[i].find("$short_version") != -1) {
  233. strnew += lines[i].replace("$short_version", short_version) + "\n";
  234. } else if (lines[i].find("$version") != -1) {
  235. strnew += lines[i].replace("$version", version) + "\n";
  236. } else if (lines[i].find("$signature") != -1) {
  237. strnew += lines[i].replace("$signature", signature) + "\n";
  238. } else if (lines[i].find("$copyright") != -1) {
  239. strnew += lines[i].replace("$copyright", copyright) + "\n";
  240. } else if (lines[i].find("$highres") != -1) {
  241. strnew += lines[i].replace("$highres", high_resolution ? "<true/>" : "<false/>") + "\n";
  242. } else {
  243. strnew += lines[i] + "\n";
  244. }
  245. }
  246. CharString cs = strnew.utf8();
  247. plist.resize(cs.size() - 1);
  248. for (int i = 0; i < cs.size() - 1; i++) {
  249. plist[i] = cs[i];
  250. }
  251. }
  252. /**
  253. If we're running the OSX version of the Godot editor we'll:
  254. - export our application bundle to a temporary folder
  255. - attempt to code sign it
  256. - and then wrap it up in a DMG
  257. **/
  258. Error EditorExportPlatformOSX::_code_sign(const String &p_path) {
  259. List<String> args;
  260. if (entitlements != "") {
  261. // this should point to our entitlements.plist file that sandboxes our application, I don't know if this should also be placed in our app bundle
  262. args.push_back("-entitlements");
  263. args.push_back(entitlements);
  264. }
  265. args.push_back("-s");
  266. args.push_back(identity);
  267. args.push_back("-v"); // provide some more feedback
  268. args.push_back(p_path);
  269. String str;
  270. Error err = OS::get_singleton()->execute("/usr/bin/codesign", args, true, NULL, &str, NULL, true);
  271. ERR_FAIL_COND_V(err != OK, err);
  272. print_line("codesign: " + str);
  273. if (str.find("no identity found") != -1) {
  274. EditorNode::add_io_error("codesign: no identity found");
  275. return FAILED;
  276. }
  277. return OK;
  278. }
  279. Error EditorExportPlatformOSX::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {
  280. OS::get_singleton()->move_path_to_trash(p_dmg_path);
  281. List<String> args;
  282. args.push_back("create");
  283. args.push_back(p_dmg_path);
  284. args.push_back("-volname");
  285. args.push_back(p_pkg_name);
  286. args.push_back("-fs");
  287. args.push_back("HFS+");
  288. args.push_back("-srcfolder");
  289. args.push_back(p_app_path_name);
  290. String str;
  291. Error err = OS::get_singleton()->execute("/usr/bin/hdiutil", args, true, NULL, &str, NULL, true);
  292. ERR_FAIL_COND_V(err != OK, err);
  293. print_line("hdiutil returned: " + str);
  294. if (str.find("create failed") != -1) {
  295. if (str.find("File exists") != -1) {
  296. EditorNode::add_io_error("hdiutil: create failed - file exists");
  297. } else {
  298. EditorNode::add_io_error("hdiutil: create failed");
  299. }
  300. return FAILED;
  301. }
  302. return OK;
  303. }
  304. Error EditorExportPlatformOSX::export_project(const String &p_path, bool p_debug, int p_flags) {
  305. EditorProgress ep("export", "Exporting for OSX", 104);
  306. String src_pkg = p_debug ? custom_debug_package : custom_release_package;
  307. if (src_pkg == "") {
  308. String err;
  309. src_pkg = find_export_template("osx.zip", &err);
  310. if (src_pkg == "") {
  311. EditorNode::add_io_error(err);
  312. return ERR_FILE_NOT_FOUND;
  313. }
  314. }
  315. FileAccess *src_f = NULL;
  316. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  317. ep.step("Creating app", 0);
  318. unzFile pkg = unzOpen2(src_pkg.utf8().get_data(), &io);
  319. if (!pkg) {
  320. EditorNode::add_io_error("Could not find template app to export:\n" + src_pkg);
  321. return ERR_FILE_NOT_FOUND;
  322. }
  323. int ret = unzGoToFirstFile(pkg);
  324. zlib_filefunc_def io2 = io;
  325. FileAccess *dst_f = NULL;
  326. io2.opaque = &dst_f;
  327. zipFile dpkg = NULL;
  328. if (!use_dmg()) {
  329. dpkg = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2);
  330. if (!dpkg) {
  331. unzClose(pkg);
  332. return ERR_CANT_OPEN;
  333. }
  334. }
  335. String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + ".";
  336. binary_to_use += String(bits_mode == BITS_FAT ? "fat" : bits_mode == BITS_64 ? "64" : "32");
  337. print_line("binary: " + binary_to_use);
  338. String pkg_name;
  339. if (app_name != "")
  340. pkg_name = app_name;
  341. else if (String(Globals::get_singleton()->get("application/name")) != "")
  342. pkg_name = String(Globals::get_singleton()->get("application/name"));
  343. else
  344. pkg_name = "Unnamed";
  345. Error err = OK;
  346. String tmp_app_path_name = "";
  347. if (use_dmg()) {
  348. // We're on OSX so we can export to DMG, but first we create our application bundle
  349. tmp_app_path_name = EditorSettings::get_singleton()->get_settings_path() + "/tmp/" + pkg_name + ".app";
  350. print_line("Exporting to " + tmp_app_path_name);
  351. DirAccess *da_tmp_app = DirAccess::create_for_path(tmp_app_path_name);
  352. if (!da_tmp_app) {
  353. err = ERR_CANT_CREATE;
  354. }
  355. // Create our folder structure or rely on unzip?
  356. if (err == OK) {
  357. print_line("Creating " + tmp_app_path_name + "/Contents/MacOS");
  358. err = da_tmp_app->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
  359. }
  360. if (err == OK) {
  361. print_line("Creating " + tmp_app_path_name + "/Contents/Resources");
  362. err = da_tmp_app->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
  363. }
  364. }
  365. bool found_binary = false;
  366. while (ret == UNZ_OK && err == OK) {
  367. bool is_execute = false;
  368. //get filename
  369. unz_file_info info;
  370. char fname[16384];
  371. ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);
  372. String file = fname;
  373. print_line("READ: " + file);
  374. Vector<uint8_t> data;
  375. data.resize(info.uncompressed_size);
  376. //read
  377. unzOpenCurrentFile(pkg);
  378. unzReadCurrentFile(pkg, data.ptr(), data.size());
  379. unzCloseCurrentFile(pkg);
  380. //write
  381. file = file.replace_first("osx_template.app/", "");
  382. if (file == "Contents/Info.plist") {
  383. print_line("parse plist");
  384. _fix_plist(data, pkg_name);
  385. }
  386. if (file.begins_with("Contents/MacOS/godot_")) {
  387. if (file != "Contents/MacOS/" + binary_to_use) {
  388. ret = unzGoToNextFile(pkg);
  389. continue; //ignore!
  390. }
  391. found_binary = true;
  392. is_execute = true;
  393. file = "Contents/MacOS/" + pkg_name;
  394. }
  395. if (file == "Contents/Resources/icon.icns") {
  396. //see if there is an icon
  397. String iconpath = Globals::get_singleton()->get("application/icon");
  398. print_line("icon? " + iconpath);
  399. if (iconpath != "") {
  400. Image icon;
  401. icon.load(iconpath);
  402. if (!icon.empty()) {
  403. print_line("loaded?");
  404. _make_icon(icon, data);
  405. }
  406. }
  407. }
  408. if (data.size() > 0) {
  409. print_line("ADDING: " + file + " size: " + itos(data.size()));
  410. if (use_dmg()) {
  411. // write it into our application bundle
  412. file = tmp_app_path_name + "/" + file;
  413. // write the file
  414. FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
  415. if (f) {
  416. f->store_buffer(data.ptr(), data.size());
  417. f->close();
  418. if (is_execute) {
  419. // Chmod with 0755 if the file is executable
  420. err = f->_chmod(file, 0755);
  421. }
  422. memdelete(f);
  423. } else {
  424. err = ERR_CANT_CREATE;
  425. }
  426. } else {
  427. zip_fileinfo fi;
  428. file = pkg_name + ".app/" + file;
  429. fi.tmz_date.tm_hour = info.tmu_date.tm_hour;
  430. fi.tmz_date.tm_min = info.tmu_date.tm_min;
  431. fi.tmz_date.tm_sec = info.tmu_date.tm_sec;
  432. fi.tmz_date.tm_mon = info.tmu_date.tm_mon;
  433. fi.tmz_date.tm_mday = info.tmu_date.tm_mday;
  434. fi.tmz_date.tm_year = info.tmu_date.tm_year;
  435. fi.dosDate = info.dosDate;
  436. fi.internal_fa = info.internal_fa;
  437. fi.external_fa = info.external_fa;
  438. int zerr = zipOpenNewFileInZip(dpkg,
  439. file.utf8().get_data(),
  440. &fi,
  441. NULL,
  442. 0,
  443. NULL,
  444. 0,
  445. NULL,
  446. Z_DEFLATED,
  447. Z_DEFAULT_COMPRESSION);
  448. print_line("OPEN ERR: " + itos(zerr));
  449. zerr = zipWriteInFileInZip(dpkg, data.ptr(), data.size());
  450. print_line("WRITE ERR: " + itos(zerr));
  451. zipCloseFileInZip(dpkg);
  452. }
  453. }
  454. ret = unzGoToNextFile(pkg);
  455. }
  456. if (!found_binary) {
  457. ERR_PRINTS("Requested template binary '" + binary_to_use + "' not found. It might be missing from your template archive.");
  458. err = ERR_FILE_NOT_FOUND;
  459. }
  460. if (err == OK) {
  461. ep.step("Making PKG", 1);
  462. String pack_path;
  463. if (use_dmg()) {
  464. pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
  465. } else {
  466. pack_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/data.pck";
  467. }
  468. FileAccess *pfs = FileAccess::open(pack_path, FileAccess::WRITE);
  469. if (pfs) {
  470. err = save_pack(pfs);
  471. memdelete(pfs);
  472. } else {
  473. err = ERR_CANT_OPEN;
  474. }
  475. if (use_dmg()) {
  476. if (err == OK && use_codesign()) {
  477. /* see if we can code sign our new package */
  478. if (err == OK && identity != "") {
  479. ep.step("Code signing bundle", 2);
  480. /* the order in which we code sign is important, this is a bit of a shame or we could do this in our loop that extracts the files from our ZIP */
  481. // start with our application
  482. err = _code_sign(tmp_app_path_name + "/Contents/MacOS/" + pkg_name);
  483. }
  484. ///@TODO we should check the contents of /Contents/Frameworks for frameworks to sign
  485. if (err == OK && identity != "") {
  486. // we should probably loop through all resources and sign them?
  487. err = _code_sign(tmp_app_path_name + "/Contents/Resources/icon.icns");
  488. }
  489. if (err == OK && identity != "") {
  490. err = _code_sign(pack_path);
  491. }
  492. if (err == OK && identity != "") {
  493. err = _code_sign(tmp_app_path_name + "/Contents/Info.plist");
  494. }
  495. }
  496. if (err == OK) {
  497. // and finally create a DMG
  498. ep.step("Making DMG", 3);
  499. err = _create_dmg(p_path, pkg_name, tmp_app_path_name);
  500. }
  501. // Clean up temporary .app dir
  502. OS::get_singleton()->move_path_to_trash(tmp_app_path_name);
  503. } else if (err == OK) {
  504. //write datapack
  505. int zerr = zipOpenNewFileInZip(dpkg,
  506. (pkg_name + ".app/Contents/Resources/data.pck").utf8().get_data(),
  507. NULL,
  508. NULL,
  509. 0,
  510. NULL,
  511. 0,
  512. NULL,
  513. Z_DEFLATED,
  514. Z_DEFAULT_COMPRESSION);
  515. FileAccess *pf = FileAccess::open(pack_path, FileAccess::READ);
  516. if (pf) {
  517. const int BSIZE = 16384;
  518. uint8_t buf[BSIZE];
  519. while (true) {
  520. int r = pf->get_buffer(buf, BSIZE);
  521. if (r <= 0)
  522. break;
  523. zipWriteInFileInZip(dpkg, buf, r);
  524. }
  525. zipCloseFileInZip(dpkg);
  526. memdelete(pf);
  527. } else {
  528. err = ERR_CANT_OPEN;
  529. }
  530. }
  531. }
  532. if (dpkg) {
  533. zipClose(dpkg, NULL);
  534. }
  535. unzClose(pkg);
  536. return err;
  537. }
  538. Error EditorExportPlatformOSX::run(int p_device, int p_flags) {
  539. return OK;
  540. }
  541. EditorExportPlatformOSX::EditorExportPlatformOSX() {
  542. Image img(_osx_logo);
  543. logo = Ref<ImageTexture>(memnew(ImageTexture));
  544. logo->create_from_image(img);
  545. info = "Made with Godot Engine";
  546. identifier = "org.godotengine.macgame";
  547. signature = "godotmacgame";
  548. short_version = "1.0";
  549. version = "1.0";
  550. bits_mode = BITS_FAT;
  551. high_resolution = false;
  552. identity = "";
  553. entitlements = "";
  554. }
  555. bool EditorExportPlatformOSX::can_export(String *r_error) const {
  556. bool valid = true;
  557. String err;
  558. if (!exists_export_template("osx.zip")) {
  559. valid = false;
  560. err += "No export templates found.\nDownload and install export templates.\n";
  561. }
  562. if (custom_debug_package != "" && !FileAccess::exists(custom_debug_package)) {
  563. valid = false;
  564. err += "Custom debug package not found.\n";
  565. }
  566. if (custom_release_package != "" && !FileAccess::exists(custom_release_package)) {
  567. valid = false;
  568. err += "Custom release package not found.\n";
  569. }
  570. if (r_error)
  571. *r_error = err;
  572. return valid;
  573. }
  574. EditorExportPlatformOSX::~EditorExportPlatformOSX() {
  575. }
  576. void register_osx_exporter() {
  577. Ref<EditorExportPlatformOSX> exporter = Ref<EditorExportPlatformOSX>(memnew(EditorExportPlatformOSX));
  578. EditorImportExport::get_singleton()->add_export_platform(exporter);
  579. }