Finger info for icculus@icculus.org...


So if you missed my previous posts, we wired up the Arcade1Up cabinet's power and volume switches over here and ran stereo speakers to the marquee over here.

This one is a quickie to solve a different problem.

Chances are, you have a very large collection of roms for a system that you obtained in a totally legal manner. And you're sitting here scrolling through 2000+ MAME titles, realizing that some of these are duplicates, some of them suck, some of them are just broken, and all of them are buried.

You might also be thinking you'd like not to spend 27 gigabytes of your 32gb SD card on all these games and preview movies that you're never going to use. Honestly, you maybe want 200 of these games...probably more like 20. And this is just the "ARCADE" menu! But how on earth do you trim this menu down?!

This is the method I came up with:

The Perl script is here, but I've also pasted it below. You run it from the same directory as gamelist.xml, and it'll generate a directory called "trimmed" with a copy of just what you need. This will completely delete "trimmed" and start over every time you run it, so don't make changes to that directory until you're completely done with the script. For safety's sake, it copies the files it needs instead of moving them, which takes a little longer and needs more disk space, but it felt safer to do it this way.

The script will remove the favorite flag from each game, since you probably don't want every game on the system marked as a favorite. The trimmed directory will have a gamelist.xml with just your desired set of games instead of all 2000+ of them, and just the roms and other metadata (preview video, logo, etc) for those games. It's likely that this directory is many many gigabytes smaller than the original. This script can run directly on the Pi.

Move the old directory out of the way and put the trimmed one in its place. If it were the "arcade" roms, and you're sitting at a shell prompt on the Pi:

cd /home/pi/RetroPie/roms
mv arcade toobig-arcade
mv toobig-arcade/trimmed arcade

# Later, when you're sure everything is working, delete the full rom set:
rm -rf toobig-arcade

(if you're doing this over the network with a GUI filemanager, just move and delete the directories as appropriate instead.)

Reboot so EmulationStation notices the gamelist change, and have fun!

Here's the script. Run it from the same directory as gamelist.xml ...

#!/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 = <SVM>;
        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 '<?xml version="1.0"?>' . "\n";
print FH "<gameList>\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 "</gameList>\n";

close(FH) or die("failed to write gamelist.xml: $!\n");

print("\n\n...done!\n\n");

# end of trimroms.pl ...

--ryan.



When this .plan was written: 2019-01-10 00:26:56
.plan archives for this user are here (RSS here).
Powered by IcculusFinger v2.1.27
A song too hard to follow that no one else can sing