mirror of
https://github.com/RetroDECK/RetroDECK.git
synced 2025-02-16 11:25:39 +00:00
RUN_GAME: adding %INJECT% logic
This commit is contained in:
parent
21984292c0
commit
c4a80119af
|
@ -900,7 +900,7 @@ find_emulator() {
|
||||||
emulator_section=$(xmllint --xpath "//emulator[@name='$emulator_name']" "/app/share/es-de/resources/systems/linux/es_find_rules.xml" 2>/dev/null)
|
emulator_section=$(xmllint --xpath "//emulator[@name='$emulator_name']" "/app/share/es-de/resources/systems/linux/es_find_rules.xml" 2>/dev/null)
|
||||||
|
|
||||||
if [ -z "$emulator_section" ]; then
|
if [ -z "$emulator_section" ]; then
|
||||||
echo "Emulator not found: $emulator_name"
|
log e "Emulator not found: $emulator_name"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -925,16 +925,16 @@ find_emulator() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$found_path" ]; then
|
if [ -z "$found_path" ]; then
|
||||||
echo "No valid path found for emulator: $emulator_name"
|
log e "No valid path found for emulator: $emulator_name"
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
|
log d "Found emulator: \"$found_path\""
|
||||||
echo "$found_path"
|
echo "$found_path"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# TODO: %INJECT% is not yet working (Dolphin, rpcs3, vita3k)
|
|
||||||
# TODO: add the logic of alt emulator and default emulator
|
# TODO: add the logic of alt emulator and default emulator
|
||||||
|
|
||||||
run_game() {
|
run_game() {
|
||||||
|
@ -943,7 +943,7 @@ run_game() {
|
||||||
emulator=""
|
emulator=""
|
||||||
system=""
|
system=""
|
||||||
|
|
||||||
# Percorso al file XML es_systems.xml
|
# Path to the es_systems.xml file
|
||||||
xml_file="/app/share/es-de/resources/systems/linux/es_systems.xml"
|
xml_file="/app/share/es-de/resources/systems/linux/es_systems.xml"
|
||||||
|
|
||||||
# Parse options
|
# Parse options
|
||||||
|
@ -977,42 +977,68 @@ run_game() {
|
||||||
system=$(echo "$game" | grep -oP '(?<=roms/)[^/]+')
|
system=$(echo "$game" | grep -oP '(?<=roms/)[^/]+')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Funzione per sostituire i placeholder
|
log d "Game: \"$game\""
|
||||||
|
log d "System: \"$system\""
|
||||||
|
|
||||||
|
# Function to handle the %INJECT% placeholder
|
||||||
|
handle_inject_placeholder() {
|
||||||
|
local cmd="$1"
|
||||||
|
|
||||||
|
# Check if .esprefix file exists
|
||||||
|
local inject_file="${game}.esprefix"
|
||||||
|
|
||||||
|
log d "Checking if \"${game}.esprefix\" exists"
|
||||||
|
|
||||||
|
if [[ ! -f "$inject_file" ]]; then
|
||||||
|
# If the inject file does not exist, strip all forms of %INJECT% from the command
|
||||||
|
|
||||||
|
log d "\"${game}.esprefix\" not existing"
|
||||||
|
|
||||||
|
# This handles cases where %INJECT% might be in different forms:
|
||||||
|
# Strip %INJECT%="value", %INJECT%="", or just %INJECT%=
|
||||||
|
cmd="${cmd//%INJECT%=\"*\"/}"
|
||||||
|
cmd="${cmd//%INJECT%=/}"
|
||||||
|
cmd="${cmd//%INJECT%/}"
|
||||||
|
|
||||||
|
cmd="${cmd//%BASENAME%.esprefix=\"*\"/}"
|
||||||
|
cmd="${cmd//%BASENAME%.esprefix=/}"
|
||||||
|
cmd="${cmd//%BASENAME%.esprefix/}"
|
||||||
|
|
||||||
|
log d "Returning the following command:$cmd"
|
||||||
|
|
||||||
|
echo "$cmd"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If the .esprefix file exists, process its content
|
||||||
|
inject_content=$(head -c 4096 "$inject_file")
|
||||||
|
log i ".esprefix file found, injecting \"$inject_content\""
|
||||||
|
cmd="${cmd//%INJECT%=\"$inject_file\"/$inject_content}"
|
||||||
|
echo "$cmd"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Function to substitute the placeholders
|
||||||
substitute_placeholders() {
|
substitute_placeholders() {
|
||||||
local cmd="$1"
|
local cmd="$1"
|
||||||
local rom_path="$game"
|
local rom_path="$game"
|
||||||
local rom_dir=$(dirname "$rom_path")
|
local rom_dir=$(dirname "$rom_path")
|
||||||
local base_name=$(basename "$rom_path" .ext)
|
local base_name=$(basename "$rom_path" .psvita) # Ensure the .psvita extension is stripped
|
||||||
local file_name=$(basename "$rom_path")
|
local file_name=$(basename "$rom_path")
|
||||||
local rom_raw="$rom_path"
|
local rom_raw="$rom_path"
|
||||||
local rom_dir_raw="$rom_dir"
|
local rom_dir_raw="$rom_dir"
|
||||||
local es_path="/path/dell/emulatore"
|
local es_path=""
|
||||||
local emulator_path="/path/dell/emulatore/bin"
|
local emulator_path=""
|
||||||
|
|
||||||
# Function to replace %EMULATOR_SOMETHING% with the actual path of the emulator
|
# Handle %INJECT% placeholder if present
|
||||||
replace_emulator_placeholder() {
|
cmd=$(handle_inject_placeholder "$cmd")
|
||||||
local placeholder=$1
|
|
||||||
local emulator_name=${placeholder//"%EMULATOR_"/} # Extract emulator name from placeholder
|
|
||||||
emulator_name=${emulator_name//"%"/} # Remove the ending "%"
|
|
||||||
local emulator_exec=$(find_emulator "$emulator_name")
|
|
||||||
|
|
||||||
if [[ -z "$emulator_exec" ]]; then
|
|
||||||
echo "Error: Emulator '$emulator_name' not found."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$emulator_exec"
|
# Substitute emulator path
|
||||||
}
|
|
||||||
|
|
||||||
# Use sed to find %EMULATOR_*% and replace with actual emulator executable by calling find_emulator
|
|
||||||
cmd=$(echo "$cmd" | sed -r 's/%EMULATOR_[A-Z0-9_]+%/$(replace_emulator_placeholder "&")/g')
|
cmd=$(echo "$cmd" | sed -r 's/%EMULATOR_[A-Z0-9_]+%/$(replace_emulator_placeholder "&")/g')
|
||||||
|
|
||||||
# Sourcing the emulator command to ensure immediate execution of placeholders
|
# Ensure that paths with spaces are properly quoted and substitute other placeholders
|
||||||
cmd=$(eval echo "$cmd")
|
|
||||||
|
|
||||||
# Ensure that paths with spaces are properly quoted
|
|
||||||
cmd="${cmd//"%ROM%"/"\"$rom_path\""}"
|
cmd="${cmd//"%ROM%"/"\"$rom_path\""}"
|
||||||
cmd="${cmd//"%BASENAME%"/"\"$base_name\""}"
|
cmd="${cmd//"%BASENAME%"/"\"$base_name\""}" # Proper base name without extra .psvita
|
||||||
cmd="${cmd//"%FILENAME%"/"\"$file_name\""}"
|
cmd="${cmd//"%FILENAME%"/"\"$file_name\""}"
|
||||||
cmd="${cmd//"%ROMRAW%"/"\"$rom_raw\""}"
|
cmd="${cmd//"%ROMRAW%"/"\"$rom_raw\""}"
|
||||||
cmd="${cmd//"%ROMPATH%"/"\"$rom_dir\""}"
|
cmd="${cmd//"%ROMPATH%"/"\"$rom_dir\""}"
|
||||||
|
@ -1020,55 +1046,55 @@ run_game() {
|
||||||
cmd="${cmd//"%EMUDIR%"/"\"$emulator_path\""}"
|
cmd="${cmd//"%EMUDIR%"/"\"$emulator_path\""}"
|
||||||
cmd="${cmd//"%GAMEDIR%"/"\"$rom_dir\""}"
|
cmd="${cmd//"%GAMEDIR%"/"\"$rom_dir\""}"
|
||||||
cmd="${cmd//"%GAMEDIRRAW%"/"\"$rom_dir_raw\""}"
|
cmd="${cmd//"%GAMEDIRRAW%"/"\"$rom_dir_raw\""}"
|
||||||
cmd="${cmd//"%CORE_RETROARCH%"/"\"/var/config/retroarch/cores\""}"
|
cmd="${cmd//"%CORE_RETROARCH%"/"/var/config/retroarch/cores"}"
|
||||||
|
|
||||||
|
log d "Final command: $cmd" # Log the final command for debugging
|
||||||
echo "$cmd"
|
echo "$cmd"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Extracting the commands from es_systems.xml for the selected system
|
||||||
|
find_system_commands() {
|
||||||
|
local system_name=$system
|
||||||
|
# Use xmllint to extract the system commands from the XML
|
||||||
|
system_section=$(xmllint --xpath "//system[name='$system_name']" "$xml_file" 2>/dev/null)
|
||||||
|
|
||||||
|
if [ -z "$system_section" ]; then
|
||||||
|
log e "System not found: $system_name"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Estrazione dei comandi da es_systems.xml per il sistema selezionato
|
# Extract commands and labels
|
||||||
find_system_commands() {
|
commands=$(echo "$system_section" | xmllint --xpath "//command" - 2>/dev/null)
|
||||||
local system_name=$system
|
|
||||||
# Use xmllint to extract the system commands from the XML
|
|
||||||
system_section=$(xmllint --xpath "//system[name='$system_name']" "$xml_file" 2>/dev/null)
|
|
||||||
|
|
||||||
if [ -z "$system_section" ]; then
|
|
||||||
echo "System not found: $system_name"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Extract commands and labels
|
# Prepare Zenity command list
|
||||||
commands=$(echo "$system_section" | xmllint --xpath "//command" - 2>/dev/null)
|
command_list=()
|
||||||
|
while IFS= read -r line; do
|
||||||
|
label=$(echo "$line" | sed -n 's/.*label="\([^"]*\)".*/\1/p')
|
||||||
|
command=$(echo "$line" | sed -n 's/.*<command[^>]*>\(.*\)<\/command>.*/\1/p')
|
||||||
|
|
||||||
|
# Substitute placeholders in the command
|
||||||
|
command=$(substitute_placeholders "$command")
|
||||||
|
|
||||||
|
# Add label and command to Zenity list (label first, command second)
|
||||||
|
command_list+=("$label" "$command")
|
||||||
|
done <<< "$commands"
|
||||||
|
|
||||||
# Prepare Zenity command list
|
# Show the list with Zenity and return the **command** (second column) selected
|
||||||
command_list=()
|
selected_command=$(zenity --list \
|
||||||
while IFS= read -r line; do
|
--title="Select an emulator for $system_name" \
|
||||||
label=$(echo "$line" | sed -n 's/.*label="\([^"]*\)".*/\1/p')
|
--column="Emulator" --column="Hidden Command" "${command_list[@]}" \
|
||||||
command=$(echo "$line" | sed -n 's/.*<command[^>]*>\(.*\)<\/command>.*/\1/p')
|
--width=800 --height=400 --print-column=2 --hide-column=2)
|
||||||
|
|
||||||
# Substitute placeholders in the command
|
|
||||||
command=$(substitute_placeholders "$command")
|
|
||||||
|
|
||||||
# Add label and command to Zenity list (label first, command second)
|
|
||||||
command_list+=("$label" "$command")
|
|
||||||
done <<< "$commands"
|
|
||||||
|
|
||||||
# Show the list with Zenity and return the **command** (second column) selected
|
echo "$selected_command"
|
||||||
selected_command=$(zenity --list \
|
}
|
||||||
--title="Select an emulator for $system_name" \
|
|
||||||
--column="Emulator" --column="Hidden Command" "${command_list[@]}" \
|
|
||||||
--width=800 --height=400 --print-column=2 --hide-column=2)
|
|
||||||
|
|
||||||
echo "$selected_command"
|
# If the emulator is not specified, ask the user to select it or get it from the XML file
|
||||||
}
|
|
||||||
|
|
||||||
# Se l'emulatore non è specificato, chiedi all'utente di selezionarlo o prendilo dal file XML
|
|
||||||
if [[ -z "$emulator" ]]; then
|
if [[ -z "$emulator" ]]; then
|
||||||
emulator=$(find_system_commands)
|
emulator=$(find_system_commands)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$emulator" ]]; then
|
if [[ -n "$emulator" ]]; then
|
||||||
log d "Running selected emulator: $emulator"
|
log d "Running: $emulator"
|
||||||
eval "$emulator"
|
eval "$emulator"
|
||||||
else
|
else
|
||||||
log e "No emulator found or selected. Exiting."
|
log e "No emulator found or selected. Exiting."
|
||||||
|
|
Loading…
Reference in a new issue