| 1 | #!/usr/bin/perl -w
|
|---|
| 2 |
|
|---|
| 3 | use strict;
|
|---|
| 4 |
|
|---|
| 5 | use XML::Simple;
|
|---|
| 6 | use Date::Manip;
|
|---|
| 7 |
|
|---|
| 8 | Date_Init();
|
|---|
| 9 |
|
|---|
| 10 | if (!$ARGV[0])
|
|---|
| 11 | {
|
|---|
| 12 | die("Not exist mame xml");
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 | my $xml = new XML::Simple;
|
|---|
| 17 |
|
|---|
| 18 | my $data = $xml->XMLin($ARGV[0]);
|
|---|
| 19 |
|
|---|
| 20 | $data->{build} =~ /\((.*?)\)/gs;
|
|---|
| 21 |
|
|---|
| 22 | my $date = UnixDate(ParseDate($1), '%Y%m%d');
|
|---|
| 23 |
|
|---|
| 24 | my $category;
|
|---|
| 25 |
|
|---|
| 26 | sub insert_sql
|
|---|
| 27 | {
|
|---|
| 28 | my ($crc, $description, $category, $year, $manufacturer, $size, $file) = @_;
|
|---|
| 29 |
|
|---|
| 30 | if (! $year)
|
|---|
| 31 | {
|
|---|
| 32 | $year = "????";
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | #my $game = $description;
|
|---|
| 36 | #$game =~ s/\s\(.*?\)//g;
|
|---|
| 37 |
|
|---|
| 38 | print "INSERT INTO romdb VALUES ('" . $crc . "'," . '"' . $description . '"' . "," . '"' . $description . '"' . ",'" .
|
|---|
| 39 | $category . "','" . $year . "'," . '"' . $manufacturer . '"'. ",'" .
|
|---|
| 40 | "Unknown','" . "Unknown','MAME'," .
|
|---|
| 41 | $size . ",'','" . $date . "','" . $file . "');\n";
|
|---|
| 42 | return;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | foreach my $key (keys (%{$data->{game}}))
|
|---|
| 46 | {
|
|---|
| 47 |
|
|---|
| 48 | next if ($data->{game}->{$key}->{isbios});
|
|---|
| 49 |
|
|---|
| 50 | if ($data->{game}->{$key}->{driver}->{status} eq 'good')
|
|---|
| 51 | {
|
|---|
| 52 | $category="Players " . $data->{game}->{$key}->{input}->{players};
|
|---|
| 53 | }
|
|---|
| 54 | else
|
|---|
| 55 | {
|
|---|
| 56 | $category='Inperfect';
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | if ($data->{game}->{$key}->{rom}->{crc})
|
|---|
| 60 | {
|
|---|
| 61 | insert_sql($data->{game}->{$key}->{rom}->{crc}, $data->{game}->{$key}->{description}, $category, $data->{game}->{$key}->{year},
|
|---|
| 62 | $data->{game}->{$key}->{manufacturer}, $data->{game}->{$key}->{rom}->{size}, $data->{game}->{$key}->{rom}->{name});
|
|---|
| 63 | }
|
|---|
| 64 | else
|
|---|
| 65 | {
|
|---|
| 66 | foreach my $rom (keys (%{$data->{game}->{$key}->{rom}}))
|
|---|
| 67 | {
|
|---|
| 68 | if ($data->{game}->{$key}->{rom}->{$rom}->{crc})
|
|---|
| 69 | {
|
|---|
| 70 | insert_sql($data->{game}->{$key}->{rom}->{$rom}->{crc}, $data->{game}->{$key}->{description},
|
|---|
| 71 | $category, $data->{game}->{$key}->{year}, $data->{game}->{$key}->{manufacturer},
|
|---|
| 72 | $data->{game}->{$key}->{rom}->{$rom}->{size}, $rom);
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|