-
Notifications
You must be signed in to change notification settings - Fork 11
/
CStackFile.cpp
1922 lines (1689 loc) · 63.1 KB
/
CStackFile.cpp
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
/*
* CStackFile.cpp
* stackimport
*
* Created by Mr. Z. on 10/06/06.
* Copyright 2006 Mr Z. All rights reserved.
*
*/
#include "CStackFile.h"
#include <iostream>
#include <fstream>
#include <sys/stat.h>
#include <unistd.h>
#include "picture.h"
#include "woba.h"
#include "CBuf.h"
#include <arpa/inet.h>
#include "snd2wav/snd2wav/snd2wav.h"
// Table of C-strings for converting the non-ASCII MacRoman characters (above 127)
// into the requisite UTF8 byte sequences:
unsigned char sMacRomanToUTF8Table[128][5] =
{
{ 0xc3, 0x84, 0x00, 0x00 }, { 0xc3, 0x85, 0x00, 0x00 }, { 0xc3, 0x87, 0x00, 0x00 }, { 0xc3, 0x89, 0x00, 0x00 },
{ 0xc3, 0x91, 0x00, 0x00 }, { 0xc3, 0x96, 0x00, 0x00 }, { 0xc3, 0x9c, 0x00, 0x00 }, { 0xc3, 0xa1, 0x00, 0x00 },
{ 0xc3, 0xa0, 0x00, 0x00 }, { 0xc3, 0xa2, 0x00, 0x00 }, { 0xc3, 0xa4, 0x00, 0x00 }, { 0xc3, 0xa3, 0x00, 0x00 },
{ 0xc3, 0xa5, 0x00, 0x00 }, { 0xc3, 0xa7, 0x00, 0x00 }, { 0xc3, 0xa9, 0x00, 0x00 }, { 0xc3, 0xa8, 0x00, 0x00 },
{ 0xc3, 0xaa, 0x00, 0x00 }, { 0xc3, 0xab, 0x00, 0x00 }, { 0xc3, 0xad, 0x00, 0x00 }, { 0xc3, 0xac, 0x00, 0x00 },
{ 0xc3, 0xae, 0x00, 0x00 }, { 0xc3, 0xaf, 0x00, 0x00 }, { 0xc3, 0xb1, 0x00, 0x00 }, { 0xc3, 0xb3, 0x00, 0x00 },
{ 0xc3, 0xb2, 0x00, 0x00 }, { 0xc3, 0xb4, 0x00, 0x00 }, { 0xc3, 0xb6, 0x00, 0x00 }, { 0xc3, 0xb5, 0x00, 0x00 },
{ 0xc3, 0xba, 0x00, 0x00 }, { 0xc3, 0xb9, 0x00, 0x00 }, { 0xc3, 0xbb, 0x00, 0x00 }, { 0xc3, 0xbc, 0x00, 0x00 },
{ 0xe2, 0x80, 0xa0, 0x00 }, { 0xc2, 0xb0, 0x00, 0x00 }, { 0xc2, 0xa2, 0x00, 0x00 }, { 0xc2, 0xa3, 0x00, 0x00 },
{ 0xc2, 0xa7, 0x00, 0x00 }, { 0xe2, 0x80, 0xa2, 0x00 }, { 0xc2, 0xb6, 0x00, 0x00 }, { 0xc3, 0x9f, 0x00, 0x00 },
{ 0xc2, 0xae, 0x00, 0x00 }, { 0xc2, 0xa9, 0x00, 0x00 }, { 0xe2, 0x84, 0xa2, 0x00 }, { 0xc2, 0xb4, 0x00, 0x00 },
{ 0xc2, 0xa8, 0x00, 0x00 }, { 0xe2, 0x89, 0xa0, 0x00 }, { 0xc3, 0x86, 0x00, 0x00 }, { 0xc3, 0x98, 0x00, 0x00 },
{ 0xe2, 0x88, 0x9e, 0x00 }, { 0xc2, 0xb1, 0x00, 0x00 }, { 0xe2, 0x89, 0xa4, 0x00 }, { 0xe2, 0x89, 0xa5, 0x00 },
{ 0xc2, 0xa5, 0x00, 0x00 }, { 0xc2, 0xb5, 0x00, 0x00 }, { 0xe2, 0x88, 0x82, 0x00 }, { 0xe2, 0x88, 0x91, 0x00 },
{ 0xe2, 0x88, 0x8f, 0x00 }, { 0xcf, 0x80, 0x00, 0x00 }, { 0xe2, 0x88, 0xab, 0x00 }, { 0xc2, 0xaa, 0x00, 0x00 },
{ 0xc2, 0xba, 0x00, 0x00 }, { 0xce, 0xa9, 0x00, 0x00 }, { 0xc3, 0xa6, 0x00, 0x00 }, { 0xc3, 0xb8, 0x00, 0x00 },
{ 0xc2, 0xbf, 0x00, 0x00 }, { 0xc2, 0xa1, 0x00, 0x00 }, { 0xc2, 0xac, 0x00, 0x00 }, { 0xe2, 0x88, 0x9a, 0x00 },
{ 0xc6, 0x92, 0x00, 0x00 }, { 0xe2, 0x89, 0x88, 0x00 }, { 0xe2, 0x88, 0x86, 0x00 }, { 0xc2, 0xab, 0x00, 0x00 },
{ 0xc2, 0xbb, 0x00, 0x00 }, { 0xe2, 0x80, 0xa6, 0x00 }, { 0xc2, 0xa0, 0x00, 0x00 }, { 0xc3, 0x80, 0x00, 0x00 },
{ 0xc3, 0x83, 0x00, 0x00 }, { 0xc3, 0x95, 0x00, 0x00 }, { 0xc5, 0x92, 0x00, 0x00 }, { 0xc5, 0x93, 0x00, 0x00 },
{ 0xe2, 0x80, 0x93, 0x00 }, { 0xe2, 0x80, 0x94, 0x00 }, { 0xe2, 0x80, 0x9c, 0x00 }, { 0xe2, 0x80, 0x9d, 0x00 },
{ 0xe2, 0x80, 0x98, 0x00 }, { 0xe2, 0x80, 0x99, 0x00 }, { 0xc3, 0xb7, 0x00, 0x00 }, { 0xe2, 0x97, 0x8a, 0x00 },
{ 0xc3, 0xbf, 0x00, 0x00 }, { 0xc5, 0xb8, 0x00, 0x00 }, { 0xe2, 0x81, 0x84, 0x00 }, { 0xe2, 0x82, 0xac, 0x00 },
{ 0xe2, 0x80, 0xb9, 0x00 }, { 0xe2, 0x80, 0xba, 0x00 }, { 0xef, 0xac, 0x81, 0x00 }, { 0xef, 0xac, 0x82, 0x00 },
{ 0xe2, 0x80, 0xa1, 0x00 }, { 0xc2, 0xb7, 0x00, 0x00 }, { 0xe2, 0x80, 0x9a, 0x00 }, { 0xe2, 0x80, 0x9e, 0x00 },
{ 0xe2, 0x80, 0xb0, 0x00 }, { 0xc3, 0x82, 0x00, 0x00 }, { 0xc3, 0x8a, 0x00, 0x00 }, { 0xc3, 0x81, 0x00, 0x00 },
{ 0xc3, 0x8b, 0x00, 0x00 }, { 0xc3, 0x88, 0x00, 0x00 }, { 0xc3, 0x8d, 0x00, 0x00 }, { 0xc3, 0x8e, 0x00, 0x00 },
{ 0xc3, 0x8f, 0x00, 0x00 }, { 0xc3, 0x8c, 0x00, 0x00 }, { 0xc3, 0x93, 0x00, 0x00 }, { 0xc3, 0x94, 0x00, 0x00 },
{ 0xef, 0xa3, 0xbf, 0x00 }, { 0xc3, 0x92, 0x00, 0x00 }, { 0xc3, 0x9a, 0x00, 0x00 }, { 0xc3, 0x9b, 0x00, 0x00 },
{ 0xc3, 0x99, 0x00, 0x00 }, { 0xc4, 0xb1, 0x00, 0x00 }, { 0xcb, 0x86, 0x00, 0x00 }, { 0xcb, 0x9c, 0x00, 0x00 },
{ 0xc2, 0xaf, 0x00, 0x00 }, { 0xcb, 0x98, 0x00, 0x00 }, { 0xcb, 0x99, 0x00, 0x00 }, { 0xcb, 0x9a, 0x00, 0x00 },
{ 0xc2, 0xb8, 0x00, 0x00 }, { 0xcb, 0x9d, 0x00, 0x00 }, { 0xcb, 0x9b, 0x00, 0x00 }, { 0xcb, 0x87, 0x00, 0x00 }
};
const unsigned char* UniCharFromMacRoman( unsigned char c )
{
if( c >= 128 )
return sMacRomanToUTF8Table[ c -128 ];
else if( c == 0x11 )
{
static unsigned char commandKey[4] = { 0xe2, 0x8c, 0x98, 0 }; // Unicode 0x2318
return commandKey;
}
else
{
static unsigned char asciiStr[2] = { 0, 0 };
asciiStr[0] = c;
return asciiStr;
}
}
void NumVersionToStr( unsigned char numVersion[4], char outStr[16] )
{
char theCh = 'v';
switch( numVersion[2] )
{
case 0x20:
theCh = 'd';
break;
case 0x40:
theCh = 'a';
break;
case 0x60:
theCh = 'b';
break;
case 0x80:
theCh = 'v';
break;
}
// NumVersion is Binary-coded decimal, i.e. 0x10 is displayed as 10, not 16 decimal:
if( numVersion[3] == 0 && (numVersion[1] & 0x0F) == 0 ) // N.N version
snprintf( outStr, 16, "%x.%x", numVersion[0], (numVersion[1] >> 4) );
else if( (numVersion[1] & 0x0F) == 0 ) // N.NxN version
snprintf( outStr, 16, "%x.%x%c%d", numVersion[0], (numVersion[1] >> 4), theCh, numVersion[3] );
else if( numVersion[3] == 0 ) // N.N.N version
snprintf( outStr, 16, "%x.%x.%x", numVersion[0], (numVersion[1] >> 4), (numVersion[1] & 0x0F) );
else // N.N.NxN version
snprintf( outStr, 16, "%x.%x.%x%c%d", numVersion[0], (numVersion[1] >> 4), (numVersion[1] & 0x0F), theCh, numVersion[3] );
}
CStackFile::CStackFile()
: mDumpRawBlockData(false), mStatusMessages(true), mXmlFile(NULL),
mCardBlockSize(-1), mListBlockID(-1), mMaxProgress(0), mCurrentProgress(0),
mFontTableBlockID(-1), mStyleTableBlockID(-1), mProgressMessages(true), mDecodeGraphics(true)
{
}
bool CStackFile::LoadStackBlock( int32_t stackID, CBuf& blockData )
{
if( mStatusMessages )
fprintf( stdout, "Status: Processing 'STAK' #-1 (%lu bytes)\n", blockData.size() );
fprintf( mXmlFile, "\t<stack id=\"%d\" file=\"stack_%d.xml\" name=\"", stackID, stackID );
for( int x = 0; mFileName[x] != 0; x++ )
{
char currCh = mFileName[x];
if( currCh == '"' )
fprintf( mXmlFile, "%%22" );
else if( currCh == '\n' )
fprintf( mXmlFile, "%%0A;" );
else if( currCh == '\r' )
fprintf( mXmlFile, "%%0D" );
else
fputc( currCh, mXmlFile ); // mFileName comes from POSIX, should already be UTF8, is *definitely* not MacRoman.
}
fprintf( mXmlFile, "\" />\n" );
if( mDumpRawBlockData )
{
char sfn[256] = { 0 };
snprintf( sfn, sizeof(sfn), "STAK_%d.data", stackID );
blockData.tofile( sfn );
}
fprintf( mStackXmlFile, "\t<id>%d</id>\n", stackID );
int32_t numberOfCards = ntohl(blockData.int32at( 32 ));
fprintf( mStackXmlFile, "\t<cardCount>%d</cardCount>\n", numberOfCards );
int32_t cardID = ntohl(blockData.int32at( 36 ));
fprintf( mStackXmlFile, "\t<cardID>%d</cardID>\n", cardID );
mListBlockID = ntohl(blockData.int32at( 40 ));
fprintf( mStackXmlFile, "\t<listID>%d</listID>\n", mListBlockID );
int16_t userLevel = ntohs(blockData.int16at( 60 ));
fprintf( mXmlFile, "\t<userLevel>%d</userLevel>\n", userLevel );
int16_t flags = ntohs(blockData.int16at( 64 ));
fprintf( mStackXmlFile, "\t<cantModify>%s</cantModify>\n", (flags & (1 << 15)) ? "<true />" : "<false />" );
fprintf( mStackXmlFile, "\t<cantDelete>%s</cantDelete>\n", (flags & (1 << 14)) ? "<true />" : "<false />" );
fprintf( mXmlFile, "\t<privateAccess>%s</privateAccess>\n", (flags & (1 << 13)) ? "<true />" : "<false />" );
fprintf( mStackXmlFile, "\t<cantAbort>%s</cantAbort>\n", (flags & (1 << 11)) ? "<true />" : "<false />" );
fprintf( mXmlFile, "\t<cantPeek>%s</cantPeek>\n", (flags & (1 << 10)) ? "<true />" : "<false />" );
char versStr[16] = { 0 };
int32_t version0 = blockData.int32at( 84 );
NumVersionToStr( (unsigned char*) &version0, versStr );
fprintf( mXmlFile, "\t<createdByVersion>HyperCard %s</createdByVersion>\n", versStr );
int32_t version1 = blockData.int32at( 88 );
NumVersionToStr( (unsigned char*) &version1, versStr );
fprintf( mXmlFile, "\t<lastCompactedVersion>HyperCard %s</lastCompactedVersion>\n", versStr );
int32_t version2 = blockData.int32at( 92 );
NumVersionToStr( (unsigned char*) &version2, versStr );
fprintf( mXmlFile, "\t<lastEditedVersion>HyperCard %s</lastEditedVersion>\n", versStr );
int32_t version3 = blockData.int32at( 96 );
NumVersionToStr( (unsigned char*) &version3, versStr );
fprintf( mXmlFile, "\t<firstEditedVersion>HyperCard %s</firstEditedVersion>\n", versStr );
mFontTableBlockID = ntohl(blockData.int32at( 420 ));
fprintf( mXmlFile, "\t<fontTableID>%d</fontTableID>\n", mFontTableBlockID );
mStyleTableBlockID = ntohl(blockData.int32at( 424 ));
fprintf( mXmlFile, "\t<styleTableID>%d</styleTableID>\n", mStyleTableBlockID );
int16_t height = ntohs(blockData.int16at( 428 ));
if( height == 0 )
height = 342;
int16_t width = ntohs(blockData.int16at( 430 ));
if( width == 0 )
width = 512;
fprintf( mStackXmlFile, "\t<cardSize>\n\t\t<width>%d</width>\n\t\t<height>%d</height>\n\t</cardSize>\n", width, height );
char pattern[8] = { 0 };
int offs = 692;
for( int n = 0; n < 40; n++ )
{
memmove( pattern, blockData.buf( offs, 8 ), 8 );
char fname[256] = { 0 };
sprintf( fname, "PAT_%u.pbm", n +1 );
picture thePicture( 8, 8, 1, false );
thePicture.memcopyin( pattern, 0, 8 );
thePicture.writebitmaptopbm( fname );
offs += 8;
fprintf(mXmlFile,"\t<media>\n\t\t<id>%u</id>\n\t\t<type>pattern</type>\n\t\t<file>PAT_%u.pbm</file>\n\t</media>\n", n+1, n+1);
}
int x = 0, startOffs = 1524;
fprintf( mStackXmlFile, "\t<script>" );
for( x = startOffs; blockData[x] != 0; x++ )
{
char currCh = blockData[x];
if( currCh == '<' )
fprintf( mStackXmlFile, "<" );
else if( currCh == '>' )
fprintf( mStackXmlFile, ">" );
else if( currCh == '&' )
fprintf( mStackXmlFile, "&" );
else
fprintf( mStackXmlFile, "%s", UniCharFromMacRoman(currCh) );
}
fprintf( mStackXmlFile, "</script>\n" );
if( mProgressMessages )
fprintf( stdout, "Progress: %d of %d\n", ++mCurrentProgress, mMaxProgress );
return true;
}
bool CStackFile::LoadStyleTable( int32_t blockID, CBuf& blockData )
{
int32_t vBlockSize = blockData.size();
if( mStatusMessages )
fprintf( stdout, "Status: Processing 'STBL' #%d %X (%d bytes)\n", blockID, blockID, vBlockSize );
if( mDumpRawBlockData )
{
char sfn[256] = { 0 };
snprintf( sfn, sizeof(sfn), "STBL_%d.data", blockID );
blockData.tofile( sfn );
}
std::vector<struct CStyleEntry> styles;
size_t currOffs = 4;
int32_t styleCount = ntohl(blockData.int32at( currOffs ));
currOffs += 4;
fprintf( mXmlFile, "\t<!-- 'STBL' #%d (%d styles) -->\n", blockID, styleCount );
std::string vLayerFilePath = mBasePath;
char vFileName[256] = { 0 };
snprintf( vFileName, 255, "stylesheet_%d.css", blockID );
mStyleSheetName = vFileName;
vLayerFilePath.append( 1, '/' );
vLayerFilePath.append( vFileName );
FILE* vStylesheetFile = fopen( vLayerFilePath.c_str(), "w" );
currOffs += 2;
int16_t nextStyleID = ntohs(blockData.int16at( currOffs ));
fprintf( mXmlFile, "\t<nextStyleID>%d</nextStyleID>\n", nextStyleID );
currOffs += 2;
currOffs += 2;
for( int s = 0; s < styleCount; s++ )
{
CStyleEntry style;
style.mStyleID = ntohs(blockData.int16at( currOffs ));
fprintf( vStylesheetFile, "\t\t.style%d\n\t\t{\n", style.mStyleID );
currOffs += 2;
currOffs += 8;
style.mFontID = ntohs(blockData.int16at( currOffs ));
if( style.mFontID != -1 )
{
style.mFontName = mFontTable[style.mFontID];
fprintf( vStylesheetFile, "\t\t\tfont-family: \"%s\";\n", style.mFontName.c_str() );
}
currOffs += 2;
int16_t textStyleFlags = ntohs(blockData.int16at( currOffs ));
currOffs += 2;
if( textStyleFlags == 0 )
fprintf( vStylesheetFile, "\t\t\tfont-style: normal;\n" );
else if( textStyleFlags != -1 ) // -1 means use field style.
{
if( textStyleFlags & (1 << 15) )
{
fprintf( vStylesheetFile, "\t\t\t/* group text style */\n" );
style.mGroup = true;
}
if( textStyleFlags & (1 << 14) )
{
fprintf( vStylesheetFile, "\t\t\tletter-spacing: 0.1em;\n" );
style.mExtend = true;
}
if( textStyleFlags & (1 << 13) )
{
fprintf( vStylesheetFile, "\t\t\tletter-spacing: -0.1em;\n" );
style.mCondense = true;
}
if( textStyleFlags & (1 << 12) )
{
fprintf( vStylesheetFile, "\t\t\ttext-shadow: 1px 1px #000000;\n" );
style.mShadow = true;
}
if( textStyleFlags & (1 << 11) )
{
fprintf( vStylesheetFile, "\t\t\tcolor: white; -webkit-text-stroke-width: 1pt; -webkit-text-stroke-color: #000;\n" );
style.mOutline = true;
}
if( textStyleFlags & (1 << 10) )
{
fprintf( vStylesheetFile, "\t\t\ttext-decoration: underline;\n" );
style.mUnderline = true;
}
if( textStyleFlags & (1 << 9) )
{
fprintf( vStylesheetFile, "\t\t\tfont-style: italic;\n" );
style.mItalic = true;
}
if( textStyleFlags & (1 << 8) )
{
fprintf( vStylesheetFile, "\t\t\tfont-weight: bold;\n" );
style.mBold = true;
}
}
int16_t fontSize = ntohs(blockData.int16at( currOffs ));
if( fontSize != -1 )
{
fprintf( vStylesheetFile, "\t\t\tfont-size: %dpt;\n", fontSize );
style.mFontSize = fontSize;
}
currOffs += 2;
currOffs += 8; // 2 bytes padding?
fprintf( vStylesheetFile, "\t\t}\n" );
mStyles[style.mStyleID] = style;
}
fclose( vStylesheetFile );
if( mProgressMessages )
fprintf( stdout, "Progress: %d of %d\n", ++mCurrentProgress, mMaxProgress );
return true;
}
bool CStackFile::LoadFontTable( int32_t blockID, CBuf& blockData )
{
uint32_t vBlockSize = blockData.size();
if( mStatusMessages )
fprintf( stdout, "Status: Processing 'FTBL' #%d %X (%d bytes)\n", blockID, blockID, vBlockSize );
fprintf( mXmlFile, "\t<!-- 'FTBL' #%d (%d bytes) -->\n", blockID, vBlockSize );
int16_t numFonts = ntohs(blockData.int16at( 6 ));
size_t currOffsIntoData = 8;
currOffsIntoData += 4; // Reserved?
for( int n = 0; n < numFonts; n++ )
{
std::string fontName;
fprintf( mXmlFile, "\t<font>\n" );
int16_t fontID = ntohs(blockData.int16at( currOffsIntoData ));
fprintf( mXmlFile, "\t\t<id>%d</id>\n", fontID );
int x = 0, startOffs = currOffsIntoData +2;
fprintf( mXmlFile, "\t\t<name>" );
for( x = startOffs; blockData[x] != 0; x++ )
{
char currCh = blockData[x];
if( currCh == '<' )
fontName.append( "<" );
else if( currCh == '>' )
fontName.append( ">" );
else if( currCh == '&' )
fontName.append( "&" );
else
fontName.append( (const char*) UniCharFromMacRoman(currCh) );
}
fprintf( mXmlFile, "%s", fontName.c_str() );
fprintf( mXmlFile, "</name>\n" );
mFontTable[fontID] = fontName;
currOffsIntoData = x +1;
currOffsIntoData += currOffsIntoData %2; // Align on even byte.
fprintf( mXmlFile, "\t</font>\n" );
}
if( mProgressMessages )
fprintf( stdout, "Progress: %d of %d\n", ++mCurrentProgress, mMaxProgress );
return true;
}
struct CStyleRun { int16_t startOffset; int16_t styleID; };
bool CStackFile::LoadLayerBlock( const char* vBlockType, int32_t blockID, CBuf& blockData, uint8_t inFlags )
{
int32_t vBlockSize = blockData.size();
std::string vLayerFilePath = mBasePath;
bool isCard = strcmp( "CARD", vBlockType ) == 0;
char vFileName[256] = { 0 };
if( !isCard )
snprintf( vFileName, 255, "/background_%d.xml", blockID );
else
snprintf( vFileName, 255, "/card_%d.xml", blockID );
vLayerFilePath.append( vFileName );
FILE* vFile = fopen( vLayerFilePath.c_str(), "w" );
if( mStatusMessages )
fprintf( stdout, "Status: Processing '%4s' #%d %X (%d bytes)\n", vBlockType, blockID, blockID, vBlockSize );
fprintf( vFile, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" );
if( !isCard )
{
fprintf( vFile, "<!DOCTYPE background PUBLIC \"-//Apple, Inc.//DTD background V 2.0//EN\" \"\" >\n" );
fprintf( vFile, "<background>\n" );
}
else
{
fprintf( vFile, "<!DOCTYPE card PUBLIC \"-//Apple, Inc.//DTD card V 2.0//EN\" \"\" >\n" );
fprintf( vFile, "<card>\n" );
}
fprintf( vFile, "\t<id>%d</id>\n", blockID );
if( mDumpRawBlockData )
{
char sfn[256] = { 0 };
snprintf( sfn, sizeof(sfn), "%s_%d.data", vBlockType, blockID );
blockData.tofile( sfn );
}
size_t currOffsIntoData = 0;
int32_t unknownFiller = ntohl(blockData.int32at( currOffsIntoData ));
currOffsIntoData += 4;
fprintf( vFile, "\t<filler1>%d</filler1>\n", unknownFiller );
int32_t bitmapID = ntohl(blockData.int32at( currOffsIntoData ));
currOffsIntoData += 4;
if( bitmapID != 0 )
fprintf( vFile, "\t<bitmap>BMAP_%u.pbm</bitmap>\n", bitmapID );
int16_t flags = ntohs(blockData.int16at( currOffsIntoData ));
currOffsIntoData += 2;
fprintf( vFile, "\t<cantDelete> %s </cantDelete>\n", (flags & (1 << 14)) ? "<true />" : "<false />" );
fprintf( vFile, "\t<showPict> %s </showPict>\n", (flags & (1 << 13)) ? "<false />" : "<true />" ); // showPict is stored reversed.
fprintf( vFile, "\t<dontSearch> %s </dontSearch>\n", (flags & (1 << 11)) ? "<true />" : "<false />" );
currOffsIntoData += 14; // Unknown data.
int32_t owner = -1;
if( isCard )
{
owner = ntohl(blockData.int32at( currOffsIntoData ));
fprintf( vFile, "\t<owner>%d</owner>\n", owner );
currOffsIntoData += 4;
if( inFlags & 16 )
fprintf( vFile, "\t<marked><true /></marked>\n" );
}
fprintf( vFile, "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />\n", mStyleSheetName.c_str() );
int16_t numParts = ntohs(blockData.int16at( currOffsIntoData ));
currOffsIntoData += 2;
currOffsIntoData += 6; // Unknown filler.
int16_t numContents = ntohs(blockData.int16at( currOffsIntoData ));
currOffsIntoData += 2;
currOffsIntoData += 4; // Unknown filler.
std::vector<int32_t> buttonIDs;
for( int n = 0; n < numParts; n++ )
{
int16_t partLength = ntohs(blockData.int16at( currOffsIntoData ));
fprintf( vFile, "\t<part>\n" );
int16_t partID = ntohs(blockData.int16at( currOffsIntoData +2 ));
fprintf( vFile, "\t\t<id>%d</id>\n", partID );
int16_t flagsAndType = ntohs(blockData.int16at( currOffsIntoData +4 ));
int16_t partType = flagsAndType >> 8;
bool isButton = partType == 1;
fprintf( vFile, "\t\t<type>%s</type>\n", isButton ? "button" : "field" );
if( isButton && !isCard )
buttonIDs.push_back( partID );
fprintf( vFile, "\t\t<visible> %s </visible>\n", (flagsAndType & (1 << 7)) ? "<false />" : "<true />" ); // Really "hidden" flag.
if( !isButton )
fprintf( vFile, "\t\t<dontWrap> %s </dontWrap>\n", (flagsAndType & (1 << 5)) ? "<true />" : "<false />" );
else
fprintf( vFile, "\t\t<reserved5> %d </reserved5>\n", (flagsAndType & (1 << 5)) >> 5 );
if( !isButton )
fprintf( vFile, "\t\t<dontSearch> %s </dontSearch>\n", (flagsAndType & (1 << 4)) ? "<true />" : "<false />" );
else
fprintf( vFile, "\t\t<reserved4> %d </reserved4>\n", (flagsAndType & (1 << 4)) >> 4 );
if( !isButton )
fprintf( vFile, "\t\t<sharedText> %s </sharedText>\n", (flagsAndType & (1 << 3)) ? "<true />" : "<false />" );
else
fprintf( vFile, "\t\t<reserved3> %d </reserved3>\n", (flagsAndType & (1 << 3)) >> 3 );
if( !isButton )
fprintf( vFile, "\t\t<fixedLineHeight> %s </fixedLineHeight>\n", (flagsAndType & (1 << 2)) ? "<false />" : "<true />" ); // Really "use real line height" flag.
else
fprintf( vFile, "\t\t<reserved2> %d </reserved2>\n", (flagsAndType & (1 << 2)) >> 2 );
if( !isButton )
fprintf( vFile, "\t\t<autoTab> %s </autoTab>\n", (flagsAndType & (1 << 1)) ? "<true />" : "<false />" );
else
fprintf( vFile, "\t\t<reserved1> %d </reserved1>\n", (flagsAndType & (1 << 1)) >> 1 );
if( isButton )
fprintf( vFile, "\t\t<enabled> %s </enabled>\n", (flagsAndType & (1 << 0)) ? "<false />" : "<true />" ); // Same as lockText on fields. Really "disabled" flag.
else
fprintf( vFile, "\t\t<lockText> %s </lockText>\n", (flagsAndType & (1 << 0)) ? "<true />" : "<false />" ); // Same as enabled on buttons.
fprintf( vFile, "\t\t<rect>\n\t\t\t<left>%d</left>\n\t\t\t<top>%d</top>\n\t\t\t<right>%d</right>\n\t\t\t<bottom>%d</bottom>\n\t\t</rect>\n",
ntohs(blockData.int16at( currOffsIntoData +8 )),
ntohs(blockData.int16at( currOffsIntoData +6 )),
ntohs(blockData.int16at( currOffsIntoData +12 )),
ntohs(blockData.int16at( currOffsIntoData +10 )) );
int16_t moreFlags = ntohs(blockData.int16at( currOffsIntoData +14 ));
int8_t styleFromLowNibble = moreFlags & 15;
const char* styleStr = "unknown";
if( isButton )
{
switch( styleFromLowNibble )
{
case 0:
styleStr = "transparent";
break;
case 1:
styleStr = "opaque";
break;
case 2:
styleStr = "rectangle";
break;
case 3:
styleStr = "roundrect";
break;
case 4:
styleStr = "shadow";
break;
case 5:
styleStr = "checkbox";
break;
case 6:
styleStr = "radiobutton";
break;
case 8:
styleStr = "standard";
break;
case 9:
styleStr = "default";
break;
case 10:
styleStr = "oval";
break;
case 11:
styleStr = "popup";
break;
}
}
else
{
switch( styleFromLowNibble )
{
case 0:
styleStr = "transparent";
break;
case 1:
styleStr = "opaque";
break;
case 2:
styleStr = "rectangle";
break;
case 4:
styleStr = "shadow";
break;
case 7:
styleStr = "scrolling";
break;
}
}
fprintf( vFile, "\t\t<style>%s</style>\n", styleStr );
moreFlags = moreFlags >> 8;
int8_t family = moreFlags & 15;
if( isButton )
fprintf( vFile, "\t\t<showName> %s </showName>\n", (moreFlags & (1 << 7)) ? "<true />" : "<false />" );
else
fprintf( vFile, "\t\t<autoSelect> %s </autoSelect>\n", (moreFlags & (1 << 7)) ? "<true />" : "<false />" );
if( isButton )
fprintf( vFile, "\t\t<highlight> %s </highlight>\n", (moreFlags & (1 << 6)) ? "<true />" : "<false />" );
else
fprintf( vFile, "\t\t<showLines> %s </showLines>\n", (moreFlags & (1 << 6)) ? "<true />" : "<false />" );
if( !isButton )
fprintf( vFile, "\t\t<wideMargins> %s </wideMargins>\n", (moreFlags & (1 << 5)) ? "<true />" : "<false />" );
else
fprintf( vFile, "\t\t<autoHighlight> %s </autoHighlight>\n", (moreFlags & (1 << 5) || family != 0) ? "<true />" : "<false />" );
if( isButton )
fprintf( vFile, "\t\t<sharedHighlight> %s </sharedHighlight>\n", (moreFlags & (1 << 4)) ? "<false />" : "<true />" );
else
fprintf( vFile, "\t\t<multipleLines> %s </multipleLines>\n", (moreFlags & (1 << 4)) ? "<true />" : "<false />" );
if( isButton )
fprintf( vFile, "\t\t<family>%d</family>\n", family );
else
fprintf( vFile, "\t\t<reservedFamily> %d </reservedFamily>\n", family );
// titleWidth & iconID are list fields' lastSelectedLine and firstSelectedLine
// We generate a list containing each selected line so users of the file
// format can add multiple selection easily.
int16_t titleWidth = ntohs(blockData.int16at( currOffsIntoData +16 ));
int16_t iconID = ntohs(blockData.int16at( currOffsIntoData +18 ));
if( !isButton && iconID > 0 )
{
if( titleWidth <= 0 )
titleWidth = iconID;
fprintf( vFile, "\t\t<selectedLines>\n" );
for( int d = iconID; d <= titleWidth; d++ )
fprintf( vFile, "\t\t\t<integer>%d</integer>\n", d );
fprintf( vFile, "\t\t</selectedLines>\n" );
}
else if( isButton && styleFromLowNibble == 11 ) // Popup buttons use icon ID for selected line:
{
fprintf( vFile, "\t\t<titleWidth>%d</titleWidth>\n", titleWidth );
if( iconID != 0 )
{
fprintf( vFile, "\t\t<selectedLines>\n" );
fprintf( vFile, "\t\t\t<integer>%d</integer>\n", iconID );
fprintf( vFile, "\t\t</selectedLines>\n" );
}
}
else
{
fprintf( vFile, "\t\t<titleWidth>%d</titleWidth>\n", titleWidth );
fprintf( vFile, "\t\t<icon>%d</icon>\n", iconID );
}
int16_t textAlign = ntohs(blockData.int16at( currOffsIntoData +20 ));
const char* textAlignStr = "unknown";
switch( textAlign )
{
case 0:
textAlignStr = "left";
break;
case 1:
textAlignStr = "center";
break;
case -1:
textAlignStr = "right";
break;
case -2:
textAlignStr = "forceLeft";
break;
}
fprintf( vFile, "\t\t<textAlign>%s</textAlign>\n", textAlignStr );
int16_t textFontID = ntohs(blockData.int16at( currOffsIntoData +22 ));
fprintf( vFile, "\t\t<font>%s</font>\n", mFontTable[textFontID].c_str() );
int16_t textSize = ntohs(blockData.int16at( currOffsIntoData +24 ));
fprintf( vFile, "\t\t<textSize>%d</textSize>\n", textSize );
int16_t textStyleFlags = ntohs(blockData.int16at( currOffsIntoData +26 ));
if( textStyleFlags & (1 << 15) )
fprintf( vFile, "\t\t<textStyle>group</textStyle>\n" );
if( textStyleFlags & (1 << 14) )
fprintf( vFile, "\t\t<textStyle>extend</textStyle>\n" );
if( textStyleFlags & (1 << 13) )
fprintf( vFile, "\t\t<textStyle>condense</textStyle>\n" );
if( textStyleFlags & (1 << 12) )
fprintf( vFile, "\t\t<textStyle>shadow</textStyle>\n" );
if( textStyleFlags & (1 << 11) )
fprintf( vFile, "\t\t<textStyle>outline</textStyle>\n" );
if( textStyleFlags & (1 << 10) )
fprintf( vFile, "\t\t<textStyle>underline</textStyle>\n" );
if( textStyleFlags & (1 << 9) )
fprintf( vFile, "\t\t<textStyle>italic</textStyle>\n" );
if( textStyleFlags & (1 << 8) )
fprintf( vFile, "\t\t<textStyle>bold</textStyle>\n" );
if( textStyleFlags == 0 )
fprintf( vFile, "\t\t<textStyle>plain</textStyle>\n" );
int16_t textHeight = ntohs(blockData.int16at( currOffsIntoData +28 ));
if( !isButton )
fprintf( vFile, "\t\t<textHeight>%d</textHeight>\n", textHeight );
int x = 0, startOffs = currOffsIntoData +30;
fprintf( vFile, "\t\t<name>" );
for( x = startOffs; blockData[x] != 0; x++ )
{
char currCh = blockData[x];
if( currCh == '<' )
fprintf( vFile, "<" );
else if( currCh == '>' )
fprintf( vFile, ">" );
else if( currCh == '&' )
fprintf( vFile, "&" );
else
fprintf( vFile, "%s", UniCharFromMacRoman(currCh) );
}
fprintf( vFile, "</name>\n" );
startOffs = x +2;
fprintf( vFile, "\t\t<script>" );
for( x = startOffs; blockData[x] != 0; x++ )
{
char currCh = blockData[x];
if( currCh == '<' )
fprintf( vFile, "<" );
else if( currCh == '>' )
fprintf( vFile, ">" );
else if( currCh == '&' )
fprintf( vFile, "&" );
else
fprintf( vFile, "%s", UniCharFromMacRoman(currCh) );
}
fprintf( vFile, "</script>\n" );
fprintf( vFile, "\t</part>\n" );
currOffsIntoData += partLength;
currOffsIntoData += (currOffsIntoData % 2); // Align on even byte.
}
if( !isCard )
mButtonIDsPerBg[blockID] = buttonIDs;
for( int n = 0; n < numContents; n++ )
{
/*
Contents are a complicated thing. Essentially, they're a storage for card-specific data
used by background objects, though for simplicity, card parts also use contents to store
that same data. There are a few specialties, though:
If the contents of a button start with a number > 32767, the number -32768 is the legth
of style data (including this length information) at the start of the content text, and
the actual text follows afterwards.
Button contents can only be the same for all cards on a background. However, if there is
a contents entry for a background button on a card, it contains a "1" as plain text if
the button is highlighted and sharedHighlight is FALSE.
*/
int16_t partID = ntohs(blockData.int16at( currOffsIntoData ));
int16_t partLength = ntohs(blockData.int16at( currOffsIntoData +2 ));
bool isBgButtonContents = false;
fprintf( vFile, "\t<content>\n" );
CBuf theText, theStyles;
if( partID < 0 ) // It's a card part's contents:
{
partID = -partID;
fprintf( vFile, "\t\t<layer>card</layer>\n" );
fprintf( vFile, "\t\t<id>%d</id>\n", partID );
uint16_t stylesLength = ntohs(blockData.uint16at( currOffsIntoData +4 ));
if( stylesLength > 32767 )
{
stylesLength = stylesLength -32768;
theStyles.resize( stylesLength -2 );
theStyles.memcpy( 0, blockData, currOffsIntoData +6, stylesLength -2 );
}
else
stylesLength = 0;
theText.resize( partLength -stylesLength +1 );
theText.memcpy( 0, blockData, currOffsIntoData +4 +stylesLength, partLength -stylesLength );
theText[theText.size()-1] = 0;
//theText.debug_print();
}
else // It's a bg part's contents:
{
if( blockID == 9428 && partID == 20 )
printf("\n"); // Help debug missing characters in Power Tools.
fprintf( vFile, "\t\t<layer>background</layer>\n" );
fprintf( vFile, "\t\t<id>%d</id>\n", partID );
uint16_t stylesLength = ntohs(blockData.uint16at( currOffsIntoData +4 ));
if( stylesLength > 32767 )
{
stylesLength = stylesLength -32768;
theStyles.resize( stylesLength -2 );
theStyles.memcpy( 0, blockData, currOffsIntoData +6, stylesLength -2 );
}
else
stylesLength = 0;
theText.resize( partLength -stylesLength +1 );
theText.memcpy( 0, blockData, currOffsIntoData +4 +stylesLength,
partLength -stylesLength );
theText[theText.size()-1] = 0;
//theText.debug_print();
if( owner != -1 )
{
std::vector<int32_t>& buttonIDs = mButtonIDsPerBg[owner];
for( size_t x = 0; x < buttonIDs.size(); x++ )
{
if( buttonIDs[x] == partID )
{
isBgButtonContents = true;
break;
}
}
}
}
if( !isBgButtonContents ) // Bg buttons have no per-card contents in HC.
{
std::vector<CStyleRun> styleRuns;
if( theStyles.size() > 0 )
{
for( size_t x = 0; x < theStyles.size(); )
{
int16_t startOffset = ntohs(theStyles.int16at( x ));
x += sizeof(int16_t);
int16_t styleID = ntohs(theStyles.int16at( x ));
x += sizeof(int16_t);
styleRuns.push_back( (CStyleRun){ startOffset, styleID } );
}
}
int16_t currStyleID = -1;
size_t currOffset = 1;
fprintf( vFile, "\t\t<text>" );
size_t numChars = theText.size();
bool currentlyGroup = false;
for( auto currRun : styleRuns )
{
if( currOffset < currRun.startOffset ) // Characters before this style run?
{ // Write them all out.
for( ; currOffset < currRun.startOffset; currOffset++ )
{
char currCh = theText[currOffset];
if( currCh == '<' )
fprintf( vFile, "<" );
else if( currCh == '>' )
fprintf( vFile, ">" );
else if( currCh == '&' )
fprintf( vFile, "&" );
else
fprintf( vFile, "%s", UniCharFromMacRoman(currCh) );
}
}
if( currentlyGroup )
{
fprintf( vFile, "</a>" );
currentlyGroup = false;
}
if( currStyleID >= 0 ) // If this isn't our first style run, close previous run:
fprintf( vFile, "</span>" );
currStyleID = currRun.styleID;
fprintf( vFile, "<span class=\"style%d\">", currStyleID );
if( mStyles[currStyleID].mGroup )
{
fprintf( vFile, "<a href=\"#\" class=\"group\">" );
currentlyGroup = true;
}
}
for( ; currOffset < numChars; currOffset++ )
{
char currCh = theText[currOffset];
if( currCh == '<' )
fprintf( vFile, "<" );
else if( currCh == '>' )
fprintf( vFile, ">" );
else if( currCh == '&' )
fprintf( vFile, "&" );
else
fprintf( vFile, "%s", UniCharFromMacRoman(currCh) );
}
if( currentlyGroup )
{
fprintf( vFile, "</a>" );
currentlyGroup = false;
}
if( currStyleID >= 0 ) // If we had any style runs before this text, close it now:
fprintf( vFile, "</span>" );
fprintf( vFile, "</text>\n" );
}
else // Bg button? May have highlight on the card:
{
if( theText.size() == 3 && theText[0] == 0 && theText[1] == '1' && theText[2] == 0 ) // If "shared Highlight" is FALSE, a button's highlight is stored as the content string "1".
fprintf( vFile, "\t\t<highlight> <true /> </highlight>\n" );
}
currOffsIntoData += partLength +4 +(partLength % 2); // Align on even byte.
fprintf( vFile, "\t</content>\n" );
}
int x = 0, startOffs = currOffsIntoData;
fprintf( vFile, "\t<name>" );
for( x = startOffs; blockData[x] != 0; x++ )
{
char currCh = blockData[x];
if( currCh == '<' )
fprintf( vFile, "<" );
else if( currCh == '>' )
fprintf( vFile, ">" );
else if( currCh == '&' )
fprintf( vFile, "&" );
else
fprintf( vFile, "%s", UniCharFromMacRoman(currCh) );
}
fprintf( vFile, "</name>\n" );
if( !isCard )
fprintf( mStackXmlFile, "\t<background id=\"%d\" file=\"%s\" name=\"", blockID, vFileName +1 );
else
fprintf( mStackXmlFile, "\t<card id=\"%d\" file=\"%s\" marked=\"%s\" name=\"", blockID, vFileName +1, ((inFlags & 16) ? "true" : "false") );
for( x = startOffs; blockData[x] != 0; x++ )
{
char currCh = blockData[x];
if( currCh == '"' )
fprintf( mStackXmlFile, "%%22" );
else if( currCh == '\n' )
fprintf( mStackXmlFile, "%%0A;" );
else if( currCh == '\r' )
fprintf( mStackXmlFile, "%%0D" );
else
fprintf( mStackXmlFile, "%s", UniCharFromMacRoman(currCh) );
}
fprintf( mStackXmlFile, "\" " );
if( isCard )
fprintf( mStackXmlFile, "owner=\"%d\" ", owner );
fprintf( mStackXmlFile, "/>\n" );
startOffs = x +1;
fprintf( vFile, "\t<script>" );
for( x = startOffs; blockData[x] != 0; x++ )
{
char currCh = blockData[x];
if( currCh == '<' )
fprintf( vFile, "<" );
else if( currCh == '>' )
fprintf( vFile, ">" );
else if( currCh == '&' )
fprintf( vFile, "&" );
else
fprintf( vFile, "%s", UniCharFromMacRoman(currCh) );
}
fprintf( vFile, "</script>\n" );
if( mProgressMessages )
fprintf( stdout, "Progress: %d of %d\n", ++mCurrentProgress, mMaxProgress );
// Read AddColor data:
#if MAC_CODE
OSType theType = (!isCard) ? 'HCbg' : 'HCcd';
Handle currIcon = Get1Resource( theType, blockID );
if( currIcon && GetHandleSize(currIcon) <= 0 )
fprintf( stdout, "Progress: %d of %d\n", ++mCurrentProgress, mMaxProgress );
else if( currIcon && GetHandleSize(currIcon) > 0 )
{
if( mStatusMessages )
fprintf( stdout, "Status: Converting AddColor '%s' %d.\n", ((theType == 'HCbg') ? "HCbg" : "HCcd"), blockID );
size_t dataLen = GetHandleSize( currIcon );
CBuf theData( dataLen );
theData.memcpy( 0, *currIcon, 0, dataLen );
size_t currOffs = 0;
while( currOffs < dataLen )
{
fprintf( vFile, "\t<addcolorobject>\n" );
int8_t currType = theData[currOffs];
bool vHidden = currType & (1 << 7);
currType &= ~(1 << 7);
currOffs += 1;
switch( currType )
{
case 0x01: // Button
{
fprintf( vFile, "\t\t<type>button</type>\n" );
int16_t buttonID = 0, bevelDepth = 0;
uint16_t r = 0, g = 0, b = 0;
buttonID = ntohs(theData.int16at( currOffs ));
currOffs += 2;
fprintf( vFile, "\t\t<id>%d</id>\n", buttonID );
bevelDepth = ntohs(theData.int16at( currOffs ));
currOffs += 2;
fprintf( vFile, "\t\t<bevel>%d</bevel>\n", bevelDepth );
fprintf( vFile, "\t\t<color>\n" );
r = ntohs(theData.uint16at( currOffs ));
currOffs += 2;
fprintf( vFile, "\t\t\t<red>%d</red>\n", r );
g = ntohs(theData.uint16at( currOffs ));
currOffs += 2;
fprintf( vFile, "\t\t\t<green>%d</green>\n", g );
b = ntohs(theData.uint16at( currOffs ));
currOffs += 2;
fprintf( vFile, "\t\t\t<blue>%d</blue>\n", b );
fprintf( vFile, "\t\t</color>\n" );
break;
}
case 0x02: // Field
{
fprintf( vFile, "\t\t<type>field</type>\n" );
int16_t buttonID = 0, bevelDepth = 0;
uint16_t r = 0, g = 0, b = 0;
buttonID = ntohs(theData.int16at( currOffs ));
currOffs += 2;