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.37 by root, Tue Jul 10 16:24:00 2007 UTC vs.
Revision 1.51 by root, Sat Aug 18 20:39:14 2007 UTC

19use IO::AIO (); 19use IO::AIO ();
20use File::Temp; 20use File::Temp;
21use Crossfire; 21use Crossfire;
22use Coro; 22use Coro;
23use Coro::AIO; 23use Coro::AIO;
24use Coro::Util;
24use POSIX (); 25use POSIX ();
25use Digest::MD5; 26use Digest::MD5;
27use Carp;
26use Coro::Storable; $Storable::canonical = 1; 28use Coro::Storable; $Storable::canonical = 1;
29
30$SIG{QUIT} = sub { Carp::cluck "QUIT" };
27 31
28sub usage { 32sub usage {
29 warn <<EOF; 33 warn <<EOF;
30Usage: cfutil [-v] [-q] [--force] [--cache] 34Usage: cfutil [-v] [-q] [--force] [--cache]
31 [--install-arch path] 35 [--install-arch path]
92 if (!-f "$path/regions") { 96 if (!-f "$path/regions") {
93 warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; 97 warn "'$path' does not look like a maps directory ('regions' file is missing).\n";
94 exit 1 unless $FORCE; 98 exit 1 unless $FORCE;
95 } 99 }
96 100
97 system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" 101 system $RSYNC, "-a", "--chmod=u=rwX,go=rX", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded"
98 and die "map installation failed.\n"; 102 and die "map installation failed.\n";
99 103
100 print "maps installed successfully.\n"; 104 print "maps installed successfully.\n";
101} 105}
102 106
167 # possibly enlarge 171 # possibly enlarge
168 if (0 > aio_stat "$stem.64x64.png") { 172 if (0 > aio_stat "$stem.64x64.png") {
169 my $other = "$stem.64x64.png~"; 173 my $other = "$stem.64x64.png~";
170 174
171 if (0 > aio_lstat $other or (-M _) > (-M $path)) { 175 if (0 > aio_lstat $other or (-M _) > (-M $path)) {
172 my $wrap = 0; # for the time being
173 fork_sub { 176 fork_sub {
174 system "convert png:\Q$path\E -depth 8 rgba:-" 177 system "convert -depth 8 png:\Q$path\E rgba:-"
175 . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" 178 . "| $exec_prefix/bin/cfhq2xa $w $h 0"
176 . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" 179 . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~"
177 and die "convert/hq2xa pipeline error: status $? ($!)"; 180 and die "convert/hq2xa pipeline error: status $? ($!)";
178 system $OPTIPNG, "-i0", "-q", "$other~"; 181 system $OPTIPNG, "-i0", "-q", "$other~";
179 die "$other~ has zero size, aborting." unless -s "$other~"; 182 die "$other~ has zero size, aborting." unless -s "$other~";
180 rename "$other~", $other; 183 rename "$other~", $other;
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
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
397 $file =~ s/\.res$//; 438 $file =~ s/\.res$//;
398 $file =~ /\.([^.]+)$/ 439 $file =~ s/\.(ogg|wav|jpg|png)$//;
399 or next;
400
401 my $type = $1;
402 440
403 substr $dir, 0, 1 + length $PATH, ""; 441 substr $dir, 0, 1 + length $PATH, "";
404 442
405 $RESOURCE{"$dir/$file"} = { 443 $RESOURCE{"$dir/$file"} = {
406 type => $1, 444 type => (delete $meta->{type}) || $type,
407 copyright => "", # TODO
408 data => $data, 445 data => $data,
409 chksum => Digest::MD5::md5 $data, 446 chksum => (Digest::MD5::md5 $data),
447 %$meta ? (meta => $meta) : (),
410 }; 448 };
411 } 449 }
412 } 450 }
413 451
414 sub find_files; 452 sub find_files;
420 my ($dirs, $nondirs) = @_; 458 my ($dirs, $nondirs) = @_;
421 459
422 find_files "$path/$_" 460 find_files "$path/$_"
423 for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; 461 for grep $_ !~ /^(?:CVS|dev)$/, @$dirs;
424 462
463 my $dir = $path;
464 substr $dir, 0, 1 + length $PATH, "";
465
425 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
426 if ($file =~ /\.png$/) { 481 } elsif ($file =~ /\.png$/) {
427 push @png, ["$path/$file", 0]; 482 push @png, ["$path/$file", 0];
483
428 } elsif ($file =~ /\.trs$/) { 484 } elsif ($file =~ /\.trs$/) {
429 push @trs, [$path, $file]; 485 push @trs, [$path, $file];
486
430 } elsif ($file =~ /\.arc$/) { 487 } elsif ($file =~ /\.arc$/) {
431 push @arc, [$path, $file]; 488 push @arc, [$path, $file];
432 } elsif ($file =~ /\.(ogg|res)$/) { 489
433 push @res, [$path, $file];
434 } else { 490 } else {
435 warn "ignoring $path/$file\n" if $VERBOSE >= 3; 491 warn "ignoring $path/$file\n" if $VERBOSE >= 3;
436 } 492 }
437 } 493 }
438 }; 494 };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines