7
# Generate md5sums for source and destination directories
8
my @src_files = `md5sum $ARGV[0]/*`;
9
my @dest_files = `md5sum $ARGV[1]/*`;
11
# Build hash for source ROMs
13
foreach $file (@src_files) {
15
($md5, $name) = split(" ", $file);
16
$src_md5{ $md5 } = $name;
18
print "Found " . keys( %src_md5 ) . " ROMs in " . $ARGV[0] . "\n";
20
# Build hash for destination ROMs
22
foreach $file (@dest_files) {
24
($md5, $name) = split(" ", $file);
25
$dest_md5{ $md5 } = $name;
27
print "Found " . keys( %dest_md5 ) . " ROMs in " . $ARGV[1] . "\n";
29
my @added = (), @removed = (), @changed = ();
31
# Check for added ROMs
32
for my $key ( keys %dest_md5 ) {
33
if (defined $src_md5{$key}) {
34
($src_rom,$path,$type) = fileparse($src_md5{$key});
35
($dest_rom,$path,$type) = fileparse($dest_md5{$key});
36
if($src_rom ne $dest_rom) {
37
push(@changed, $dest_md5{$key});
41
push(@added, $dest_md5{$key});
45
# Check for removed ROMs
46
for my $key ( keys %src_md5 ) {
47
if (!defined $dest_md5{$key}) {
48
push(@removed, $src_md5{$key});
52
# Report our findings, create directories and copy files
54
my $numAdded = @added;
55
print "Added ROMs: $numAdded\n";
57
system("mkdir -p ADDED");
58
foreach $rom (@added) {
59
system("cp \"$rom\" ADDED/");
62
my $numRemoved = @removed;
63
print "Removed ROMs: $numRemoved\n";
64
if ($numRemoved > 0) {
65
system("mkdir -p REMOVED");
66
foreach $rom (@removed) {
67
system("cp \"$rom\" REMOVED/");
70
my $numChanged = @changed;
71
print "Changed ROMs: $numChanged\n";
72
if ($numChanged > 0) {
73
system("mkdir -p CHANGED");
74
foreach $rom (@changed) {
75
system("cp \"$rom\" CHANGED/");
81
print "rom_diff.pl <source directory> <destination directory>\n";
83
print "Analyze the ROMs in both directories by md5sum and name.\n";
84
print "Three directories are created named 'ADDED', 'REMOVED' and 'CHANGED',\n";
85
print "indicating the differences in ROMs from the source and destination\n";
86
print "directories. ROMs are then copied into these new directories as specified.\n";