Launch emulator script

I completly forgotten to give the update I made… There it is :

#!/bin/bash
EMULATORS_ROOT_DIR="/home/cpi/apps/emulators"
FILE="$EMULATORS_ROOT_DIR/assoc.txt"
OUT="$EMULATORS_ROOT_DIR/out.txt"
ERRORS="$EMULATORS_ROOT_DIR/errors.txt"
ASSOC=0
RETROARCH_CORE=0
EMULATOR="null"
DIRECTORY="null"
GAMETORUN=$1
SYSTEM=$2
DEBUG=$3

# Check if there is already an association of game/emulator in file assoc.txt
while IFS=';' read game emulator directory
do
	if [ "$game" == "$1" ]; then
		ASSOC=1
		EMULATOR="$emulator"
		DIRECTORY="$directory"
	fi
done < $FILE

if [ "$DEBUG" == 1 ]; then
	echo "===========" >> $OUT 2>> $ERRORS
	echo "1 $SYSTEM" >> $OUT 2>> $ERRORS
	echo "2 $GAMETORUN" >> $OUT 2>> $ERRORS
	echo "3 $EMULATOR" >> $OUT 2>> $ERRORS
	echo "4 $DIRECTORY" >> $OUT 2>> $ERRORS
fi

# Find the extension of the rom, even if it's zipped
FILENAME=$(basename "$GAMETORUN")
EXTENSION="${FILENAME##*.}"
if [ "$EXTENSION" == "zip" ] && [ "$SYSTEM" != "cps" ] && [ "$SYSTEM" != "neogeo" ]; then
  TEMP=`zipinfo -1 "$GAMETORUN"`
  TEMP2=$(basename "$TEMP")
  EXTENSION="${TEMP2##*.}"
fi

if [ "$DEBUG" == 1 ]; then
	echo "5 $EXTENSION" >> $OUT 2>> $ERRORS
fi

#default emulators
if [ "$EMULATOR" == "null" ] && [ "$DIRECTORY" == "null" ]; then
	if [ "$DEBUG" == 1 ]; then
		echo "6 EMULATOR and DIRECTORY are null" >> $OUT 2>> $ERRORS
	fi
		
	if [ "$EXTENSION" == "gb" ] || [ "$EXTENSION" == "gbc" ]; then
		EMULATOR="ohboy"
		DIRECTORY="ohboy"
	elif [ "$EXTENSION" == "nes" ]; then
		EMULATOR="fceux"
		DIRECTORY="fceux"
	elif [ "$EXTENSION" == "smc" ] || [ "$EXTENSION" == "fig" ] || [ "$EXTENSION" == "sfc" ]; then
		EMULATOR="PocketSNES"
	elif [ "$EXTENSION" == "gba" ]; then
		EMULATOR="gpsp"
		DIRECTORY="gpsp"
	elif [ "$EXTENSION" == "gg" ]; then
		EMULATOR="genesis_plus_gx_libretro.so"
	elif [ "$EXTENSION" == "ngc" ]; then
		EMULATOR="mednafen_ngp_libretro.so"
	elif [ "$EXTENSION" == "cue" ]; then
		EMULATOR="pcsx_rearmed_libretro.so"
	elif [ "$EXTENSION" == "smd" ] || [ "$EXTENSION" == "bin" ] || [ "$EXTENSION" == "md" ]; then
		EMULATOR="PicoDrive"
		DIRECTORY="PicoDrive"
	elif [ "$EXTENSION" == "zip" ]; then
		if [ "$SYSTEM" == "cps" ]; then
			EMULATOR="fbneo_libretro.so"
		elif [ "$SYSTEM" == "neogeo" ]; then
			EMULATOR="fbalpha2012_neogeo_libretro.so"
		fi
	elif [ "$EXTENSION" == "pce" ]; then
		EMULATOR="mednafen_pce_fast_libretro.so"
	fi
fi

if [ "$DEBUG" == 1 ]; then
	echo "7 $EMULATOR" >> $OUT 2>> $ERRORS
	echo "8 $DIRECTORY" >> $OUT 2>> $ERRORS
fi

# Find the extension of the emulator to determine if it's retroarch or not
FILENAME_EMU=$(basename "$EMULATOR")
EXTENSION_EMU="${FILENAME_EMU##*.}"
if [ "$EXTENSION_EMU" == "so" ]; then
  RETROARCH_CORE=1
fi


# if we didn't find a line in the assoc file we create it with the selected core
if [ "$ASSOC" == 0 ] && [ "$EMULATOR" != "null" ]; then
	if [ "$DIRECTORY" == "null" ]; then
		echo "$GAMETORUN;$EMULATOR" >> $FILE
	else
		echo "$GAMETORUN;$EMULATOR;$DIRECTORY" >> $FILE
	fi
fi

# launch the game
if [ "$RETROARCH_CORE" == 1 ]; then
	retroarch -L ~/apps/emulators/"$EMULATOR" "$GAMETORUN" >> $OUT 2>> $ERRORS
else
	cd ~/apps/emulators/"$DIRECTORY"

	./"$EMULATOR" "$GAMETORUN" >> $OUT 2>> $ERRORS
fi

if [ "$DEBUG" == 1 ]; then
	echo "===========" >> $OUT 2>> $ERRORS
fi

exit
1 Like