export.cpp 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392
  1. /*************************************************************************/
  2. /* export.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. /*************************************************************************
  30. * The code for signing the package was ported from fb-util-for-appx
  31. * available at https://github.com/facebook/fb-util-for-appx
  32. * and distributed also under the following license:
  33. BSD License
  34. For fb-util-for-appx software
  35. Copyright (c) 2016, Facebook, Inc. All rights reserved.
  36. Redistribution and use in source and binary forms, with or without modification,
  37. are permitted provided that the following conditions are met:
  38. * Redistributions of source code must retain the above copyright notice, this
  39. list of conditions and the following disclaimer.
  40. * Redistributions in binary form must reproduce the above copyright notice,
  41. this list of conditions and the following disclaimer in the documentation
  42. and/or other materials provided with the distribution.
  43. * Neither the name Facebook nor the names of its contributors may be used to
  44. endorse or promote products derived from this software without specific
  45. prior written permission.
  46. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  47. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  48. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  49. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  50. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  52. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  53. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  54. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  55. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  56. *************************************************************************/
  57. #include "version.h"
  58. #include "export.h"
  59. #include "object.h"
  60. #include "tools/editor/editor_import_export.h"
  61. #include "tools/editor/editor_node.h"
  62. #include "platform/uwp/logo.h"
  63. #include "os/file_access.h"
  64. #include "io/zip.h"
  65. #include "io/unzip.h"
  66. #include "io/zip_io.h"
  67. #include "io/sha256.h"
  68. #include "io/base64.h"
  69. #include "bind/core_bind.h"
  70. #include "globals.h"
  71. #include "io/marshalls.h"
  72. #include <zlib.h>
  73. // Capabilities
  74. static const char* uwp_capabilities[] = {
  75. "allJoyn",
  76. "codeGeneration",
  77. "internetClient",
  78. "internetClientServer",
  79. "privateNetworkClientServer",
  80. NULL
  81. };
  82. static const char* uwp_uap_capabilities[] = {
  83. "appointments",
  84. "blockedChatMessages",
  85. "chat",
  86. "contacts",
  87. "enterpriseAuthentication",
  88. "musicLibrary",
  89. "objects3D",
  90. "picturesLibrary",
  91. "phoneCall",
  92. "removableStorage",
  93. "sharedUserCertificates",
  94. "userAccountInformation",
  95. "videosLibrary",
  96. "voipCall",
  97. NULL
  98. };
  99. static const char* uwp_device_capabilites[] = {
  100. "bluetooth",
  101. "location",
  102. "microphone",
  103. "proximity",
  104. "webcam",
  105. NULL
  106. };
  107. #ifdef OPENSSL_ENABLED
  108. #include <openssl/bio.h>
  109. #include <openssl/asn1.h>
  110. #include <openssl/pkcs7.h>
  111. #include <openssl/pkcs12.h>
  112. #include <openssl/err.h>
  113. #include <openssl/asn1t.h>
  114. #include <openssl/x509.h>
  115. #include <openssl/ossl_typ.h>
  116. namespace asn1 {
  117. // https://msdn.microsoft.com/en-us/gg463180.aspx
  118. struct SPCStatementType {
  119. ASN1_OBJECT *type;
  120. };
  121. DECLARE_ASN1_FUNCTIONS(SPCStatementType)
  122. struct SPCSpOpusInfo {
  123. ASN1_TYPE *programName;
  124. ASN1_TYPE *moreInfo;
  125. };
  126. DECLARE_ASN1_FUNCTIONS(SPCSpOpusInfo)
  127. struct DigestInfo {
  128. X509_ALGOR *digestAlgorithm;
  129. ASN1_OCTET_STRING *digest;
  130. };
  131. DECLARE_ASN1_FUNCTIONS(DigestInfo)
  132. struct SPCAttributeTypeAndOptionalValue {
  133. ASN1_OBJECT *type;
  134. ASN1_TYPE *value; // SPCInfoValue
  135. };
  136. DECLARE_ASN1_FUNCTIONS(SPCAttributeTypeAndOptionalValue)
  137. // Undocumented.
  138. struct SPCInfoValue {
  139. ASN1_INTEGER *i1;
  140. ASN1_OCTET_STRING *s1;
  141. ASN1_INTEGER *i2;
  142. ASN1_INTEGER *i3;
  143. ASN1_INTEGER *i4;
  144. ASN1_INTEGER *i5;
  145. ASN1_INTEGER *i6;
  146. };
  147. DECLARE_ASN1_FUNCTIONS(SPCInfoValue)
  148. struct SPCIndirectDataContent {
  149. SPCAttributeTypeAndOptionalValue *data;
  150. DigestInfo *messageDigest;
  151. };
  152. DECLARE_ASN1_FUNCTIONS(SPCIndirectDataContent)
  153. IMPLEMENT_ASN1_FUNCTIONS(SPCIndirectDataContent)
  154. ASN1_SEQUENCE(SPCIndirectDataContent) = {
  155. ASN1_SIMPLE(SPCIndirectDataContent, data,
  156. SPCAttributeTypeAndOptionalValue),
  157. ASN1_SIMPLE(SPCIndirectDataContent, messageDigest, DigestInfo),
  158. } ASN1_SEQUENCE_END(SPCIndirectDataContent)
  159. IMPLEMENT_ASN1_FUNCTIONS(SPCAttributeTypeAndOptionalValue)
  160. ASN1_SEQUENCE(SPCAttributeTypeAndOptionalValue) = {
  161. ASN1_SIMPLE(SPCAttributeTypeAndOptionalValue, type,
  162. ASN1_OBJECT),
  163. ASN1_OPT(SPCAttributeTypeAndOptionalValue, value, ASN1_ANY),
  164. } ASN1_SEQUENCE_END(SPCAttributeTypeAndOptionalValue)
  165. IMPLEMENT_ASN1_FUNCTIONS(SPCInfoValue)
  166. ASN1_SEQUENCE(SPCInfoValue) = {
  167. ASN1_SIMPLE(SPCInfoValue, i1, ASN1_INTEGER),
  168. ASN1_SIMPLE(SPCInfoValue, s1, ASN1_OCTET_STRING),
  169. ASN1_SIMPLE(SPCInfoValue, i2, ASN1_INTEGER),
  170. ASN1_SIMPLE(SPCInfoValue, i3, ASN1_INTEGER),
  171. ASN1_SIMPLE(SPCInfoValue, i4, ASN1_INTEGER),
  172. ASN1_SIMPLE(SPCInfoValue, i5, ASN1_INTEGER),
  173. ASN1_SIMPLE(SPCInfoValue, i6, ASN1_INTEGER),
  174. } ASN1_SEQUENCE_END(SPCInfoValue)
  175. IMPLEMENT_ASN1_FUNCTIONS(DigestInfo)
  176. ASN1_SEQUENCE(DigestInfo) = {
  177. ASN1_SIMPLE(DigestInfo, digestAlgorithm, X509_ALGOR),
  178. ASN1_SIMPLE(DigestInfo, digest, ASN1_OCTET_STRING),
  179. } ASN1_SEQUENCE_END(DigestInfo)
  180. ASN1_SEQUENCE(SPCSpOpusInfo) = {
  181. ASN1_OPT(SPCSpOpusInfo, programName, ASN1_ANY),
  182. ASN1_OPT(SPCSpOpusInfo, moreInfo, ASN1_ANY),
  183. } ASN1_SEQUENCE_END(SPCSpOpusInfo)
  184. IMPLEMENT_ASN1_FUNCTIONS(SPCSpOpusInfo)
  185. ASN1_SEQUENCE(SPCStatementType) = {
  186. ASN1_SIMPLE(SPCStatementType, type, ASN1_OBJECT),
  187. } ASN1_SEQUENCE_END(SPCStatementType)
  188. IMPLEMENT_ASN1_FUNCTIONS(SPCStatementType)
  189. }
  190. class EncodedASN1 {
  191. uint8_t* i_data;
  192. size_t i_size;
  193. EncodedASN1(uint8_t** p_data, size_t p_size) {
  194. i_data = *p_data;
  195. i_size = p_size;
  196. }
  197. public:
  198. template <typename T, int(*TEncode)(T *, uint8_t **)>
  199. static EncodedASN1 FromItem(T *item) {
  200. uint8_t *dataRaw = NULL;
  201. int size = TEncode(item, &dataRaw);
  202. return EncodedASN1(&dataRaw, size);
  203. }
  204. const uint8_t *data() const {
  205. return i_data;
  206. }
  207. size_t size() const {
  208. return i_size;
  209. }
  210. // Assumes the encoded ASN.1 represents a SEQUENCE and puts it into
  211. // an ASN1_STRING.
  212. //
  213. // The returned object holds a copy of this object's data.
  214. ASN1_STRING* ToSequenceString() {
  215. ASN1_STRING* string = ASN1_STRING_new();
  216. if (!string) {
  217. return NULL;
  218. }
  219. if (!ASN1_STRING_set(string, i_data, i_size)) {
  220. return NULL;
  221. }
  222. return string;
  223. }
  224. // Assumes the encoded ASN.1 represents a SEQUENCE and puts it into
  225. // an ASN1_TYPE.
  226. //
  227. // The returned object holds a copy of this object's data.
  228. ASN1_TYPE* ToSequenceType() {
  229. ASN1_STRING* string = ToSequenceString();
  230. ASN1_TYPE* type = ASN1_TYPE_new();
  231. if (!type) {
  232. return NULL;
  233. }
  234. type->type = V_ASN1_SEQUENCE;
  235. type->value.sequence = string;
  236. return type;
  237. }
  238. };
  239. #endif // OPENSSL_ENABLED
  240. class AppxPackager {
  241. enum {
  242. FILE_HEADER_MAGIC = 0x04034b50,
  243. DATA_DESCRIPTOR_MAGIC = 0x08074b50,
  244. CENTRAL_DIR_MAGIC = 0x02014b50,
  245. END_OF_CENTRAL_DIR_MAGIC = 0x06054b50,
  246. ZIP64_END_OF_CENTRAL_DIR_MAGIC = 0x06064b50,
  247. ZIP64_END_DIR_LOCATOR_MAGIC = 0x07064b50,
  248. P7X_SIGNATURE = 0x58434b50,
  249. ZIP64_HEADER_ID = 0x0001,
  250. ZIP_VERSION = 20,
  251. ZIP_ARCHIVE_VERSION = 45,
  252. GENERAL_PURPOSE = 0x00,
  253. BASE_FILE_HEADER_SIZE = 30,
  254. DATA_DESCRIPTOR_SIZE = 24,
  255. BASE_CENTRAL_DIR_SIZE = 46,
  256. EXTRA_FIELD_LENGTH = 28,
  257. ZIP64_HEADER_SIZE = 24,
  258. ZIP64_END_OF_CENTRAL_DIR_SIZE = (56 - 12),
  259. END_OF_CENTRAL_DIR_SIZE = 42,
  260. BLOCK_SIZE = 65536,
  261. };
  262. struct BlockHash {
  263. String base64_hash;
  264. size_t compressed_size;
  265. };
  266. struct FileMeta {
  267. String name;
  268. int lfh_size;
  269. bool compressed;
  270. size_t compressed_size;
  271. size_t uncompressed_size;
  272. Vector<BlockHash> hashes;
  273. uLong file_crc32;
  274. ZPOS64_T zip_offset;
  275. };
  276. String progress_task;
  277. FileAccess *package;
  278. String tmp_blockmap_file_path;
  279. String tmp_content_types_file_path;
  280. Set<String> mime_types;
  281. Vector<FileMeta> file_metadata;
  282. ZPOS64_T central_dir_offset;
  283. ZPOS64_T end_of_central_dir_offset;
  284. Vector<uint8_t> central_dir_data;
  285. String hash_block(uint8_t* p_block_data, size_t p_block_len);
  286. void make_block_map();
  287. void make_content_types();
  288. _FORCE_INLINE_ unsigned int buf_put_int16(uint16_t p_val, uint8_t * p_buf) {
  289. for (int i = 0; i < 2; i++) {
  290. *p_buf++ = (p_val >> (i * 8)) & 0xFF;
  291. }
  292. return 2;
  293. }
  294. _FORCE_INLINE_ unsigned int buf_put_int32(uint32_t p_val, uint8_t * p_buf) {
  295. for (int i = 0; i < 4; i++) {
  296. *p_buf++ = (p_val >> (i * 8)) & 0xFF;
  297. }
  298. return 4;
  299. }
  300. _FORCE_INLINE_ unsigned int buf_put_int64(uint64_t p_val, uint8_t * p_buf) {
  301. for (int i = 0; i < 8; i++) {
  302. *p_buf++ = (p_val >> (i * 8)) & 0xFF;
  303. }
  304. return 8;
  305. }
  306. _FORCE_INLINE_ unsigned int buf_put_string(String p_val, uint8_t * p_buf) {
  307. for (int i = 0; i < p_val.length(); i++) {
  308. *p_buf++ = p_val.utf8().get(i);
  309. }
  310. return p_val.length();
  311. }
  312. Vector<uint8_t> make_file_header(FileMeta p_file_meta);
  313. void store_central_dir_header(const FileMeta p_file, bool p_do_hash = true);
  314. Vector<uint8_t> make_end_of_central_record();
  315. String content_type(String p_extension);
  316. #ifdef OPENSSL_ENABLED
  317. // Signing methods and structs:
  318. String certificate_path;
  319. String certificate_pass;
  320. bool sign_package;
  321. struct CertFile {
  322. EVP_PKEY* private_key;
  323. X509* certificate;
  324. };
  325. SHA256_CTX axpc_context; // SHA256 context for ZIP file entries
  326. SHA256_CTX axcd_context; // SHA256 context for ZIP directory entries
  327. struct AppxDigests {
  328. uint8_t axpc[SHA256_DIGEST_LENGTH]; // ZIP file entries
  329. uint8_t axcd[SHA256_DIGEST_LENGTH]; // ZIP directory entry
  330. uint8_t axct[SHA256_DIGEST_LENGTH]; // Content types XML
  331. uint8_t axbm[SHA256_DIGEST_LENGTH]; // Block map XML
  332. uint8_t axci[SHA256_DIGEST_LENGTH]; // Code Integrity file (optional)
  333. };
  334. CertFile cert_file;
  335. AppxDigests digests;
  336. void MakeSPCInfoValue(asn1::SPCInfoValue &info);
  337. Error MakeIndirectDataContent(asn1::SPCIndirectDataContent &idc);
  338. Error add_attributes(PKCS7_SIGNER_INFO *signerInfo);
  339. void make_digests();
  340. void write_digest(Vector<uint8_t> &p_out_buffer);
  341. Error openssl_error(unsigned long p_err);
  342. Error read_cert_file(const String &p_path, const String &p_password, CertFile* p_out_cf);
  343. Error sign(const CertFile &p_cert, const AppxDigests &digests, PKCS7* p_out_signature);
  344. #endif // OPENSSL_ENABLED
  345. public:
  346. enum SignOption {
  347. SIGN,
  348. DONT_SIGN,
  349. };
  350. void set_progress_task(String p_task) { progress_task = p_task; }
  351. void init(FileAccess* p_fa, SignOption p_sign, String &p_certificate_path, String &p_certificate_password);
  352. void add_file(String p_file_name, const uint8_t* p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress = false);
  353. void finish();
  354. AppxPackager();
  355. ~AppxPackager();
  356. };
  357. class EditorExportPlatformUWP : public EditorExportPlatform {
  358. GDCLASS(EditorExportPlatformUWP, EditorExportPlatform);
  359. Ref<ImageTexture> logo;
  360. enum Platform {
  361. ARM,
  362. X86,
  363. X64
  364. } arch;
  365. bool is_debug;
  366. String custom_release_package;
  367. String custom_debug_package;
  368. String cmdline;
  369. String display_name;
  370. String short_name;
  371. String unique_name;
  372. String description;
  373. String publisher;
  374. String publisher_display_name;
  375. String product_guid;
  376. String publisher_guid;
  377. int version_major;
  378. int version_minor;
  379. int version_build;
  380. int version_revision;
  381. bool orientation_landscape;
  382. bool orientation_portrait;
  383. bool orientation_landscape_flipped;
  384. bool orientation_portrait_flipped;
  385. String background_color;
  386. Ref<ImageTexture> store_logo;
  387. Ref<ImageTexture> square44;
  388. Ref<ImageTexture> square71;
  389. Ref<ImageTexture> square150;
  390. Ref<ImageTexture> square310;
  391. Ref<ImageTexture> wide310;
  392. Ref<ImageTexture> splash;
  393. bool name_on_square150;
  394. bool name_on_square310;
  395. bool name_on_wide;
  396. Set<String> capabilities;
  397. Set<String> uap_capabilities;
  398. Set<String> device_capabilities;
  399. bool sign_package;
  400. String certificate_path;
  401. String certificate_pass;
  402. _FORCE_INLINE_ bool array_has(const char** p_array, const char* p_value) const {
  403. while (*p_array) {
  404. if (String(*p_array) == String(p_value)) return true;
  405. p_array++;
  406. }
  407. return false;
  408. }
  409. bool _valid_resource_name(const String &p_name) const;
  410. bool _valid_guid(const String &p_guid) const;
  411. bool _valid_bgcolor(const String &p_color) const;
  412. bool _valid_image(const Ref<ImageTexture> p_image, int p_width, int p_height) const;
  413. Vector<uint8_t> _fix_manifest(const Vector<uint8_t> &p_template, bool p_give_internet) const;
  414. Vector<uint8_t> _get_image_data(const String &p_path);
  415. static Error save_appx_file(void *p_userdata, const String& p_path, const Vector<uint8_t>& p_data, int p_file, int p_total);
  416. static bool _should_compress_asset(const String& p_path, const Vector<uint8_t>& p_data);
  417. protected:
  418. bool _set(const StringName& p_name, const Variant& p_value);
  419. bool _get(const StringName& p_name, Variant &r_ret) const;
  420. void _get_property_list(List<PropertyInfo> *p_list) const;
  421. public:
  422. virtual String get_name() const { return "Windows Universal"; }
  423. virtual ImageCompression get_image_compression() const { return IMAGE_COMPRESSION_ETC1; }
  424. virtual Ref<Texture> get_logo() const { return logo; }
  425. virtual bool can_export(String *r_error = NULL) const;
  426. virtual String get_binary_extension() const { return "appx"; }
  427. virtual Error export_project(const String& p_path, bool p_debug, int p_flags = 0);
  428. EditorExportPlatformUWP();
  429. ~EditorExportPlatformUWP();
  430. };
  431. ///////////////////////////////////////////////////////////////////////////
  432. String AppxPackager::hash_block(uint8_t * p_block_data, size_t p_block_len) {
  433. char hash[32];
  434. char base64[45];
  435. sha256_context ctx;
  436. sha256_init(&ctx);
  437. sha256_hash(&ctx, p_block_data, p_block_len);
  438. sha256_done(&ctx, (uint8_t*)hash);
  439. base64_encode(base64, hash, 32);
  440. base64[44] = '\0';
  441. return String(base64);
  442. }
  443. void AppxPackager::make_block_map() {
  444. FileAccess* tmp_file = FileAccess::open(tmp_blockmap_file_path, FileAccess::WRITE);
  445. tmp_file->store_string("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
  446. tmp_file->store_string("<BlockMap xmlns=\"http://schemas.microsoft.com/appx/2010/blockmap\" HashMethod=\"http://www.w3.org/2001/04/xmlenc#sha256\">");
  447. for (int i = 0; i < file_metadata.size(); i++) {
  448. FileMeta file = file_metadata[i];
  449. tmp_file->store_string(
  450. "<File Name=\"" + file.name.replace("/", "\\")
  451. + "\" Size=\"" + itos(file.uncompressed_size)
  452. + "\" LfhSize=\"" + itos(file.lfh_size) + "\">");
  453. for (int j = 0; j < file.hashes.size(); j++) {
  454. tmp_file->store_string("<Block Hash=\""
  455. + file.hashes[j].base64_hash + "\" ");
  456. if (file.compressed)
  457. tmp_file->store_string("Size=\"" + itos(file.hashes[j].compressed_size) + "\" ");
  458. tmp_file->store_string("/>");
  459. }
  460. tmp_file->store_string("</File>");
  461. }
  462. tmp_file->store_string("</BlockMap>");
  463. tmp_file->close();
  464. memdelete(tmp_file);
  465. tmp_file = NULL;
  466. }
  467. String AppxPackager::content_type(String p_extension) {
  468. if (p_extension == "png")
  469. return "image/png";
  470. else if (p_extension == "jpg")
  471. return "image/jpg";
  472. else if (p_extension == "xml")
  473. return "application/xml";
  474. else if (p_extension == "exe" || p_extension == "dll")
  475. return "application/x-msdownload";
  476. else
  477. return "application/octet-stream";
  478. }
  479. void AppxPackager::make_content_types() {
  480. FileAccess* tmp_file = FileAccess::open(tmp_content_types_file_path, FileAccess::WRITE);
  481. tmp_file->store_string("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  482. tmp_file->store_string("<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">");
  483. Map<String, String> types;
  484. for (int i = 0; i < file_metadata.size(); i++) {
  485. String ext = file_metadata[i].name.get_extension();
  486. if (types.has(ext)) continue;
  487. types[ext] = content_type(ext);
  488. tmp_file->store_string("<Default Extension=\"" + ext + "\" ContentType=\"" + types[ext] + "\" />");
  489. }
  490. // Appx signature file
  491. tmp_file->store_string("<Default Extension=\"p7x\" ContentType=\"application/octet-stream\" />");
  492. // Override for package files
  493. tmp_file->store_string("<Override PartName=\"/AppxManifest.xml\" ContentType=\"application/vnd.ms-appx.manifest+xml\" />");
  494. tmp_file->store_string("<Override PartName=\"/AppxBlockMap.xml\" ContentType=\"application/vnd.ms-appx.blockmap+xml\" />");
  495. tmp_file->store_string("<Override PartName=\"/AppxSignature.p7x\" ContentType=\"application/vnd.ms-appx.signature\" />");
  496. tmp_file->store_string("<Override PartName=\"/AppxMetadata/CodeIntegrity.cat\" ContentType=\"application/vnd.ms-pkiseccat\" />");
  497. tmp_file->store_string("</Types>");
  498. tmp_file->close();
  499. memdelete(tmp_file);
  500. tmp_file = NULL;
  501. }
  502. Vector<uint8_t> AppxPackager::make_file_header(FileMeta p_file_meta) {
  503. Vector<uint8_t> buf;
  504. buf.resize(BASE_FILE_HEADER_SIZE + p_file_meta.name.length());
  505. int offs = 0;
  506. // Write magic
  507. offs += buf_put_int32(FILE_HEADER_MAGIC, &buf[offs]);
  508. // Version
  509. offs += buf_put_int16(ZIP_VERSION, &buf[offs]);
  510. // Special flag
  511. offs += buf_put_int16(GENERAL_PURPOSE, &buf[offs]);
  512. // Compression
  513. offs += buf_put_int16(p_file_meta.compressed ? Z_DEFLATED : 0, &buf[offs]);
  514. // File date and time
  515. offs += buf_put_int32(0, &buf[offs]);
  516. // CRC-32
  517. offs += buf_put_int32(p_file_meta.file_crc32, &buf[offs]);
  518. // Compressed size
  519. offs += buf_put_int32(p_file_meta.compressed_size, &buf[offs]);
  520. // Uncompressed size
  521. offs += buf_put_int32(p_file_meta.uncompressed_size, &buf[offs]);
  522. // File name length
  523. offs += buf_put_int16(p_file_meta.name.length(), &buf[offs]);
  524. // Extra data length
  525. offs += buf_put_int16(0, &buf[offs]);
  526. // File name
  527. offs += buf_put_string(p_file_meta.name, &buf[offs]);
  528. // Done!
  529. return buf;
  530. }
  531. void AppxPackager::store_central_dir_header(const FileMeta p_file, bool p_do_hash) {
  532. Vector<uint8_t> &buf = central_dir_data;
  533. int offs = buf.size();
  534. buf.resize(buf.size() + BASE_CENTRAL_DIR_SIZE + p_file.name.length());
  535. // Write magic
  536. offs += buf_put_int32(CENTRAL_DIR_MAGIC, &buf[offs]);
  537. // ZIP versions
  538. offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf[offs]);
  539. offs += buf_put_int16(ZIP_VERSION, &buf[offs]);
  540. // General purpose flag
  541. offs += buf_put_int16(GENERAL_PURPOSE, &buf[offs]);
  542. // Compression
  543. offs += buf_put_int16(p_file.compressed ? Z_DEFLATED : 0, &buf[offs]);
  544. // Modification date/time
  545. offs += buf_put_int32(0, &buf[offs]);
  546. // Crc-32
  547. offs += buf_put_int32(p_file.file_crc32, &buf[offs]);
  548. // File sizes
  549. offs += buf_put_int32(p_file.compressed_size, &buf[offs]);
  550. offs += buf_put_int32(p_file.uncompressed_size, &buf[offs]);
  551. // File name length
  552. offs += buf_put_int16(p_file.name.length(), &buf[offs]);
  553. // Extra field length
  554. offs += buf_put_int16(0, &buf[offs]);
  555. // Comment length
  556. offs += buf_put_int16(0, &buf[offs]);
  557. // Disk number start, internal/external file attributes
  558. for (int i = 0; i < 8; i++) {
  559. buf[offs++] = 0;
  560. }
  561. // Relative offset
  562. offs += buf_put_int32(p_file.zip_offset, &buf[offs]);
  563. // File name
  564. offs += buf_put_string(p_file.name, &buf[offs]);
  565. #ifdef OPENSSL_ENABLED
  566. // Calculate the hash for signing
  567. if (p_do_hash)
  568. SHA256_Update(&axcd_context, buf.ptr(), buf.size());
  569. #endif // OPENSSL_ENABLED
  570. // Done!
  571. }
  572. Vector<uint8_t> AppxPackager::make_end_of_central_record() {
  573. Vector<uint8_t> buf;
  574. buf.resize(ZIP64_END_OF_CENTRAL_DIR_SIZE + 12 + END_OF_CENTRAL_DIR_SIZE); // Size plus magic
  575. int offs = 0;
  576. // Write magic
  577. offs += buf_put_int32(ZIP64_END_OF_CENTRAL_DIR_MAGIC, &buf[offs]);
  578. // Size of this record
  579. offs += buf_put_int64(ZIP64_END_OF_CENTRAL_DIR_SIZE, &buf[offs]);
  580. // Version (yes, twice)
  581. offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf[offs]);
  582. offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf[offs]);
  583. // Disk number
  584. for (int i = 0; i < 8; i++) {
  585. buf[offs++] = 0;
  586. }
  587. // Number of entries (total and per disk)
  588. offs += buf_put_int64(file_metadata.size(), &buf[offs]);
  589. offs += buf_put_int64(file_metadata.size(), &buf[offs]);
  590. // Size of central dir
  591. offs += buf_put_int64(central_dir_data.size(), &buf[offs]);
  592. // Central dir offset
  593. offs += buf_put_int64(central_dir_offset, &buf[offs]);
  594. ////// ZIP64 locator
  595. // Write magic for zip64 central dir locator
  596. offs += buf_put_int32(ZIP64_END_DIR_LOCATOR_MAGIC, &buf[offs]);
  597. // Disk number
  598. for (int i = 0; i < 4; i++) {
  599. buf[offs++] = 0;
  600. }
  601. // Relative offset
  602. offs += buf_put_int64(end_of_central_dir_offset, &buf[offs]);
  603. // Number of disks
  604. offs += buf_put_int32(1, &buf[offs]);
  605. /////// End of zip directory
  606. // Write magic for end central dir
  607. offs += buf_put_int32(END_OF_CENTRAL_DIR_MAGIC, &buf[offs]);
  608. // Dummy stuff for Zip64
  609. for (int i = 0; i < 4; i++) {
  610. buf[offs++] = 0x0;
  611. }
  612. for (int i = 0; i < 12; i++) {
  613. buf[offs++] = 0xFF;
  614. }
  615. // Size of comments
  616. for (int i = 0; i < 2; i++) {
  617. buf[offs++] = 0;
  618. }
  619. // Done!
  620. return buf;
  621. }
  622. void AppxPackager::init(FileAccess * p_fa, SignOption p_sign, String &p_certificate_path, String &p_certificate_password) {
  623. package = p_fa;
  624. central_dir_offset = 0;
  625. end_of_central_dir_offset = 0;
  626. tmp_blockmap_file_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmpblockmap.xml";
  627. tmp_content_types_file_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmpcontenttypes.xml";
  628. #ifdef OPENSSL_ENABLED
  629. certificate_path = p_certificate_path;
  630. certificate_pass = p_certificate_password;
  631. sign_package = p_sign == SIGN;
  632. SHA256_Init(&axpc_context);
  633. SHA256_Init(&axcd_context);
  634. #endif // OPENSSL_ENABLED
  635. }
  636. void AppxPackager::add_file(String p_file_name, const uint8_t * p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress) {
  637. if (p_file_no >= 1 && p_total_files >= 1) {
  638. EditorNode::progress_task_step(progress_task, "File: " + p_file_name, (p_file_no * 100) / p_total_files);
  639. }
  640. bool do_hash = p_file_name != "AppxSignature.p7x";
  641. FileMeta meta;
  642. meta.name = p_file_name;
  643. meta.uncompressed_size = p_len;
  644. meta.compressed_size = p_len;
  645. meta.compressed = p_compress;
  646. meta.zip_offset = package->get_pos();
  647. Vector<uint8_t> file_buffer;
  648. // Data for compression
  649. z_stream strm;
  650. FileAccess* strm_f = NULL;
  651. Vector<uint8_t> strm_in;
  652. strm_in.resize(BLOCK_SIZE);
  653. Vector<uint8_t> strm_out;
  654. if (p_compress) {
  655. strm.zalloc = zipio_alloc;
  656. strm.zfree = zipio_free;
  657. strm.opaque = &strm_f;
  658. strm_out.resize(BLOCK_SIZE + 8);
  659. deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
  660. }
  661. int step = 0;
  662. while (p_len - step > 0) {
  663. size_t block_size = (p_len - step) > BLOCK_SIZE ? BLOCK_SIZE : (p_len - step);
  664. for (int i = 0; i < block_size; i++) {
  665. strm_in[i] = p_buffer[step + i];
  666. }
  667. BlockHash bh;
  668. bh.base64_hash = hash_block(strm_in.ptr(), block_size);
  669. if (p_compress) {
  670. strm.avail_in = block_size;
  671. strm.avail_out = strm_out.size();
  672. strm.next_in = strm_in.ptr();
  673. strm.next_out = strm_out.ptr();
  674. int total_out_before = strm.total_out;
  675. deflate(&strm, Z_FULL_FLUSH);
  676. bh.compressed_size = strm.total_out - total_out_before;
  677. //package->store_buffer(strm_out.ptr(), strm.total_out - total_out_before);
  678. int start = file_buffer.size();
  679. file_buffer.resize(file_buffer.size() + bh.compressed_size);
  680. for (int i = 0; i < bh.compressed_size; i++)
  681. file_buffer[start + i] = strm_out[i];
  682. #ifdef OPENSSL_ENABLED
  683. if (do_hash)
  684. SHA256_Update(&axpc_context, strm_out.ptr(), strm.total_out - total_out_before);
  685. #endif // OPENSSL_ENABLED
  686. } else {
  687. bh.compressed_size = block_size;
  688. //package->store_buffer(strm_in.ptr(), block_size);
  689. int start = file_buffer.size();
  690. file_buffer.resize(file_buffer.size() + block_size);
  691. for (int i = 0; i < bh.compressed_size; i++)
  692. file_buffer[start + i] = strm_in[i];
  693. #ifdef OPENSSL_ENABLED
  694. if (do_hash)
  695. SHA256_Update(&axpc_context, strm_in.ptr(), block_size);
  696. #endif // OPENSSL_ENABLED
  697. }
  698. meta.hashes.push_back(bh);
  699. step += block_size;
  700. }
  701. if (p_compress) {
  702. strm.avail_in = 0;
  703. strm.avail_out = strm_out.size();
  704. strm.next_in = strm_in.ptr();
  705. strm.next_out = strm_out.ptr();
  706. int total_out_before = strm.total_out;
  707. deflate(&strm, Z_FINISH);
  708. //package->store_buffer(strm_out.ptr(), strm.total_out - total_out_before);
  709. int start = file_buffer.size();
  710. file_buffer.resize(file_buffer.size() + (strm.total_out - total_out_before));
  711. for (int i = 0; i < (strm.total_out - total_out_before); i++)
  712. file_buffer[start + i] = strm_out[i];
  713. #ifdef OPENSSL_ENABLED
  714. if (do_hash)
  715. SHA256_Update(&axpc_context, strm_out.ptr(), strm.total_out - total_out_before);
  716. #endif // OPENSSL_ENABLED
  717. deflateEnd(&strm);
  718. meta.compressed_size = strm.total_out;
  719. } else {
  720. meta.compressed_size = p_len;
  721. }
  722. // Calculate file CRC-32
  723. uLong crc = crc32(0L, Z_NULL, 0);
  724. crc = crc32(crc, p_buffer, p_len);
  725. meta.file_crc32 = crc;
  726. // Create file header
  727. Vector<uint8_t> file_header = make_file_header(meta);
  728. meta.lfh_size = file_header.size();
  729. #ifdef OPENSSL_ENABLED
  730. // Hash the data for signing
  731. if (do_hash) {
  732. SHA256_Update(&axpc_context, file_header.ptr(), file_header.size());
  733. SHA256_Update(&axpc_context, file_buffer.ptr(), file_buffer.size());
  734. }
  735. #endif // OPENSSL_ENABLED
  736. // Store the header and file;
  737. package->store_buffer(file_header.ptr(), file_header.size());
  738. package->store_buffer(file_buffer.ptr(), file_buffer.size());
  739. file_metadata.push_back(meta);
  740. }
  741. void AppxPackager::finish() {
  742. // Create and add block map file
  743. EditorNode::progress_task_step("export", "Creating block map...", 4);
  744. make_block_map();
  745. FileAccess* blockmap_file = FileAccess::open(tmp_blockmap_file_path, FileAccess::READ);
  746. Vector<uint8_t> blockmap_buffer;
  747. blockmap_buffer.resize(blockmap_file->get_len());
  748. blockmap_file->get_buffer(blockmap_buffer.ptr(), blockmap_buffer.size());
  749. #ifdef OPENSSL_ENABLED
  750. // Hash the file for signing
  751. if (sign_package) {
  752. SHA256_CTX axbm_context;
  753. SHA256_Init(&axbm_context);
  754. SHA256_Update(&axbm_context, blockmap_buffer.ptr(), blockmap_buffer.size());
  755. SHA256_Final(digests.axbm, &axbm_context);
  756. }
  757. #endif // OPENSSL_ENABLED
  758. add_file("AppxBlockMap.xml", blockmap_buffer.ptr(), blockmap_buffer.size(), -1, -1, true);
  759. blockmap_file->close();
  760. memdelete(blockmap_file);
  761. blockmap_file = NULL;
  762. // Add content types
  763. EditorNode::progress_task_step("export", "Setting content types...", 5);
  764. make_content_types();
  765. FileAccess* types_file = FileAccess::open(tmp_content_types_file_path, FileAccess::READ);
  766. Vector<uint8_t> types_buffer;
  767. types_buffer.resize(types_file->get_len());
  768. types_file->get_buffer(types_buffer.ptr(), types_buffer.size());
  769. #ifdef OPENSSL_ENABLED
  770. if (sign_package) {
  771. // Hash the file for signing
  772. SHA256_CTX axct_context;
  773. SHA256_Init(&axct_context);
  774. SHA256_Update(&axct_context, types_buffer.ptr(), types_buffer.size());
  775. SHA256_Final(digests.axct, &axct_context);
  776. }
  777. #endif // OPENSSL_ENABLED
  778. add_file("[Content_Types].xml", types_buffer.ptr(), types_buffer.size(), -1, -1, true);
  779. types_file->close();
  780. memdelete(types_file);
  781. types_file = NULL;
  782. // Pre-process central directory before signing
  783. for (int i = 0; i < file_metadata.size(); i++) {
  784. store_central_dir_header(file_metadata[i]);
  785. }
  786. #ifdef OPENSSL_ENABLED
  787. // Create the signature file
  788. if (sign_package) {
  789. Error err = read_cert_file(certificate_path, certificate_pass, &cert_file);
  790. if (err != OK) {
  791. EditorNode::add_io_error(TTR("Couldn't read the certficate file. Are the path and password both correct?"));
  792. package->close();
  793. memdelete(package);
  794. package = NULL;
  795. return;
  796. }
  797. // Make a temp end of the zip for hashing
  798. central_dir_offset = package->get_pos();
  799. end_of_central_dir_offset = central_dir_offset + central_dir_data.size();
  800. Vector<uint8_t> zip_end_dir = make_end_of_central_record();
  801. // Hash the end directory
  802. SHA256_Update(&axcd_context, zip_end_dir.ptr(), zip_end_dir.size());
  803. // Finish the hashes
  804. make_digests();
  805. PKCS7* signature = PKCS7_new();
  806. if (!signature) {
  807. EditorNode::add_io_error(TTR("Error creating the signature object."));
  808. package->close();
  809. memdelete(package);
  810. package = NULL;
  811. return;
  812. }
  813. err = sign(cert_file, digests, signature);
  814. if (err != OK) {
  815. EditorNode::add_io_error(TTR("Error creating the package signature."));
  816. package->close();
  817. memdelete(package);
  818. package = NULL;
  819. return;
  820. }
  821. // Read the signature as bytes
  822. BIO* bio_out = BIO_new(BIO_s_mem());
  823. i2d_PKCS7_bio(bio_out, signature);
  824. BIO_flush(bio_out);
  825. uint8_t* bio_ptr;
  826. size_t bio_size = BIO_get_mem_data(bio_out, &bio_ptr);
  827. // Create the signature buffer with magic number
  828. Vector<uint8_t> signature_file;
  829. signature_file.resize(4 + bio_size);
  830. buf_put_int32(P7X_SIGNATURE, signature_file.ptr());
  831. for (int i = 0; i < bio_size; i++)
  832. signature_file[i + 4] = bio_ptr[i];
  833. // Add the signature to the package
  834. add_file("AppxSignature.p7x", signature_file.ptr(), signature_file.size(), -1, -1, true);
  835. // Add central directory entry
  836. store_central_dir_header(file_metadata[file_metadata.size() - 1], false);
  837. }
  838. #endif // OPENSSL_ENABLED
  839. // Write central directory
  840. EditorNode::progress_task_step("export", "Finishing package...", 6);
  841. central_dir_offset = package->get_pos();
  842. package->store_buffer(central_dir_data.ptr(), central_dir_data.size());
  843. // End record
  844. end_of_central_dir_offset = package->get_pos();
  845. Vector<uint8_t> end_record = make_end_of_central_record();
  846. package->store_buffer(end_record.ptr(), end_record.size());
  847. package->close();
  848. memdelete(package);
  849. package = NULL;
  850. }
  851. #ifdef OPENSSL_ENABLED
  852. // https://support.microsoft.com/en-us/kb/287547
  853. const char SPC_INDIRECT_DATA_OBJID[] = "1.3.6.1.4.1.311.2.1.4";
  854. const char SPC_STATEMENT_TYPE_OBJID[] = "1.3.6.1.4.1.311.2.1.11";
  855. const char SPC_SP_OPUS_INFO_OBJID[] = "1.3.6.1.4.1.311.2.1.12";
  856. const char SPC_SIPINFO_OBJID[] = "1.3.6.1.4.1.311.2.1.30";
  857. #endif // OPENSSL_ENABLED
  858. AppxPackager::AppxPackager() {}
  859. AppxPackager::~AppxPackager() {}
  860. ////////////////////////////////////////////////////////////////////
  861. #ifdef OPENSSL_ENABLED
  862. Error AppxPackager::openssl_error(unsigned long p_err) {
  863. ERR_load_crypto_strings();
  864. char buffer[256];
  865. ERR_error_string_n(p_err, buffer, sizeof(buffer));
  866. String err(buffer);
  867. ERR_EXPLAIN(err);
  868. ERR_FAIL_V(FAILED);
  869. }
  870. void AppxPackager::MakeSPCInfoValue(asn1::SPCInfoValue &info) {
  871. // I have no idea what these numbers mean.
  872. static uint8_t s1Magic[] = {
  873. 0x4B, 0xDF, 0xC5, 0x0A, 0x07, 0xCE, 0xE2, 0x4D,
  874. 0xB7, 0x6E, 0x23, 0xC8, 0x39, 0xA0, 0x9F, 0xD1,
  875. };
  876. ASN1_INTEGER_set(info.i1, 0x01010000);
  877. ASN1_OCTET_STRING_set(info.s1, s1Magic, sizeof(s1Magic));
  878. ASN1_INTEGER_set(info.i2, 0x00000000);
  879. ASN1_INTEGER_set(info.i3, 0x00000000);
  880. ASN1_INTEGER_set(info.i4, 0x00000000);
  881. ASN1_INTEGER_set(info.i5, 0x00000000);
  882. ASN1_INTEGER_set(info.i6, 0x00000000);
  883. }
  884. Error AppxPackager::MakeIndirectDataContent(asn1::SPCIndirectDataContent &idc) {
  885. using namespace asn1;
  886. ASN1_TYPE* algorithmParameter = ASN1_TYPE_new();
  887. if (!algorithmParameter) {
  888. return openssl_error(ERR_peek_last_error());
  889. }
  890. algorithmParameter->type = V_ASN1_NULL;
  891. SPCInfoValue* infoValue = SPCInfoValue_new();
  892. if (!infoValue) {
  893. return openssl_error(ERR_peek_last_error());
  894. }
  895. MakeSPCInfoValue(*infoValue);
  896. ASN1_TYPE* value =
  897. EncodedASN1::FromItem<asn1::SPCInfoValue,
  898. asn1::i2d_SPCInfoValue>(infoValue)
  899. .ToSequenceType();
  900. {
  901. Vector<uint8_t> digest;
  902. write_digest(digest);
  903. if (!ASN1_OCTET_STRING_set(idc.messageDigest->digest,
  904. digest.ptr(), digest.size())) {
  905. return openssl_error(ERR_peek_last_error());
  906. }
  907. }
  908. idc.data->type = OBJ_txt2obj(SPC_SIPINFO_OBJID, 1);
  909. idc.data->value = value;
  910. idc.messageDigest->digestAlgorithm->algorithm = OBJ_nid2obj(NID_sha256);
  911. idc.messageDigest->digestAlgorithm->parameter = algorithmParameter;
  912. return OK;
  913. }
  914. Error AppxPackager::add_attributes(PKCS7_SIGNER_INFO * p_signer_info) {
  915. // Add opus attribute
  916. asn1::SPCSpOpusInfo* opus = asn1::SPCSpOpusInfo_new();
  917. if (!opus) return openssl_error(ERR_peek_last_error());
  918. ASN1_STRING* opus_value =
  919. EncodedASN1::FromItem<asn1::SPCSpOpusInfo,
  920. asn1::i2d_SPCSpOpusInfo>(opus)
  921. .ToSequenceString();
  922. if (!PKCS7_add_signed_attribute(
  923. p_signer_info,
  924. OBJ_txt2nid(SPC_SP_OPUS_INFO_OBJID),
  925. V_ASN1_SEQUENCE,
  926. opus_value
  927. )) {
  928. asn1::SPCSpOpusInfo_free(opus);
  929. ASN1_STRING_free(opus_value);
  930. return openssl_error(ERR_peek_last_error());
  931. }
  932. // Add content type attribute
  933. if (!PKCS7_add_signed_attribute(
  934. p_signer_info,
  935. NID_pkcs9_contentType,
  936. V_ASN1_OBJECT,
  937. OBJ_txt2obj(SPC_INDIRECT_DATA_OBJID, 1)
  938. )) {
  939. asn1::SPCSpOpusInfo_free(opus);
  940. ASN1_STRING_free(opus_value);
  941. return openssl_error(ERR_peek_last_error());
  942. }
  943. // Add statement type attribute
  944. asn1::SPCStatementType* statement_type = asn1::SPCStatementType_new();
  945. if (!statement_type) return openssl_error(ERR_peek_last_error());
  946. statement_type->type = OBJ_nid2obj(NID_ms_code_ind);
  947. ASN1_STRING* statement_type_value =
  948. EncodedASN1::FromItem<asn1::SPCStatementType,
  949. asn1::i2d_SPCStatementType>(statement_type)
  950. .ToSequenceString();
  951. if (!PKCS7_add_signed_attribute(
  952. p_signer_info,
  953. OBJ_txt2nid(SPC_STATEMENT_TYPE_OBJID),
  954. V_ASN1_SEQUENCE,
  955. statement_type_value
  956. )) {
  957. ASN1_STRING_free(opus_value);
  958. asn1::SPCStatementType_free(statement_type);
  959. ASN1_STRING_free(statement_type_value);
  960. return openssl_error(ERR_peek_last_error());
  961. }
  962. return OK;
  963. }
  964. void AppxPackager::make_digests() {
  965. // AXPC
  966. SHA256_Final(digests.axpc, &axpc_context);
  967. // AXCD
  968. SHA256_Final(digests.axcd, &axcd_context);
  969. // AXCI
  970. for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
  971. digests.axci[i] = 0;
  972. }
  973. void AppxPackager::write_digest(Vector<uint8_t>& p_out_buffer) {
  974. // Size of digests plus 6 32-bit magic numbers
  975. p_out_buffer.resize((SHA256_DIGEST_LENGTH * 5) + (6 * 4));
  976. int offs = 0;
  977. // APPX
  978. uint32_t sig = 0x58505041;
  979. offs += buf_put_int32(sig, &p_out_buffer[offs]);
  980. // AXPC
  981. uint32_t axpc_sig = 0x43505841;
  982. offs += buf_put_int32(axpc_sig, &p_out_buffer[offs]);
  983. for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
  984. p_out_buffer[offs++] = digests.axpc[i];
  985. }
  986. // AXCD
  987. uint32_t axcd_sig = 0x44435841;
  988. offs += buf_put_int32(axcd_sig, &p_out_buffer[offs]);
  989. for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
  990. p_out_buffer[offs++] = digests.axcd[i];
  991. }
  992. // AXCT
  993. uint32_t axct_sig = 0x54435841;
  994. offs += buf_put_int32(axct_sig, &p_out_buffer[offs]);
  995. for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
  996. p_out_buffer[offs++] = digests.axct[i];
  997. }
  998. // AXBM
  999. uint32_t axbm_sig = 0x4D425841;
  1000. offs += buf_put_int32(axbm_sig, &p_out_buffer[offs]);
  1001. for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
  1002. p_out_buffer[offs++] = digests.axbm[i];
  1003. }
  1004. // AXCI
  1005. uint32_t axci_sig = 0x49435841;
  1006. offs += buf_put_int32(axci_sig, &p_out_buffer[offs]);
  1007. for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
  1008. p_out_buffer[offs++] = digests.axci[i];
  1009. }
  1010. // Done!
  1011. }
  1012. Error AppxPackager::read_cert_file(const String & p_path, const String &p_password, CertFile* p_out_cf) {
  1013. ERR_FAIL_COND_V(!p_out_cf, ERR_INVALID_PARAMETER);
  1014. BIO* bio = BIO_new_file(p_path.utf8().get_data(), "rb");
  1015. if (!bio) {
  1016. return openssl_error(ERR_peek_last_error());
  1017. }
  1018. PKCS12* data = d2i_PKCS12_bio(bio, NULL);
  1019. if (!data) {
  1020. BIO_free(bio);
  1021. return openssl_error(ERR_peek_last_error());
  1022. }
  1023. /* Fails to link with GCC, need to solve when implement signing
  1024. if (!PKCS12_parse(data, p_password.utf8().get_data(), &p_out_cf->private_key, &p_out_cf->certificate, NULL)) {
  1025. PKCS12_free(data);
  1026. BIO_free(bio);
  1027. return openssl_error(ERR_peek_last_error());
  1028. }*/
  1029. if (!p_out_cf->private_key) {
  1030. PKCS12_free(data);
  1031. BIO_free(bio);
  1032. return openssl_error(ERR_peek_last_error());
  1033. }
  1034. if (!p_out_cf->certificate) {
  1035. PKCS12_free(data);
  1036. BIO_free(bio);
  1037. return openssl_error(ERR_peek_last_error());
  1038. }
  1039. PKCS12_free(data);
  1040. BIO_free(bio);
  1041. return OK;
  1042. }
  1043. Error AppxPackager::sign(const CertFile & p_cert, const AppxDigests & digests, PKCS7 * p_out_signature) {
  1044. OpenSSL_add_all_algorithms();
  1045. // Register object IDs
  1046. OBJ_create_and_add_object(SPC_INDIRECT_DATA_OBJID, NULL, NULL);
  1047. OBJ_create_and_add_object(SPC_SIPINFO_OBJID, NULL, NULL);
  1048. OBJ_create_and_add_object(SPC_SP_OPUS_INFO_OBJID, NULL, NULL);
  1049. OBJ_create_and_add_object(SPC_STATEMENT_TYPE_OBJID, NULL, NULL);
  1050. if (!PKCS7_set_type(p_out_signature, NID_pkcs7_signed)) {
  1051. return openssl_error(ERR_peek_last_error());
  1052. }
  1053. PKCS7_SIGNER_INFO *signer_info = PKCS7_add_signature(p_out_signature, p_cert.certificate, p_cert.private_key, EVP_sha256());
  1054. if (!signer_info) return openssl_error(ERR_peek_last_error());
  1055. add_attributes(signer_info);
  1056. if (!PKCS7_content_new(p_out_signature, NID_pkcs7_data)) {
  1057. return openssl_error(ERR_peek_last_error());
  1058. }
  1059. if (!PKCS7_add_certificate(p_out_signature, p_cert.certificate)) {
  1060. return openssl_error(ERR_peek_last_error());
  1061. }
  1062. asn1::SPCIndirectDataContent* idc = asn1::SPCIndirectDataContent_new();
  1063. MakeIndirectDataContent(*idc);
  1064. EncodedASN1 idc_encoded =
  1065. EncodedASN1::FromItem<asn1::SPCIndirectDataContent, asn1::i2d_SPCIndirectDataContent>(idc);
  1066. BIO* signed_data = PKCS7_dataInit(p_out_signature, NULL);
  1067. if (idc_encoded.size() < 2) {
  1068. ERR_EXPLAIN("Invalid encoded size");
  1069. ERR_FAIL_V(FAILED);
  1070. }
  1071. if ((idc_encoded.data()[1] & 0x80) == 0x00) {
  1072. ERR_EXPLAIN("Invalid encoded data");
  1073. ERR_FAIL_V(FAILED);
  1074. }
  1075. size_t skip = 4;
  1076. if (BIO_write(signed_data, idc_encoded.data() + skip, idc_encoded.size() - skip)
  1077. != idc_encoded.size() - skip) {
  1078. return openssl_error(ERR_peek_last_error());
  1079. }
  1080. if (BIO_flush(signed_data) != 1) {
  1081. return openssl_error(ERR_peek_last_error());
  1082. }
  1083. if (!PKCS7_dataFinal(p_out_signature, signed_data)) {
  1084. return openssl_error(ERR_peek_last_error());
  1085. }
  1086. PKCS7* content = PKCS7_new();
  1087. if (!content) {
  1088. return openssl_error(ERR_peek_last_error());
  1089. }
  1090. content->type = OBJ_txt2obj(SPC_INDIRECT_DATA_OBJID, 1);
  1091. ASN1_TYPE* idc_sequence = idc_encoded.ToSequenceType();
  1092. content->d.other = idc_sequence;
  1093. if (!PKCS7_set_content(p_out_signature, content)) {
  1094. return openssl_error(ERR_peek_last_error());
  1095. }
  1096. return OK;
  1097. }
  1098. #endif // OPENSSL_ENABLED
  1099. ////////////////////////////////////////////////////////////////////
  1100. bool EditorExportPlatformUWP::_valid_resource_name(const String &p_name) const {
  1101. if (p_name.empty()) return false;
  1102. if (p_name.ends_with(".")) return false;
  1103. static const char* invalid_names[] = {
  1104. "CON","PRN","AUX","NUL","COM1","COM2","COM3","COM4","COM5","COM6","COM7",
  1105. "COM8","COM9","LPT1","LPT2","LPT3","LPT4","LPT5","LPT6","LPT7","LPT8","LPT9",
  1106. NULL
  1107. };
  1108. const char** t = invalid_names;
  1109. while (*t) {
  1110. if (p_name == *t) return false;
  1111. t++;
  1112. }
  1113. return true;
  1114. }
  1115. bool EditorExportPlatformUWP::_valid_guid(const String & p_guid) const {
  1116. Vector<String> parts = p_guid.split("-");
  1117. if (parts.size() != 5) return false;
  1118. if (parts[0].length() != 8) return false;
  1119. for (int i = 1; i < 4; i++)
  1120. if (parts[i].length() != 4) return false;
  1121. if (parts[4].length() != 12) return false;
  1122. return true;
  1123. }
  1124. bool EditorExportPlatformUWP::_valid_bgcolor(const String & p_color) const {
  1125. if (p_color.empty()) return true;
  1126. if (p_color.begins_with("#") && p_color.is_valid_html_color()) return true;
  1127. // Colors from https://msdn.microsoft.com/en-us/library/windows/apps/dn934817.aspx
  1128. static const char* valid_colors[] = {
  1129. "aliceBlue","antiqueWhite","aqua","aquamarine","azure","beige",
  1130. "bisque","black","blanchedAlmond","blue","blueViolet","brown",
  1131. "burlyWood","cadetBlue","chartreuse","chocolate","coral","cornflowerBlue",
  1132. "cornsilk","crimson","cyan","darkBlue","darkCyan","darkGoldenrod",
  1133. "darkGray","darkGreen","darkKhaki","darkMagenta","darkOliveGreen","darkOrange",
  1134. "darkOrchid","darkRed","darkSalmon","darkSeaGreen","darkSlateBlue","darkSlateGray",
  1135. "darkTurquoise","darkViolet","deepPink","deepSkyBlue","dimGray","dodgerBlue",
  1136. "firebrick","floralWhite","forestGreen","fuchsia","gainsboro","ghostWhite",
  1137. "gold","goldenrod","gray","green","greenYellow","honeydew",
  1138. "hotPink","indianRed","indigo","ivory","khaki","lavender",
  1139. "lavenderBlush","lawnGreen","lemonChiffon","lightBlue","lightCoral","lightCyan",
  1140. "lightGoldenrodYellow","lightGreen","lightGray","lightPink","lightSalmon","lightSeaGreen",
  1141. "lightSkyBlue","lightSlateGray","lightSteelBlue","lightYellow","lime","limeGreen",
  1142. "linen","magenta","maroon","mediumAquamarine","mediumBlue","mediumOrchid",
  1143. "mediumPurple","mediumSeaGreen","mediumSlateBlue","mediumSpringGreen","mediumTurquoise","mediumVioletRed",
  1144. "midnightBlue","mintCream","mistyRose","moccasin","navajoWhite","navy",
  1145. "oldLace","olive","oliveDrab","orange","orangeRed","orchid",
  1146. "paleGoldenrod","paleGreen","paleTurquoise","paleVioletRed","papayaWhip","peachPuff",
  1147. "peru","pink","plum","powderBlue","purple","red",
  1148. "rosyBrown","royalBlue","saddleBrown","salmon","sandyBrown","seaGreen",
  1149. "seaShell","sienna","silver","skyBlue","slateBlue","slateGray",
  1150. "snow","springGreen","steelBlue","tan","teal","thistle",
  1151. "tomato","transparent","turquoise","violet","wheat","white",
  1152. "whiteSmoke","yellow","yellowGreen",
  1153. NULL
  1154. };
  1155. const char** color = valid_colors;
  1156. while(*color) {
  1157. if (p_color == *color) return true;
  1158. color++;
  1159. }
  1160. return false;
  1161. }
  1162. bool EditorExportPlatformUWP::_valid_image(const Ref<ImageTexture> p_image, int p_width, int p_height) const {
  1163. if (!p_image.is_valid()) return false;
  1164. // TODO: Add resource creation or image rescaling to enable other scales:
  1165. // 1.25, 1.5, 2.0
  1166. real_t scales[] = { 1.0 };
  1167. bool valid_w = false;
  1168. bool valid_h = false;
  1169. for (int i = 0; i < 1; i++) {
  1170. int w = ceil(p_width * scales[i]);
  1171. int h = ceil(p_height * scales[i]);
  1172. if (w == p_image->get_width())
  1173. valid_w = true;
  1174. if (h == p_image->get_height())
  1175. valid_h = true;
  1176. }
  1177. return valid_w && valid_h;
  1178. }
  1179. Vector<uint8_t> EditorExportPlatformUWP::_fix_manifest(const Vector<uint8_t> &p_template, bool p_give_internet) const {
  1180. String result = String::utf8((const char*)p_template.ptr(), p_template.size());
  1181. result = result.replace("$godot_version$", VERSION_FULL_NAME);
  1182. result = result.replace("$identity_name$", unique_name);
  1183. result = result.replace("$publisher$", publisher);
  1184. result = result.replace("$product_guid$", product_guid);
  1185. result = result.replace("$publisher_guid$", publisher_guid);
  1186. String version = itos(version_major) + "." + itos(version_minor) + "." + itos(version_build) + "." + itos(version_revision);
  1187. result = result.replace("$version_string$", version);
  1188. String architecture = arch == ARM ? "ARM" : arch == X86 ? "x86" : "x64";
  1189. result = result.replace("$architecture$", architecture);
  1190. result = result.replace("$display_name$", display_name.empty() ? (String)GlobalConfig::get_singleton()->get("application/name") : display_name);
  1191. result = result.replace("$publisher_display_name$", publisher_display_name);
  1192. result = result.replace("$app_description$", description);
  1193. result = result.replace("$bg_color$", background_color);
  1194. result = result.replace("$short_name$", short_name);
  1195. String name_on_tiles = "";
  1196. if (name_on_square150) {
  1197. name_on_tiles += " <uap:ShowOn Tile=\"square150x150Logo\" />\n";
  1198. }
  1199. if (name_on_wide) {
  1200. name_on_tiles += " <uap:ShowOn Tile=\"wide310x150Logo\" />\n";
  1201. }
  1202. if (name_on_square310) {
  1203. name_on_tiles += " <uap:ShowOn Tile=\"square310x310Logo\" />\n";
  1204. }
  1205. String show_name_on_tiles = "";
  1206. if (!name_on_tiles.empty()) {
  1207. show_name_on_tiles = "<uap:ShowNameOnTiles>\n" + name_on_tiles + " </uap:ShowNameOnTiles>";
  1208. }
  1209. result = result.replace("$name_on_tiles$", name_on_tiles);
  1210. String rotations = "";
  1211. if (orientation_landscape) {
  1212. rotations += " <uap:Rotation Preference=\"landscape\" />\n";
  1213. }
  1214. if (orientation_portrait) {
  1215. rotations += " <uap:Rotation Preference=\"portrait\" />\n";
  1216. }
  1217. if (orientation_landscape_flipped) {
  1218. rotations += " <uap:Rotation Preference=\"landscapeFlipped\" />\n";
  1219. }
  1220. if (orientation_portrait_flipped) {
  1221. rotations += " <uap:Rotation Preference=\"portraitFlipped\" />\n";
  1222. }
  1223. String rotation_preference = "";
  1224. if (!rotations.empty()) {
  1225. rotation_preference = "<uap:InitialRotationPreference>\n" + rotations + " </uap:InitialRotationPreference>";
  1226. }
  1227. result = result.replace("$rotation_preference$", rotation_preference);
  1228. String capabilities_elements = "";
  1229. const char **basic = uwp_capabilities;
  1230. while (*basic) {
  1231. if (capabilities.has(*basic)) {
  1232. capabilities_elements += " <Capability Name=\"" + String(*basic) + "\" />\n";
  1233. }
  1234. basic++;
  1235. }
  1236. const char **uap = uwp_uap_capabilities;
  1237. while (*uap) {
  1238. if (uap_capabilities.has(*uap)) {
  1239. capabilities_elements += " <uap:Capability Name=\"" + String(*uap) + "\" />\n";
  1240. }
  1241. uap++;
  1242. }
  1243. const char **device = uwp_device_capabilites;
  1244. while (*device) {
  1245. if (uap_capabilities.has(*device)) {
  1246. capabilities_elements += " <DeviceCapability Name=\"" + String(*device) + "\" />\n";
  1247. }
  1248. device++;
  1249. }
  1250. if (!capabilities.has("internetClient") && p_give_internet) {
  1251. capabilities_elements += " <Capability Name=\"internetClient\" />\n";
  1252. }
  1253. String capabilities_string = "<Capabilities />";
  1254. if (!capabilities_elements.empty()) {
  1255. capabilities_string = "<Capabilities>\n" + capabilities_elements + " </Capabilities>";
  1256. }
  1257. result = result.replace("$capabilities_place$", capabilities_string);
  1258. Vector<uint8_t> r_ret;
  1259. r_ret.resize(result.length());
  1260. for (int i = 0; i < result.length(); i++)
  1261. r_ret[i] = result.utf8().get(i);
  1262. return r_ret;
  1263. }
  1264. Vector<uint8_t> EditorExportPlatformUWP::_get_image_data(const String & p_path) {
  1265. Vector<uint8_t> data;
  1266. Ref<ImageTexture> ref;
  1267. if (p_path.find("StoreLogo") != -1) {
  1268. ref = store_logo;
  1269. } else if (p_path.find("Square44x44Logo") != -1) {
  1270. ref = square44;
  1271. } else if (p_path.find("Square71x71Logo") != -1) {
  1272. ref = square71;
  1273. } else if (p_path.find("Square150x150Logo") != -1) {
  1274. ref = square150;
  1275. } else if (p_path.find("Square310x310Logo") != -1) {
  1276. ref = square310;
  1277. } else if (p_path.find("Wide310x150Logo") != -1) {
  1278. ref = wide310;
  1279. } else if (p_path.find("SplashScreen") != -1) {
  1280. ref = splash;
  1281. }
  1282. if (!ref.is_valid()) return data;
  1283. String tmp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/uwp_tmp_logo.png");
  1284. Error err = ref->get_data().save_png(tmp_path);
  1285. if (err != OK) {
  1286. String err_string = "Couldn't save temp logo file.";
  1287. EditorNode::add_io_error(err_string);
  1288. ERR_EXPLAIN(err_string);
  1289. ERR_FAIL_V(data);
  1290. }
  1291. FileAccess* f = FileAccess::open(tmp_path, FileAccess::READ, &err);
  1292. if (err != OK) {
  1293. String err_string = "Couldn't open temp logo file.";
  1294. EditorNode::add_io_error(err_string);
  1295. ERR_EXPLAIN(err_string);
  1296. ERR_FAIL_V(data);
  1297. }
  1298. data.resize(f->get_len());
  1299. f->get_buffer(data.ptr(), data.size());
  1300. f->close();
  1301. memdelete(f);
  1302. // Delete temp file
  1303. DirAccess* dir = DirAccess::open(tmp_path.get_base_dir(), &err);
  1304. if (err != OK) {
  1305. String err_string = "Couldn't open temp path to remove temp logo file.";
  1306. EditorNode::add_io_error(err_string);
  1307. ERR_EXPLAIN(err_string);
  1308. ERR_FAIL_V(data);
  1309. }
  1310. err = dir->remove(tmp_path);
  1311. memdelete(dir);
  1312. if (err != OK) {
  1313. String err_string = "Couldn't remove temp logo file.";
  1314. EditorNode::add_io_error(err_string);
  1315. ERR_EXPLAIN(err_string);
  1316. ERR_FAIL_V(data);
  1317. }
  1318. return data;
  1319. }
  1320. Error EditorExportPlatformUWP::save_appx_file(void * p_userdata, const String & p_path, const Vector<uint8_t>& p_data, int p_file, int p_total) {
  1321. AppxPackager *packager = (AppxPackager*)p_userdata;
  1322. String dst_path = p_path.replace_first("res://", "game/");
  1323. packager->add_file(dst_path, p_data.ptr(), p_data.size(), p_file, p_total, _should_compress_asset(p_path, p_data));
  1324. return OK;
  1325. }
  1326. bool EditorExportPlatformUWP::_should_compress_asset(const String & p_path, const Vector<uint8_t>& p_data) {
  1327. /* TODO: This was copied verbatim from Android export. It should be
  1328. * refactored to the parent class and also be used for .zip export.
  1329. */
  1330. /*
  1331. * By not compressing files with little or not benefit in doing so,
  1332. * a performance gain is expected at runtime. Moreover, if the APK is
  1333. * zip-aligned, assets stored as they are can be efficiently read by
  1334. * Android by memory-mapping them.
  1335. */
  1336. // -- Unconditional uncompress to mimic AAPT plus some other
  1337. static const char* unconditional_compress_ext[] = {
  1338. // From https://github.com/android/platform_frameworks_base/blob/master/tools/aapt/Package.cpp
  1339. // These formats are already compressed, or don't compress well:
  1340. ".jpg", ".jpeg", ".png", ".gif",
  1341. ".wav", ".mp2", ".mp3", ".ogg", ".aac",
  1342. ".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet",
  1343. ".rtttl", ".imy", ".xmf", ".mp4", ".m4a",
  1344. ".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2",
  1345. ".amr", ".awb", ".wma", ".wmv",
  1346. // Godot-specific:
  1347. ".webp", // Same reasoning as .png
  1348. ".cfb", // Don't let small config files slow-down startup
  1349. // Trailer for easier processing
  1350. NULL
  1351. };
  1352. for (const char** ext = unconditional_compress_ext; *ext; ++ext) {
  1353. if (p_path.to_lower().ends_with(String(*ext))) {
  1354. return false;
  1355. }
  1356. }
  1357. // -- Compressed resource?
  1358. if (p_data.size() >= 4 && p_data[0] == 'R' && p_data[1] == 'S' && p_data[2] == 'C' && p_data[3] == 'C') {
  1359. // Already compressed
  1360. return false;
  1361. }
  1362. // --- TODO: Decide on texture resources according to their image compression setting
  1363. return true;
  1364. }
  1365. bool EditorExportPlatformUWP::_set(const StringName& p_name, const Variant& p_value) {
  1366. String n = p_name;
  1367. if (n == "architecture/target")
  1368. arch = (Platform)((int)p_value);
  1369. else if (n == "custom_package/debug")
  1370. custom_debug_package = p_value;
  1371. else if (n == "custom_package/release")
  1372. custom_release_package = p_value;
  1373. else if (n == "command_line/extra_args")
  1374. cmdline = p_value;
  1375. else if (n == "package/display_name")
  1376. display_name = p_value;
  1377. else if (n == "package/short_name")
  1378. short_name = p_value;
  1379. else if (n == "package/unique_name")
  1380. unique_name = p_value;
  1381. else if (n == "package/description")
  1382. description = p_value;
  1383. else if (n == "package/publisher")
  1384. publisher = p_value;
  1385. else if (n == "package/publisher_display_name")
  1386. publisher_display_name = p_value;
  1387. else if (n == "identity/product_guid")
  1388. product_guid = p_value;
  1389. else if (n == "identity/publisher_guid")
  1390. publisher_guid = p_value;
  1391. else if (n == "version/major")
  1392. version_major = p_value;
  1393. else if (n == "version/minor")
  1394. version_minor = p_value;
  1395. else if (n == "version/build")
  1396. version_build = p_value;
  1397. else if (n == "version/revision")
  1398. version_revision = p_value;
  1399. else if (n == "orientation/landscape")
  1400. orientation_landscape = p_value;
  1401. else if (n == "orientation/portrait")
  1402. orientation_portrait = p_value;
  1403. else if (n == "orientation/landscape_flipped")
  1404. orientation_landscape_flipped = p_value;
  1405. else if (n == "orientation/portrait_flipped")
  1406. orientation_portrait_flipped = p_value;
  1407. else if (n == "images/background_color")
  1408. background_color = p_value;
  1409. else if (n == "images/store_logo")
  1410. store_logo = p_value;
  1411. else if (n == "images/square44x44_logo")
  1412. square44 = p_value;
  1413. else if (n == "images/square71x71_logo")
  1414. square71 = p_value;
  1415. else if (n == "images/square150x150_logo")
  1416. square150 = p_value;
  1417. else if (n == "images/square310x310_logo")
  1418. square310 = p_value;
  1419. else if (n == "images/wide310x150_logo")
  1420. wide310 = p_value;
  1421. else if (n == "images/splash_screen")
  1422. splash = p_value;
  1423. else if (n == "tiles/show_name_on_square150x150")
  1424. name_on_square150 = p_value;
  1425. else if (n == "tiles/show_name_on_wide310x150")
  1426. name_on_wide = p_value;
  1427. else if (n == "tiles/show_name_on_square310x310")
  1428. name_on_square310 = p_value;
  1429. #if 0 // Signing disabled
  1430. else if (n == "signing/sign")
  1431. sign_package = p_value;
  1432. else if (n == "signing/certificate_file")
  1433. certificate_path = p_value;
  1434. else if (n == "signing/certificate_password")
  1435. certificate_pass = p_value;
  1436. #endif
  1437. else if (n.begins_with("capabilities/")) {
  1438. String what = n.get_slice("/", 1).replace("_", "");
  1439. bool enable = p_value;
  1440. if (array_has(uwp_capabilities, what.utf8().get_data())) {
  1441. if (enable)
  1442. capabilities.insert(what);
  1443. else
  1444. capabilities.erase(what);
  1445. } else if (array_has(uwp_uap_capabilities, what.utf8().get_data())) {
  1446. if (enable)
  1447. uap_capabilities.insert(what);
  1448. else
  1449. uap_capabilities.erase(what);
  1450. } else if (array_has(uwp_device_capabilites, what.utf8().get_data())) {
  1451. if (enable)
  1452. device_capabilities.insert(what);
  1453. else
  1454. device_capabilities.erase(what);
  1455. }
  1456. } else return false;
  1457. return true;
  1458. }
  1459. bool EditorExportPlatformUWP::_get(const StringName& p_name, Variant &r_ret) const {
  1460. String n = p_name;
  1461. if (n == "architecture/target")
  1462. r_ret = (int)arch;
  1463. else if (n == "custom_package/debug")
  1464. r_ret = custom_debug_package;
  1465. else if (n == "custom_package/release")
  1466. r_ret = custom_release_package;
  1467. else if (n == "command_line/extra_args")
  1468. r_ret = cmdline;
  1469. else if (n == "package/display_name")
  1470. r_ret = display_name;
  1471. else if (n == "package/short_name")
  1472. r_ret = short_name;
  1473. else if (n == "package/unique_name")
  1474. r_ret = unique_name;
  1475. else if (n == "package/description")
  1476. r_ret = description;
  1477. else if (n == "package/publisher")
  1478. r_ret = publisher;
  1479. else if (n == "package/publisher_display_name")
  1480. r_ret = publisher_display_name;
  1481. else if (n == "identity/product_guid")
  1482. r_ret = product_guid;
  1483. else if (n == "identity/publisher_guid")
  1484. r_ret = publisher_guid;
  1485. else if (n == "version/major")
  1486. r_ret = version_major;
  1487. else if (n == "version/minor")
  1488. r_ret = version_minor;
  1489. else if (n == "version/build")
  1490. r_ret = version_build;
  1491. else if (n == "version/revision")
  1492. r_ret = version_revision;
  1493. else if (n == "orientation/landscape")
  1494. r_ret = orientation_landscape;
  1495. else if (n == "orientation/portrait")
  1496. r_ret = orientation_portrait;
  1497. else if (n == "orientation/landscape_flipped")
  1498. r_ret = orientation_landscape_flipped;
  1499. else if (n == "orientation/portrait_flipped")
  1500. r_ret = orientation_portrait_flipped;
  1501. else if (n == "images/background_color")
  1502. r_ret = background_color;
  1503. else if (n == "images/store_logo")
  1504. r_ret = store_logo;
  1505. else if (n == "images/square44x44_logo")
  1506. r_ret = square44;
  1507. else if (n == "images/square71x71_logo")
  1508. r_ret = square71;
  1509. else if (n == "images/square150x150_logo")
  1510. r_ret = square150;
  1511. else if (n == "images/square310x310_logo")
  1512. r_ret = square310;
  1513. else if (n == "images/wide310x150_logo")
  1514. r_ret = wide310;
  1515. else if (n == "images/splash_screen")
  1516. r_ret = splash;
  1517. else if (n == "tiles/show_name_on_square150x150")
  1518. r_ret = name_on_square150;
  1519. else if (n == "tiles/show_name_on_wide310x150")
  1520. r_ret = name_on_wide;
  1521. else if (n == "tiles/show_name_on_square310x310")
  1522. r_ret = name_on_square310;
  1523. #if 0 // Signing disabled
  1524. else if (n == "signing/sign")
  1525. r_ret = sign_package;
  1526. else if (n == "signing/certificate_file")
  1527. r_ret = certificate_path;
  1528. else if (n == "signing/certificate_password")
  1529. r_ret = certificate_pass;
  1530. #endif
  1531. else if (n.begins_with("capabilities/")) {
  1532. String what = n.get_slice("/", 1).replace("_", "");
  1533. if (array_has(uwp_capabilities, what.utf8().get_data())) {
  1534. r_ret = capabilities.has(what);
  1535. } else if (array_has(uwp_uap_capabilities, what.utf8().get_data())) {
  1536. r_ret = uap_capabilities.has(what);
  1537. } else if (array_has(uwp_device_capabilites, what.utf8().get_data())) {
  1538. r_ret = device_capabilities.has(what);
  1539. }
  1540. } else return false;
  1541. return true;
  1542. }
  1543. void EditorExportPlatformUWP::_get_property_list(List<PropertyInfo>* p_list) const {
  1544. p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "appx"));
  1545. p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "appx"));
  1546. p_list->push_back(PropertyInfo(Variant::INT, "architecture/target", PROPERTY_HINT_ENUM, "ARM,x86,x64"));
  1547. p_list->push_back(PropertyInfo(Variant::STRING, "command_line/extra_args"));
  1548. p_list->push_back(PropertyInfo(Variant::STRING, "package/display_name"));
  1549. p_list->push_back(PropertyInfo(Variant::STRING, "package/short_name"));
  1550. p_list->push_back(PropertyInfo(Variant::STRING, "package/unique_name"));
  1551. p_list->push_back(PropertyInfo(Variant::STRING, "package/description"));
  1552. p_list->push_back(PropertyInfo(Variant::STRING, "package/publisher"));
  1553. p_list->push_back(PropertyInfo(Variant::STRING, "package/publisher_display_name"));
  1554. p_list->push_back(PropertyInfo(Variant::STRING, "identity/product_guid"));
  1555. p_list->push_back(PropertyInfo(Variant::STRING, "identity/publisher_guid"));
  1556. p_list->push_back(PropertyInfo(Variant::INT, "version/major"));
  1557. p_list->push_back(PropertyInfo(Variant::INT, "version/minor"));
  1558. p_list->push_back(PropertyInfo(Variant::INT, "version/build"));
  1559. p_list->push_back(PropertyInfo(Variant::INT, "version/revision"));
  1560. p_list->push_back(PropertyInfo(Variant::BOOL, "orientation/landscape"));
  1561. p_list->push_back(PropertyInfo(Variant::BOOL, "orientation/portrait"));
  1562. p_list->push_back(PropertyInfo(Variant::BOOL, "orientation/landscape_flipped"));
  1563. p_list->push_back(PropertyInfo(Variant::BOOL, "orientation/portrait_flipped"));
  1564. p_list->push_back(PropertyInfo(Variant::STRING, "images/background_color"));
  1565. p_list->push_back(PropertyInfo(Variant::OBJECT, "images/store_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture"));
  1566. p_list->push_back(PropertyInfo(Variant::OBJECT, "images/square44x44_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture"));
  1567. p_list->push_back(PropertyInfo(Variant::OBJECT, "images/square71x71_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture"));
  1568. p_list->push_back(PropertyInfo(Variant::OBJECT, "images/square150x150_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture"));
  1569. p_list->push_back(PropertyInfo(Variant::OBJECT, "images/square310x310_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture"));
  1570. p_list->push_back(PropertyInfo(Variant::OBJECT, "images/wide310x150_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture"));
  1571. p_list->push_back(PropertyInfo(Variant::OBJECT, "images/splash_screen", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture"));
  1572. p_list->push_back(PropertyInfo(Variant::BOOL, "tiles/show_name_on_square150x150"));
  1573. p_list->push_back(PropertyInfo(Variant::BOOL, "tiles/show_name_on_wide310x150"));
  1574. p_list->push_back(PropertyInfo(Variant::BOOL, "tiles/show_name_on_square310x310"));
  1575. #if 0 // Signing does not work :( disabling for now
  1576. p_list->push_back(PropertyInfo(Variant::BOOL, "signing/sign"));
  1577. p_list->push_back(PropertyInfo(Variant::STRING, "signing/certificate_file", PROPERTY_HINT_GLOBAL_FILE, "pfx"));
  1578. p_list->push_back(PropertyInfo(Variant::STRING, "signing/certificate_password"));
  1579. #endif
  1580. // Capabilites
  1581. const char **basic = uwp_capabilities;
  1582. while (*basic) {
  1583. p_list->push_back(PropertyInfo(Variant::BOOL, "capabilities/" + String(*basic).camelcase_to_underscore(false)));
  1584. basic++;
  1585. }
  1586. const char **uap = uwp_uap_capabilities;
  1587. while (*uap) {
  1588. p_list->push_back(PropertyInfo(Variant::BOOL, "capabilities/" + String(*uap).camelcase_to_underscore(false)));
  1589. uap++;
  1590. }
  1591. const char **device = uwp_device_capabilites;
  1592. while (*device) {
  1593. p_list->push_back(PropertyInfo(Variant::BOOL, "capabilities/" + String(*device).camelcase_to_underscore(false)));
  1594. device++;
  1595. }
  1596. }
  1597. bool EditorExportPlatformUWP::can_export(String * r_error) const {
  1598. String err;
  1599. bool valid = true;
  1600. if (!exists_export_template("uwp_x86_debug.zip") || !exists_export_template("uwp_x86_release.zip")
  1601. || !exists_export_template("uwp_arm_debug.zip") || !exists_export_template("uwp_arm_release.zip")
  1602. || !exists_export_template("uwp_x64_debug.zip") || !exists_export_template("uwp_x64_release.zip")) {
  1603. valid = false;
  1604. err += TTR("No export templates found.\nDownload and install export templates.") + "\n";
  1605. }
  1606. if (custom_debug_package != "" && !FileAccess::exists(custom_debug_package)) {
  1607. valid = false;
  1608. err += TTR("Custom debug package not found.") + "\n";
  1609. }
  1610. if (custom_release_package != "" && !FileAccess::exists(custom_release_package)) {
  1611. valid = false;
  1612. err += TTR("Custom release package not found.") + "\n";
  1613. }
  1614. if (!_valid_resource_name(unique_name)) {
  1615. valid = false;
  1616. err += TTR("Invalid unique name.") + "\n";
  1617. }
  1618. if (!_valid_guid(product_guid)) {
  1619. valid = false;
  1620. err += TTR("Invalid product GUID.") + "\n";
  1621. }
  1622. if (!_valid_guid(publisher_guid)) {
  1623. valid = false;
  1624. err += TTR("Invalid publisher GUID.") + "\n";
  1625. }
  1626. if (!_valid_bgcolor(background_color)) {
  1627. valid = false;
  1628. err += TTR("Invalid background color.") + "\n";
  1629. }
  1630. if (store_logo.is_valid() && !_valid_image(store_logo, 50, 50)) {
  1631. valid = false;
  1632. err += TTR("Invalid Store Logo image dimensions (should be 50x50).") + "\n";
  1633. }
  1634. if (square44.is_valid() && !_valid_image(square44, 44, 44)) {
  1635. valid = false;
  1636. err += TTR("Invalid square 44x44 logo image dimensions (should be 44x44).") + "\n";
  1637. }
  1638. if (square71.is_valid() && !_valid_image(square71, 71, 71)) {
  1639. valid = false;
  1640. err += TTR("Invalid square 71x71 logo image dimensions (should be 71x71).") + "\n";
  1641. }
  1642. if (square150.is_valid() && !_valid_image(square150, 150, 150)) {
  1643. valid = false;
  1644. err += TTR("Invalid square 150x150 logo image dimensions (should be 150x150).") + "\n";
  1645. }
  1646. if (square310.is_valid() && !_valid_image(square310, 310, 310)) {
  1647. valid = false;
  1648. err += TTR("Invalid square 310x310 logo image dimensions (should be 310x310).") + "\n";
  1649. }
  1650. if (wide310.is_valid() && !_valid_image(wide310, 310, 150)) {
  1651. valid = false;
  1652. err += TTR("Invalid wide 310x150 logo image dimensions (should be 310x150).") + "\n";
  1653. }
  1654. if (splash.is_valid() && !_valid_image(splash, 620, 300)) {
  1655. valid = false;
  1656. err += TTR("Invalid splash screen image dimensions (should be 620x300).") + "\n";
  1657. }
  1658. if (r_error)
  1659. *r_error = err;
  1660. return valid;
  1661. }
  1662. Error EditorExportPlatformUWP::export_project(const String & p_path, bool p_debug, int p_flags) {
  1663. String src_appx;
  1664. EditorProgress ep("export", "Exporting for Windows Universal", 7);
  1665. if (is_debug)
  1666. src_appx = custom_debug_package;
  1667. else
  1668. src_appx = custom_release_package;
  1669. if (src_appx == "") {
  1670. String err;
  1671. if (p_debug) {
  1672. switch (arch) {
  1673. case X86: {
  1674. src_appx = find_export_template("uwp_x86_debug.zip", &err);
  1675. break;
  1676. }
  1677. case X64: {
  1678. src_appx = find_export_template("uwp_x64_debug.zip", &err);
  1679. break;
  1680. }
  1681. case ARM: {
  1682. src_appx = find_export_template("uwp_arm_debug.zip", &err);
  1683. break;
  1684. }
  1685. }
  1686. } else {
  1687. switch (arch) {
  1688. case X86: {
  1689. src_appx = find_export_template("uwp_x86_release.zip", &err);
  1690. break;
  1691. }
  1692. case X64: {
  1693. src_appx = find_export_template("uwp_x64_release.zip", &err);
  1694. break;
  1695. }
  1696. case ARM: {
  1697. src_appx = find_export_template("uwp_arm_release.zip", &err);
  1698. break;
  1699. }
  1700. }
  1701. }
  1702. if (src_appx == "") {
  1703. EditorNode::add_io_error(err);
  1704. return ERR_FILE_NOT_FOUND;
  1705. }
  1706. }
  1707. Error err = OK;
  1708. FileAccess *fa_pack = FileAccess::open(p_path, FileAccess::WRITE, &err);
  1709. ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);
  1710. AppxPackager packager;
  1711. packager.init(fa_pack, sign_package ? AppxPackager::SIGN : AppxPackager::DONT_SIGN, certificate_path, certificate_pass);
  1712. FileAccess *src_f = NULL;
  1713. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  1714. ep.step("Creating package...", 0);
  1715. unzFile pkg = unzOpen2(src_appx.utf8().get_data(), &io);
  1716. if (!pkg) {
  1717. EditorNode::add_io_error("Could not find template appx to export:\n" + src_appx);
  1718. return ERR_FILE_NOT_FOUND;
  1719. }
  1720. int ret = unzGoToFirstFile(pkg);
  1721. ep.step("Copying template files...", 1);
  1722. EditorNode::progress_add_task("template_files", "Template files", 100);
  1723. packager.set_progress_task("template_files");
  1724. int template_files_amount = 9;
  1725. int template_file_no = 1;
  1726. while (ret == UNZ_OK) {
  1727. // get file name
  1728. unz_file_info info;
  1729. char fname[16834];
  1730. ret = unzGetCurrentFileInfo(pkg, &info, fname, 16834, NULL, 0, NULL, 0);
  1731. String path = fname;
  1732. if (path.ends_with("/")) {
  1733. // Ignore directories
  1734. ret = unzGoToNextFile(pkg);
  1735. continue;
  1736. }
  1737. Vector<uint8_t> data;
  1738. bool do_read = true;
  1739. if (path.begins_with("Assets/")) {
  1740. path = path.replace(".scale-100", "");
  1741. data = _get_image_data(path);
  1742. if (data.size() > 0) do_read = false;
  1743. }
  1744. //read
  1745. if (do_read) {
  1746. data.resize(info.uncompressed_size);
  1747. unzOpenCurrentFile(pkg);
  1748. unzReadCurrentFile(pkg, data.ptr(), data.size());
  1749. unzCloseCurrentFile(pkg);
  1750. }
  1751. if (path == "AppxManifest.xml") {
  1752. data = _fix_manifest(data, p_flags&(EXPORT_DUMB_CLIENT | EXPORT_REMOTE_DEBUG));
  1753. }
  1754. print_line("ADDING: " + path);
  1755. packager.add_file(path, data.ptr(), data.size(), template_file_no++, template_files_amount, _should_compress_asset(path, data));
  1756. ret = unzGoToNextFile(pkg);
  1757. }
  1758. EditorNode::progress_end_task("template_files");
  1759. ep.step("Creating command line...", 2);
  1760. Vector<String> cl = cmdline.strip_edges().split(" ");
  1761. for (int i = 0;i<cl.size();i++) {
  1762. if (cl[i].strip_edges().length() == 0) {
  1763. cl.remove(i);
  1764. i--;
  1765. }
  1766. }
  1767. if (!(p_flags & EXPORT_DUMB_CLIENT)) {
  1768. cl.push_back("-path");
  1769. cl.push_back("game");
  1770. }
  1771. gen_export_flags(cl, p_flags);
  1772. // Command line file
  1773. Vector<uint8_t> clf;
  1774. // Argc
  1775. clf.resize(4);
  1776. encode_uint32(cl.size(), clf.ptr());
  1777. for (int i = 0; i < cl.size(); i++) {
  1778. CharString txt = cl[i].utf8();
  1779. int base = clf.size();
  1780. clf.resize(base + 4 + txt.length());
  1781. encode_uint32(txt.length(), &clf[base]);
  1782. copymem(&clf[base + 4], txt.ptr(), txt.length());
  1783. print_line(itos(i) + " param: " + cl[i]);
  1784. }
  1785. packager.add_file("__cl__.cl", clf.ptr(), clf.size(), -1, -1, false);
  1786. ep.step("Adding project files...", 3);
  1787. EditorNode::progress_add_task("project_files", "Project Files", 100);
  1788. packager.set_progress_task("project_files");
  1789. err = export_project_files(save_appx_file, &packager, false);
  1790. EditorNode::progress_end_task("project_files");
  1791. ep.step("Closing package...", 7);
  1792. unzClose(pkg);
  1793. packager.finish();
  1794. return OK;
  1795. }
  1796. EditorExportPlatformUWP::EditorExportPlatformUWP() {
  1797. Image img(_uwp_logo);
  1798. logo = Ref<ImageTexture>(memnew(ImageTexture));
  1799. logo->create_from_image(img);
  1800. is_debug = true;
  1801. custom_release_package = "";
  1802. custom_debug_package = "";
  1803. arch = X86;
  1804. display_name = "";
  1805. short_name = "Godot";
  1806. unique_name = "Godot.Engine";
  1807. description = "Godot Engine";
  1808. publisher = "CN=GodotEngine";
  1809. publisher_display_name = "Godot Engine";
  1810. product_guid = "00000000-0000-0000-0000-000000000000";
  1811. publisher_guid = "00000000-0000-0000-0000-000000000000";
  1812. version_major = 1;
  1813. version_minor = 0;
  1814. version_build = 0;
  1815. version_revision = 0;
  1816. orientation_landscape = true;
  1817. orientation_portrait = true;
  1818. orientation_landscape_flipped = true;
  1819. orientation_portrait_flipped = true;
  1820. background_color = "transparent";
  1821. name_on_square150 = false;
  1822. name_on_square310 = false;
  1823. name_on_wide = false;
  1824. sign_package = false;
  1825. certificate_path = "";
  1826. certificate_pass = "";
  1827. }
  1828. EditorExportPlatformUWP::~EditorExportPlatformUWP() {}
  1829. void register_uwp_exporter() {
  1830. Ref<EditorExportPlatformUWP> exporter = Ref<EditorExportPlatformUWP>(memnew(EditorExportPlatformUWP));
  1831. EditorImportExport::get_singleton()->add_export_platform(exporter);
  1832. }