… | |
… | |
6 | my $exec_prefix = "@exec_prefix@"; |
6 | my $exec_prefix = "@exec_prefix@"; |
7 | my $datarootdir = "@datarootdir@"; |
7 | my $datarootdir = "@datarootdir@"; |
8 | my $DATADIR = "@datadir@/@PACKAGE@"; |
8 | my $DATADIR = "@datadir@/@PACKAGE@"; |
9 | |
9 | |
10 | my $CONVERT = "@CONVERT@"; |
10 | my $CONVERT = "@CONVERT@"; |
11 | my $IDENTIFY = "@IDENTIFY@"; |
11 | #my $IDENTIFY = "@IDENTIFY@"; |
12 | my $OPTIPNG = "@OPTIPNG@"; |
12 | my $OPTIPNG = "@OPTIPNG@"; |
13 | my $RSYNC = "@RSYNC@"; |
13 | my $RSYNC = "@RSYNC@"; |
14 | my $PNGNQ = "@PNGNQ@"; |
14 | my $PNGNQ = "@PNGNQ@"; |
15 | |
15 | |
16 | use Getopt::Long; |
16 | use Getopt::Long; |
… | |
… | |
21 | use Crossfire; |
21 | use Crossfire; |
22 | use Coro; |
22 | use Coro; |
23 | use Coro::AIO; |
23 | use Coro::AIO; |
24 | use POSIX (); |
24 | use POSIX (); |
25 | use Digest::MD5; |
25 | use Digest::MD5; |
|
|
26 | use Carp; |
26 | use Coro::Storable; $Storable::canonical = 1; |
27 | use Coro::Storable; $Storable::canonical = 1; |
|
|
28 | |
|
|
29 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
27 | |
30 | |
28 | sub usage { |
31 | sub usage { |
29 | warn <<EOF; |
32 | warn <<EOF; |
30 | Usage: cfutil [-v] [-q] [--force] [--cache] |
33 | Usage: cfutil [-v] [-q] [--force] [--cache] |
31 | [--install-arch path] |
34 | [--install-arch path] |
… | |
… | |
92 | if (!-f "$path/regions") { |
95 | if (!-f "$path/regions") { |
93 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
96 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
94 | exit 1 unless $FORCE; |
97 | exit 1 unless $FORCE; |
95 | } |
98 | } |
96 | |
99 | |
97 | system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" |
100 | system $RSYNC, "-a", "--chmod=u=rwX,go=rX", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" |
98 | and die "map installation failed.\n"; |
101 | and die "map installation failed.\n"; |
99 | |
102 | |
100 | print "maps installed successfully.\n"; |
103 | print "maps installed successfully.\n"; |
101 | } |
104 | } |
102 | |
105 | |
103 | { |
106 | { |
104 | our %ANIMINFO; |
107 | our %ANIMINFO; |
105 | our %FACEINFO; |
108 | our %FACEINFO; |
|
|
109 | our %RESOURCE; |
106 | our @ARC; |
110 | our @ARC; |
107 | our %ARC; |
111 | our %ARC; |
108 | our $TRS; |
112 | our $TRS; |
109 | our $NFILE; |
113 | our $NFILE; |
|
|
114 | our $PATH; |
110 | |
115 | |
111 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
116 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
112 | |
117 | |
113 | our (@png, @trs, @arc); # files we are interested in |
118 | our (@png, @trs, @arc, @res); # files we are interested in |
114 | |
119 | |
115 | sub commit_png($$$) { |
120 | sub commit_png($$$) { |
116 | my ($name, $data, $T) = @_; |
121 | my ($name, $data, $T) = @_; |
117 | |
122 | |
118 | $FACEINFO{$name}{"data$T"} = $data; |
123 | $FACEINFO{$name}{"data$T"} = $data; |
… | |
… | |
383 | |
388 | |
384 | $TRS .= $trs; |
389 | $TRS .= $trs; |
385 | } |
390 | } |
386 | } |
391 | } |
387 | |
392 | |
|
|
393 | sub process_res { |
|
|
394 | while (@res) { |
|
|
395 | my ($dir, $file, $type) = @{pop @res}; |
|
|
396 | |
|
|
397 | my $data; |
|
|
398 | aio_load "$dir/$file", $data; |
|
|
399 | |
|
|
400 | my $copyright; |
|
|
401 | aio_load "$dir/copyright", $copyright; |
|
|
402 | |
|
|
403 | $file =~ s/\.res$//; |
|
|
404 | $file =~ /\.([^.]+)$/ |
|
|
405 | or next; |
|
|
406 | |
|
|
407 | substr $dir, 0, 1 + length $PATH, ""; |
|
|
408 | |
|
|
409 | $RESOURCE{"$dir/$file"} = { |
|
|
410 | type => $type, |
|
|
411 | copyright => $copyright, |
|
|
412 | data => $data, |
|
|
413 | chksum => Digest::MD5::md5 $data, |
|
|
414 | }; |
|
|
415 | } |
|
|
416 | } |
|
|
417 | |
388 | sub find_files; |
418 | sub find_files; |
389 | sub find_files { |
419 | sub find_files { |
390 | my ($path) = @_; |
420 | my ($path) = @_; |
391 | |
421 | |
392 | IO::AIO::aioreq_pri 4; |
422 | IO::AIO::aioreq_pri 4; |
… | |
… | |
394 | my ($dirs, $nondirs) = @_; |
424 | my ($dirs, $nondirs) = @_; |
395 | |
425 | |
396 | find_files "$path/$_" |
426 | find_files "$path/$_" |
397 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
427 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
398 | |
428 | |
|
|
429 | my $dir = $path; |
|
|
430 | substr $dir, 0, 1 + length $PATH, ""; |
|
|
431 | |
399 | for my $file (@$nondirs) { |
432 | for my $file (@$nondirs) { |
|
|
433 | if ($dir =~ /^music(?:\/|$)/) { |
|
|
434 | push @res, [$path, $file, 3] # FT_MUSIC |
|
|
435 | if $file =~ /\.(ogg)$/; |
|
|
436 | |
|
|
437 | } elsif ($dir =~ /^sounds(?:\/|$)/) { |
|
|
438 | push @res, [$path, $file, 5] # FT_SOUND |
|
|
439 | if $file =~ /\.(wav|ogg)$/; |
|
|
440 | |
|
|
441 | } elsif ($dir =~ /^res(?:\/|$)/) { |
|
|
442 | push @res, [$path, $file, 0] # FT_FACE |
|
|
443 | if $file =~ /\.(jpg|png)$/; |
|
|
444 | push @res, [$path, $file, 7] # FT_RSRC |
|
|
445 | if $file =~ /\.(res)$/; |
|
|
446 | |
400 | if ($file =~ /\.png$/) { |
447 | } elsif ($file =~ /\.png$/) { |
401 | push @png, ["$path/$file", 0]; |
448 | push @png, ["$path/$file", 0]; |
|
|
449 | |
402 | } elsif ($file =~ /\.trs$/) { |
450 | } elsif ($file =~ /\.trs$/) { |
403 | push @trs, [$path, $file]; |
451 | push @trs, [$path, $file]; |
|
|
452 | |
404 | } elsif ($file =~ /\.arc$/) { |
453 | } elsif ($file =~ /\.arc$/) { |
405 | push @arc, [$path, $file]; |
454 | push @arc, [$path, $file]; |
|
|
455 | |
406 | } else { |
456 | } else { |
407 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
457 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
408 | } |
458 | } |
409 | } |
459 | } |
410 | }; |
460 | }; |
411 | } |
461 | } |
412 | |
462 | |
413 | sub inst_arch($) { |
463 | sub inst_arch($) { |
414 | my (undef, $path) = @_; |
464 | my (undef, $path) = @_; |
|
|
465 | |
|
|
466 | $PATH = $path; |
415 | |
467 | |
416 | print "\n", |
468 | print "\n", |
417 | "Installing '$path' to '$DATADIR'\n", |
469 | "Installing '$path' to '$DATADIR'\n", |
418 | "\n", |
470 | "\n", |
419 | "This can take a long time if you run this\n", |
471 | "This can take a long time if you run this\n", |
… | |
… | |
434 | $_->join for ( |
486 | $_->join for ( |
435 | # four png crunchers work fine for my 2x smp machine |
487 | # four png crunchers work fine for my 2x smp machine |
436 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
488 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
437 | (async \&process_trs), (async \&process_trs), |
489 | (async \&process_trs), (async \&process_trs), |
438 | (async \&process_arc), (async \&process_arc), |
490 | (async \&process_arc), (async \&process_arc), |
|
|
491 | (async \&process_res), (async \&process_res), |
439 | ); |
492 | ); |
440 | |
493 | |
441 | { |
494 | { |
442 | # remove path prefix from editor_folder |
495 | # remove path prefix from editor_folder |
443 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
496 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
… | |
… | |
511 | |
564 | |
512 | print $fh freeze { |
565 | print $fh freeze { |
513 | version => 2, |
566 | version => 2, |
514 | faceinfo => \%FACEINFO, |
567 | faceinfo => \%FACEINFO, |
515 | animinfo => \%ANIMINFO, |
568 | animinfo => \%ANIMINFO, |
|
|
569 | resource => \%RESOURCE, |
516 | }; |
570 | }; |
517 | } |
571 | } |
518 | |
572 | |
519 | for (qw(archetypes facedata treasures)) { |
573 | for (qw(archetypes facedata treasures)) { |
520 | chmod 0644, "$DATADIR/$_~"; |
574 | chmod 0644, "$DATADIR/$_~"; |