#!/bin/bash

## Este script copia las carpetas y ficheros necesarios desde skraper a es-de

## Variables
ES_DE_FOLDER=/sustancia/downloads/es-de
readonly ES_DE_FOLDER

DOWNLOADED_MEDIA_FOLDER="${ES_DE_FOLDER}"/.emulationstation/downloaded_media
readonly DOWNLOADED_MEDIA_FOLDER

GAMELIST_FOLDER="${ES_DE_FOLDER}"/.emulationstation/gamelists
readonly GAMELIST_FOLDER

SYSTEMS="3do ags amiga amiga1200 amiga600 amigacd32 amstradcpc android apple2 apple2gs arcade astrocde atari2600 atari5200 atari7800 atari800 atarijaguar atarijaguarcd atarilynx atarist atarixe atomiswave bbcmicro c64 cavestory cdimono1 cdtv chailove channelf coco colecovision cps daphne desktop doom dos dragon32 dreamcast easyrpg epic famicom fba fbneo fds flash fmtowns gameandwatch gamegear gb gba gbc gc genesis gx4000 intellivision j2me kodi lutris lutro macintosh mame mame-advmame mame-mame4all mastersystem megacd megacdjp megadrive megaduck mess model2 model3 moonlight moto msx msx1 msx2 msxturbor mugen multivision n3ds n64 n64dd naomi naomigd nds neogeo neogeocd neogeocdjp nes ngp ngpc odyssey2 openbor oric palm pc pc88 pc98 pcengine pcenginecd pcfx pico8 pokemini ports ps2 ps3 ps4 psp psvita psx samcoupe satellaview saturn saturnjp scummvm sega32x sega32xjp sega32xna segacd sfc sg-1000 sgb snes snesna solarus spectravideo steam stratagus sufami supergrafx supervision switch symbian tanodragon tg16 tg-cd ti99 tic80 to8 trs-80 uzebox vectrex vic20 videopac virtualboy wii wiiu wonderswan wonderswancolor x1 x68000 xbox xbox360 zmachine zx81 zxspectrum"
readonly SYSTEMS

for SYSTEM in ${SYSTEMS}; do
    ## Copy media folders
    if [ -d "${ES_DE_FOLDER}/ROMs/${SYSTEM}/media" ]; then
        if [ ! -d "${DOWNLOADED_MEDIA_FOLDER}/${SYSTEM}" ]; then
            mkdir -p "${DOWNLOADED_MEDIA_FOLDER}/${SYSTEM}"
        fi
        rsync -avh --delete "${ES_DE_FOLDER}/ROMs/${SYSTEM}/media/" "${DOWNLOADED_MEDIA_FOLDER}/${SYSTEM}/"
    fi

    ## Copy gamelist.xml
    if [ -f "${ES_DE_FOLDER}/ROMs/${SYSTEM}/gamelist.xml" ]; then
        if [ ! -d "${GAMELIST_FOLDER}/${SYSTEM}" ]; then
            mkdir -p "${GAMELIST_FOLDER}/${SYSTEM}"
        fi
        rsync -avh --delete "${ES_DE_FOLDER}/ROMs/${SYSTEM}/gamelist.xml" "${GAMELIST_FOLDER}/${SYSTEM}/"
    fi
done
