… | |
… | |
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) = @{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 | my $type = $1; |
|
|
408 | |
|
|
409 | substr $dir, 0, 1 + length $PATH, ""; |
|
|
410 | |
|
|
411 | $RESOURCE{"$dir/$file"} = { |
|
|
412 | type => $1, |
|
|
413 | copyright => $copyright, |
|
|
414 | data => $data, |
|
|
415 | chksum => Digest::MD5::md5 $data, |
|
|
416 | }; |
|
|
417 | } |
|
|
418 | } |
|
|
419 | |
388 | sub find_files; |
420 | sub find_files; |
389 | sub find_files { |
421 | sub find_files { |
390 | my ($path) = @_; |
422 | my ($path) = @_; |
391 | |
423 | |
392 | IO::AIO::aioreq_pri 4; |
424 | IO::AIO::aioreq_pri 4; |
… | |
… | |
401 | push @png, ["$path/$file", 0]; |
433 | push @png, ["$path/$file", 0]; |
402 | } elsif ($file =~ /\.trs$/) { |
434 | } elsif ($file =~ /\.trs$/) { |
403 | push @trs, [$path, $file]; |
435 | push @trs, [$path, $file]; |
404 | } elsif ($file =~ /\.arc$/) { |
436 | } elsif ($file =~ /\.arc$/) { |
405 | push @arc, [$path, $file]; |
437 | push @arc, [$path, $file]; |
|
|
438 | } elsif ($file =~ /\.(ogg|jpg|res)$/) { |
|
|
439 | push @res, [$path, $file]; |
406 | } else { |
440 | } else { |
407 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
441 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
408 | } |
442 | } |
409 | } |
443 | } |
410 | }; |
444 | }; |
411 | } |
445 | } |
412 | |
446 | |
413 | sub inst_arch($) { |
447 | sub inst_arch($) { |
414 | my (undef, $path) = @_; |
448 | my (undef, $path) = @_; |
|
|
449 | |
|
|
450 | $PATH = $path; |
415 | |
451 | |
416 | print "\n", |
452 | print "\n", |
417 | "Installing '$path' to '$DATADIR'\n", |
453 | "Installing '$path' to '$DATADIR'\n", |
418 | "\n", |
454 | "\n", |
419 | "This can take a long time if you run this\n", |
455 | "This can take a long time if you run this\n", |
… | |
… | |
434 | $_->join for ( |
470 | $_->join for ( |
435 | # four png crunchers work fine for my 2x smp machine |
471 | # four png crunchers work fine for my 2x smp machine |
436 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
472 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
437 | (async \&process_trs), (async \&process_trs), |
473 | (async \&process_trs), (async \&process_trs), |
438 | (async \&process_arc), (async \&process_arc), |
474 | (async \&process_arc), (async \&process_arc), |
|
|
475 | (async \&process_res), (async \&process_res), |
439 | ); |
476 | ); |
440 | |
477 | |
441 | { |
478 | { |
442 | # remove path prefix from editor_folder |
479 | # remove path prefix from editor_folder |
443 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
480 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
… | |
… | |
511 | |
548 | |
512 | print $fh freeze { |
549 | print $fh freeze { |
513 | version => 2, |
550 | version => 2, |
514 | faceinfo => \%FACEINFO, |
551 | faceinfo => \%FACEINFO, |
515 | animinfo => \%ANIMINFO, |
552 | animinfo => \%ANIMINFO, |
|
|
553 | resource => \%RESOURCE, |
516 | }; |
554 | }; |
517 | } |
555 | } |
518 | |
556 | |
519 | for (qw(archetypes facedata treasures)) { |
557 | for (qw(archetypes facedata treasures)) { |
520 | chmod 0644, "$DATADIR/$_~"; |
558 | chmod 0644, "$DATADIR/$_~"; |