Assumes:
-
Emustation Desktop Edition (ES-DE) running on OSX
-
ROM media (via ES-DE Screenscraper) includes at least cover art, marquees, miximages, and video
Knulli is the version for RG28XX as of Jul 2024, but directory structure should be similar for other Anbernic RG devices.
(If you're here, you probably know what you're doing. I had to do it this way because Anbernic RG28XX doesn't have wifi, so you can't use a screenscraper account directly from the device. Instead, run the scraper from ES-DE, then use this script to copy the media over to the RG28XX SDCARD, while converting gamelists in the process.)
#!/bin/bash
# Ensure xmlstarlet is installed
if ! command -v xmlstarlet &> /dev/null; then
echo "xmlstarlet could not be found, installing it..."
brew install xmlstarlet
fi
EMUSTATION_DIR=$HOME/ES-DE
KNULLI_SDCARD_DIR=/Volumes/HANDHELD/roms
# Process each <game> entry adding media tags <image>, <video>, <marquee> and <thumbnail>.
process_game() {
local path="$1"
local output_file="$2"
local gamename=$(basename "$path" | sed 's/\.[^.]*$//')
echo -e "\nProcessing game: $gamename..."
xmlstarlet ed -L \
-s "/gameList/game[path=\"$path\"]" -t elem -n "image" -v "./miximages/${gamename}.png" \
"$output_file"
xmlstarlet ed -L \
-s "/gameList/game[path=\"$path\"]" -t elem -n "video" -v "./videos/${gamename}.mp4" \
"$output_file"
xmlstarlet ed -L \
-s "/gameList/game[path=\"$path\"]" -t elem -n "marquee" -v "./marquees/${gamename}.png" \
"$output_file"
xmlstarlet ed -L \
-s "/gameList/game[path=\"$path\"]" -t elem -n "thumbnail" -v "./covers/${gamename}.png" \
"$output_file"
}
# Export the function to use with xargs
export -f process_game
for emu_path in $EMUSTATION_DIR/downloaded_media/*; do
emu=$(basename "$emu_path")
echo -e "\nCopying ES-DE media dirs to KNULLI SDCARD for emulator $emu..."
rsync -a --delete $emu_path/miximages $KNULLI_SDCARD_DIR/$emu/miximages
rsync -a --delete $emu_path/videos $KNULLI_SDCARD_DIR/$emu/videos
rsync -a --delete $emu_path/marquees $KNULLI_SDCARD_DIR/$emu/marquees
rsync -a --delete $emu_path/covers $KNULLI_SDCARD_DIR/$emu/covers
done
for emu_path in $EMUSTATION_DIR/gamelists/*; do
emu=$(basename "$emu_path")
input_xml="$emu_path/gamelist.xml"
output_xml="$KNULLI_SDCARD_DIR/$emu/gamelist.xml"
# just in case cp is aliased to "cp -i"
/bin/cp -rf $input_xml $output_xml
echo -e "\nConverting ES-DE gamelist.xml to KNULLI for emulator $emu..."
xmlstarlet sel -t -m "//game/path" -v . -n "$input_xml" | while IFS= read -r gamepath; do
process_game "$gamepath" "$output_xml"
done
done