… | |
… | |
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 | |
… | |
… | |
387 | } |
390 | } |
388 | } |
391 | } |
389 | |
392 | |
390 | sub process_res { |
393 | sub process_res { |
391 | while (@res) { |
394 | while (@res) { |
392 | my ($dir, $file) = @{pop @res}; |
395 | my ($dir, $file, $type) = @{pop @res}; |
393 | |
396 | |
394 | my $data; |
397 | my $data; |
395 | aio_load "$dir/$file", $data; |
398 | aio_load "$dir/$file", $data; |
|
|
399 | |
|
|
400 | my $copyright; |
|
|
401 | aio_load "$dir/copyright", $copyright; |
396 | |
402 | |
397 | $file =~ s/\.res$//; |
403 | $file =~ s/\.res$//; |
398 | $file =~ /\.([^.]+)$/ |
404 | $file =~ /\.([^.]+)$/ |
399 | or next; |
405 | or next; |
400 | |
406 | |
401 | my $type = $1; |
|
|
402 | |
|
|
403 | substr $dir, 0, 1 + length $PATH, ""; |
407 | substr $dir, 0, 1 + length $PATH, ""; |
404 | |
408 | |
405 | $RESOURCE{"$dir/$file"} = { |
409 | $RESOURCE{"$dir/$file"} = { |
406 | type => $1, |
410 | type => $type, |
407 | copyright => "", # TODO |
411 | copyright => $copyright, |
408 | data => $data, |
412 | data => $data, |
409 | chksum => Digest::MD5::md5 $data, |
413 | chksum => Digest::MD5::md5 $data, |
410 | }; |
414 | }; |
411 | } |
415 | } |
412 | } |
416 | } |
… | |
… | |
420 | my ($dirs, $nondirs) = @_; |
424 | my ($dirs, $nondirs) = @_; |
421 | |
425 | |
422 | find_files "$path/$_" |
426 | find_files "$path/$_" |
423 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
427 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
424 | |
428 | |
|
|
429 | my $dir = $path; |
|
|
430 | substr $dir, 0, 1 + length $PATH, ""; |
|
|
431 | |
425 | 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 | |
426 | if ($file =~ /\.png$/) { |
447 | } elsif ($file =~ /\.png$/) { |
427 | push @png, ["$path/$file", 0]; |
448 | push @png, ["$path/$file", 0]; |
|
|
449 | |
428 | } elsif ($file =~ /\.trs$/) { |
450 | } elsif ($file =~ /\.trs$/) { |
429 | push @trs, [$path, $file]; |
451 | push @trs, [$path, $file]; |
|
|
452 | |
430 | } elsif ($file =~ /\.arc$/) { |
453 | } elsif ($file =~ /\.arc$/) { |
431 | push @arc, [$path, $file]; |
454 | push @arc, [$path, $file]; |
432 | } elsif ($file =~ /\.(ogg|res)$/) { |
455 | |
433 | push @res, [$path, $file]; |
|
|
434 | } else { |
456 | } else { |
435 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
457 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
436 | } |
458 | } |
437 | } |
459 | } |
438 | }; |
460 | }; |