#!/usr/bin/perl -w # This code is public domain. use strict; use warnings; use XML::LibXML; use File::Path; use File::Basename; sub copyfile { my $fname = shift; if (not -f $fname) { return; } $fname =~ s#\A\./##; mkpath(dirname("trimmed/$fname")); die("failed to copy $fname, aborting!\n") if (system("cp -Rv '$fname' 'trimmed/$fname'") != 0); # Special magic for ScummVM games; there might be other systems that need something similar. if ($fname =~ /\.svm\Z/i) { open SVM, '<', $fname or die("Can't open '$fname' for reading: $!\n"); my $subdir = ; close(SVM); chomp($subdir); die("failed to copy $subdir, aborting!\n") if (system("cp -Rv '$subdir' 'trimmed/$subdir'") != 0); } } system("rm -rf trimmed"); mkdir("trimmed"); my $dom = XML::LibXML->load_xml(location => 'gamelist.xml'); open FH,'>','trimmed/gamelist.xml' or die("failed to open trimmed/gamelist.xml for writing: $!\n"); print FH '' . "\n"; print FH "\n"; foreach my $game ($dom->findnodes('/gameList/game')) { my $fave = $game->findvalue('./favorite'); next if ((not $fave) or ($fave ne 'true')); foreach ($game->findnodes('./favorite')) { $game->removeChild($_); } print $game->findvalue('./name'); print(" ...\n"); print FH "\t"; print FH $game->toString(); print FH "\n"; copyfile($game->findvalue('./path')); copyfile($game->findvalue('./image')); copyfile($game->findvalue('./video')); copyfile($game->findvalue('./marquee')); print("\n"); } print FH "\n"; close(FH) or die("failed to write gamelist.xml: $!\n"); print("\n\n...done!\n\n"); # end of trimroms.pl ...