… | |
… | |
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 | if ($_[1]) { |
|
|
400 | $data = eval { $_[1]->($data) }; |
|
|
401 | warn "$_[0]: $@" if $@; |
|
|
402 | } |
|
|
403 | } |
|
|
404 | |
|
|
405 | $FILECACHE{$_[0]} = $data; |
|
|
406 | } |
|
|
407 | |
|
|
408 | $FILECACHE{$_[0]} |
|
|
409 | } |
|
|
410 | |
|
|
411 | sub process_res { |
|
|
412 | while (@res) { |
|
|
413 | my ($dir, $file, $type) = @{pop @res}; |
|
|
414 | |
|
|
415 | my $data; |
|
|
416 | aio_load "$dir/$file", $data; |
|
|
417 | |
|
|
418 | my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; |
|
|
419 | |
|
|
420 | next if $meta && !exists $meta->{$file}; |
|
|
421 | |
|
|
422 | $meta = { |
|
|
423 | %{ $meta->{"" } || {} }, |
|
|
424 | %{ $meta->{$file} || {} }, |
|
|
425 | }; |
|
|
426 | |
|
|
427 | if ($meta->{license} =~ s/^#//) { |
|
|
428 | $meta->{license} = ({ |
|
|
429 | "pd" => "Public Domain", |
|
|
430 | "gpl" => "GNU General Public License, version 3.0 or any later", |
|
|
431 | "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", |
|
|
432 | "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.5/", |
|
|
433 | "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", |
|
|
434 | })->{$meta->{license}} |
|
|
435 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
|
|
436 | } |
|
|
437 | |
|
|
438 | $file =~ s/\.res$//; |
|
|
439 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
|
|
440 | |
|
|
441 | substr $dir, 0, 1 + length $PATH, ""; |
|
|
442 | |
|
|
443 | $RESOURCE{"$dir/$file"} = { |
|
|
444 | type => (delete $meta->{type}) || $type, |
|
|
445 | data => $data, |
|
|
446 | chksum => (Digest::MD5::md5 $data), |
|
|
447 | %$meta ? (meta => $meta) : (), |
|
|
448 | }; |
|
|
449 | } |
|
|
450 | } |
|
|
451 | |
388 | sub find_files; |
452 | sub find_files; |
389 | sub find_files { |
453 | sub find_files { |
390 | my ($path) = @_; |
454 | my ($path) = @_; |
391 | |
455 | |
392 | IO::AIO::aioreq_pri 4; |
456 | IO::AIO::aioreq_pri 4; |
… | |
… | |
394 | my ($dirs, $nondirs) = @_; |
458 | my ($dirs, $nondirs) = @_; |
395 | |
459 | |
396 | find_files "$path/$_" |
460 | find_files "$path/$_" |
397 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
461 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
398 | |
462 | |
|
|
463 | my $dir = $path; |
|
|
464 | substr $dir, 0, 1 + length $PATH, ""; |
|
|
465 | |
399 | for my $file (@$nondirs) { |
466 | for my $file (@$nondirs) { |
|
|
467 | if ($dir =~ /^music(?:\/|$)/) { |
|
|
468 | push @res, [$path, $file, 3] # FT_MUSIC |
|
|
469 | if $file =~ /\.(ogg)$/; |
|
|
470 | |
|
|
471 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
|
|
472 | push @res, [$path, $file, 5] # FT_SOUND |
|
|
473 | if $file =~ /\.(wav|ogg)$/; |
|
|
474 | |
|
|
475 | } elsif ($dir =~ /^res(?:\/|$)/) { |
|
|
476 | push @res, [$path, $file, 0] # FT_FACE |
|
|
477 | if $file =~ /\.(jpg|png)$/; |
|
|
478 | push @res, [$path, $file, 7] # FT_RSRC |
|
|
479 | if $file =~ /\.(res)$/; |
|
|
480 | |
400 | if ($file =~ /\.png$/) { |
481 | } elsif ($file =~ /\.png$/) { |
401 | push @png, ["$path/$file", 0]; |
482 | push @png, ["$path/$file", 0]; |
|
|
483 | |
402 | } elsif ($file =~ /\.trs$/) { |
484 | } elsif ($file =~ /\.trs$/) { |
403 | push @trs, [$path, $file]; |
485 | push @trs, [$path, $file]; |
|
|
486 | |
404 | } elsif ($file =~ /\.arc$/) { |
487 | } elsif ($file =~ /\.arc$/) { |
405 | push @arc, [$path, $file]; |
488 | push @arc, [$path, $file]; |
|
|
489 | |
406 | } else { |
490 | } else { |
407 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
491 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
408 | } |
492 | } |
409 | } |
493 | } |
410 | }; |
494 | }; |
411 | } |
495 | } |
412 | |
496 | |
413 | sub inst_arch($) { |
497 | sub inst_arch($) { |
414 | my (undef, $path) = @_; |
498 | my (undef, $path) = @_; |
|
|
499 | |
|
|
500 | $PATH = $path; |
415 | |
501 | |
416 | print "\n", |
502 | print "\n", |
417 | "Installing '$path' to '$DATADIR'\n", |
503 | "Installing '$path' to '$DATADIR'\n", |
418 | "\n", |
504 | "\n", |
419 | "This can take a long time if you run this\n", |
505 | "This can take a long time if you run this\n", |
… | |
… | |
434 | $_->join for ( |
520 | $_->join for ( |
435 | # four png crunchers work fine for my 2x smp machine |
521 | # four png crunchers work fine for my 2x smp machine |
436 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
522 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
437 | (async \&process_trs), (async \&process_trs), |
523 | (async \&process_trs), (async \&process_trs), |
438 | (async \&process_arc), (async \&process_arc), |
524 | (async \&process_arc), (async \&process_arc), |
|
|
525 | (async \&process_res), (async \&process_res), |
439 | ); |
526 | ); |
440 | |
527 | |
441 | { |
528 | { |
442 | # remove path prefix from editor_folder |
529 | # remove path prefix from editor_folder |
443 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
530 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
… | |
… | |
511 | |
598 | |
512 | print $fh freeze { |
599 | print $fh freeze { |
513 | version => 2, |
600 | version => 2, |
514 | faceinfo => \%FACEINFO, |
601 | faceinfo => \%FACEINFO, |
515 | animinfo => \%ANIMINFO, |
602 | animinfo => \%ANIMINFO, |
|
|
603 | resource => \%RESOURCE, |
516 | }; |
604 | }; |
517 | } |
605 | } |
518 | |
606 | |
519 | for (qw(archetypes facedata treasures)) { |
607 | for (qw(archetypes facedata treasures)) { |
520 | chmod 0644, "$DATADIR/$_~"; |
608 | chmod 0644, "$DATADIR/$_~"; |