ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/utils/cfutil.in
(Generate patch)

Comparing deliantra/server/utils/cfutil.in (file contents):
Revision 1.39 by root, Sun Jul 15 22:39:48 2007 UTC vs.
Revision 1.50 by root, Thu Aug 9 22:54:28 2007 UTC

21use Crossfire; 21use Crossfire;
22use Coro; 22use Coro;
23use Coro::AIO; 23use Coro::AIO;
24use POSIX (); 24use POSIX ();
25use Digest::MD5; 25use Digest::MD5;
26use Carp;
26use Coro::Storable; $Storable::canonical = 1; 27use Coro::Storable; $Storable::canonical = 1;
28
29$SIG{QUIT} = sub { Carp::cluck "QUIT" };
27 30
28sub usage { 31sub usage {
29 warn <<EOF; 32 warn <<EOF;
30Usage: cfutil [-v] [-q] [--force] [--cache] 33Usage: 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
385 388
386 $TRS .= $trs; 389 $TRS .= $trs;
387 } 390 }
388 } 391 }
389 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
390 sub process_res { 411 sub process_res {
391 while (@res) { 412 while (@res) {
392 my ($dir, $file) = @{pop @res}; 413 my ($dir, $file, $type) = @{pop @res};
393 414
394 my $data; 415 my $data;
395 aio_load "$dir/$file", $data; 416 aio_load "$dir/$file", $data;
396 417
397 my $copyright; 418 my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift };
398 aio_load "$dir/copyright", $copyright; 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 }
399 437
400 $file =~ s/\.res$//; 438 $file =~ s/\.res$//;
401 $file =~ /\.([^.]+)$/ 439 $file =~ s/\.(ogg|wav|jpg|png)$//;
402 or next;
403
404 my $type = $1;
405 440
406 substr $dir, 0, 1 + length $PATH, ""; 441 substr $dir, 0, 1 + length $PATH, "";
407 442
408 $RESOURCE{"$dir/$file"} = { 443 $RESOURCE{"$dir/$file"} = {
409 type => $1, 444 type => (delete $meta->{type}) || $type,
410 copyright => $copyright,
411 data => $data, 445 data => $data,
412 chksum => Digest::MD5::md5 $data, 446 chksum => (Digest::MD5::md5 $data),
447 %$meta ? (meta => $meta) : (),
413 }; 448 };
414 } 449 }
415 } 450 }
416 451
417 sub find_files; 452 sub find_files;
423 my ($dirs, $nondirs) = @_; 458 my ($dirs, $nondirs) = @_;
424 459
425 find_files "$path/$_" 460 find_files "$path/$_"
426 for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; 461 for grep $_ !~ /^(?:CVS|dev)$/, @$dirs;
427 462
463 my $dir = $path;
464 substr $dir, 0, 1 + length $PATH, "";
465
428 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
429 if ($file =~ /\.png$/) { 481 } elsif ($file =~ /\.png$/) {
430 push @png, ["$path/$file", 0]; 482 push @png, ["$path/$file", 0];
483
431 } elsif ($file =~ /\.trs$/) { 484 } elsif ($file =~ /\.trs$/) {
432 push @trs, [$path, $file]; 485 push @trs, [$path, $file];
486
433 } elsif ($file =~ /\.arc$/) { 487 } elsif ($file =~ /\.arc$/) {
434 push @arc, [$path, $file]; 488 push @arc, [$path, $file];
435 } elsif ($file =~ /\.(ogg|jpg|res)$/) { 489
436 push @res, [$path, $file];
437 } else { 490 } else {
438 warn "ignoring $path/$file\n" if $VERBOSE >= 3; 491 warn "ignoring $path/$file\n" if $VERBOSE >= 3;
439 } 492 }
440 } 493 }
441 }; 494 };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines