… | |
… | |
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 | my %FILECACHE; |
|
|
394 | |
|
|
395 | sub load_cached($;$) { |
|
|
396 | unless (exists $FILECACHE{$_[0]}) { |
|
|
397 | my $data; |
|
|
398 | if (0 < aio_load $_[0], $data) { |
|
|
399 | $data = $_[1]->($data) |
|
|
400 | if $_[1]; |
|
|
401 | } |
|
|
402 | |
|
|
403 | $FILECACHE{$_[0]} = $data; |
|
|
404 | } |
|
|
405 | |
|
|
406 | $FILECACHE{$_[0]} |
|
|
407 | } |
|
|
408 | |
|
|
409 | sub process_res { |
|
|
410 | while (@res) { |
|
|
411 | my ($dir, $file, $type) = @{pop @res}; |
|
|
412 | |
|
|
413 | my $data; |
|
|
414 | aio_load "$dir/$file", $data; |
|
|
415 | |
|
|
416 | my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; |
|
|
417 | |
|
|
418 | $file =~ s/\.res$//; |
|
|
419 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
|
|
420 | |
|
|
421 | substr $dir, 0, 1 + length $PATH, ""; |
|
|
422 | |
|
|
423 | $meta = { |
|
|
424 | %{ $meta->{"" } || {} }, |
|
|
425 | %{ $meta->{$file} || {} }, |
|
|
426 | }; |
|
|
427 | |
|
|
428 | $RESOURCE{"$dir/$file"} = { |
|
|
429 | type => (delete $meta->{type}) || $type, |
|
|
430 | data => $data, |
|
|
431 | chksum => (Digest::MD5::md5 $data), |
|
|
432 | %$meta ? (meta => $meta) : (), |
|
|
433 | }; |
|
|
434 | } |
|
|
435 | } |
|
|
436 | |
388 | sub find_files; |
437 | sub find_files; |
389 | sub find_files { |
438 | sub find_files { |
390 | my ($path) = @_; |
439 | my ($path) = @_; |
391 | |
440 | |
392 | IO::AIO::aioreq_pri 4; |
441 | IO::AIO::aioreq_pri 4; |
… | |
… | |
394 | my ($dirs, $nondirs) = @_; |
443 | my ($dirs, $nondirs) = @_; |
395 | |
444 | |
396 | find_files "$path/$_" |
445 | find_files "$path/$_" |
397 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
446 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
398 | |
447 | |
|
|
448 | my $dir = $path; |
|
|
449 | substr $dir, 0, 1 + length $PATH, ""; |
|
|
450 | |
399 | for my $file (@$nondirs) { |
451 | for my $file (@$nondirs) { |
|
|
452 | if ($dir =~ /^music(?:\/|$)/) { |
|
|
453 | push @res, [$path, $file, 3] # FT_MUSIC |
|
|
454 | if $file =~ /\.(ogg)$/; |
|
|
455 | |
|
|
456 | } elsif ($dir =~ /^sounds(?:\/|$)/) { |
|
|
457 | push @res, [$path, $file, 5] # FT_SOUND |
|
|
458 | if $file =~ /\.(wav|ogg)$/; |
|
|
459 | |
|
|
460 | } elsif ($dir =~ /^res(?:\/|$)/) { |
|
|
461 | push @res, [$path, $file, 0] # FT_FACE |
|
|
462 | if $file =~ /\.(jpg|png)$/; |
|
|
463 | push @res, [$path, $file, 7] # FT_RSRC |
|
|
464 | if $file =~ /\.(res)$/; |
|
|
465 | |
400 | if ($file =~ /\.png$/) { |
466 | } elsif ($file =~ /\.png$/) { |
401 | push @png, ["$path/$file", 0]; |
467 | push @png, ["$path/$file", 0]; |
|
|
468 | |
402 | } elsif ($file =~ /\.trs$/) { |
469 | } elsif ($file =~ /\.trs$/) { |
403 | push @trs, [$path, $file]; |
470 | push @trs, [$path, $file]; |
|
|
471 | |
404 | } elsif ($file =~ /\.arc$/) { |
472 | } elsif ($file =~ /\.arc$/) { |
405 | push @arc, [$path, $file]; |
473 | push @arc, [$path, $file]; |
|
|
474 | |
406 | } else { |
475 | } else { |
407 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
476 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
408 | } |
477 | } |
409 | } |
478 | } |
410 | }; |
479 | }; |
411 | } |
480 | } |
412 | |
481 | |
413 | sub inst_arch($) { |
482 | sub inst_arch($) { |
414 | my (undef, $path) = @_; |
483 | my (undef, $path) = @_; |
|
|
484 | |
|
|
485 | $PATH = $path; |
415 | |
486 | |
416 | print "\n", |
487 | print "\n", |
417 | "Installing '$path' to '$DATADIR'\n", |
488 | "Installing '$path' to '$DATADIR'\n", |
418 | "\n", |
489 | "\n", |
419 | "This can take a long time if you run this\n", |
490 | "This can take a long time if you run this\n", |
… | |
… | |
434 | $_->join for ( |
505 | $_->join for ( |
435 | # four png crunchers work fine for my 2x smp machine |
506 | # four png crunchers work fine for my 2x smp machine |
436 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
507 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
437 | (async \&process_trs), (async \&process_trs), |
508 | (async \&process_trs), (async \&process_trs), |
438 | (async \&process_arc), (async \&process_arc), |
509 | (async \&process_arc), (async \&process_arc), |
|
|
510 | (async \&process_res), (async \&process_res), |
439 | ); |
511 | ); |
440 | |
512 | |
441 | { |
513 | { |
442 | # remove path prefix from editor_folder |
514 | # remove path prefix from editor_folder |
443 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
515 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
… | |
… | |
511 | |
583 | |
512 | print $fh freeze { |
584 | print $fh freeze { |
513 | version => 2, |
585 | version => 2, |
514 | faceinfo => \%FACEINFO, |
586 | faceinfo => \%FACEINFO, |
515 | animinfo => \%ANIMINFO, |
587 | animinfo => \%ANIMINFO, |
|
|
588 | resource => \%RESOURCE, |
516 | }; |
589 | }; |
517 | } |
590 | } |
518 | |
591 | |
519 | for (qw(archetypes facedata treasures)) { |
592 | for (qw(archetypes facedata treasures)) { |
520 | chmod 0644, "$DATADIR/$_~"; |
593 | chmod 0644, "$DATADIR/$_~"; |