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