From 099bf7f642bd440b8833397218a311a71c0f9210 Mon Sep 17 00:00:00 2001 From: icenine451 Date: Tue, 27 Feb 2024 11:55:28 -0500 Subject: [PATCH] Add MAME XML-based .cfg file support to patching system --- functions/patching.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/functions/patching.sh b/functions/patching.sh index 4af54660..5f98a450 100644 --- a/functions/patching.sh +++ b/functions/patching.sh @@ -53,9 +53,13 @@ set_setting_value() { fi ;; - "mame" ) # This only works for mame .ini files, not the .cfg XML files - local mame_current_value=$(get_setting_value $1 "$setting_name_to_change" $4) - sed -i '\^\^'"$setting_name_to_change"'\s^s^'"$mame_current_value"'^'"$setting_value_to_change"'^' "$1" + "mame" ) + local mame_current_value=$(get_setting_value "$1" "$setting_name_to_change" "$4" "$current_section_name") + if [[ "$1" =~ (.ini)$ ]]; then # If this is a MAME .ini file + sed -i '\^\^'"$setting_name_to_change"'\s^s^'"$mame_current_value"'^'"$setting_value_to_change"'^' "$1" + elif [[ "$1" =~ (.cfg)$ ]]; then # If this is an XML-based MAME .cfg file + sed -i '\^\^,\^<\/system>^s^'"$mame_current_value"'^'"$setting_value_to_change"'^' "$1" + fi ;; "es_settings" ) @@ -141,8 +145,12 @@ get_setting_value() { fi ;; - "mame" ) # This only works for mame .ini files, not the .cfg XML files - echo $(sed -n '\^\^'"$current_setting_name"'\s^p' "$1" | awk '{print $2}') + "mame" ) + if [[ "$1" =~ (.ini)$ ]]; then # If this is a MAME .ini file + echo $(sed -n '\^\^'"$current_setting_name"'\s^p' "$1" | awk '{print $2}') + elif [[ "$1" =~ (.cfg)$ ]]; then # If this is an XML-based MAME .cfg file + echo $(xml sel -t -v "/mameconfig/system[@name='$current_section_name']//*[@type='$current_setting_name']//*" -v "text()" -n "$1") + fi ;; "es_settings" )