ODROID-GO Advance Tips And Tricks: Unzip ROMs While Maintaining Box Art And Game List

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 files 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’s a good idea. The savings in space is minimal on games from the 8- and 16-bit generations and we do not 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. As you know, Batocera (https://batocera.org/download) makes a great RecallBox-based OS, 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 will 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 are processing, or we have to edit the gamelist.xml by hand, which would take considerable effort. I will 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. We will do it all with a bash script from the command line, so you can run it via SSH if necessary.

Preparation

In order for us to make the necessary changes to an XML file from a bash script we are going to need a little help. The tool we will use is called XmlStarlet. Install it onto the system that you will be using to process the ROM sets. You will 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 will set up our script. You can download a copy of the script from https://bit.ly/34Y7LNX 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.

  • Creates a tmp folder in the local directory.
  • Copies the next ZIP file into the tmp folder.
  • Expands the ZIP file.
  • If a matching file with extension is found, it renames the resulting file with the same name as the ZIP file but with the current extension.
  • Moves the resulting file back into the main ROM directory.
  • Replaces the entry in gamelist.xml with the new extension, i.e. non-zip.
  • If processed, moves the ZIP file into the done folder.
  • Deletes the tmp dir.
  • Repeats the above processes, until all files are handled.

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 operation 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 these operations, but I have 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 are 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 us 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 will have to edit the line where xmlstarlet is called and set up a different structure to match your XML file. First let us make sure we can execute the script.

$ sudo chmod +x ./clean_unzip
Next we will run the script and target the expected file extension. Let us use Sega Mega Drive as an example.
$ sudo ./clean_unzip bin gamelist.xml
We will have some left over ZIP files. Let us open one up. Turns out, the content has an smd extension. Let us 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 a particular ROM set. The script will work with the remaining ZIP files so it is 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.

Figure 01 - Before: Notice the "zip" in the file name entry

Figure 02 - After: Notice that the file name has been changed

Here is the view of the directory itself.

Figure 03 - Before: ZIP files and no "done" directory

Figure 04 - After: Unzipped ROMs and a "done" folder holding completed zip files

Wrapping Up

This 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 do not want to use the extra CPU cycles to expand the game file. For comments, questions and suggestions, please visit the original article at http://middlemind.net/tutorials/odroid_go/oga_rl_dc_build.html.

Be the first to comment

Leave a Reply