#!/usr/bin/env perl

use strict;
use Carp;
use warnings;

open (IFD, "<skinlist.lua") || die;
undef $/;
my $data = <IFD>;
   $data = "" unless defined $data;
close IFD;
die unless $data =~ m@coderskins\.list\s*=\s*\{([^{}]+)\}@;
$data = $1;

my %list = ();
my %dire = ();

while ($data =~ s@^.*?"(sdskin|skin|sscharacter|uskins)(_[^"]+)"@@s)
{
    my $base = "$1$2";
    for my $what ("$base.png" ,
        "${base}_preview.png" ,
        "${base}_preview_back.png" )
    {
        $what = "textures/$what";
        print "Error: Invalid or missing in directory: $what\n"
            unless -f $what && !-z $what;
    }

    $list {$base} = 1;
}

opendir (DIR, "textures") || die;
while (defined (my $de = readdir (DIR)))
{
    next unless $de =~ m@^(sdskin|skin|sscharacter|uskins)(_\S+)\.png\z@;
    $de =~ s@_preview.*@@;
    $de =~ s@.png\z@@;
    $dire {$de} = 1; 
}

for my $key (keys %dire)
{
    print "Error: Missing in list: $key\n"
        unless defined $list {$key};
}

print "list count = " . scalar (keys %list) . "\n";
print "Done\n";
