Debian Codegraph @

tools/macosx/fixbundle.c

raw
1 /* ______ ___ ___
2 * /\ _ \ /\_ \ /\_ \
3 * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
5 * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
6 * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7 * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8 * /\____/
9 * \_/__/
10 *
11 * MacOS X application bundle fixer utility. Creates an application
12 * bundle out of an executable and some optional icon image files.
13 *
14 * By Angelo Mottola.
15 *
16 * See readme.txt for copyright information.
17 */
18
19 #define ALLEGRO_USE_CONSOLE
20
21 #include <stdio.h>
22 #include <string.h>
23 #include <allegro5.h>
24 #include <math.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27
28 #undef TRUE
29 #undef FALSE
30
31 #ifndef SCAN_DEPEND
32 #include <Carbon/Carbon.h>
33 #endif
34
35 #undef TRUE
36 #undef FALSE
37 #define TRUE -1
38 #define FALSE 0
39
40 /* 16x16 */
41 #define ICON_SMALL 0
42 /* 32x32 */
43 #define ICON_LARGE 1
44 /* 48x48 */
45 #define ICON_HUGE 2
46 /* 128x128 */
47 #define ICON_THUMBNAIL 3
48
49
50 #define F_SMALL_DEFINED 0x1
51 #define F_LARGE_DEFINED 0x2
52 #define F_HUGE_DEFINED 0x4
53 #define F_THUMBNAIL_DEFINED 0x8
54 #define F_ICONS_DEFINED 0xf
55 #define F_MOVE 0x10
56 #define F_GOT_VERSION 0x20
57 #define F_GOT_LONG_VERSION 0x40
58 #define F_EMBED_FRAMEWORK 0x80
59
60 #define MAX_STRING_SIZE 1024
61 #define ONE_SIXTH (1.0 / 6.0)
62
63
64 typedef struct ICON_DATA
65 {
66 BITMAP *original, *workspace, *scaled;
67 int size;
68 OSType data, mask8, mask1;
69 int defined;
70 } ICON_DATA;
71
72
73 static ICON_DATA icon_data[4] = {
74 { NULL, NULL, NULL, 16, kSmall32BitData, kSmall8BitMask, kSmall1BitMask, F_SMALL_DEFINED },
75 { NULL, NULL, NULL, 32, kLarge32BitData, kLarge8BitMask, kLarge1BitMask, F_LARGE_DEFINED },
76 { NULL, NULL, NULL, 48, kHuge32BitData, kHuge8BitMask, kHuge1BitMask, F_HUGE_DEFINED },
77 { NULL, NULL, NULL, 128, kThumbnail32BitData, kThumbnail8BitMask, 0, F_THUMBNAIL_DEFINED }
78 };
79 static int flags = 0;
80
81
82
83 static float cubic_bspline(float x)
84 {
85 float a, b, c, d;
86
87 if (x <= -2.0)
88 a = 0.0;
89 else
90 a = (x + 2.0) * (x + 2.0) * (x + 2.0);
91
92 if (x <= -1.0)
93 b = 0.0;
94 else
95 b = ((x + 1.0) * (x + 1.0) * (x + 1.0)) * -4.0;
96
97 if (x <= 0)
98 c = 0.0;
99 else
100 c = (x * x * x) * 6.0;
101
102 if (x <= 1.0)
103 d = 0.0;
104 else
105 d = ((x - 1.0) * (x - 1.0) * (x - 1.0)) * -4.0;
106
107 return (a + b + c + d) * ONE_SIXTH;
108 }
109
110
111
112 static int scale_icon(ICON_DATA *icon)
113 {
114 BITMAP *shape;
115 int size, x_ofs = 2, y_ofs = 2;
116 int x, y, m, n;
117 int i_x, i_y;
118 float k, f_x, f_y, a, b, r1, r2;
119 float red, green, blue, alpha;
120 unsigned char *p;
121 unsigned int color;
122
123 if (icon->original->w > icon->original->h) {
124 size = 4 + icon->original->w;
125 y_ofs = 2 + ((icon->original->w - icon->original->h) / 2);
126 }
127 else {
128 size = 4 + icon->original->h;
129 x_ofs = 2 + ((icon->original->h - icon->original->w) / 2);
130 }
131 k = (float)(size - 4) / (float)icon->size;
132 icon->workspace = create_bitmap_ex(32, size, size);
133 if (!icon->workspace)
134 return -1;
135 icon->scaled = create_bitmap_ex(32, icon->size, icon->size);
136 if (!icon->scaled)
137 return -1;
138 shape = create_bitmap_ex(32, icon->original->w, icon->original->h);
139 if (!shape)
140 return -1;
141 blit(icon->original, shape, 0, 0, 0, 0, icon->original->w, icon->original->h);
142 clear_to_color(icon->workspace, makeacol32(0, 0, 0, 255));
143 shape->vtable->mask_color = makeacol32(255, 0, 255, 0);
144 masked_blit(shape, icon->workspace, 0, 0, x_ofs, y_ofs, shape->w, shape->h);
145 destroy_bitmap(shape);
146
147 for (y = 0; y < icon->size; y++) {
148 f_y = (float)y * k;
149 i_y = (int)floor(f_y);
150 a = f_y - floor(f_y);
151 for (x = 0; x < icon->size; x++) {
152 f_x = (float)x * k;
153 i_x = (int)floor(f_x);
154 b = f_x - floor(f_x);
155 red = green = blue = alpha = 0.0;
156 for (m = -1; m < 3; m++) {
157 r1 = cubic_bspline((float)m - a);
158 for (n = -1; n < 3; n++) {
159 r2 = cubic_bspline(b - (float)n);
160 color = ((unsigned int *)(icon->workspace->line[i_y + m + 2]))[i_x + n + 2];
161 red += ((float)getr32(color) * r1 * r2);
162 green += ((float)getg32(color) * r1 * r2);
163 blue += ((float)getb32(color) * r1 * r2);
164 alpha += ((float)geta32(color) * r1 * r2);
165 }
166 }
167 color = makeacol32((int)floor(red), (int)floor(green), (int)floor(blue), 255 - (int)floor(alpha));
168 ((unsigned int *)(icon->scaled->line[y]))[x] = color;
169 }
170 }
171
172 return 0;
173 }
174
175
176
177 static int load_resource(char *datafile, char *name, ICON_DATA *icon)
178 {
179 DATAFILE *data;
180 BITMAP *temp, *bitmap = NULL;
181 RLE_SPRITE *rle_sprite;
182 PALETTE palette;
183 int size, type, i;
184 int result = 0;
185
186 if (datafile[0] != '\0') {
187 data = load_datafile_object(datafile, name);
188 if (!data) {
189 fprintf(stderr, "Error loading object '%s' from %s\n", name, datafile);
190 return -1;
191 }
192 switch (data->type) {
193
194 case DAT_BITMAP:
195 temp = (BITMAP *)data->dat;
196 bitmap = create_bitmap_ex(temp->vtable->color_depth, temp->w, temp->h);
197 blit(temp, bitmap, 0, 0, 0, 0, temp->w, temp->h);
198 break;
199
200 case DAT_RLE_SPRITE:
201 rle_sprite = (RLE_SPRITE *)data->dat;
202 bitmap = create_bitmap_ex(rle_sprite->color_depth, rle_sprite->w, rle_sprite->h);
203 clear_to_color(bitmap, bitmap->vtable->mask_color);
204 draw_rle_sprite(bitmap, rle_sprite, 0, 0);
205 break;
206
207 case DAT_PALETTE:
208 select_palette((RGB *)data->dat);
209 unload_datafile_object(data);
210 return 0;
211
212 default:
213 fprintf(stderr, "'%s' is not a BITMAP, RLE_SPRITE or PALETTE object in datafile '%s'\n", name, datafile);
214 unload_datafile_object(data);
215 return -1;
216 }
217 unload_datafile_object(data);
218 }
219 else {
220 bitmap = load_bitmap(name, palette);
221 select_palette(palette);
222 if (!bitmap) {
223 fprintf(stderr, "Unable to load '%s'\n", name);
224 return -1;
225 }
226 }
227
228 if (!icon) {
229 size = MAX(bitmap->w, bitmap->h);
230 if (size <= 16)
231 type = ICON_SMALL;
232 else if (size <= 32)
233 type = ICON_LARGE;
234 else if (size <= 48)
235 type = ICON_HUGE;
236 else
237 type = ICON_THUMBNAIL;
238 icon = &icon_data[type];
239 if (flags & icon->defined) {
240 for (i = 0; i < 3; i++) {
241 type = (type + 1) % 4;
242 icon = &icon_data[type];
243 if (!(flags & icon->defined))
244 break;
245 }
246 if (flags & icon->defined) {
247 fprintf(stderr, "Too many icon resources!");
248 result = -1;
249 goto exit_error;
250 }
251 }
252 }
253 else {
254 if (icon->scaled) {
255 fprintf(stderr, "Multiple icon resources of the same size");
256 result = -1;
257 goto exit_error;
258 }
259 }
260 icon->original = create_bitmap_ex(bitmap->vtable->color_depth, bitmap->w, bitmap->h);
261 blit(bitmap, icon->original, 0, 0, 0, 0, bitmap->w, bitmap->h);
262 result = scale_icon(icon);
263 flags |= icon->defined;
264
265 exit_error:
266 destroy_bitmap(bitmap);
267
268 return result;
269 }
270
271
272
273 static void usage(void)
274 {
275 fprintf(stderr, "\nMacOS X application bundle fixer utility for Allegro " ALLEGRO_VERSION_STR "\n"
276 "By Angelo Mottola, " ALLEGRO_DATE_STR "\n\n"
277 "Usage: fixbundle exename [-m] [-o bundlename] [-v version] [-V long_version]\n"
278 "\t\t[-e] [[-d datafile] [[palette] [-{16,32,48,128}] icon] ...]\n"
279 "\twhere icon is either a datafile bitmap or a RLE sprite object, either\n"
280 "\tan image file.\n"
281 "Options:\n"
282 "\t-m\t\tMoves executable inside bundle instead of copying it\n"
283 "\t-o bundlename\tSpecifies a bundle name (default: exename.app)\n"
284 "\t-v version\tSets application version string (default: 1.0)\n"
285 "\t-V long_version\tSets long application version string\n"
286 "\t-e\t\tEmbeds the Allegro framework into the application bundle\n"
287 "\t-d datafile\tUses datafile as source for objects and palettes\n"
288 "\t-{16,32,48,128}\tForces next icon image into the 16x16, 32x32, 48x48 or\n"
289 "\t\t\t128x128 icon resource slot\n"
290 "\n");
291 exit(EXIT_FAILURE);
292 }
293
294
295
296 static int copy_file(const char *filename, const char *dest_path)
297 {
298 char *buffer = NULL;
299 char dest_file[1024];
300 PACKFILE *f;
301 size_t size;
302
303 if (!exists(filename))
304 return -1;
305 buffer = malloc(size = file_size_ex(filename));
306 if (!buffer)
307 return -1;
308 append_filename(dest_file, dest_path, get_filename(filename), 1024);
309 f = pack_fopen(filename, F_READ);
310 if (!f) {
311 free(buffer);
312 return -1;
313 }
314 pack_fread(buffer, size, f);
315 pack_fclose(f);
316 f = pack_fopen(dest_file, F_WRITE);
317 if (!f) {
318 free(buffer);
319 return -1;
320 }
321 pack_fwrite(buffer, size, f);
322 pack_fclose(f);
323 free(buffer);
324
325 return 0;
326 }
327
328
329
330 /* main:
331 * Guess what this function does.
332 */
333 int main(int argc, char *argv[])
334 {
335 PACKFILE *f;
336 CFURLRef cf_url_ref;
337 FSRef fs_ref;
338 FSSpec fs_spec;
339 IconFamilyHandle icon_family;
340 Handle raw_data;
341 char datafile[MAX_STRING_SIZE];
342 char bundle[MAX_STRING_SIZE];
343 char bundle_dir[MAX_STRING_SIZE];
344 char bundle_contents_dir[MAX_STRING_SIZE];
345 char bundle_contents_resources_dir[MAX_STRING_SIZE];
346 char bundle_contents_macos_dir[MAX_STRING_SIZE];
347 char bundle_contents_frameworks_dir[MAX_STRING_SIZE];
348 char *bundle_exe = NULL;
349 char bundle_plist[MAX_STRING_SIZE];
350 char bundle_pkginfo[MAX_STRING_SIZE];
351 char bundle_icns[MAX_STRING_SIZE];
352 char bundle_version[MAX_STRING_SIZE];
353 char bundle_long_version[MAX_STRING_SIZE];
354 char *buffer = NULL;
355 int arg, type = 0, result = 0;
356 int i, size, x, y, mask_bit, mask_byte;
357 unsigned char *data;
358
359 install_allegro(SYSTEM_NONE, &errno, &atexit);
360 set_color_depth(32);
361 set_color_conversion(COLORCONV_TOTAL | COLORCONV_KEEP_TRANS);
362
363 if (argc < 2)
364 usage();
365
366 datafile[0] = '\0';
367 bundle[0] = '\0';
368 select_palette(black_palette);
369
370 /* Parse command line and load any given resource */
371 for (arg = 2; arg < argc; arg++) {
372 if (!strcmp(argv[arg], "-m"))
373 flags |= F_MOVE;
374 else if (!strcmp(argv[arg], "-e"))
375 flags |= F_EMBED_FRAMEWORK;
376 else if (!strcmp(argv[arg], "-o")) {
377 if ((argc < arg + 2) || (bundle[0] != '\0'))
378 usage();
379 strcpy(bundle, argv[++arg]);
380 }
381 else if (!strcmp(argv[arg], "-v")) {
382 if (argc < arg + 2)
383 usage();
384 flags |= F_GOT_VERSION;
385 strcpy(bundle_version, argv[++arg]);
386 }
387 else if (!strcmp(argv[arg], "-V")) {
388 if (argc < arg + 2)
389 usage();
390 flags |= F_GOT_LONG_VERSION;
391 strcpy(bundle_long_version, argv[++arg]);
392 }
393 else if (!strcmp(argv[arg], "-d")) {
394 if (argc < arg + 2)
395 usage();
396 strcpy(datafile, argv[++arg]);
397 }
398 else if ((!strcmp(argv[arg], "-16")) || (!strcmp(argv[arg], "-32")) ||
399 (!strcmp(argv[arg], "-48")) || (!strcmp(argv[arg], "-128"))) {
400 if (argc < arg + 2)
401 usage();
402 switch (atoi(&argv[arg][1])) {
403 case 16: type = 0; break;
404 case 32: type = 1; break;
405 case 48: type = 2; break;
406 case 128: type = 3; break;
407 }
408 if (load_resource(datafile, argv[++arg], &icon_data[type])) {
409 result = -1;
410 goto exit_error;
411 }
412 }
413 else {
414 if (load_resource(datafile, argv[arg], NULL)) {
415 result = -1;
416 goto exit_error;
417 }
418 }
419 }
420
421 buffer = malloc(4096);
422 if (!buffer) {
423 result = -1;
424 goto exit_error_bundle;
425 }
426
427 bundle_exe = argv[1];
428 if (!exists(bundle_exe)) {
429 fprintf(stderr, "Cannot locate executable file '%s'\n", bundle_exe);
430 result = -1;
431 goto exit_error;
432 }
433 if (bundle[0] == '\0')
434 strcpy(bundle, bundle_exe);
435 replace_extension(bundle_dir, bundle, "app", MAX_STRING_SIZE);
436 strcpy(bundle_contents_dir, bundle_dir);
437 strcat(bundle_contents_dir, "/Contents");
438 strcpy(bundle_contents_resources_dir, bundle_contents_dir);
439 strcat(bundle_contents_resources_dir, "/Resources");
440 strcpy(bundle_contents_macos_dir, bundle_contents_dir);
441 strcat(bundle_contents_macos_dir, "/MacOS");
442 strcpy(bundle_contents_frameworks_dir, bundle_contents_dir);
443 strcat(bundle_contents_frameworks_dir, "/Frameworks");
444 bundle_icns[0] = '\0';
445 bundle_plist[0] = '\0';
446 bundle_pkginfo[0] = '\0';
447
448 /* Create bundle structure */
449 if ((mkdir(bundle_dir, 0777) && (errno != EEXIST)) ||
450 (mkdir(bundle_contents_dir, 0777) && (errno != EEXIST)) ||
451 (mkdir(bundle_contents_resources_dir, 0777) && (errno != EEXIST)) ||
452 (mkdir(bundle_contents_macos_dir, 0777) && (errno != EEXIST))) {
453 fprintf(stderr, "Cannot create %s\n", bundle_dir);
454 result = -1;
455 goto exit_error_bundle;
456 }
457
458 /* Copy/move executable into the bundle */
459 if (copy_file(bundle_exe, bundle_contents_macos_dir)) {
460 fprintf(stderr, "Cannot create %s\n", bundle_contents_macos_dir);
461 result = -1;
462 goto exit_error_bundle;
463 }
464 strcat(bundle_contents_macos_dir, "/");
465 strcat(bundle_contents_macos_dir, get_filename(bundle_exe));
466 chmod(bundle_contents_macos_dir, 0755);
467 if (flags & F_MOVE)
468 unlink(bundle_exe);
469
470 /* Embed Allegro framework if requested */
471 if (flags & F_EMBED_FRAMEWORK) {
472 if (!file_exists("/Library/Frameworks/Allegro.framework", FA_RDONLY | FA_DIREC, NULL)) {
473 fprintf(stderr, "Cannot find Allegro framework\n");
474 result = -1;
475 goto exit_error_bundle;
476 }
477 if (!exists("/Library/Frameworks/Allegro.framework/Resources/Embeddable")) {
478 fprintf(stderr, "Cannot embed system wide Allegro framework; install embeddable version first!\n");
479 result = -1;
480 goto exit_error_bundle;
481 }
482 sprintf(buffer, "/Developer/Tools/pbxcp -exclude .DS_Store -exclude CVS -resolve-src-symlinks /Library/Frameworks/Allegro.framework %s", bundle_contents_frameworks_dir);
483 if ((mkdir(bundle_contents_frameworks_dir, 0777) && (errno != EEXIST)) ||
484 (system(buffer))) {
485 fprintf(stderr, "Cannot create %s\n", bundle_contents_frameworks_dir);
486 result = -1;
487 goto exit_error_bundle;
488 }
489 }
490
491 /* Setup the .icns resource */
492 if (flags & F_ICONS_DEFINED) {
493 strcat(bundle_contents_resources_dir, "/");
494 strcat(bundle_contents_resources_dir, get_filename(bundle));
495 replace_extension(bundle_icns, bundle_contents_resources_dir, "icns", MAX_STRING_SIZE);
496
497 icon_family = (IconFamilyHandle)NewHandle(0);
498
499 for (i = 0; i < 4; i++) {
500 if (flags & icon_data[i].defined) {
501 /* Set 32bit RGBA data */
502 raw_data = NewHandle(icon_data[i].size * icon_data[i].size * 4);
503 data = *(unsigned char **)raw_data;
504 for (y = 0; y < icon_data[i].size; y++) {
505 for (x = 0; x < icon_data[i].size; x++) {
506 *data++ = geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
507 *data++ = getr32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
508 *data++ = getg32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
509 *data++ = getb32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
510 }
511 }
512 if (SetIconFamilyData(icon_family, icon_data[i].data, raw_data) != noErr) {
513 DisposeHandle(raw_data);
514 fprintf(stderr, "Error setting %dx%d icon resource RGBA data\n", icon_data[i].size, icon_data[i].size);
515 result = -1;
516 goto exit_error_bundle;
517 }
518 DisposeHandle(raw_data);
519 /* Set 8bit mask */
520 raw_data = NewHandle(icon_data[i].size * icon_data[i].size);
521 data = *(unsigned char **)raw_data;
522 for (y = 0; y < icon_data[i].size; y++) {
523 for (x = 0; x < icon_data[i].size; x++) {
524 *data++ = geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
525 }
526 }
527 if (SetIconFamilyData(icon_family, icon_data[i].mask8, raw_data) != noErr) {
528 DisposeHandle(raw_data);
529 fprintf(stderr, "Error setting %dx%d icon resource 8bit mask\n", icon_data[i].size, icon_data[i].size);
530 result = -1;
531 goto exit_error_bundle;
532 }
533 DisposeHandle(raw_data);
534 /* Set 1bit mask */
535 if (icon_data[i].mask1) {
536 size = ((icon_data[i].size * icon_data[i].size) + 7) / 8;
537 raw_data = NewHandle(size * 2);
538 data = *(unsigned char **)raw_data;
539 mask_byte = 0;
540 mask_bit = 7;
541 for (y = 0; y < icon_data[i].size; y++) {
542 for (x = 0; x < icon_data[i].size; x++) {
543 if (geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]) >= 0xfd)
544 mask_byte |= (1 << mask_bit);
545 mask_bit--;
546 if (mask_bit < 0) {
547 *data++ = mask_byte;
548 mask_byte = 0;
549 mask_bit = 7;
550 }
551 }
552 }
553 memcpy(*raw_data + size, *raw_data, size);
554 if (SetIconFamilyData(icon_family, icon_data[i].mask1, raw_data) != noErr) {
555 DisposeHandle(raw_data);
556 fprintf(stderr, "Error setting %dx%d icon resource 1bit mask\n", icon_data[i].size, icon_data[i].size);
557 result = -1;
558 goto exit_error_bundle;
559 }
560 DisposeHandle(raw_data);
561 }
562 }
563 }
564
565 f = pack_fopen(bundle_icns, F_WRITE);
566 if (!f) {
567 fprintf(stderr, "Cannot create %s\n", bundle_icns);
568 result = -1;
569 goto exit_error_bundle;
570 }
571 pack_fclose(f);
572
573 cf_url_ref = CFURLCreateWithBytes(kCFAllocatorDefault, (unsigned char *)bundle_icns, strlen(bundle_icns), 0, NULL);
574 if (!cf_url_ref) {
575 fprintf(stderr, "Cannot create %s\n", bundle_icns);
576 result = -1;
577 goto exit_error_bundle;
578 }
579 CFURLGetFSRef(cf_url_ref, &fs_ref);
580 CFRelease(cf_url_ref);
581 if ((FSGetCatalogInfo(&fs_ref, kFSCatInfoNone, NULL, NULL, &fs_spec, NULL)) ||
582 (WriteIconFile(icon_family, &fs_spec) != noErr)) {
583 fprintf(stderr, "Cannot create %s\n", bundle_icns);
584 result = -1;
585 goto exit_error_bundle;
586 }
587 DisposeHandle((Handle)icon_family);
588 }
589
590 /* Setup Info.plist */
591 sprintf(bundle_plist, "%s/Info.plist", bundle_contents_dir);
592 f = pack_fopen(bundle_plist, F_WRITE);
593 if (!f) {
594 fprintf(stderr, "Cannot create %s\n", bundle_plist);
595 result = -1;
596 goto exit_error_bundle;
597 }
598 sprintf(buffer, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
599 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
600 "<plist version=\"1.0\">\n"
601 "<dict>\n"
602 "\t<key>CFBundleExecutable</key>\n"
603 "\t<string>%s</string>\n"
604 "\t<key>CFBundleInfoDictionaryVersion</key>\n"
605 "\t<string>6.0</string>\n"
606 "\t<key>CFBundlePackageType</key>\n"
607 "\t<string>APPL</string>\n"
608 "\t<key>CFBundleSignature</key>\n"
609 "\t<string>%s</string>\n"
610 "\t<key>CFBundleVersion</key>\n"
611 "\t<string>%s</string>\n"
612 "\t<key>CFBundleDocumentTypes</key>\n"
613 "\t<array>\n"
614 "\t\t<dict>\n"
615 "\t\t\t<key>CFBundleTypeExtensions</key>\n"
616 "\t\t\t<array>\n"
617 "\t\t\t\t<string>*</string>\n"
618 "\t\t\t</array>\n"
619 "\t\t\t<key>CFBundleTypeName</key>\n"
620 "\t\t\t<string>NSStringPboardType</string>\n"
621 "\t\t\t<key>CFBundleTypeOSTypes</key>\n"
622 "\t\t\t<array>\n"
623 "\t\t\t\t<string>****</string>\n"
624 "\t\t\t</array>\n"
625 "\t\t\t<key>CFBundleTypeRole</key>\n"
626 "\t\t\t<string>Viewer</string>\n"
627 "\t\t</dict>\n"
628 "\t</array>\n",
629 get_filename(bundle_exe), "????", (flags & F_GOT_VERSION) ? bundle_version : "1.0");
630 pack_fputs(buffer, f);
631 if (flags & F_GOT_LONG_VERSION) {
632 sprintf(buffer, "\t<key>CFBundleGetInfoString</key>\n"
633 "\t<string>%s</string>\n", bundle_long_version);
634 pack_fputs(buffer, f);
635 }
636 if (flags & F_ICONS_DEFINED) {
637 sprintf(buffer, "\t<key>CFBundleIconFile</key>\n"
638 "\t<string>%s</string>\n", get_filename(bundle_icns));
639 pack_fputs(buffer, f);
640 }
641 pack_fputs("</dict>\n</plist>\n", f);
642 pack_fclose(f);
643
644 /* Setup PkgInfo */
645 sprintf(bundle_pkginfo, "%s/PkgInfo", bundle_contents_dir);
646 f = pack_fopen(bundle_pkginfo, F_WRITE);
647 if (!f) {
648 fprintf(stderr, "Cannot create %s\n", bundle_pkginfo);
649 result = -1;
650 goto exit_error_bundle;
651 }
652 pack_fputs("APPL????", f);
653 pack_fclose(f);
654
655 exit_error:
656 if (buffer)
657 free(buffer);
658 for (i = 0; i < 4; i++) {
659 if (icon_data[i].original)
660 destroy_bitmap(icon_data[i].original);
661 if (icon_data[i].workspace)
662 destroy_bitmap(icon_data[i].workspace);
663 if (icon_data[i].scaled)
664 destroy_bitmap(icon_data[i].scaled);
665 }
666 return result;
667
668 exit_error_bundle:
669 sprintf(buffer, "%s/%s", bundle_contents_macos_dir, get_filename(bundle_exe));
670 unlink(buffer);
671 unlink(bundle_plist);
672 unlink(bundle_pkginfo);
673 unlink(bundle_icns);
674 rmdir(bundle_dir);
675 rmdir(bundle_contents_dir);
676 rmdir(bundle_contents_resources_dir);
677 rmdir(bundle_contents_macos_dir);
678 goto exit_error;
679 }