Skip to content

Commit

Permalink
Create system_specific_arcade_launching_images.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
meleu committed Jan 11, 2018
1 parent 461dfd7 commit 4df4800
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions system_specific_arcade_launching_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
function custom_arcade_launching_images() {
if [[ "$1" != "arcade" ]]; then
return
fi
local emulator="$2"
local rom_name="$(basename "$3")"
local rom_no_ext="${rom_name%.*}"
local arcade_imgs_dir="$HOME/RetroPie/roms/arcade/images"
local img_no_ext="$arcade_imgs_dir/$rom_no_ext"
local img
local config_dir="/opt/retropie/configs"
local system
local system_img_no_ext
local system_img
local ext

# checking if it's mame or fba emulator
if grep -q "^$emulator \?=" "$config_dir/mame/emulators.cfg"; then
system="mame"
elif grep -q "^$emulator \?=" "$config_dir/fba/emulators.cfg"; then
system="fba"
else
return 1 # system not found
fi

# checking if there's a launching image for the respective system
system_img_no_ext="$config_dir/$system/launching"
for ext in jpg png; do
if [[ -f "$system_img_no_ext.$ext" ]]; then
system_img="$system_img_no_ext.$ext"
break
fi
done
if [[ -z "$system_img" ]]; then
return
fi

# checking if the game already has a dedicated launching-image.
for ext in jpg png; do
if [[ -f "$img_no_ext.$ext" ]]; then
img="$img_no_ext.$ext"
break
fi
done
# if the image is not a symlink, then do not change it
if [[ -f "$img" && ! -L "$img" ]]; then
return
fi

# if the file doesn't exists OR is a symbolic link, then we can mess with it
rm -f "$img"

# avoiding duplicated launching images with different extensions
ext="${system_img##*.}"
case "$ext" in
jpg) rm -f "$img_no_ext.png" ;;
png) rm -f "$img_no_ext.jpg" ;;
esac

# Phew! We're finally ready to create the symbolic link!
ln -s "$system_img" "$img_no_ext.$ext"
}

custom_arcade_launching_images "$@"

0 comments on commit 4df4800

Please sign in to comment.