mirror of
https://github.com/RetroDECK/RetroDECK.git
synced 2024-11-22 05:55:38 +00:00
RUN_GAME: working but looping - fix
This commit is contained in:
parent
38806dabc1
commit
d0644c82e6
|
@ -981,37 +981,42 @@ run_game() {
|
||||||
log d "Game: \"$game\""
|
log d "Game: \"$game\""
|
||||||
log d "System: \"$system\""
|
log d "System: \"$system\""
|
||||||
|
|
||||||
# Function to handle the %INJECT% placeholder
|
# Function to handle the %INJECT% placeholder
|
||||||
handle_inject_placeholder() {
|
handle_inject_placeholder() {
|
||||||
local cmd="$1"
|
local cmd="$1"
|
||||||
|
local rom_dir=$(dirname "$game") # Define rom_dir based on the game path
|
||||||
|
|
||||||
# Find all occurrences of %INJECT%=something
|
# Find all occurrences of %INJECT%=something
|
||||||
while [[ "$cmd" =~ %INJECT%=(.*) ]]; do
|
while [[ "$cmd" =~ %INJECT%=(.*) ]]; do
|
||||||
inject_file="${BASH_REMATCH[1]}" # Extract the file name
|
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
|
# Function to replace %EMULATOR_SOMETHING% with the actual path of the emulator
|
||||||
replace_emulator_placeholder() {
|
replace_emulator_placeholder() {
|
||||||
|
|
Loading…
Reference in a new issue