Author: Brian A. Ree
Sections
0: Introduction
This is a short tutorial to help you with your ROM sets and the ODROID-GO Advance. Many of us have ROM sets with accompanying
media file like box art, screen shots, logos, etc. Sometimes these ROM sets have compressed files. Now do we really want to be
using up precious battery power to decompress games before we load them up? I don't think that we do. The savings in space is minimal
on games from the 8 and 16 bit generation and we don't want to be decompressing CD ISOs and IMGs on our ODROID-GO Advance so how can we
reprocess all those files and maintain the connection to the media files via the gamelist XML file.
So as you know Batocera makes a great OS, RecallBox based, for the ODROID-GO Advance. The way ROMs
with associated media are read in by the system is via the gamelist.xml file. The problem here is if we decompress the zip file we'll often
end up with a really different file name and extension. Now we have to get a whole new set of box art for our ROMs which can take a while
depending on how many systems you're processing. Or we have to edit the gamelist.xml by hand, which would take forever.
I'll show you how to process a compressed ROM set in a few steps all while maintaining proper entries in the gamelist.xml file so
that your box art is still mapped properly. And we'll do it all with a bash script from the command line, so you can run it via SSH if necessary.
1: Preparation
In order for us to make the necessary changes to an XML file from a bash script we're going to need a little help.
The tool we'll use is called XmlStarlet. Install it onto the system you'll be using to process the ROM sets. You'll need a Linux
system to do this part though OSX and Ubuntu under Windows can probably handle this script as well. It is actually very simple
the only complex part is taken care of by XmlStarlet.
To install the package run the following from the command line.
sudo apt-get install xmlstarlet
Next we'll setup our script. You can download a copy of the script from here or you can copy and paste
the following text into a local file, clean_unzip, and follow the next few steps.
#!/bin/bash
if [ ! -d ./done ]; then
mkdir ./done
fi
for z in *.zip
do
mkdir tmp
cp "$z" tmp
cd tmp
unzip "$z"
echo "Looking for *.$1"
echo $(ls ./*.$1 2>/dev/null | wc -w)
files=( ./*.$1 )
if (( $(ls ./*.$1 2>/dev/null | wc -w) )); then
echo "files do exist $y"
if [ ! -f "${z%.zip}.$1" ]; then
mv *.$1 "${z%.zip}.$1"
fi
mv *.$1 ../
TF="${z%.zip}.$1"
OF="${z}"
NF="${TF}"
if [ -f ../${2} ]; then
echo "replace $OF with $NF"
xmlstarlet ed --inplace -u "//gameList/game[path=\"./${OF}\"]/path" -v "./$NF" ../${2}
#../gamelist.xml
fi
mv ../"$z" ../done/
fi
cd ..
rm -r tmp
#break
done
What does the script do? Well, it performs the following steps.
- 1. Create a tmp folder in the local directory.
- 2. Copy the next zip file into the tmp folder.
- 3. Decompress the zip file.
- 4. If matching file extension found, rename resulting file with the same name as the zip file but with current extension.
- 5. Move the resulting file back into the main ROM dir.
- 6. Replace the entry in gamelist.xml with the new extension, i.e. non-zip.
- 7. If processed, move the zip file to the done folder.
- 8. Delete the tmp dir.
- 9. Repeat.
2: Usage
You can run the script on an SD card via SSH or on a mounted SD card on your ODROID-GO device. It does use a fair amount of file system operations
to complete cleaning up a ROM set. In general I would recommend not doing it directly on an SD card because of the number of operations but I've
actually cleaned up 30 ROM sets with it, directly on a mounted card, with no trouble.
When you are running it on large ROM sets you will have left over zip files in the directory you're processing. Some zip files will be processed and
moved to the done folder. This means that the compressed files that are left over have contents with a different file extension.
Let's look at the commands used in an example.
ALERT: The script is designed to run with RecallBox based media XML files. If you are using a different XML format
you'll have to edit the line where xmlstarlet is called and setup a different structure to match your XML file.
First let's make sure we can execute the script.
sudo chmod +x ./clean_unzip
Next we'll run the script and target the expected file extension. Let's use Sega Mega Drive as an example.
sudo ./clean_unzip bin gamelist.xml
We'll have some left over zip files. Let's open one up. Ahh, the contents has a smd extension.
Let's run the script on the remaining zip files.
sudo ./clean_unzip smd gamelist.xml
You may have to run the command a few times to handle the remaining file extensions in the particular ROM set
you're working with. The script will work with the remaining zip files so it's really not that bad.
With a few calls we can clean up any ROM set. Below we have some before and after pictures so you can get an idea
of what the script does.
Before: Notice the "zip" in the file name entry.
After: Notice the file name has been changed.
And a view of the directory itself.
Before: Zip files and no "done" directory.
After: Unzipped ROMs and a "done" folder holding completed zip files.
3: Wrapping Up
The brings us to the end of this tutorial. This was a quick one and it should be of great use to you if you
do need to unzip a ROM set that has media files mapped to the zipped copy of your ROM.
This script is great for adjusting compressed ROM sets for use with handheld devices where maybe you don't want to use the
extra CPU cycles to decompress the game file. Enjoy!!