--- deliantra/server/utils/cfutil.in 2007/07/24 04:55:35 1.44 +++ deliantra/server/utils/cfutil.in 2007/07/31 02:24:43 1.48 @@ -390,6 +390,22 @@ } } + my %FILECACHE; + + sub load_cached($;$) { + unless (exists $FILECACHE{$_[0]}) { + my $data; + if (0 < aio_load $_[0], $data) { + $data = $_[1]->($data) + if $_[1]; + } + + $FILECACHE{$_[0]} = $data; + } + + $FILECACHE{$_[0]} + } + sub process_res { while (@res) { my ($dir, $file, $type) = @{pop @res}; @@ -397,20 +413,23 @@ 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 }; + + $meta = { + %{ $meta->{"" } || {} }, + %{ $meta->{$file} || {} }, + }; $file =~ s/\.res$//; - $file =~ /\.([^.]+)$/ - or next; + $file =~ s/\.(ogg|wav|jpg|png)$//; substr $dir, 0, 1 + length $PATH, ""; $RESOURCE{"$dir/$file"} = { - type => $type, - copyright => $copyright, - data => $data, - chksum => Digest::MD5::md5 $data, + type => (delete $meta->{type}) || $type, + data => $data, + chksum => (Digest::MD5::md5 $data), + %$meta ? (meta => $meta) : (), }; } } @@ -434,7 +453,7 @@ push @res, [$path, $file, 3] # FT_MUSIC if $file =~ /\.(ogg)$/; - } elsif ($dir =~ /^sounds(?:\/|$)/) { + } elsif ($dir =~ /^sound(?:\/|$)/) { push @res, [$path, $file, 5] # FT_SOUND if $file =~ /\.(wav|ogg)$/;