--- deliantra/server/utils/cfutil.in 2007/07/15 22:39:48 1.39 +++ deliantra/server/utils/cfutil.in 2007/08/09 22:54:28 1.50 @@ -23,8 +23,11 @@ use Coro::AIO; use POSIX (); use Digest::MD5; +use Carp; use Coro::Storable; $Storable::canonical = 1; +$SIG{QUIT} = sub { Carp::cluck "QUIT" }; + sub usage { warn <($data) }; + warn "$_[0]: $@" if $@; + } + } + + $FILECACHE{$_[0]} = $data; + } + + $FILECACHE{$_[0]} + } + sub process_res { while (@res) { - my ($dir, $file) = @{pop @res}; + my ($dir, $file, $type) = @{pop @res}; my $data; aio_load "$dir/$file", $data; - my $copyright; - aio_load "$dir/copyright", $copyright; + my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; - $file =~ s/\.res$//; - $file =~ /\.([^.]+)$/ - or next; + next if $meta && !exists $meta->{$file}; - my $type = $1; + $meta = { + %{ $meta->{"" } || {} }, + %{ $meta->{$file} || {} }, + }; + + if ($meta->{license} =~ s/^#//) { + $meta->{license} = ({ + "pd" => "Public Domain", + "gpl" => "GNU General Public License, version 3.0 or any later", + "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", + "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.5/", + "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", + })->{$meta->{license}} + || warn "$dir/$file: license tag '$meta->{license}' not found."; + } + + $file =~ s/\.res$//; + $file =~ s/\.(ogg|wav|jpg|png)$//; substr $dir, 0, 1 + length $PATH, ""; $RESOURCE{"$dir/$file"} = { - type => $1, - copyright => $copyright, - data => $data, - chksum => Digest::MD5::md5 $data, + type => (delete $meta->{type}) || $type, + data => $data, + chksum => (Digest::MD5::md5 $data), + %$meta ? (meta => $meta) : (), }; } } @@ -425,15 +460,33 @@ find_files "$path/$_" for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; + my $dir = $path; + substr $dir, 0, 1 + length $PATH, ""; + for my $file (@$nondirs) { - if ($file =~ /\.png$/) { + if ($dir =~ /^music(?:\/|$)/) { + push @res, [$path, $file, 3] # FT_MUSIC + if $file =~ /\.(ogg)$/; + + } elsif ($dir =~ /^sound(?:\/|$)/) { + push @res, [$path, $file, 5] # FT_SOUND + if $file =~ /\.(wav|ogg)$/; + + } elsif ($dir =~ /^res(?:\/|$)/) { + push @res, [$path, $file, 0] # FT_FACE + if $file =~ /\.(jpg|png)$/; + push @res, [$path, $file, 7] # FT_RSRC + if $file =~ /\.(res)$/; + + } elsif ($file =~ /\.png$/) { push @png, ["$path/$file", 0]; + } elsif ($file =~ /\.trs$/) { push @trs, [$path, $file]; + } elsif ($file =~ /\.arc$/) { push @arc, [$path, $file]; - } elsif ($file =~ /\.(ogg|jpg|res)$/) { - push @res, [$path, $file]; + } else { warn "ignoring $path/$file\n" if $VERBOSE >= 3; }