#!/bin/bash
function help_message() {
    echo "$USAGE"
    echo
    echo "Where [SYSTEMS] are:"
    for WORD in $SYSTEMS; do
        echo -e "\t$WORD"
    done
}

readonly USAGE="
USAGE:
$(basename "$0") [ROM_FOLDER] [THUMBNAILS_FOLDER]"

# check if there are all the parameters
if [ "$#" -ne 2 ]; then
    help_message
    exit 0
fi

if ! test -d "${ROM_FOLDER}"/"${SYSTEM}"; then
    echo "${ROM_FOLDER}"/"${SYSTEM}" does not exists
    exit 0
fi

readonly ROM_FOLDER="$1"
readonly THUMBNAILS_FOLDER="$2"
readonly SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
readonly SYSTEMS="pcenginecd 3do 3ds amiga amstradcpc apple2 arcade arcadia astrocde atari800 atari2600 atari5200 atari7800 atarijaguar atarilynx atarist c16 c64 c128 coco coleco daphne dragon32 dreamcast fba fds gameandwatch gamegear gb gba gbc gc genesis intellivision mame-advmame mame-libretro mame-mame4all mastersystem megacd megadrive msx n64 nds neogeo nes ngp ngpc oric pc pc88 pc98 pcfx pcengine pokemini ports ps2 psp psx saturn scummvm sega32x segacd sg-1000 snes steam ti99 trs-80 vectrex vic20 videopac virtualboy wii wonderswan wonderswancolor x68000 x1 zmachine zx81 zxspectrum"

for SYSTEM in $SYSTEMS; do
    "${SCRIPT_DIR}"/create_retroarch_thumbnails.sh "${SYSTEM}" "${ROM_FOLDER}" "${THUMBNAILS_FOLDER}"
done
