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.45 by root, Tue Jul 24 22:49:41 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 $data = $_[1]->($data)
400 if $_[1];
401 }
402
403 $FILECACHE{$_[0]} = $data;
404 }
405
406 $FILECACHE{$_[0]}
407 }
408
390 sub process_res { 409 sub process_res {
391 while (@res) { 410 while (@res) {
392 my ($dir, $file) = @{pop @res}; 411 my ($dir, $file, $type) = @{pop @res};
393 412
394 my $data; 413 my $data;
395 aio_load "$dir/$file", $data; 414 aio_load "$dir/$file", $data;
396 415
397 my $copyright; 416 my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift };
398 aio_load "$dir/copyright", $copyright;
399 417
400 $file =~ s/\.res$//; 418 $file =~ s/\.res$//;
401 $file =~ /\.([^.]+)$/ 419 $file =~ /\.(ogg|wav|jpg|png)$/;
402 or next;
403
404 my $type = $1;
405 420
406 substr $dir, 0, 1 + length $PATH, ""; 421 substr $dir, 0, 1 + length $PATH, "";
407 422
423 $meta = {
424 %{ $meta->{"" } || {} },
425 %{ $meta->{$file} || {} },
426 };
427
408 $RESOURCE{"$dir/$file"} = { 428 $RESOURCE{"$dir/$file"} = {
409 type => $1, 429 type => (delete $meta->{type}) || $type,
410 copyright => $copyright,
411 data => $data, 430 data => $data,
412 chksum => Digest::MD5::md5 $data, 431 chksum => (Digest::MD5::md5 $data),
432 %$meta ? (meta => $meta) : (),
413 }; 433 };
414 } 434 }
415 } 435 }
416 436
417 sub find_files; 437 sub find_files;
423 my ($dirs, $nondirs) = @_; 443 my ($dirs, $nondirs) = @_;
424 444
425 find_files "$path/$_" 445 find_files "$path/$_"
426 for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; 446 for grep $_ !~ /^(?:CVS|dev)$/, @$dirs;
427 447
448 my $dir = $path;
449 substr $dir, 0, 1 + length $PATH, "";
450
428 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
429 if ($file =~ /\.png$/) { 466 } elsif ($file =~ /\.png$/) {
430 push @png, ["$path/$file", 0]; 467 push @png, ["$path/$file", 0];
468
431 } elsif ($file =~ /\.trs$/) { 469 } elsif ($file =~ /\.trs$/) {
432 push @trs, [$path, $file]; 470 push @trs, [$path, $file];
471
433 } elsif ($file =~ /\.arc$/) { 472 } elsif ($file =~ /\.arc$/) {
434 push @arc, [$path, $file]; 473 push @arc, [$path, $file];
435 } elsif ($file =~ /\.(ogg|jpg|res)$/) { 474
436 push @res, [$path, $file];
437 } else { 475 } else {
438 warn "ignoring $path/$file\n" if $VERBOSE >= 3; 476 warn "ignoring $path/$file\n" if $VERBOSE >= 3;
439 } 477 }
440 } 478 }
441 }; 479 };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines