This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathdeploy.cpp
More file actions
1397 lines (1174 loc) · 44.4 KB
/
deploy.cpp
File metadata and controls
1397 lines (1174 loc) · 44.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 2003-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
////////////////////////////////////////////////////////////////////////////////
//
// Private Source File:
// deploy.cpp
//
// Description:
// This file contains common methods for use by the various deploy modules.
// In particular, it contains the implementation of the MCDeployFile
// abstraction, and implementation of the ide 'deploy' command.
//
// Changes:
// 2009-06-20 MW Created.
// 2009-06-22 MW Committed first working version.
// 2009-06-23 MW Refactored common project writing code to here.
// 2009-06-24 MW Expanded MCDeployWriteProject to allow creation of more
// robust project info suitable for both revlets and exes.
// 2009-06-25 MW Added error catching to the deploy command.
// Fixed glitch in md5_append_file to make sure stream begins
// at start.
// 2009-06-26 MW Fixed error in MCDeployCompress* methods causing wrong data
// to be used (buffer overwritten in wrong place).
// 2009-06-29 MW Added in native path conversion to file paths in deploy.
// Added implementation of MCDeployCatch - used to get the last
// error thrown by a deploy method.
// Added MCDeployErrorToString - used to get a human-readable
// account of a deploy error.
// Added setting of 'version_info' member of params to enable
// creation of VERSIONINFO resource on Windows.
// 2009-06-30 MW Restructed projectinfo output to use new extensible section
// based format.
// 2009-07-01 MW Added check for media edition in deploy command.
// 2009-07-04 MW Rewrote project generation portion to use new capsule
// abstraction.
// 2009-07-07 MW Added support for manifest embedding on Windows (currently
// Enterprise only).
// Added support spill file creation.
// 2009-07-12 MW Added support for _internal sign command for Windows
// Authenticode signing.
// 2010-05-08 MW Added support for payload option when building installers.
// Adjusted icon and manifest option fetching to use filepath
// routines.
// 2010-09-06 MW Removed edition restrictions for switch to LiveCode.
//
////////////////////////////////////////////////////////////////////////////////
#include "prefix.h"
#include "globdefs.h"
#include "objdefs.h"
#include "parsedef.h"
#include "filedefs.h"
#include "exec.h"
#include "handler.h"
#include "scriptpt.h"
#include "variable.h"
#include "statemnt.h"
#include "globals.h"
#include "param.h"
#include "dispatch.h"
#include "osspec.h"
#include "ide.h"
#include "deploy.h"
#include "mode.h"
#include "license.h"
#include "stacksecurity.h"
#include "debug.h"
#include "capsule.h"
////////////////////////////////////////////////////////////////////////////////
extern Boolean InitSSLCrypt(void);
////////////////////////////////////////////////////////////////////////////////
static const char *kMCDeployArchitectureStrings[] =
{
"",
"i386",
"x86-64",
"armv6",
"armv7",
"armv7s",
"arm64",
"ppc",
"ppc64",
nil,
};
typedef struct
{
MCDeployParameters* params;
MCExecContext* ctxt;
}
MCDeployArrayApplyCallbackContext;
static bool MCDeployMapArchitectureString(MCStringRef p_string, MCDeployArchitecture& r_architecture)
{
for(uindex_t i = 0; kMCDeployArchitectureStrings[i] != nil; i++)
{
// As 'p_string' is an MCString the '==' operator does a caseless comparison.
if (MCStringIsEqualToCString(p_string, kMCDeployArchitectureStrings[i], kMCStringOptionCompareCaseless))
{
r_architecture = (MCDeployArchitecture)i;
return true;
}
}
return false;
}
static bool MCDeployPushMinOSVersion(MCDeployParameters* p_params, MCDeployArchitecture p_arch, MCStringRef p_vers_string)
{
// Use sscanf to parse out the version string. We don't check the return value of
// sscanf as we don't care - any malformed / missing components will come out as
// 0.
int t_major, t_minor, t_inc;
t_major = t_minor = t_inc = 0;
MCAutoPointer<char> t_native_string;
MCStringConvertToCString(p_vers_string, &t_native_string);
sscanf(*t_native_string, "%d.%d.%d", &t_major, &t_minor, &t_inc);
if (!MCMemoryResizeArray(p_params -> min_os_version_count + 1, p_params -> min_os_versions, p_params -> min_os_version_count))
return false;
uint32_t t_version;
t_version = (t_major & 0xFFFF) << 16;
t_version |= (t_minor & 0xFF) << 8;
t_version |= (t_inc & 0xFF) << 0;
p_params -> min_os_versions[p_params -> min_os_version_count - 1] . architecture = p_arch;
p_params -> min_os_versions[p_params -> min_os_version_count - 1] . version = t_version;
return true;
}
static bool MCDeployGetArchitectures(void *context, MCArrayRef array, MCNameRef key, MCValueRef value)
{
MCDeployArrayApplyCallbackContext *t_context;
t_context = (MCDeployArrayApplyCallbackContext*)context;
MCAutoStringRef t_value_as_string;
MCDeployArchitecture t_arch;
if (!t_context -> ctxt -> ConvertToString(value, &t_value_as_string))
return false;
if (!MCDeployMapArchitectureString(MCNameGetString(key), t_arch))
return false;
if (!MCDeployPushMinOSVersion(t_context -> params, t_arch, *t_value_as_string))
return false;
return true;
}
bool MCDeployParameters::InitWithArray(MCExecContext &ctxt, MCArrayRef p_array)
{
MCStringRef t_temp_string;
MCArrayRef t_temp_array;
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("engine_ppc"), false, t_temp_string))
return false;
MCValueAssign(engine_ppc, t_temp_string);
MCValueRelease(t_temp_string);
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("engine_x86"), false, t_temp_string))
return false;
MCValueAssign(engine_x86, t_temp_string);
MCValueRelease(t_temp_string);
if (MCStringIsEmpty(engine_ppc) && MCStringIsEmpty(engine_x86))
{
if (!ctxt.CopyElementAsFilepath(p_array, MCNAME("engine"), false, t_temp_string))
return false;
MCValueAssign(engine, t_temp_string);
MCValueRelease(t_temp_string);
}
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("stackfile"), false, t_temp_string))
return false;
MCValueAssign(stackfile, t_temp_string);
MCValueRelease(t_temp_string);
if (!ctxt.CopyOptElementAsFilepathArray(p_array, MCNAME("auxiliary_stackfiles"), false, t_temp_array))
return false;
MCValueAssign(auxiliary_stackfiles, t_temp_array);
MCValueRelease(t_temp_array);
// The externals listed by the IDE are LF separated
if (!ctxt.CopyOptElementAsString(p_array, MCNAME("externals"), false, t_temp_string))
return false;
MCStringSplit(t_temp_string, MCSTR("\n"), nil, kMCStringOptionCompareExact, t_temp_array);
MCValueAssign(externals, t_temp_array);
MCValueRelease(t_temp_string);
MCValueRelease(t_temp_array);
if (!ctxt.CopyOptElementAsString(p_array, MCNAME("startup_script"), false, t_temp_string))
return false;
MCValueAssign(startup_script, t_temp_string);
MCValueRelease(t_temp_string);
// The redirects listed by the IDE are LF separated
if (!ctxt.CopyOptElementAsString(p_array, MCNAME("redirects"), false, t_temp_string))
return false;
MCStringSplit(t_temp_string, MCSTR("\n"), nil, kMCStringOptionCompareExact, t_temp_array);
MCValueAssign(redirects, t_temp_array);
MCValueRelease(t_temp_string);
MCValueRelease(t_temp_array);
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("appicon"), false, t_temp_string))
return false;
MCValueAssign(app_icon, t_temp_string);
MCValueRelease(t_temp_string);
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("docicon"), false, t_temp_string))
return false;
MCValueAssign(doc_icon, t_temp_string);
MCValueRelease(t_temp_string);
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("manifest"), false, t_temp_string))
return false;
MCValueAssign(manifest, t_temp_string);
MCValueRelease(t_temp_string);
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("payload"), false, t_temp_string))
return false;
MCValueAssign(payload, t_temp_string);
MCValueRelease(t_temp_string);
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("spill"), false, t_temp_string))
return false;
MCValueAssign(spill, t_temp_string);
MCValueRelease(t_temp_string);
if (!ctxt.CopyElementAsFilepath(p_array, MCNAME("output"), false, t_temp_string))
return false;
MCValueAssign(output, t_temp_string);
MCValueRelease(t_temp_string);
if (!ctxt.CopyOptElementAsArray(p_array, MCNAME("version"), false, t_temp_array))
return false;
MCValueAssign(version_info, t_temp_array);
MCValueRelease(t_temp_array);
// AL-2015-02-10: [[ Standalone Inclusions ]] Fetch the resource mappings, if any.
if (!ctxt.CopyOptElementAsString(p_array, MCNAME("library"), false, t_temp_string))
return false;
MCStringSplit(t_temp_string, MCSTR("\n"), nil, kMCStringOptionCompareExact, t_temp_array);
MCValueAssign(library, t_temp_array);
MCValueRelease(t_temp_string);
MCValueRelease(t_temp_array);
// SN-2015-02-16: [[ iOS Font mapping ]] Read the fontmappings options from the deploy parameters.
if (!ctxt.CopyOptElementAsString(p_array, MCNAME("fontmappings"), false, t_temp_string))
return false;
MCStringSplit(t_temp_string, MCSTR("\n"), nil, kMCStringOptionCompareExact, t_temp_array);
MCValueAssign(fontmappings, t_temp_array);
MCValueRelease(t_temp_string);
MCValueRelease(t_temp_array);
// The 'min_os_version' is either a string or an array. If it is a string then
// it encodes the version against the 'Unknown' architecture which is interpreted
// by the deploy command to mean all architectures. Otherwise, the keys in the
// array are assumed to be architecture names and each is pushed on the array.
// If the 'min_os_version' is empty, then no change is brought to the binaries.
// If multiple entries are present, then the 'unknown' mapping is used for any
// architecture not explicitly specified. The current architecture strings that are
// known are:
// i386, x86-64, armv6, armv7, armv7s, arm64, ppc, ppc64
// The empty string is taken to be 'unknown'.
if (!ctxt . CopyOptElementAsArray(p_array, MCNAME("min_os_version"), false, t_temp_array))
return false;
// SN-2015-02-04: [[ Merge-6.7.2 ]] If the array is empty, try to convert to a string.
if (!MCArrayIsEmpty(t_temp_array))
{
MCDeployArrayApplyCallbackContext t_context;
t_context . ctxt = &ctxt;
t_context . params = this;
bool t_success;
t_success = MCArrayApply(t_temp_array, MCDeployGetArchitectures, (void*)&t_context);
MCValueRelease(t_temp_array);
if (!t_success)
return false;
}
else
{
MCValueRelease(t_temp_array);
if (!ctxt . CopyOptElementAsString(p_array, MCNAME("min_os_version"), false, t_temp_string))
return false;
if (!MCStringIsEmpty(t_temp_string))
MCDeployPushMinOSVersion(this, kMCDeployArchitecture_Unknown, t_temp_string);
MCValueRelease(t_temp_string);
}
if (!ctxt.CopyOptElementAsFilepathArray(p_array, MCNAME("modules"), false, t_temp_array))
return false;
MCValueAssign(modules, t_temp_array);
MCValueRelease(t_temp_array);
MCAutoStringRef t_architectures_string;
if (!ctxt.CopyOptElementAsString(p_array, MCNAME("architectures"), false, &t_architectures_string))
return false;
if (!MCStringIsEmpty(*t_architectures_string))
{
// Split the string up into items
MCAutoProperListRef t_architectures;
if (!MCStringSplitByDelimiter(*t_architectures_string, MCSTR(","), kMCStringOptionCompareExact, &t_architectures))
return false;
// Process the architectures
MCValueRef t_architecture;
for (uindex_t i = 0; i < MCProperListGetLength(*t_architectures); i++)
{
// Fetch this item and make sure it is a string
t_architecture = MCProperListFetchElementAtIndex(*t_architectures, i);
if (t_architecture == nil || MCValueGetTypeCode(t_architecture) != kMCValueTypeCodeString)
return false;
// Map it to an architecture ID
MCDeployArchitecture t_id;
if (!MCDeployMapArchitectureString((MCStringRef)t_architecture, t_id))
return false;
// Append it to the list of desired architectures
if (!architectures.Push(t_id))
return false;
}
}
// If the 'banner_class' string is present, then set the class override.
MCAutoStringRef t_banner_class;
if (!ctxt . CopyOptElementAsString(p_array, MCNAME("banner_class"), false, &t_banner_class))
return false;
if (MCStringIsEqualToCString(*t_banner_class,
"commercial",
kMCStringOptionCompareCaseless))
banner_class = kMCLicenseClassEvaluation;
else if (MCStringIsEqualToCString(*t_banner_class,
"professional",
kMCStringOptionCompareCaseless))
banner_class = kMCLicenseClassProfessionalEvaluation;
if (!ctxt.CopyOptElementAsString(p_array, MCNAME("uuid"), false, t_temp_string))
return false;
MCValueAssign(uuid, t_temp_string);
MCValueRelease(t_temp_string);
return true;
}
////////////////////////////////////////////////////////////////////////////////
static bool MCDeployWriteDefinePrologueSection(const MCDeployParameters& p_params, MCDeployCapsuleRef p_capsule)
{
MCCapsulePrologueSection t_prologue;
t_prologue . banner_timeout = p_params . banner_timeout;
t_prologue . program_timeout = p_params . timeout;
MCDeployByteSwapRecord(true, "ll", &t_prologue, sizeof(t_prologue));
return MCDeployCapsuleDefine(p_capsule, kMCCapsuleSectionTypePrologue, &t_prologue, sizeof(t_prologue));
}
static bool MCDeployWriteDefineLicenseSection(const MCDeployParameters& p_params, MCDeployCapsuleRef p_capsule)
{
bool t_success = true;
IO_handle t_stream_handle;
t_stream_handle = nullptr;
if (t_success)
{
t_stream_handle = MCS_fakeopenwrite();
t_success = t_stream_handle != nullptr;
}
if (t_success)
{
t_success = IO_write_uint1((uint1)MClicenseparameters . license_class, t_stream_handle) == IO_NORMAL;
}
if (t_success && MClicenseparameters . addons != nullptr)
{
t_success = IO_write_valueref_new(MClicenseparameters . addons, t_stream_handle) == IO_NORMAL;
}
//////////
void *t_buffer;
size_t t_length = 0;
t_buffer = nullptr;
if (t_success)
{
t_success = MCS_closetakingbuffer(t_stream_handle, t_buffer, t_length) == IO_NORMAL;
}
if (t_success)
{
t_success = MCDeployCapsuleDefine(p_capsule,
kMCCapsuleSectionTypeLicense,
t_buffer,
uint32_t(t_length));
}
if (t_buffer != nullptr)
{
free(t_buffer);
}
return t_success;
}
static bool MCDeployWriteDefineBannerSecion(const MCDeployParameters& p_params, MCDeployCapsuleRef p_capsule)
{
return MCDeployCapsuleDefine(p_capsule, kMCCapsuleSectionTypeBanner, MCDataGetBytePtr(p_params . banner_stackfile), MCDataGetLength(p_params . banner_stackfile));
}
// This method generates the standalone specific capsule elements. This is
// just a Standalone Prologue section at the moment.
static bool MCDeployWriteCapsuleDefineStandaloneSections(const MCDeployParameters& p_params, MCDeployCapsuleRef p_capsule)
{
bool t_success;
t_success = true;
// First emit the prologue.
if (t_success)
t_success = MCDeployWriteDefinePrologueSection(p_params, p_capsule);
// Next emit the license info.
if (t_success)
t_success = MCDeployWriteDefineLicenseSection(p_params, p_capsule);
// Next emit the banner.
if (t_success &&
!MCDataIsEmpty(p_params . banner_stackfile))
t_success = MCDeployWriteDefineBannerSecion(p_params, p_capsule);
return t_success;
}
static bool MCDeployCapsuleDefineFromStackFile(MCDeployCapsuleRef p_self, MCStringRef p_filename, MCDeployFileRef p_file, bool p_mainstack)
{
MCAutoDataRef t_contents;
if (!MCS_loadbinaryfile(p_filename, &t_contents))
return false;
IO_handle t_stream = nil;
t_stream = MCS_fakeopen(MCDataGetBytePtr(*t_contents),MCDataGetLength(*t_contents));
if (t_stream == nil)
return false;
bool t_script_only = MCdispatcher -> streamstackisscriptonly(t_stream);
MCS_close(t_stream);
MCCapsuleSectionType t_type;
if (p_mainstack)
{
if (t_script_only)
{
t_type = kMCCapsuleSectionTypeScriptOnlyMainStack;
}
else
{
t_type = kMCCapsuleSectionTypeMainStack;
}
}
else
{
if (t_script_only)
{
t_type = kMCCapsuleSectionTypeScriptOnlyAuxiliaryStack;
}
else
{
t_type = kMCCapsuleSectionTypeAuxiliaryStack;
}
}
return MCDeployCapsuleDefineFromFile(p_self, t_type, p_file);
}
// This method constructs and then writes out a capsule to the given output file.
// The capsule contents is derived from the deploy parameters structure.
// The offset in the file after writing is returned in x_offset.
bool MCDeployWriteCapsule(const MCDeployParameters& p_params, MCDeployFileRef p_output, uint32_t& x_offset)
{
bool t_success;
t_success = true;
// Open the stackfile.
MCDeployFileRef t_stackfile;
t_stackfile = NULL;
if (t_success && !MCDeployFileOpen(p_params . stackfile, kMCOpenFileModeRead, t_stackfile))
t_success = MCDeployThrow(kMCDeployErrorNoStackfile);
// Open the spill file, if required
MCDeployFileRef t_spill;
t_spill = NULL;
if (t_success && !MCStringIsEmpty(p_params . spill) && !MCDeployFileOpen(p_params . spill, kMCOpenFileModeCreate, t_spill))
t_success = MCDeployThrow(kMCDeployErrorNoSpill);
// First create our deployment capsule
MCDeployCapsuleRef t_capsule;
t_capsule = nil;
if (t_success)
t_success = MCDeployCapsuleCreate(t_capsule);
// Next, the first thing to do is to add the the header section.
if (t_success)
t_success = MCDeployWriteCapsuleDefineStandaloneSections(p_params, t_capsule);
// Add any redirects
if (t_success)
for(uindex_t i = 0; i < MCArrayGetCount(p_params.redirects) && t_success; i++)
{
MCValueRef t_val;
/* UNCHECKED */ MCArrayFetchValueAtIndex(p_params.redirects, i + 1, t_val);
t_success = MCDeployCapsuleDefineString(t_capsule, kMCCapsuleSectionTypeRedirect, (MCStringRef)t_val);
}
////////
// AL-2015-02-10: [[ Standalone Inclusions ]] Add the resource mappings, if any.
if (t_success)
for(uindex_t i = 0; i < MCArrayGetCount(p_params.library) && t_success; i++)
{
MCValueRef t_val;
/* UNCHECKED */ MCArrayFetchValueAtIndex(p_params.library, i + 1, t_val);
t_success = MCDeployCapsuleDefineString(t_capsule, kMCCapsuleSectionTypeLibrary, (MCStringRef)t_val);
}
////////
// Add all the modules before the stacks, this is so that widgets can resolve
// themselves on load.
MCAutoArray<MCDeployFileRef> t_module_files;
if (t_success)
t_success = t_module_files . New(MCArrayGetCount(p_params . modules));
if (t_success)
for(uindex_t i = 0; i < MCArrayGetCount(p_params.modules) && t_success; i++)
{
MCValueRef t_module_filename;
/* UNCHECKED */ MCArrayFetchValueAtIndex(p_params .modules, i + 1, t_module_filename);
if (t_success && !MCDeployFileOpen((MCStringRef)t_module_filename, kMCOpenFileModeRead, t_module_files[i]))
t_success = MCDeployThrow(kMCDeployErrorNoModule);
if (t_success)
t_success = MCDeployCapsuleDefineFromFile(t_capsule, kMCCapsuleSectionTypeModule, t_module_files[i]);
}
////////
// Add any font mappings
if (t_success)
for(uint32_t i = 0; i < MCArrayGetCount(p_params.fontmappings) && t_success; i++)
{
MCValueRef t_val;
/* UNCHECKED */ MCArrayFetchValueAtIndex(p_params.fontmappings, i + 1, t_val);
t_success = MCDeployCapsuleDefineString(t_capsule, kMCCapsuleSectionTypeFontmap, (MCStringRef)t_val);
}
// Now we add the main stack
if (t_success)
t_success = MCDeployCapsuleDefineFromStackFile(t_capsule, p_params . stackfile, t_stackfile, true);
// Now we add the auxillary stackfiles, if any
MCAutoArray<MCDeployFileRef> t_aux_stackfiles;
if (t_success)
t_success = t_aux_stackfiles . New(MCArrayGetCount(p_params . auxiliary_stackfiles));
if (t_success)
for(uindex_t i = 0; i < MCArrayGetCount(p_params.auxiliary_stackfiles) && t_success; i++)
{
MCValueRef t_val;
/* UNCHECKED */ MCArrayFetchValueAtIndex(p_params.auxiliary_stackfiles, i + 1, t_val);
if (t_success && !MCDeployFileOpen((MCStringRef)t_val, kMCOpenFileModeRead, t_aux_stackfiles[i]))
t_success = MCDeployThrow(kMCDeployErrorNoAuxStackfile);
if (t_success)
t_success = MCDeployCapsuleDefineFromStackFile(t_capsule, (MCStringRef)t_val, t_aux_stackfiles[i], false);
}
// Now add the externals, if any
if (t_success)
for(uindex_t i = 0; i < MCArrayGetCount(p_params.externals) && t_success; i++)
{
MCValueRef t_val;
/* UNCHECKED */ MCArrayFetchValueAtIndex(p_params.externals, i + 1, t_val);
t_success = MCDeployCapsuleDefineString(t_capsule, kMCCapsuleSectionTypeExternal, (MCStringRef)t_val);
}
// Now add the startup script, if any.
if (t_success && (!MCStringIsEmpty(p_params . startup_script)))
t_success = MCDeployCapsuleDefineString(t_capsule, kMCCapsuleSectionTypeStartupScript, p_params . startup_script);
// Now a digest
if (t_success)
t_success = MCDeployCapsuleChecksum(t_capsule);
// Finally the epilogue
if (t_success)
t_success = MCDeployCapsuleDefine(t_capsule, kMCCapsuleSectionTypeEpilogue, nil, 0);
// Now we write it
if (t_success)
t_success = MCDeployCapsuleGenerate(t_capsule, p_output, t_spill, x_offset);
MCDeployCapsuleDestroy(t_capsule);
for(uindex_t i = 0; i < t_aux_stackfiles . Size(); i++)
MCDeployFileClose(t_aux_stackfiles[i]);
for(uindex_t i = 0; i < t_module_files . Size(); i++)
MCDeployFileClose(t_module_files[i]);
MCDeployFileClose(t_spill);
MCDeployFileClose(t_stackfile);
return t_success;
}
// This method writes out a project capsule. This consists of a length uint32_t
// followed by the capsule data. The size returned always falls on a 4-byte
// boundary.
bool MCDeployWriteProject(const MCDeployParameters& p_params, bool p_to_network, MCDeployFileRef p_output, uint32_t p_output_offset, uint32_t& r_project_size)
{
bool t_success;
t_success = true;
// A capsule struct is simply a uint32_t followed by the data
uint32_t t_offset;
t_offset = p_output_offset + sizeof(uint32_t);
// First write the capsule to the output file, leaving room for the size field.
// Note that a capsule is always a multiple of four bytes in length, so offset
// will be rounded to a nice value.
if (t_success)
t_success = MCDeployWriteCapsule(p_params, p_output, t_offset);
// Work out the size of the capsule struct (including size field)
uint32_t t_project_size;
if (t_success)
t_project_size = t_offset - p_output_offset;
// Now write out the size field
if (t_success)
{
uint32_t t_swapped_size;
t_swapped_size = t_project_size;
if (!MCStringIsEmpty(p_params . spill))
t_swapped_size |= 1U << 31;
MCDeployByteSwap32(p_to_network, t_swapped_size);
t_success = MCDeployFileWriteAt(p_output, &t_swapped_size, sizeof(uint32_t), p_output_offset);
}
// Return the project size
if (t_success)
r_project_size = t_project_size;
return t_success;
}
// This method writes out a payload capsule. This is a length uint32_t followed
// by the contents of the given file. The size returned always falls on a 4-byte
// boundary.
bool MCDeployWritePayload(const MCDeployParameters& p_params, bool p_to_network, MCDeployFileRef p_output, uint32_t p_output_offset, uint32_t& r_payload_size)
{
bool t_success;
t_success = true;
// First try to open the payload file
MCDeployFileRef t_payload;
t_payload = nil;
if (t_success && !MCDeployFileOpen(p_params . payload, kMCOpenFileModeRead, t_payload))
t_success = MCDeployThrow(kMCDeployErrorNoPayload);
// Next measure the file to find out how big it is
uint32_t t_payload_size;
t_payload_size = 0;
if (t_success)
t_success = MCDeployFileMeasure(t_payload, t_payload_size);
// Now write out the uint32_t size field (including itself)
if (t_success)
{
uint32_t t_swapped_size;
t_swapped_size = t_payload_size + sizeof(uint32_t);
MCDeployByteSwap32(p_to_network, t_swapped_size);
t_success = MCDeployFileWriteAt(p_output, &t_swapped_size, sizeof(uint32_t), p_output_offset);
}
// Next copy across the payload data
if (t_success)
t_success = MCDeployFileCopy(p_output, p_output_offset + sizeof(uint32_t), t_payload, 0, t_payload_size);
// Return the actual payload size, including padding up to nearest 4 byte
// boundary.
if (t_success)
{
t_payload_size += sizeof(uint32_t);
t_payload_size = (t_payload_size + 3) & ~3;
r_payload_size = t_payload_size;
}
// Close any file that we open
if (t_payload != nil)
MCDeployFileClose(t_payload);
return t_success;
}
////////////////////////////////////////////////////////////////////////////////
MCIdeDeploy::MCIdeDeploy(void)
{
m_params = NULL;
m_platform = PLATFORM_NONE;
}
MCIdeDeploy::~MCIdeDeploy(void)
{
delete m_params;
}
Parse_stat MCIdeDeploy::parse(MCScriptPoint& sp)
{
Symbol_type t_type;
if (sp . next(t_type) == PS_NORMAL && t_type == ST_ID)
{
if (sp . token_is_cstring("windows"))
m_platform = PLATFORM_WINDOWS;
else if (sp . token_is_cstring("linux"))
m_platform = PLATFORM_LINUX;
else if (sp . token_is_cstring("macosx"))
m_platform = PLATFORM_MACOSX;
else if (sp . token_is_cstring("ios"))
m_platform = PLATFORM_IOS;
else if (sp . token_is_cstring("android"))
m_platform = PLATFORM_ANDROID;
else if (sp . token_is_cstring("winmobile"))
m_platform = PLATFORM_WINMOBILE;
else if (sp . token_is_cstring("linuxmobile"))
m_platform = PLATFORM_LINUXMOBILE;
else if (sp . token_is_cstring("iosembedded"))
m_platform = PLATFORM_IOS_EMBEDDED;
else if (sp . token_is_cstring("androidembedded"))
m_platform = PLATFORM_ANDROID_EMBEDDED;
else if (sp . token_is_cstring("emscripten"))
m_platform = PLATFORM_EMSCRIPTEN;
else
return PS_ERROR;
}
else
return PS_ERROR;
return sp . parseexp(False, True, &m_params);
}
void MCIdeDeploy::exec_ctxt(MCExecContext& ctxt)
{
bool t_soft_error;
t_soft_error = false;
bool t_has_error;
t_has_error = false;
// Clear the result as we return an error there
ctxt . SetTheResultToEmpty();
MCAutoArrayRef t_array;
if (!ctxt . EvalExprAsArrayRef(m_params, EE_UNDEFINED, &t_array))
return;
MCDeployParameters t_params;
t_has_error = !t_params.InitWithArray(ctxt, *t_array);
// If platform is iOS and we are not Mac then error
#ifndef _MACOSX
if (!t_has_error && (m_platform == PLATFORM_IOS || m_platform == PLATFORM_IOS_EMBEDDED))
{
ctxt . SetTheResultToCString("ios deployment not supported on this platform");
t_soft_error = true;
t_has_error = true;
}
#endif
// If the banner_class field is set and we are not a trial license, we
// override the license class with that specified.
MCLicenseClass t_license_class = kMCLicenseClassNone;
if (MClicenseparameters . license_class == kMCLicenseClassCommercial)
{
// If we have a commercial license, then we only allow a commercial
// evaluation.
if (t_params . banner_class == kMCLicenseClassEvaluation)
t_license_class = kMCLicenseClassEvaluation;
}
else if (MClicenseparameters . license_class == kMCLicenseClassProfessional)
{
// If we are a professional license, then we allow any kind of
// trial.
t_license_class = t_params . banner_class;
}
if (t_license_class == kMCLicenseClassNone)
t_license_class = MClicenseparameters . license_class;
t_params . banner_class = t_license_class;
// Now check to see if we should build a trial - this if the license class is a
// trail, or the banner_class override is specified and the chosen option is
// compatible with the license class.
bool t_is_trial;
t_is_trial = false;
if (t_license_class == kMCLicenseClassEvaluation ||
t_license_class == kMCLicenseClassProfessionalEvaluation)
t_is_trial = true;
// Now, if we are not licensed for a target, then its an error. If we are in trial
// mode, however, all platforms are licensed (apart from embedded) they just will
// timeout.
bool t_is_licensed;
t_is_licensed = false;
if (MCnoui && MClicenseparameters . license_class == kMCLicenseClassCommunity)
t_is_licensed = true;
else if (t_is_trial &&
m_platform != PLATFORM_IOS_EMBEDDED &&
m_platform != PLATFORM_ANDROID_EMBEDDED)
t_is_licensed = true;
else if (m_platform == PLATFORM_WINDOWS)
t_is_licensed = (MClicenseparameters . deploy_targets & kMCLicenseDeployToWindows) != 0;
else if (m_platform == PLATFORM_MACOSX)
t_is_licensed = (MClicenseparameters . deploy_targets & kMCLicenseDeployToMacOSX) != 0;
else if (m_platform == PLATFORM_LINUX)
t_is_licensed = (MClicenseparameters . deploy_targets & kMCLicenseDeployToLinux) != 0;
else if (m_platform == PLATFORM_IOS)
t_is_licensed = (MClicenseparameters . deploy_targets & kMCLicenseDeployToIOS) != 0;
else if (m_platform == PLATFORM_ANDROID)
t_is_licensed = (MClicenseparameters . deploy_targets & kMCLicenseDeployToAndroid) != 0;
else if (m_platform == PLATFORM_IOS_EMBEDDED)
t_is_licensed = (MClicenseparameters . deploy_targets & kMCLicenseDeployToIOSEmbedded) != 0;
else if (m_platform == PLATFORM_ANDROID_EMBEDDED)
t_is_licensed = (MClicenseparameters . deploy_targets & kMCLicenseDeployToAndroidEmbedded) != 0;
else if (m_platform == PLATFORM_EMSCRIPTEN)
t_is_licensed = (MClicenseparameters . deploy_targets & kMCLicenseDeployToHTML5) != 0;
if (!t_is_licensed)
{
ctxt . SetTheResultToCString("not licensed to deploy to target platform");
t_soft_error = true;
t_has_error = true;
}
if (t_is_trial &&
m_platform == PLATFORM_EMSCRIPTEN)
{
ctxt . SetTheResultToCString("trial of html5 is not possible");
t_soft_error = true;
t_has_error = true;
}
uint32_t t_platform = PLATFORM_NONE;
switch(m_platform)
{
case PLATFORM_MACOSX:
t_platform = kMCLicenseDeployToMacOSX;
break;
case PLATFORM_WINDOWS:
t_platform = kMCLicenseDeployToWindows;
break;
case PLATFORM_LINUX:
t_platform = kMCLicenseDeployToLinux;
break;
case PLATFORM_IOS:
t_platform = kMCLicenseDeployToIOS;
break;
case PLATFORM_ANDROID:
t_platform = kMCLicenseDeployToAndroid;
break;
case PLATFORM_IOS_EMBEDDED:
t_platform = kMCLicenseDeployToIOSEmbedded;
break;
case PLATFORM_ANDROID_EMBEDDED:
t_platform = kMCLicenseDeployToAndroidEmbedded;
break;
case PLATFORM_EMSCRIPTEN:
t_platform = kMCLicenseDeployToHTML5;
break;
}
if (!t_has_error)
{
// If this is a trial then set the timeout.
if (t_is_trial)
{
if (m_platform != PLATFORM_IOS &&
m_platform != PLATFORM_ANDROID &&
m_platform != PLATFORM_EMSCRIPTEN)
t_params . timeout = 5 * 60;
else
t_params . timeout = 1 * 60;
t_params . banner_timeout = 10;
}
// Pass the deploy parameters through any stack security related steps.
if (!MCStackSecurityPreDeploy(t_platform, t_params))
{
t_soft_error = true;
t_has_error = true;
}
}
if (!t_has_error)
{
if (m_platform == PLATFORM_WINDOWS)
MCDeployToWindows(t_params);
else if (m_platform == PLATFORM_LINUX)
MCDeployToLinux(t_params);
else if (m_platform == PLATFORM_MACOSX)
MCDeployToMacOSX(t_params);
else if (m_platform == PLATFORM_IOS)
MCDeployToIOS(t_params, false);
else if (m_platform == PLATFORM_ANDROID)
MCDeployToAndroid(t_params);
else if (m_platform == PLATFORM_IOS_EMBEDDED)
MCDeployToIOS(t_params, true);
else if (m_platform == PLATFORM_EMSCRIPTEN)
MCDeployToEmscripten(t_params);
MCDeployError t_error;
t_error = MCDeployCatch();
if (t_error != kMCDeployErrorNone)
ctxt . SetTheResultToCString(MCDeployErrorToString(t_error));
else
ctxt . SetTheResultToEmpty();
}
if (t_has_error && !t_soft_error)
ctxt . Throw();
}
////////////////////////////////////////////////////////////////////////////////
MCIdeSign::MCIdeSign(void)
{
m_params = NULL;
m_platform = PLATFORM_NONE;
}
MCIdeSign::~MCIdeSign(void)
{
delete m_params;
}
Parse_stat MCIdeSign::parse(MCScriptPoint& sp)
{
Symbol_type t_type;
if (sp . next(t_type) == PS_NORMAL && t_type == ST_ID)
{
if (sp . token_is_cstring("windows"))
m_platform = PLATFORM_WINDOWS;
else if (sp . token_is_cstring("linux"))
m_platform = PLATFORM_LINUX;
else if (sp . token_is_cstring("macosx"))
m_platform = PLATFORM_MACOSX;
else
return PS_ERROR;
}
else
return PS_ERROR;
return sp . parseexp(False, True, &m_params);
}
void MCIdeSign::exec_ctxt(MCExecContext &ctxt)