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.43 by root, Mon Jul 23 23:38:18 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;
26use Carp; 27use Carp;
27use Coro::Storable; $Storable::canonical = 1; 28use Coro::Storable; $Storable::canonical = 1;
28 29
170 # possibly enlarge 171 # possibly enlarge
171 if (0 > aio_stat "$stem.64x64.png") { 172 if (0 > aio_stat "$stem.64x64.png") {
172 my $other = "$stem.64x64.png~"; 173 my $other = "$stem.64x64.png~";
173 174
174 if (0 > aio_lstat $other or (-M _) > (-M $path)) { 175 if (0 > aio_lstat $other or (-M _) > (-M $path)) {
175 my $wrap = 0; # for the time being
176 fork_sub { 176 fork_sub {
177 system "convert png:\Q$path\E -depth 8 rgba:-" 177 system "convert -depth 8 png:\Q$path\E rgba:-"
178 . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" 178 . "| $exec_prefix/bin/cfhq2xa $w $h 0"
179 . "| 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~"
180 and die "convert/hq2xa pipeline error: status $? ($!)"; 180 and die "convert/hq2xa pipeline error: status $? ($!)";
181 system $OPTIPNG, "-i0", "-q", "$other~"; 181 system $OPTIPNG, "-i0", "-q", "$other~";
182 die "$other~ has zero size, aborting." unless -s "$other~"; 182 die "$other~ has zero size, aborting." unless -s "$other~";
183 rename "$other~", $other; 183 rename "$other~", $other;
388 388
389 $TRS .= $trs; 389 $TRS .= $trs;
390 } 390 }
391 } 391 }
392 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
393 sub process_res { 411 sub process_res {
394 while (@res) { 412 while (@res) {
395 my ($dir, $file) = @{pop @res}; 413 my ($dir, $file, $type) = @{pop @res};
396 414
397 my $data; 415 my $data;
398 aio_load "$dir/$file", $data; 416 aio_load "$dir/$file", $data;
399 417
400 my $copyright; 418 my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift };
401 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 }
402 437
403 $file =~ s/\.res$//; 438 $file =~ s/\.res$//;
404 $file =~ /\.([^.]+)$/ 439 $file =~ s/\.(ogg|wav|jpg|png)$//;
405 or next;
406
407 my $type = $1;
408 440
409 substr $dir, 0, 1 + length $PATH, ""; 441 substr $dir, 0, 1 + length $PATH, "";
410 442
411 $RESOURCE{"$dir/$file"} = { 443 $RESOURCE{"$dir/$file"} = {
412 type => $1, 444 type => (delete $meta->{type}) || $type,
413 copyright => $copyright,
414 data => $data, 445 data => $data,
415 chksum => Digest::MD5::md5 $data, 446 chksum => (Digest::MD5::md5 $data),
447 %$meta ? (meta => $meta) : (),
416 }; 448 };
417 } 449 }
418 } 450 }
419 451
420 sub find_files; 452 sub find_files;
430 462
431 my $dir = $path; 463 my $dir = $path;
432 substr $dir, 0, 1 + length $PATH, ""; 464 substr $dir, 0, 1 + length $PATH, "";
433 465
434 for my $file (@$nondirs) { 466 for my $file (@$nondirs) {
435 if ($file =~ /\.(ogg|jpg|res)$/ || $dir =~ /^res(?:\/|$)/) { 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(?:\/|$)/) {
436 push @res, [$path, $file]; 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
437 } elsif ($file =~ /\.png$/) { 481 } elsif ($file =~ /\.png$/) {
438 push @png, ["$path/$file", 0]; 482 push @png, ["$path/$file", 0];
483
439 } elsif ($file =~ /\.trs$/) { 484 } elsif ($file =~ /\.trs$/) {
440 push @trs, [$path, $file]; 485 push @trs, [$path, $file];
486
441 } elsif ($file =~ /\.arc$/) { 487 } elsif ($file =~ /\.arc$/) {
442 push @arc, [$path, $file]; 488 push @arc, [$path, $file];
489
443 } else { 490 } else {
444 warn "ignoring $path/$file\n" if $VERBOSE >= 3; 491 warn "ignoring $path/$file\n" if $VERBOSE >= 3;
445 } 492 }
446 } 493 }
447 }; 494 };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines