Advertisement
Guest User

runcommand-onstart.sh

a guest
Feb 7th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. function custom_arcade_launching_images() {
  2. if [[ "$1" != "arcade" ]]; then
  3. return
  4. fi
  5. local emulator="$2"
  6. local rom_name="$(basename "$3")"
  7. local rom_no_ext="${rom_name%.*}"
  8. local arcade_imgs_dir="$HOME/RetroPie/roms/arcade/images"
  9. local img_no_ext="$arcade_imgs_dir/$rom_no_ext"
  10. local img
  11. local config_dir="/opt/retropie/configs"
  12. local system
  13. local system_img_no_ext
  14. local system_img
  15. local ext
  16.  
  17. # checking if it's mame or fba emulator
  18. if grep -q "^$emulator \?=" "$config_dir/mame/emulators.cfg"; then
  19. system="mame"
  20. elif grep -q "^$emulator \?=" "$config_dir/fba/emulators.cfg"; then
  21. system="fba"
  22. else
  23. return 1 # system not found
  24. fi
  25.  
  26. # checking if there's a launching image for the respective system
  27. system_img_no_ext="$config_dir/$system/launching"
  28. for ext in jpg png; do
  29. if [[ -f "$system_img_no_ext.$ext" ]]; then
  30. system_img="$system_img_no_ext.$ext"
  31. break
  32. fi
  33. done
  34. if [[ -z "$system_img" ]]; then
  35. return
  36. fi
  37.  
  38. # checking if the game already has a dedicated launching-image.
  39. for ext in jpg png; do
  40. if [[ -f "$img_no_ext.$ext" ]]; then
  41. img="$img_no_ext.$ext"
  42. break
  43. fi
  44. done
  45. # if the image is not a symlink, then do not change it
  46. if [[ -f "$img" && ! -L "$img" ]]; then
  47. return
  48. fi
  49.  
  50. # if the file doesn't exists OR is a symbolic link, then we can mess with it
  51. rm -f "$img"
  52.  
  53. # avoiding duplicated launching images with different extensions
  54. ext="${system_img##*.}"
  55. case "$ext" in
  56. jpg) rm -f "$img_no_ext.png" ;;
  57. png) rm -f "$img_no_ext.jpg" ;;
  58. esac
  59.  
  60. # Phew! We're finally ready to create the symbolic link!
  61. ln -s "$system_img" "$img_no_ext.$ext"
  62. }
  63.  
  64. custom_arcade_launching_images "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement