From e2ef2e8823b9eee29025e51de6b428860936b71b Mon Sep 17 00:00:00 2001 From: XargonWan Date: Tue, 10 Sep 2024 18:41:40 +0900 Subject: [PATCH 01/13] RUN_GAME: now it's scraping the commands from es_systems and es_find_rules --- functions/other_functions.sh | 201 ++++++++++++++++++++++------------- 1 file changed, 128 insertions(+), 73 deletions(-) diff --git a/functions/other_functions.sh b/functions/other_functions.sh index 53ebf2d4..7b6fe033 100644 --- a/functions/other_functions.sh +++ b/functions/other_functions.sh @@ -892,12 +892,56 @@ start_retrodeck() { es-de } +find_emulator() { + local emulator_name=$1 + local found_path="" + + # Search the es_find_rules.xml file for the emulator + 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 + echo "Emulator not found: $emulator_name" + return 1 + fi + + # Search systempath entries + while IFS= read -r line; do + command_path=$(echo "$line" | sed -n 's/.*\(.*\)<\/entry>.*/\1/p') + if [ -x "$(command -v $command_path)" ]; then + found_path=$command_path + break + fi + done <<< "$(echo "$emulator_section" | xmllint --xpath "//rule[@type='systempath']/entry" - 2>/dev/null)" + + # If not found, search staticpath entries + if [ -z "$found_path" ]; then + while IFS= read -r line; do + command_path=$(eval echo "$line" | sed -n 's/.*\(.*\)<\/entry>.*/\1/p') + if [ -x "$command_path" ]; then + found_path=$command_path + break + fi + done <<< "$(echo "$emulator_section" | xmllint --xpath "//rule[@type='staticpath']/entry" - 2>/dev/null)" + fi + + if [ -z "$found_path" ]; then + echo "No valid path found for emulator: $emulator_name" + return 1 + else + echo "$found_path" + return 0 + fi +} + run_game() { # Initialize variables emulator="" system="" + # Percorso al file XML es_systems.xml + xml_file="/app/share/es-de/resources/systems/linux/es_systems.xml" + # Parse options while getopts ":e:s:" opt; do case ${opt} in @@ -929,87 +973,98 @@ run_game() { system=$(echo "$game" | grep -oP '(?<=roms/)[^/]+') fi - log d "Emulator: $emulator" - log d "System: $system" - log d "Game: $game" + # Funzione per sostituire i placeholder + substitute_placeholders() { + local cmd="$1" + local rom_path="$game" + local rom_dir=$(dirname "$rom_path") + local base_name=$(basename "$rom_path" .ext) + local file_name=$(basename "$rom_path") + local rom_raw="$rom_path" + local rom_dir_raw="$rom_dir" + local es_path="/path/dell/emulatore" + local emulator_path="/path/dell/emulatore/bin" - # Query the features JSON for emulators that support the system - local emulators=$(jq -r --arg system "$system" ' - .emulator | to_entries[] | - select( - (.value.system == $system) or - (.value.system[]? == $system) - ) | .key' "$features") + # Function to replace %EMULATOR_SOMETHING% with the actual path of the emulator + replace_emulator_placeholder() { + 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 - # Check if the system is handled by RetroArch cores - local retroarch_cores=$(jq -r --arg system "$system" ' - .emulator.retroarch.cores | to_entries[] | - select( - .value.system == $system or - (.value.system[]? == $system) - ) | .key' "$features") + echo "$emulator_exec" + } - # if the emulator is given and it's a retroarch core just execute it - if [[ "$emulator" == *"_libretro" ]]; then - local core_path="/var/config/retroarch/cores/$emulator.so" - log d "Running RetroArch core: $core_path" - log d "Command: retroarch -L $core_path \"$game\"" - eval "retroarch -L $core_path \"$game\"" - return 1 - fi + # 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') - # If the system is handled by RetroArch cores, add them to the list of emulators - if [[ -n "$retroarch_cores" ]]; then - emulators=$(echo -e "$emulators\n$retroarch_cores") - fi + # Sourcing the emulator command to ensure immediate execution of placeholders + cmd=$(eval echo "$cmd") - local pretty_system=$(jq -r --arg system "$system" '.system[$system].name' "$features") + # Ensure that paths with spaces are properly quoted + cmd="${cmd//"%ROM%"/"\"$rom_path\""}" + cmd="${cmd//"%BASENAME%"/"\"$base_name\""}" + cmd="${cmd//"%FILENAME%"/"\"$file_name\""}" + cmd="${cmd//"%ROMRAW%"/"\"$rom_raw\""}" + cmd="${cmd//"%ROMPATH%"/"\"$rom_dir\""}" + cmd="${cmd//"%ESPATH%"/"\"$es_path\""}" + cmd="${cmd//"%EMUDIR%"/"\"$emulator_path\""}" + cmd="${cmd//"%GAMEDIR%"/"\"$rom_dir\""}" + cmd="${cmd//"%GAMEDIRRAW%"/"\"$rom_dir_raw\""}" + cmd="${cmd//"%CORE_RETROARCH%"/"\"/var/config/retroarch/cores\""}" - # Check if multiple emulators are found and prompt the user to select one with zenity - if [[ $(echo "$emulators" | wc -l) -gt 1 ]]; then - emulator=$(echo "$emulators" | zenity --list --title="Select Emulator" --text="Multiple emulators found for $pretty_system. Select one to run." --column="Emulator") - else - emulator="$emulators" - fi + echo "$cmd" +} - # If no emulator was selected, exit - if [[ -z "$emulator" ]]; then - log e "No emulator selected. Exiting." - return 1 - fi - log d "Run game: selected emulator $emulator" - - # Handle RetroArch core separately - if [[ "$emulator" == *"_libretro" ]]; then - local core_path="/var/config/retroarch/cores/$emulator.so" - log d "Running RetroArch core: $core_path" - log d "Command: retroarch -L $core_path \"$game\"" - eval "retroarch -L $core_path \"$game\"" - else - # Check if launch-override exists - local launch_override=$(jq -r ".emulator.$emulator.\"launch-override\"" "$features") - if [[ "$launch_override" != "null" ]]; then - # Use launch-override - launch_override=${launch_override//\$game/\"$game\"} - log d "Using launch-override: $launch_override" - eval "$launch_override" - else - # Use standard launch and launch-args - local launch_command=$(jq -r ".emulator.$emulator.launch" "$features") - local launch_args=$(jq -r ".emulator.$emulator.\"launch-args\"" "$features") - log d "launch args: $launch_args" - - # Only add launch_args if they are not null - if [[ "$launch_args" != "null" ]]; then - # Replace $game in launch_args with the actual game path, quoting it to handle spaces - launch_args=${launch_args//\$game/\"$game\"} - log d "Command: \"$launch_command $launch_args\"" - eval "$launch_command $launch_args" - else - log d "Command: \"$launch_command\"" - eval "$launch_command \"$game\"" - fi + # Estrazione dei comandi da es_systems.xml per il sistema selezionato +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 + echo "System not found: $system_name" + exit 1 fi + + # Extract commands and labels + commands=$(echo "$system_section" | xmllint --xpath "//command" - 2>/dev/null) + + # Prepare Zenity command list + command_list=() + while IFS= read -r line; do + label=$(echo "$line" | sed -n 's/.*label="\([^"]*\)".*/\1/p') + command=$(echo "$line" | sed -n 's/.*]*>\(.*\)<\/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" + + # Show the list with Zenity and return the **command** (second column) selected + selected_command=$(zenity --list --title="Select an emulator for $system_name" --column="Emulator" --column="Command" "${command_list[@]}" --width=800 --height=400 --print-column=2) + + echo "$selected_command" +} + + # Se l'emulatore non è specificato, chiedi all'utente di selezionarlo o prendilo dal file XML + if [[ -z "$emulator" ]]; then + emulator=$(find_system_commands) + fi + + if [[ -n "$emulator" ]]; then + log d "Running selected emulator: $emulator" + eval "$emulator" + else + log e "No emulator found or selected. Exiting." + return 1 fi } \ No newline at end of file From 21984292c0c7e024b07e5718dfd5468ae7f9f6d0 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Tue, 10 Sep 2024 20:41:54 +0900 Subject: [PATCH 02/13] RUN_GAME: hiding full commands in zenity list --- functions/other_functions.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/functions/other_functions.sh b/functions/other_functions.sh index 7b6fe033..8543f5bd 100644 --- a/functions/other_functions.sh +++ b/functions/other_functions.sh @@ -933,6 +933,10 @@ find_emulator() { fi } + +# TODO: %INJECT% is not yet working (Dolphin, rpcs3, vita3k) +# TODO: add the logic of alt emulator and default emulator + run_game() { # Initialize variables @@ -1050,7 +1054,10 @@ find_system_commands() { done <<< "$commands" # Show the list with Zenity and return the **command** (second column) selected - selected_command=$(zenity --list --title="Select an emulator for $system_name" --column="Emulator" --column="Command" "${command_list[@]}" --width=800 --height=400 --print-column=2) + 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" } From c4a80119af93afc101c756c6fe2104f3a582d8b7 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Tue, 10 Sep 2024 21:36:28 +0900 Subject: [PATCH 03/13] RUN_GAME: adding %INJECT% logic --- functions/other_functions.sh | 152 ++++++++++++++++++++--------------- 1 file changed, 89 insertions(+), 63 deletions(-) diff --git a/functions/other_functions.sh b/functions/other_functions.sh index 8543f5bd..6dc58a4c 100644 --- a/functions/other_functions.sh +++ b/functions/other_functions.sh @@ -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) if [ -z "$emulator_section" ]; then - echo "Emulator not found: $emulator_name" + log e "Emulator not found: $emulator_name" return 1 fi @@ -925,16 +925,16 @@ find_emulator() { fi 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 else + log d "Found emulator: \"$found_path\"" echo "$found_path" return 0 fi } -# TODO: %INJECT% is not yet working (Dolphin, rpcs3, vita3k) # TODO: add the logic of alt emulator and default emulator run_game() { @@ -943,7 +943,7 @@ run_game() { emulator="" 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" # Parse options @@ -977,42 +977,68 @@ run_game() { system=$(echo "$game" | grep -oP '(?<=roms/)[^/]+') 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() { local cmd="$1" local rom_path="$game" 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 rom_raw="$rom_path" local rom_dir_raw="$rom_dir" - local es_path="/path/dell/emulatore" - local emulator_path="/path/dell/emulatore/bin" + local es_path="" + local emulator_path="" - # Function to replace %EMULATOR_SOMETHING% with the actual path of the emulator - replace_emulator_placeholder() { - 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 + # Handle %INJECT% placeholder if present + cmd=$(handle_inject_placeholder "$cmd") - echo "$emulator_exec" - } - - # Use sed to find %EMULATOR_*% and replace with actual emulator executable by calling find_emulator + # Substitute emulator path cmd=$(echo "$cmd" | sed -r 's/%EMULATOR_[A-Z0-9_]+%/$(replace_emulator_placeholder "&")/g') - # Sourcing the emulator command to ensure immediate execution of placeholders - cmd=$(eval echo "$cmd") - - # Ensure that paths with spaces are properly quoted + # Ensure that paths with spaces are properly quoted and substitute other placeholders 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//"%ROMRAW%"/"\"$rom_raw\""}" cmd="${cmd//"%ROMPATH%"/"\"$rom_dir\""}" @@ -1020,55 +1046,55 @@ run_game() { cmd="${cmd//"%EMUDIR%"/"\"$emulator_path\""}" cmd="${cmd//"%GAMEDIR%"/"\"$rom_dir\""}" 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" } + # 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 -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 - echo "System not found: $system_name" - exit 1 - fi + # Extract commands and labels + commands=$(echo "$system_section" | xmllint --xpath "//command" - 2>/dev/null) - # Extract commands and labels - commands=$(echo "$system_section" | xmllint --xpath "//command" - 2>/dev/null) + # Prepare Zenity command list + command_list=() + while IFS= read -r line; do + label=$(echo "$line" | sed -n 's/.*label="\([^"]*\)".*/\1/p') + command=$(echo "$line" | sed -n 's/.*]*>\(.*\)<\/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 - command_list=() - while IFS= read -r line; do - label=$(echo "$line" | sed -n 's/.*label="\([^"]*\)".*/\1/p') - command=$(echo "$line" | sed -n 's/.*]*>\(.*\)<\/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" + # Show the list with Zenity and return the **command** (second column) selected + 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) - # Show the list with Zenity and return the **command** (second column) selected - 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" + } - echo "$selected_command" -} - - # Se l'emulatore non è specificato, chiedi all'utente di selezionarlo o prendilo dal file XML + # If the emulator is not specified, ask the user to select it or get it from the XML file if [[ -z "$emulator" ]]; then emulator=$(find_system_commands) fi if [[ -n "$emulator" ]]; then - log d "Running selected emulator: $emulator" + log d "Running: $emulator" eval "$emulator" else log e "No emulator found or selected. Exiting." From 38806dabc1d1d5ec52bfe344aeaa225ead54588a Mon Sep 17 00:00:00 2001 From: XargonWan Date: Tue, 10 Sep 2024 22:13:26 +0900 Subject: [PATCH 04/13] RUN_GAME: working but looping --- functions/other_functions.sh | 183 +++++++++++++++++++---------------- 1 file changed, 102 insertions(+), 81 deletions(-) diff --git a/functions/other_functions.sh b/functions/other_functions.sh index 6dc58a4c..2330dcb5 100644 --- a/functions/other_functions.sh +++ b/functions/other_functions.sh @@ -936,6 +936,7 @@ find_emulator() { # TODO: add the logic of alt emulator and default emulator +# TODO: if the emulator is only one just skip the zenity and run it run_game() { @@ -983,109 +984,129 @@ run_game() { # 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" + # Find all occurrences of %INJECT%=something + while [[ "$cmd" =~ %INJECT%=(.*) ]]; do + inject_file="${BASH_REMATCH[1]}" # Extract the file name - # 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%/}" + # Prepend the directory path to ensure we have the full path to the file + inject_file_full_path="$rom_dir/$inject_file" - cmd="${cmd//%BASENAME%.esprefix=\"*\"/}" - cmd="${cmd//%BASENAME%.esprefix=/}" - cmd="${cmd//%BASENAME%.esprefix/}" + log d "Found %INJECT% pointing to file \"$inject_file_full_path\"" - log d "Returning the following command:$cmd" - - echo "$cmd" - return - fi + # Check if the file exists + if [[ -f "$inject_file_full_path" ]]; then + # Read the content of the file + inject_content=$(cat "$inject_file_full_path") + log i "File \"$inject_file_full_path\" found, injecting content \"$inject_content\"" + + # Replace the %INJECT% placeholder with the content of the file + cmd="${cmd//%INJECT%=$inject_file/$inject_content}" + else + log e "File \"$inject_file_full_path\" not found. Removing %INJECT% placeholder." + # If the file does not exist, just remove the placeholder + cmd="${cmd//%INJECT%=$inject_file/}" + fi + done - # 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}" + log d "Returning the command with injected content: $cmd" echo "$cmd" } +# Function to replace %EMULATOR_SOMETHING% with the actual path of the emulator +replace_emulator_placeholder() { + local placeholder=$1 + # Extract emulator name from placeholder without changing case + local emulator_name="${placeholder//"%EMULATOR_"/}" # Extract emulator name after %EMULATOR_ + emulator_name="${emulator_name//"%"/}" # Remove the trailing % + + # Use the find_emulator function to get the emulator path using the correct casing + local emulator_exec=$(find_emulator "$emulator_name") + + if [[ -z "$emulator_exec" ]]; then + log e "Emulator '$emulator_name' not found." + exit 1 + fi + echo "$emulator_exec" +} # Function to substitute the placeholders substitute_placeholders() { - local cmd="$1" - local rom_path="$game" - local rom_dir=$(dirname "$rom_path") - local base_name=$(basename "$rom_path" .psvita) # Ensure the .psvita extension is stripped - local file_name=$(basename "$rom_path") - local rom_raw="$rom_path" - local rom_dir_raw="$rom_dir" - local es_path="" - local emulator_path="" + local cmd="$1" + local rom_path="$game" + local rom_dir=$(dirname "$rom_path") + + # Strip all file extensions from the base name + local base_name=$(basename "$rom_path") + base_name="${base_name%%.*}" - # Handle %INJECT% placeholder if present - cmd=$(handle_inject_placeholder "$cmd") + local file_name=$(basename "$rom_path") + local rom_raw="$rom_path" + local rom_dir_raw="$rom_dir" + local es_path="" + local emulator_path="" - # Substitute emulator path - cmd=$(echo "$cmd" | sed -r 's/%EMULATOR_[A-Z0-9_]+%/$(replace_emulator_placeholder "&")/g') + # Manually replace %EMULATOR_*% placeholders + while [[ "$cmd" =~ (%EMULATOR_[A-Z0-9_]+%) ]]; do + placeholder="${BASH_REMATCH[1]}" + emulator_path=$(replace_emulator_placeholder "$placeholder") + cmd="${cmd//$placeholder/$emulator_path}" + done - # Ensure that paths with spaces are properly quoted and substitute other placeholders - cmd="${cmd//"%ROM%"/"\"$rom_path\""}" - cmd="${cmd//"%BASENAME%"/"\"$base_name\""}" # Proper base name without extra .psvita - cmd="${cmd//"%FILENAME%"/"\"$file_name\""}" - cmd="${cmd//"%ROMRAW%"/"\"$rom_raw\""}" - cmd="${cmd//"%ROMPATH%"/"\"$rom_dir\""}" - cmd="${cmd//"%ESPATH%"/"\"$es_path\""}" - cmd="${cmd//"%EMUDIR%"/"\"$emulator_path\""}" - cmd="${cmd//"%GAMEDIR%"/"\"$rom_dir\""}" - cmd="${cmd//"%GAMEDIRRAW%"/"\"$rom_dir_raw\""}" - cmd="${cmd//"%CORE_RETROARCH%"/"/var/config/retroarch/cores"}" + # Substitute %BASENAME% and other placeholders + cmd="${cmd//"%BASENAME%"/"$base_name"}" + cmd="${cmd//"%FILENAME%"/"$file_name"}" + cmd="${cmd//"%ROMRAW%"/"$rom_raw"}" + cmd="${cmd//"%ROMPATH%"/"$rom_dir"}" + + # Ensure paths are quoted correctly + cmd="${cmd//"%ROM%"/"\"$rom_path\""}" + cmd="${cmd//"%GAMEDIR%"/"\"$rom_dir\""}" + cmd="${cmd//"%GAMEDIRRAW%"/"\"$rom_dir_raw\""}" + cmd="${cmd//"%CORE_RETROARCH%"/"/var/config/retroarch/cores"}" - log d "Final command: $cmd" # Log the final command for debugging - echo "$cmd" -} + log d "Command after %BASENAME% and other substitutions: $cmd" + + # Now handle %INJECT% after %BASENAME% has been substituted + cmd=$(handle_inject_placeholder "$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 + 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 - # Extract commands and labels - commands=$(echo "$system_section" | xmllint --xpath "//command" - 2>/dev/null) + # Extract commands and labels + commands=$(echo "$system_section" | xmllint --xpath "//command" - 2>/dev/null) - # Prepare Zenity command list - command_list=() - while IFS= read -r line; do - label=$(echo "$line" | sed -n 's/.*label="\([^"]*\)".*/\1/p') - command=$(echo "$line" | sed -n 's/.*]*>\(.*\)<\/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 + command_list=() + while IFS= read -r line; do + label=$(echo "$line" | sed -n 's/.*label="\([^"]*\)".*/\1/p') + command=$(echo "$line" | sed -n 's/.*]*>\(.*\)<\/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" - # Show the list with Zenity and return the **command** (second column) selected - 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) + # Show the list with Zenity and return the **command** (second column) selected + 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" + echo "$selected_command" } # If the emulator is not specified, ask the user to select it or get it from the XML file From d0644c82e600722aab5cc7ca724516ddef1b8579 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Tue, 10 Sep 2024 22:22:30 +0900 Subject: [PATCH 05/13] RUN_GAME: working but looping - fix --- functions/other_functions.sh | 57 ++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/functions/other_functions.sh b/functions/other_functions.sh index 2330dcb5..9826868a 100644 --- a/functions/other_functions.sh +++ b/functions/other_functions.sh @@ -981,37 +981,42 @@ run_game() { log d "Game: \"$game\"" log d "System: \"$system\"" - # Function to handle the %INJECT% placeholder - handle_inject_placeholder() { - local cmd="$1" +# Function to handle the %INJECT% placeholder +handle_inject_placeholder() { + local cmd="$1" + local rom_dir=$(dirname "$game") # Define rom_dir based on the game path - # Find all occurrences of %INJECT%=something - while [[ "$cmd" =~ %INJECT%=(.*) ]]; do - inject_file="${BASH_REMATCH[1]}" # Extract the file name + # Find all occurrences of %INJECT%=something + while [[ "$cmd" =~ %INJECT%=(.*) ]]; do + inject_file="${BASH_REMATCH[1]}" # Extract the file name + + # Prepend the directory path to ensure we have the full path to the file + inject_file_full_path="$rom_dir/$inject_file" + + log d "Found %INJECT% pointing to file \"$inject_file_full_path\"" + + # Check if the file exists (no escaping needed, just quotes) + if [[ -f "$inject_file_full_path" ]]; then + # Read the content of the file + inject_content=$(cat "$inject_file_full_path") + log i "File \"$inject_file_full_path\" found, injecting content \"$inject_content\"" + + # Replace the %INJECT% placeholder with the content of the file + cmd="${cmd//%INJECT%=$inject_file/$inject_content}" + else + log e "File \"$inject_file_full_path\" not found. Removing %INJECT% placeholder." + # If the file does not exist, just remove the placeholder + cmd="${cmd//%INJECT%=$inject_file/}" + fi + done + + log d "Returning the command with injected content: $cmd" + echo "$cmd" +} - # Prepend the directory path to ensure we have the full path to the file - inject_file_full_path="$rom_dir/$inject_file" - log d "Found %INJECT% pointing to file \"$inject_file_full_path\"" - # Check if the file exists - if [[ -f "$inject_file_full_path" ]]; then - # Read the content of the file - inject_content=$(cat "$inject_file_full_path") - log i "File \"$inject_file_full_path\" found, injecting content \"$inject_content\"" - - # Replace the %INJECT% placeholder with the content of the file - cmd="${cmd//%INJECT%=$inject_file/$inject_content}" - else - log e "File \"$inject_file_full_path\" not found. Removing %INJECT% placeholder." - # If the file does not exist, just remove the placeholder - cmd="${cmd//%INJECT%=$inject_file/}" - fi - done - log d "Returning the command with injected content: $cmd" - echo "$cmd" - } # Function to replace %EMULATOR_SOMETHING% with the actual path of the emulator replace_emulator_placeholder() { From 6496e1f051ad222df7987cd6d805000c86cfd816 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Wed, 11 Sep 2024 10:18:03 +0900 Subject: [PATCH 06/13] RUN_GAME: fixed %INJECT% placeholder in both of the cases --- functions/other_functions.sh | 59 +++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/functions/other_functions.sh b/functions/other_functions.sh index 9826868a..42fe9701 100644 --- a/functions/other_functions.sh +++ b/functions/other_functions.sh @@ -984,29 +984,37 @@ run_game() { # Function to handle the %INJECT% placeholder handle_inject_placeholder() { local cmd="$1" - local rom_dir=$(dirname "$game") # Define rom_dir based on the game path + local rom_dir=$(dirname "$game") # Get the ROM directory based on the game path - # Find all occurrences of %INJECT%=something - while [[ "$cmd" =~ %INJECT%=(.*) ]]; do - inject_file="${BASH_REMATCH[1]}" # Extract the file name + # Find and process all occurrences of %INJECT%='something'.extension + while [[ "$cmd" =~ (%INJECT%=\'([^\']+)\')(.[^ ]+)? ]]; do + inject_file="${BASH_REMATCH[2]}" # Extract the quoted file name + extension="${BASH_REMATCH[3]}" # Extract the extension (if any) + inject_file_full_path="$rom_dir/$inject_file$extension" # Form the full path - # Prepend the directory path to ensure we have the full path to the file - inject_file_full_path="$rom_dir/$inject_file" + log d "Found inject part: %INJECT%='$inject_file'$extension" - log d "Found %INJECT% pointing to file \"$inject_file_full_path\"" - - # Check if the file exists (no escaping needed, just quotes) + # Check if the file exists if [[ -f "$inject_file_full_path" ]]; then - # Read the content of the file - inject_content=$(cat "$inject_file_full_path") - log i "File \"$inject_file_full_path\" found, injecting content \"$inject_content\"" - - # Replace the %INJECT% placeholder with the content of the file - cmd="${cmd//%INJECT%=$inject_file/$inject_content}" + # Read the content of the file and replace newlines with spaces + inject_content=$(cat "$inject_file_full_path" | tr '\n' ' ') + log i "File \"$inject_file_full_path\" found. Replacing %INJECT% with content." + + # Escape special characters in the inject part for the replacement + escaped_inject_part=$(printf '%s' "%INJECT%='$inject_file'$extension" | sed 's/[]\/$*.^[]/\\&/g') + + # Replace the entire %INJECT%=...'something'.extension part with the file content + cmd=$(echo "$cmd" | sed "s|$escaped_inject_part|$inject_content|g") + + log d "Replaced cmd: $cmd" else log e "File \"$inject_file_full_path\" not found. Removing %INJECT% placeholder." - # If the file does not exist, just remove the placeholder - cmd="${cmd//%INJECT%=$inject_file/}" + + # Use sed to remove the entire %INJECT%=...'something'.extension + escaped_inject_part=$(printf '%s' "%INJECT%='$inject_file'$extension" | sed 's/[]\/$*.^[]/\\&/g') + cmd=$(echo "$cmd" | sed "s|$escaped_inject_part||g") + + log d "sedded cmd: $cmd" fi done @@ -1015,9 +1023,6 @@ handle_inject_placeholder() { } - - - # Function to replace %EMULATOR_SOMETHING% with the actual path of the emulator replace_emulator_placeholder() { local placeholder=$1 @@ -1059,15 +1064,15 @@ replace_emulator_placeholder() { done # Substitute %BASENAME% and other placeholders - cmd="${cmd//"%BASENAME%"/"$base_name"}" - cmd="${cmd//"%FILENAME%"/"$file_name"}" - cmd="${cmd//"%ROMRAW%"/"$rom_raw"}" - cmd="${cmd//"%ROMPATH%"/"$rom_dir"}" + cmd="${cmd//"%BASENAME%"/"'$base_name'"}" + cmd="${cmd//"%FILENAME%"/"'$file_name'"}" + cmd="${cmd//"%ROMRAW%"/"'$rom_raw'"}" + cmd="${cmd//"%ROMPATH%"/"'$rom_dir'"}" # Ensure paths are quoted correctly - cmd="${cmd//"%ROM%"/"\"$rom_path\""}" - cmd="${cmd//"%GAMEDIR%"/"\"$rom_dir\""}" - cmd="${cmd//"%GAMEDIRRAW%"/"\"$rom_dir_raw\""}" + cmd="${cmd//"%ROM%"/"'$rom_path'"}" + cmd="${cmd//"%GAMEDIR%"/"'$rom_dir'"}" + cmd="${cmd//"%GAMEDIRRAW%"/"'$rom_dir_raw'"}" cmd="${cmd//"%CORE_RETROARCH%"/"/var/config/retroarch/cores"}" log d "Command after %BASENAME% and other substitutions: $cmd" From e80c30a1d9bdab49e3a78db686ab79f54b32f687 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Wed, 11 Sep 2024 10:20:28 +0900 Subject: [PATCH 07/13] RUN_GAME: if the emulator is only one just skip the zenity and run it --- functions/other_functions.sh | 63 +++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/functions/other_functions.sh b/functions/other_functions.sh index 42fe9701..760b81ad 100644 --- a/functions/other_functions.sh +++ b/functions/other_functions.sh @@ -936,7 +936,6 @@ find_emulator() { # TODO: add the logic of alt emulator and default emulator -# TODO: if the emulator is only one just skip the zenity and run it run_game() { @@ -1085,38 +1084,44 @@ replace_emulator_placeholder() { # 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 + 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 - # Extract commands and labels - commands=$(echo "$system_section" | xmllint --xpath "//command" - 2>/dev/null) + # Extract commands and labels + commands=$(echo "$system_section" | xmllint --xpath "//command" - 2>/dev/null) - # Prepare Zenity command list - command_list=() - while IFS= read -r line; do - label=$(echo "$line" | sed -n 's/.*label="\([^"]*\)".*/\1/p') - command=$(echo "$line" | sed -n 's/.*]*>\(.*\)<\/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 + command_list=() + while IFS= read -r line; do + label=$(echo "$line" | sed -n 's/.*label="\([^"]*\)".*/\1/p') + command=$(echo "$line" | sed -n 's/.*]*>\(.*\)<\/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" - # Show the list with Zenity and return the **command** (second column) selected - 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) + # Check if there's only one command + if [ ${#command_list[@]} -eq 2 ]; then + log d "Only one command found for $system_name, running it directly: ${command_list[1]}" + selected_command="${command_list[1]}" + else + # Show the list with Zenity and return the **command** (second column) selected + 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) + fi - echo "$selected_command" + echo "$selected_command" } # If the emulator is not specified, ask the user to select it or get it from the XML file From 32c6a2009bffbc86fbb71de360150807acf40281 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Wed, 11 Sep 2024 13:35:45 +0900 Subject: [PATCH 08/13] FEATURES: removed launch-args as they are no more useful for the scope of RUN_GAME --- config/retrodeck/reference_lists/features.json | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/config/retrodeck/reference_lists/features.json b/config/retrodeck/reference_lists/features.json index f9cd535e..977383b3 100644 --- a/config/retrodeck/reference_lists/features.json +++ b/config/retrodeck/reference_lists/features.json @@ -960,8 +960,7 @@ "system": [ "arcade" ], - "launch": "mame", - "launch-args": "-inipath /var/config/mame/ini -rompath $(dirname \"$game\") $game" + "launch": "mame" }, "citra": { "description": "Citra Nintendo 3DS Emulator (via Ponzu)", @@ -997,7 +996,6 @@ "url": "https://retrodeck.readthedocs.io/en/latest/wiki_emulator_guides/pcsx2/pcsx2-guide/", "system": "ps2", "launch": "pcsx2-qt", - "launch-args": "-batch $game", "properties": [ { "ask_to_exit": true, @@ -1010,7 +1008,6 @@ "description": "PlayStation Emulator", "url": "https://retrodeck.readthedocs.io/en/latest/wiki_emulator_guides/duckstation/duckstation-guide/", "launch": "duckstation-qt", - "launch-args": "-batch $game", "system": "psx", "properties": [ { @@ -1037,8 +1034,7 @@ "description": "Vita3K PSVita Emulator", "url": "https://retrodeck.readthedocs.io/en/latest/wiki_emulator_guides/vita3k/vita3k-guide/", "system": "psvita", - "launch": "Vita3K", - "launch-args": "-r $game.psvita" + "launch": "Vita3K" }, "rpcs3": { "name": "RPCS3", @@ -1066,7 +1062,6 @@ "url": "https://retrodeck.readthedocs.io/en/latest/wiki_about/what-is-retrodeck/", "launch": "Yuzu", "system": "switch", - "launch-args": "-f -g $game", "ponzu": true, "abxy_button": true }, @@ -1075,7 +1070,6 @@ "description": "Dolphin Wii and GameCube Emulator", "url": "https://retrodeck.readthedocs.io/en/latest/wiki_emulator_guides/dolphin-primehack/dolphin-primehack-guide/", "launch": "dolphin-emu-wrapper", - "launch-args": "-e $game", "system": [ "gc", "wii" @@ -1095,7 +1089,6 @@ "description": "A fork of Dolphiin to enhance Metroid Prime experience", "url": "https://retrodeck.readthedocs.io/en/latest/wiki_emulator_guides/dolphin-primehack/dolphin-primehack-guide/", "launch": "primehack-wrapper", - "launch-args": "-e $game", "system": [ "wii" ], @@ -1112,7 +1105,6 @@ "url": "https://retrodeck.readthedocs.io/en/latest/wiki_emulator_guides/cemu/cemu-guide/", "system": "wiiu", "launch": "Cemu-wrapper", - "launch-args": "-g $game", "properties": [ { "abxy_button": true, @@ -1125,8 +1117,7 @@ "name": "xemu", "url": "https://retrodeck.readthedocs.io/en/latest/wiki_emulator_guides/xemu/xemu-guide/", "system": "xbox", - "launch": "xemu", - "launch-args": "-dvd_path $game" + "launch": "xemu" }, "es-de": { "description": "ES-DE Emulation Frontend", From 24b35b7175cd319aee8053a1016fafa87d9f60c7 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Wed, 11 Sep 2024 13:38:32 +0900 Subject: [PATCH 09/13] RUN_GAME: replaced --run with "start" --- retrodeck.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/retrodeck.sh b/retrodeck.sh index e76f8df0..94be9b78 100644 --- a/retrodeck.sh +++ b/retrodeck.sh @@ -32,7 +32,7 @@ Arguments: --reset-component \t Reset one or more component or emulator configs to the default values --reset-retrodeck \t Starts the initial RetroDECK installer (backup your data first!) - --run [-s ] [-e ] \t Run a game from cli, if no system is defined it will deducted from the path.\n\t\t\t\t\t\t For example --run ~/retrodeck/roms/system/game.ext will be run with the system "system".\n\t\t\t\t\t\t Optionally -e (emulator) and -s (system) can be passed as arguments. + start [-s ] [-e ] \t Start a game from cli, if no system is defined it will deducted from the path.\n\t\t\t\t\t\t For example flatpak run net.retrodeck.retrodeck start ~/retrodeck/roms/system/game.ext will be run with the system "system".\n\t\t\t\t\t\t Optionally -e (emulator) and -s (system) can be passed as arguments. For flatpak run specific options please run: flatpak run -h @@ -44,8 +44,8 @@ https://retrodeck.net echo "RetroDECK v$version" exit ;; - --run*) - shift # Remove --run + start*) + shift # Remove "start" run_game "$@" exit ;; From 51485497ae14116cc321eec4016493d7c866bea6 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Wed, 11 Sep 2024 13:55:04 +0900 Subject: [PATCH 10/13] RUN_GAME: code prettyfication --- functions/other_functions.sh | 111 ++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 53 deletions(-) diff --git a/functions/other_functions.sh b/functions/other_functions.sh index 760b81ad..b9c7f74a 100644 --- a/functions/other_functions.sh +++ b/functions/other_functions.sh @@ -895,9 +895,10 @@ start_retrodeck() { find_emulator() { local emulator_name=$1 local found_path="" + local es_find_rules="/app/share/es-de/resources/systems/linux/es_find_rules.xml" # Search the es_find_rules.xml file for the 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']" "$es_find_rules" 2>/dev/null) if [ -z "$emulator_section" ]; then log e "Emulator not found: $emulator_name" @@ -938,13 +939,15 @@ find_emulator() { # TODO: add the logic of alt emulator and default emulator run_game() { + # call me with (-e emulator) (-s system) game/path, examples: + # run_game -e gambatte_libretro ~/retrodeck/roms/gb/Capumon.gb + # run_game ~/retrodeck/roms/gb/Capumon.gb + # run_game -s gbc ~/retrodeck/roms/gb/Capumon.gb # Initialize variables emulator="" system="" - - # Path to the es_systems.xml file - xml_file="/app/share/es-de/resources/systems/linux/es_systems.xml" + es_systems="/app/share/es-de/resources/systems/linux/es_systems.xml" # Parse options while getopts ":e:s:" opt; do @@ -965,8 +968,8 @@ run_game() { # Check for game argument if [[ -z "$1" ]]; then - echo "Error: Game file is required." - echo "Usage: $0 --run [-e emulator] [-s system] game" + log e "Game path is required." + log i "Usage: $0 start [-e emulator] [-s system] game" exit 1 fi @@ -980,64 +983,66 @@ run_game() { log d "Game: \"$game\"" log d "System: \"$system\"" -# Function to handle the %INJECT% placeholder -handle_inject_placeholder() { - local cmd="$1" - local rom_dir=$(dirname "$game") # Get the ROM directory based on the game path + # Function to handle the %INJECT% placeholder + # When %INJECT%=filename is found in the game command it will check for the existence of the file + # If the file is found the "%INJECT%=file" will be replaced with the contents of the found file + handle_inject_placeholder() { + local cmd="$1" + local rom_dir=$(dirname "$game") # Get the ROM directory based on the game path - # Find and process all occurrences of %INJECT%='something'.extension - while [[ "$cmd" =~ (%INJECT%=\'([^\']+)\')(.[^ ]+)? ]]; do - inject_file="${BASH_REMATCH[2]}" # Extract the quoted file name - extension="${BASH_REMATCH[3]}" # Extract the extension (if any) - inject_file_full_path="$rom_dir/$inject_file$extension" # Form the full path + # Find and process all occurrences of %INJECT%='something'.extension + while [[ "$cmd" =~ (%INJECT%=\'([^\']+)\')(.[^ ]+)? ]]; do + inject_file="${BASH_REMATCH[2]}" # Extract the quoted file name + extension="${BASH_REMATCH[3]}" # Extract the extension (if any) + inject_file_full_path="$rom_dir/$inject_file$extension" # Form the full path - log d "Found inject part: %INJECT%='$inject_file'$extension" + log d "Found inject part: %INJECT%='$inject_file'$extension" - # Check if the file exists - if [[ -f "$inject_file_full_path" ]]; then - # Read the content of the file and replace newlines with spaces - inject_content=$(cat "$inject_file_full_path" | tr '\n' ' ') - log i "File \"$inject_file_full_path\" found. Replacing %INJECT% with content." + # Check if the file exists + if [[ -f "$inject_file_full_path" ]]; then + # Read the content of the file and replace newlines with spaces + inject_content=$(cat "$inject_file_full_path" | tr '\n' ' ') + log i "File \"$inject_file_full_path\" found. Replacing %INJECT% with content." - # Escape special characters in the inject part for the replacement - escaped_inject_part=$(printf '%s' "%INJECT%='$inject_file'$extension" | sed 's/[]\/$*.^[]/\\&/g') + # Escape special characters in the inject part for the replacement + escaped_inject_part=$(printf '%s' "%INJECT%='$inject_file'$extension" | sed 's/[]\/$*.^[]/\\&/g') - # Replace the entire %INJECT%=...'something'.extension part with the file content - cmd=$(echo "$cmd" | sed "s|$escaped_inject_part|$inject_content|g") + # Replace the entire %INJECT%=...'something'.extension part with the file content + cmd=$(echo "$cmd" | sed "s|$escaped_inject_part|$inject_content|g") - log d "Replaced cmd: $cmd" - else - log e "File \"$inject_file_full_path\" not found. Removing %INJECT% placeholder." + log d "Replaced cmd: $cmd" + else + log e "File \"$inject_file_full_path\" not found. Removing %INJECT% placeholder." - # Use sed to remove the entire %INJECT%=...'something'.extension - escaped_inject_part=$(printf '%s' "%INJECT%='$inject_file'$extension" | sed 's/[]\/$*.^[]/\\&/g') - cmd=$(echo "$cmd" | sed "s|$escaped_inject_part||g") + # Use sed to remove the entire %INJECT%=...'something'.extension + escaped_inject_part=$(printf '%s' "%INJECT%='$inject_file'$extension" | sed 's/[]\/$*.^[]/\\&/g') + cmd=$(echo "$cmd" | sed "s|$escaped_inject_part||g") - log d "sedded cmd: $cmd" - fi - done + log d "sedded cmd: $cmd" + fi + done - log d "Returning the command with injected content: $cmd" - echo "$cmd" -} + log d "Returning the command with injected content: $cmd" + echo "$cmd" + } -# Function to replace %EMULATOR_SOMETHING% with the actual path of the emulator -replace_emulator_placeholder() { - local placeholder=$1 - # Extract emulator name from placeholder without changing case - local emulator_name="${placeholder//"%EMULATOR_"/}" # Extract emulator name after %EMULATOR_ - emulator_name="${emulator_name//"%"/}" # Remove the trailing % + # Function to replace %EMULATOR_SOMETHING% with the actual path of the emulator + replace_emulator_placeholder() { + local placeholder=$1 + # Extract emulator name from placeholder without changing case + local emulator_name="${placeholder//"%EMULATOR_"/}" # Extract emulator name after %EMULATOR_ + emulator_name="${emulator_name//"%"/}" # Remove the trailing % - # Use the find_emulator function to get the emulator path using the correct casing - local emulator_exec=$(find_emulator "$emulator_name") - - if [[ -z "$emulator_exec" ]]; then - log e "Emulator '$emulator_name' not found." - exit 1 - fi - echo "$emulator_exec" -} + # Use the find_emulator function to get the emulator path using the correct casing + local emulator_exec=$(find_emulator "$emulator_name") + + if [[ -z "$emulator_exec" ]]; then + log e "Emulator '$emulator_name' not found." + exit 1 + fi + echo "$emulator_exec" + } # Function to substitute the placeholders substitute_placeholders() { @@ -1086,7 +1091,7 @@ replace_emulator_placeholder() { 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) + system_section=$(xmllint --xpath "//system[name='$system_name']" "$es_systems" 2>/dev/null) if [ -z "$system_section" ]; then log e "System not found: $system_name" From aadd5b3b7bc10a0f3c58ac3a806b5f37fa0b4325 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Wed, 11 Sep 2024 15:39:55 +0900 Subject: [PATCH 11/13] STEAM_SYNC: using new start command + cleanup --- functions/steam_sync.sh | 262 +--------------------------------------- 1 file changed, 1 insertion(+), 261 deletions(-) diff --git a/functions/steam_sync.sh b/functions/steam_sync.sh index 17af3174..6318fae0 100644 --- a/functions/steam_sync.sh +++ b/functions/steam_sync.sh @@ -1,264 +1,5 @@ #!/bin/bash -# Associative arrays for command lists -# TODO: make them dynamic by readin es_config and features.json -# declare -A command_list_default=( -# ["3do"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/opera_libretro.so" -# ["amiga"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/puae_libretro.so" -# ["amiga1200"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/puae_libretro.so" -# ["amiga600"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/puae_libretro.so" -# ["amigacd32"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/puae_libretro.so" -# ["amstradcpc"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/cap32_libretro.so" -# ["arcade"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame_libretro.so" -# ["arduboy"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/arduous_libretro.so" -# ["astrocde"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame_libretro.so" -# ["atari2600"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/stella_libretro.so" -# ["atari5200"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/a5200_libretro.so" -# ["atari7800"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/prosystem_libretro.so" -# ["atari800"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/atari800_libretro.so" -# ["atarijaguar"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/virtualjaguar_libretro.so" -# ["atarijaguarcd"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/virtualjaguar_libretro.so" -# ["atarilynx"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/handy_libretro.so" -# ["atarist"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/hatari_libretro.so" -# ["atarixe"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/atari800_libretro.so" -# ["atomiswave"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/flycast_libretro.so" -# ["c64"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vice_x64sc_libretro.so" -# ["cavestory"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/nxengine_libretro.so" -# ["cdimono1"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/same_cdi_libretro.so" -# ["cdtv"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/puae_libretro.so" -# ["chailove"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/chailove_libretro.so" -# ["channelf"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/freechaf_libretro.so" -# ["colecovision"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/bluemsx_libretro.so" -# ["cps"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame_libretro.so" -# ["cps1"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame_libretro.so" -# ["cps2"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame_libretro.so" -# ["cps3"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame_libretro.so" -# ["doom"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/prboom_libretro.so" -# ["dos"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/dosbox_pure_libretro.so" -# ["dreamcast"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/flycast_libretro.so" -# ["easyrpg"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/easyrpg_libretro.so" -# ["famicom"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mesen_libretro.so" -# ["flash"]="TODO: I have to catch how it works" #TODO -# ["fba"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/fbalpha2012_libretro.so" -# ["fbneo"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/fbneo_libretro.so" -# ["fds"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mesen_libretro.so" -# ["gameandwatch"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/gw_libretro.so" -# ["gamegear"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/genesis_plus_gx_libretro.so" -# ["gb"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/gambatte_libretro.so" -# ["gba"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mgba_libretro.so" -# ["gbc"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/gambatte_libretro.so" -# ["genesis"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/genesis_plus_gx_libretro.so" -# ["gx4000"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/cap32_libretro.so" -# ["intellivision"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/freeintv_libretro.so" -# ["j2me"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/squirreljme_libretro.so" -# ["lcdgames"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/gw_libretro.so" -# ["lutro"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/lutro_libretro.so" -# ["mame"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame_libretro.so" -# ["mastersystem"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/genesis_plus_gx_libretro.so" -# ["megacd"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/genesis_plus_gx_libretro.so" -# ["megacdjp"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/genesis_plus_gx_libretro.so" -# ["megadrive"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/genesis_plus_gx_libretro.so" -# ["megaduck"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/sameduck_libretro.so" -# ["mess"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mess2015_libretro.so" -# ["model2"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame_libretro.so" -# ["moto"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/theodore_libretro.so" -# ["msx"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/bluemsx_libretro.so" -# ["msx1"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/bluemsx_libretro.so" -# ["msx2"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/bluemsx_libretro.so" -# ["msxturbor"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/bluemsx_libretro.so" -# ["multivision"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/gearsystem_libretro.so" -# ["n64"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mupen64plus_next_libretro.so" -# ["n64dd"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/parallel_n64_libretro.so" -# ["naomi"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/flycast_libretro.so" -# ["naomigd"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/flycast_libretro.so" -# ["nds"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/desmume_libretro.so" -# ["neogeo"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/fbneo_libretro.so" -# ["neogeocd"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/neocd_libretro.so" -# ["neogeocdjp"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/neocd_libretro.so" -# ["nes"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mesen_libretro.so" -# ["ngp"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_ngp_libretro.so" -# ["ngpc"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_ngp_libretro.so" -# ["odyssey2"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/o2em_libretro.so" -# ["palm"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mu_libretro.so" -# ["pc88"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/quasi88_libretro.so" -# ["pc98"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/np2kai_libretro.so" -# ["pcengine"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_pce_libretro.so" -# ["pcenginecd"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_pce_libretro.so" -# ["pcfx"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_pcfx_libretro.so" -# ["pokemini"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/pokemini_libretro.so" -# ["psx"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/swanstation_libretro.so" -# ["quake"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/tyrquake_libretro.so" -# ["satellaview"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/snes9x_libretro.so" -# ["saturn"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_saturn_libretro.so" -# ["saturnjp"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_saturn_libretro.so" -# ["scummvm"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/scummvm_libretro.so" -# ["sega32x"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/picodrive_libretro.so" -# ["sega32xjp"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/picodrive_libretro.so" -# ["sega32xna"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/picodrive_libretro.so" -# ["segacd"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/genesis_plus_gx_libretro.so" -# ["sfc"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/snes9x_libretro.so" -# ["sg-1000"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/genesis_plus_gx_libretro.so" -# ["sgb"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mesen-s_libretro.so" -# ["snes"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/snes9x_libretro.so" -# ["snesna"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/snes9x_libretro.so" -# ["spectravideo"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/bluemsx_libretro.so" -# ["sufami"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/snes9x_libretro.so" -# ["supergrafx"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_supergrafx_libretro.so" -# ["supervision"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/potator_libretro.so" -# ["tg16"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_pce_libretro.so" -# ["tg-cd"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_pce_libretro.so" -# ["tic80"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/tic80_libretro.so" -# ["to8"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/theodore_libretro.so" -# ["uzebox"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/uzem_libretro.so" -# ["vectrex"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vecx_libretro.so" -# ["vic20"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vice_xvic_libretro.so" -# ["videopac"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/o2em_libretro.so" -# ["virtualboy"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_vb_libretro.so" -# ["wasm4"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/wasm4_libretro.so" -# ["wonderswan"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_wswan_libretro.so" -# ["wonderswancolor"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_wswan_libretro.so" -# ["x1"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/x1_libretro.so" -# ["x68000"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/px68k_libretro.so" -# ["zx81"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/81_libretro.so" -# ["zxspectrum"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/fuse_libretro.so" -# ["switch"]="flatpak run --command=/var/data/ponzu/Yuzu/bin/yuzu net.retrodeck.retrodeck -f -g" -# ["n3ds"]="flatpak run --command=/var/data/ponzu/Citra/bin/citra-qt net.retrodeck.retrodeck" -# ["ps2"]="flatpak run --command=pcsx2-qt net.retrodeck.retrodeck -batch" -# ["wiiu"]="flatpak run --command=Cemu-wrapper net.retrodeck.retrodeck -g" -# ["gc"]="flatpak run --command=dolphin-emu-wrapper net.retrodeck.retrodeck -b -e" -# ["wii"]="flatpak run --command=dolphin-emu-wrapper net.retrodeck.retrodeck -b -e" -# ["xbox"]="flatpak run --command=xemu net.retrodeck.retrodeck -dvd_path" -# ["ps3"]="flatpak run --command=pcsx3 net.retrodeck.retrodeck --no-gui" -# ["psp"]="flatpak run --command=PPSSPPSDL net.retrodeck.retrodeck" -# ["pico8"]="flatpak run --command=pico8 net.retrodeck.retrodeck -desktop_path ~/retrodeck/screenshots -root_path {GAMEDIR} -run" -# ) - -# declare -A alt_command_list=( -# ["PUAE"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/puae_libretro.so" -# ["Caprice32"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/cap32_libretro.so" -# ["MAME - CURRENT"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame_libretro.so" -# ["Stella"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/stella_libretro.so" -# ["a5200"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/a5200_libretro.so" -# ["Atari800"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/atari800_libretro.so" -# ["Handy"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/handy_libretro.so" -# ["VICE x64sc Accurate"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vice_x64sc_libretro.so" -# ["SAME CDi"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/same_cdi_libretro.so" -# ["blueMSX"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/bluemsx_libretro.so" -# ["MAME - CURRENT"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame_libretro.so" -# ["PrBoom"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/prboom_libretro.so" -# ["DOSBox-Pure"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/dosbox_pure_libretro.so" -# ["Mesen"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mesen_libretro.so" -# ["Genesis Plus GX"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/genesis_plus_gx_libretro.so" -# ["Gamebatte"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/gambatte_libretro.so" -# ["mGBA"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mgba_libretro.so" -# ["ParaLLEI N64"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/parallel_n64_libretro.so" -# ["DeSmuME"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/desmume_libretro.so" -# ["NeoCD"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/neocd_libretro.so" -# ["Beetle NeoPop"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_ngp_libretro.so" -# ["Neko Project II Kai"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/np2kai_libretro.so" -# ["Beetle PCE"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_pce_libretro.so" -# ["Swanstation"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/swanstation_libretro.so" -# ["TyrQuake"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/tyrquake_libretro.so" -# ["Beetle Saturn"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_saturn_libretro.so" -# ["Snes 9x - Current"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/snes9x_libretro.so" -# ["Beetle SuperGrafx"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_supergrafx_libretro.so" -# ["Yuzu (Standalone)"]="flatpak run --command=yuzu net.retrodeck.retrodeck -f -g" -# ["Citra (Standalone)"]="flatpak run --command=citra net.retrodeck.retrodeck" -# ["PCSX2 (Standalone)"]="flatpak run --command=pcsx2-qt net.retrodeck.retrodeck -batch" -# ["Dolphin (Standalone)"]="flatpak run --command=dolphin-emu-wrapper net.retrodeck.retrodeck -b -e" -# ["RPCS3 Directory (Standalone)"]="flatpak run --command=pcsx3 net.retrodeck.retrodeck --no-gui" -# ["PPSSPP (Standalone)"]="flatpak run --command=PPSSPPSDL net.retrodeck.retrodeck" -# ["PICO-8 (Standalone)"]="flatpak run --command=pico8 net.retrodeck.retrodeck -desktop_path ~/retrodeck/screenshots -root_path {GAMEDIR} -run" -# ["PUAE 2021"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/puae2021_libretro.so" -# ["CrocoDS"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/crocods_libretro.so" -# ["CPCemu (Standalone)"]="NYI" #NYI -# ["MAME 2010"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame2010_libretro.so" -# ["MAME 2003-Plus"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame2003_plus_libretro.so" -# ["MAME 2000"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mame2000_libretro.so" -# ["MAME (Standalone)"]="NYI" #NYI -# ["FinalBurn Neo"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/fbneo_libretro.so" -# ["FinalBurn Neo (Standalone)"]="NYI" #NYI -# ["FB Alpha 2012"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/fbalpha2012_libretro.so" -# ["Flycast"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/flycast_libretro.so" -# ["Flycast (Standalone)"]="NYI" #NYI -# ["Kronos"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/kronos_libretro.so" -# ["Supermodel (Standalone)"]="NYI" #NYI -# ["Supermodel [Fullscreen] (Standalone)"]="NYI" #NYI -# ["Shortcut or script"]="TODO: I have to catch how it works" #TODO -# ["Atari800 (Standalone)"]="NYI" #NYI -# ["Stella 2014"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/stella2014_libretro.so" -# ["Atari800"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/atari800_libretro.so" -# ["Beetle Lynx"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_lynx_libretro.so" -# ["VICE x64 Fast"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vice_x64_libretro.so" -# ["VICE x64 SuperCPU"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vice_xscpu64_libretro.so" -# ["VICE x128"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vice_x128_libretro.so" -# ["Frodo"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/frodo_libretro.so" -# ["CDi 2015"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/cdi2015_libretro.so" -# ["Gearcoleco"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/gearcoleco_libretro.so" -# ["FB Alpha 2012 CPS-1"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/fbalpha2012_cps1_libretro.so" -# ["FB Alpha 2012 CPS-2"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/fbalpha2012_cps2_libretro.so" -# ["FB Alpha 2012 CPS-3"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/fbalpha2012_cps3_libretro.so" -# ["Boom 3"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/boom3_libretro.so" -# ["Boom 3 xp"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/boom3_libretro_xp.so" -# ["DOSBox-Core"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/dosbox_core_libretro.so" -# ["DOSBox-SVN"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/dosbox_svn_libretro.so" -# ["Keep ES-DE running"]="TODO: I have to catch how it works" #TODO -# ["AppImage (Suspend ES-DE)"]="TODO: I have to catch how it works" #TODO -# ["AppImage (Keep ES-DE running)"]="TODO: I have to catch how it works" #TODO -# ["Nestopia UE"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/nestopia_libretro.so" -# ["FCEUmm"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/fceumm_libretro.so" -# ["QuickNES"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/quicknes_libretro.so" -# ["Genesis Plus GX Wide"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/genesis_plus_gx_wide_libretro.so" -# ["Gearsystem"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/gearsystem_libretro.so" -# ["SMS Plus GX"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/smsplus_libretro.so" -# ["SameBoy"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/sameboy_libretro.so" -# ["Gearboy"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/gearboy_libretro.so" -# ["TGB Dual"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/tgbdual_libretro.so" -# ["Mesen-S"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mesen-s_libretro.so" -# ["VBA-M"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vbam_libretro.so" -# ["bsnes"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/bsnes_libretro.so" -# ["mGBA"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mgba_libretro.so" -# ["VBA Next"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vba_next_libretro.so" -# ["gpSP"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/gpsp_libretro.so" -# ["Dolphin"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/dolphin_libretro.so" -# ["PrimeHack (Standalone)"]="flatpak run --command=primehack-wrapper net.retrodeck.retrodeck -b -e" -# ["PicoDrive"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/picodrive_libretro.so" -# ["BlastEm"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/blastem_libretro.so" -# ["CrocoDS"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/crocods_libretro.so" -# ["fMSX"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/fmsx_libretro.so" -# ["Citra"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/citra_libretro.so" -# ["Citra 2018"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/citra2018_libretro.so" -# ["Mupen64Plus-Next"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mupen64plus_next_libretro.so" -# ["DeSmuME 2015"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/desmume2015_libretro.so" -# ["melonDS"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/melonds_libretro.so" -# ["melonDS (Standalone)"]="flatpak run --command=melonDS net.retrodeck.retrodeck" -# ["FinalBurn Neo neogeocd"]="flatpak run --command=retroarch net.retrodeck.retrodeck --subsystem neocd -L /var/config/retroarch/cores/fbneo_libretro.so" -# ["RACE"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/race_libretro.so" -# ["Neko Project II"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/nekop2_libretro.so" -# ["Beetle PCE FAST"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_pce_fast_libretro.so" -# ["PICO-8 Splore (Standalone)"]="flatpak run --command=pico8 net.retrodeck.retrodeck -desktop_path ~/retrodeck/screenshots -root_path {GAMEDIR} -splore" -# ["AppImage"]="TODO: I have to catch how it works" #TODO -# ["LRPS2"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/pcsx2_libretro.so" -# ["PCSX2"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/pcsx2_libretro.so" -# ["RPCS3 Shortcut (Standalone)"]="TODO: I have to catch how it works" #TODO -# ["PPSSPP"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/ppsspp_libretro.so" -# ["Beetle PSX"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_psx_libretro.so" -# ["Beetle PSX HW"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_psx_hw_libretro.so" -# ["PCSX ReARMed"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/pcsx_rearmed_libretro.so" -# ["DuckStation (Standalone)"]="flatpak run --command=duckstation-qt net.retrodeck.retrodeck -batch" -# ["vitaQuake 2"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vitaquake2_libretro.so" -# ["vitaQuake 2 [Rogue]"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vitaquake2-rogue_libretro.so" -# ["vitaQuake 2 [Xatrix]"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vitaquake2-xatrix_libretro.so" -# ["vitaQuake 2 [Zaero]"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vitaquake2-zaero_libretro.so" -# ["vitaQuake 3"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/vitaquake3_libretro.so" -# ["YabaSanshiro"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/yabasanshiro_libretro.so" -# ["Yabause"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/yabause_libretro.so" -# ["Snes9x 2010"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/snes9x2010_libretro.so" -# ["bsnes-hd"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/bsnes_hd_beta_libretro.so" -# ["bsnes-mercury Accuracy"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/bsnes_mercury_accuracy_libretro.so" -# ["Beetle Supafaust"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_supafaust_libretro.so" -# ["Beetle PCE"]="flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_pce_libretro.so" -# ) # Add games to Steam function add_to_steam() { @@ -345,9 +86,8 @@ add_to_steam() { # fi # Populate the .sync script with the correct command - # TODO: we need to implement the emulator parameter: # TODO: if there is any emulator defined in the xml we use that, else... how we can know which is the default one? - local command="flatpak run net.retrodeck.retrodeck --run -s $system \"$roms_folder/$system/$path\"" + local command="flatpak run net.retrodeck.retrodeck start -s $system \"$roms_folder/$system/$path\"" echo -e '#!/bin/bash\n' > "$launcher" echo -e "if [ test \"$(whereis flatpak)\" = \"flatpak:\" ]; then" >> "$launcher" echo -e "\tflatpak-spawn --host $command" >> "$launcher" From 80cdbabde6c6fbbc9ef6a3ce7ccb0b994013c7c2 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Wed, 11 Sep 2024 16:01:52 +0900 Subject: [PATCH 12/13] STEAM_SYNC: migrated launches to .desktop files --- .../steam-rom-manager/userConfigurations.json | 2 +- functions/steam_sync.sh | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/config/steam-rom-manager/userConfigurations.json b/config/steam-rom-manager/userConfigurations.json index 94243acf..f0d40b21 100644 --- a/config/steam-rom-manager/userConfigurations.json +++ b/config/steam-rom-manager/userConfigurations.json @@ -23,7 +23,7 @@ "appendArgsToExecutable": true }, "parserInputs": { - "glob": "${title}.sh" + "glob": "${title}.desktop" }, "titleFromVariable": { "limitToGroups": "", diff --git a/functions/steam_sync.sh b/functions/steam_sync.sh index 6318fae0..a41fd9cf 100644 --- a/functions/steam_sync.sh +++ b/functions/steam_sync.sh @@ -75,8 +75,8 @@ add_to_steam() { log d "Sanitized Name: $sanitized_name" - local launcher="$steamsync_folder/${sanitized_name}.sh" - log d "Creating shortcut at path: $launcher" + local launcher="$steamsync_folder/${sanitized_name}.desktop" + log d "Creating desktop file: $launcher" # if [[ -v command_list_default[$system] ]]; then # command="${command_list_default[$system]}" @@ -88,13 +88,17 @@ add_to_steam() { # Populate the .sync script with the correct command # TODO: if there is any emulator defined in the xml we use that, else... how we can know which is the default one? local command="flatpak run net.retrodeck.retrodeck start -s $system \"$roms_folder/$system/$path\"" - echo -e '#!/bin/bash\n' > "$launcher" - echo -e "if [ test \"$(whereis flatpak)\" = \"flatpak:\" ]; then" >> "$launcher" - echo -e "\tflatpak-spawn --host $command" >> "$launcher" - echo -e "else" >> "$launcher" - echo -e "\t$command" >> "$launcher" - echo -e "fi" >> "$launcher" - + cat < "$launcher" +[Desktop Entry] +Version=1.0 +Name=$name +Comment=$name via RetroDECK +Exec=bash -c 'if [ "\$(whereis flatpak)" = "flatpak:" ]; then flatpak-spawn --host $command; else $command; fi' +Icon=net.retrodeck.retrodeck +Terminal=false +Type=Application +Categories=Game;Emulator; +EOF chmod +x "$launcher" done fi From d1216b696c2de78b3ef893d6aa38f93c8e0a376e Mon Sep 17 00:00:00 2001 From: XargonWan Date: Wed, 11 Sep 2024 19:12:52 +0900 Subject: [PATCH 13/13] STEAM_SYNC: reverted .desktop files --- .../steam-rom-manager/userConfigurations.json | 2 +- functions/steam_sync.sh | 33 ++++++++++++------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/config/steam-rom-manager/userConfigurations.json b/config/steam-rom-manager/userConfigurations.json index f0d40b21..94243acf 100644 --- a/config/steam-rom-manager/userConfigurations.json +++ b/config/steam-rom-manager/userConfigurations.json @@ -23,7 +23,7 @@ "appendArgsToExecutable": true }, "parserInputs": { - "glob": "${title}.desktop" + "glob": "${title}.sh" }, "titleFromVariable": { "limitToGroups": "", diff --git a/functions/steam_sync.sh b/functions/steam_sync.sh index a41fd9cf..4768c543 100644 --- a/functions/steam_sync.sh +++ b/functions/steam_sync.sh @@ -75,7 +75,7 @@ add_to_steam() { log d "Sanitized Name: $sanitized_name" - local launcher="$steamsync_folder/${sanitized_name}.desktop" + local launcher="$steamsync_folder/${sanitized_name}.sh" log d "Creating desktop file: $launcher" # if [[ -v command_list_default[$system] ]]; then @@ -87,19 +87,28 @@ add_to_steam() { # Populate the .sync script with the correct command # TODO: if there is any emulator defined in the xml we use that, else... how we can know which is the default one? - local command="flatpak run net.retrodeck.retrodeck start -s $system \"$roms_folder/$system/$path\"" + # TODO: if steam is flatpak the command wrapping will change in .desktop + local command="flatpak run net.retrodeck.retrodeck start -s $system '$roms_folder/$system/$path'" + # Create the launcher file using a heredoc - if you enable .desktp this remember to edit .desktop in SRM userConfigurations.json and the above launcher variable (and vice versa) +# cat < "$launcher" +# [Desktop Entry] +# Version=1.0 +# Name=$name +# Comment=$name via RetroDECK +# Exec=$command +# Icon=net.retrodeck.retrodeck +# Terminal=false +# Type=Application +# Categories=Game;Emulator; +# EOF cat < "$launcher" -[Desktop Entry] -Version=1.0 -Name=$name -Comment=$name via RetroDECK -Exec=bash -c 'if [ "\$(whereis flatpak)" = "flatpak:" ]; then flatpak-spawn --host $command; else $command; fi' -Icon=net.retrodeck.retrodeck -Terminal=false -Type=Application -Categories=Game;Emulator; +#!/bin/bash +if [ test "$(whereis flatpak)" = "flatpak:" ]; then + flatpak-spawn --host $command +else + $command +fi EOF - chmod +x "$launcher" done fi done