#!/bin/bash ########################################################################### ## Copyright (C) Wizardry and Steamworks 2020 - License: GNU GPLv3 ## ## Please see: http://www.gnu.org/licenses/gpl.html for legal details, ## ## rights of fair usage, the disclaimer and warranty conditions. ## ########################################################################### ## The following is a short script meant to read a retroarch playlist ## ## and assign a default core for all ROMs previously scanned. ## ########################################################################### ## The script works on the principle that certain roms within ROM sets ## ## (ie: Goodset, No-Intro or MAME ROMs) work best with a specific core ## ## or core version and it is mostly impossible for retroarch to guess ## ## what core variant a certain ROM works with. ## ## ## ## A playlist generated by retroarch may contain set the "core_path" and ## ## "core_name" to "DETECT", indicating that the ROM will be ran with the ## ## best-guess core that retroarch can find. Then, assuming, for example, ## ## multiple MAME ROM sets stored on the drive in separate folders such ## ## as 2003+, 0.37b5 or FBA 0.2.97.42, this script can be used to set the ## ## "core_path" parameter to the core matching the folder names. ## ########################################################################### ## Requirements: ## ## * jq ## ## * Bourne Shell (pure POSIX will not work, ie: dash) ## ## Example invocation: ## ## $ cat MAME.lpl | ./coreMapper.sh >> MAME_mapped.lpl ## ########################################################################### ########################################################################### ## CONFIGURATION ## ########################################################################### # An array containing parts of paths in a retroarch playlist for which # cores should be assigned. PATH_MATCH=( "2003+" "FBA 0.2.97.42" "0.37b5" ) # A list of retroarch cores matching the path parts that must be set. ASSIGNED_CORE=( "/tmp/cores/mame2003_plus_libretro.so" "/tmp/cores/fbneo_libretro.so" "/tmp/cores/mame2003_plus_libretro.so" ) ASSIGNED_CORE_NAME=( "MAME 2003-Plus" "FinalBurn Neo" "MAME 2000 (0.37b5)" ) # Set the jq binary that should be used (default: jq-win64.exe for Windows) JQ="jq-win64.exe" ########################################################################### ## INTERNALS ## ########################################################################### # Grab STDIN (pine input) INPUT="$(< /dev/stdin)" # Split indices using IFS (without other tools). OIFS=$IFS IFS=" " INDICES=${!PATH_MATCH[*]} IFS=$OIFS # Perform all core substitutions based on the matching path part. JSON=$INPUT for i in $INDICES; do MATCH="${PATH_MATCH[$i]}" CORE="${ASSIGNED_CORE[$i]}" NAME="${ASSIGNED_CORE_NAME[$i]}" # Variable overloading without storing intermediary partial results. IFS="{}" read -d '' JSON <<< $(printf '%s' "$JSON" | \ $JQ " walk( if type == \"object\" and (.path | type == \"string\" and contains (\""$MATCH"\")) then (.core_path |= \""$CORE\"" | .core_name |= \""$NAME\"") else . end )") IFS=$OIFS done # Pretty print JSON result. echo $JSON | $JQ .