From 1827bfecda4bd4e5ee7b14038cc70489e5eda5a0 Mon Sep 17 00:00:00 2001 From: icenine451 <benjamin.r.shelton@protonmail.com> Date: Mon, 21 Nov 2022 22:07:53 -0500 Subject: [PATCH] Fix regex, Zenity operations and cleanup --- functions.sh | 85 +++++++++++++++------ tools/configurator.sh | 167 +++++++++++++++++++++--------------------- 2 files changed, 145 insertions(+), 107 deletions(-) diff --git a/functions.sh b/functions.sh index b17333d4..ca70d297 100644 --- a/functions.sh +++ b/functions.sh @@ -96,18 +96,42 @@ set_setting_value() { case $4 in - "emulationstation" ) - sed -i "s%$setting_name_to_change\" \" value=\".*\"%$setting_name_to_change\" \" value=\"$setting_value_to_change\"" $1 + "retrodeck" | "citra" | "melonds" | "yuzu" ) + if [[ -z $current_section_name ]]; then + sed -i 's^'"$setting_name_to_change"'=.*^'"$setting_name_to_change"'='"$setting_value_to_change"'^' $1 + else + sed -i '\^\['"$current_section_name"'\]^,\^'"$setting_name_to_change"'.*^s^'"$setting_name_to_change"'=.*^'"$setting_name_to_change"'='"$setting_value_to_change"'^' $1 + fi ;; - * ) + "retroarch" ) if [[ -z $current_section_name ]]; then - sed -i -E 's^\b'"$setting_name_to_change"'(\s?[=:]\s?).*^'"$setting_name_to_change"'\1'"$setting_value_to_change"'^' $1 + sed -i 's^'"$setting_name_to_change"' = \".*\"^'"$setting_name_to_change"' = \"'"$setting_value_to_change"'\"^' $1 else - sed -i -E '\^\['"$current_section_name"'\]|\b'"$current_section"':$^,\^\b'"$setting_name_to_change"'.*^s^\b'"$setting_name_to_change"'(\s?[=:]\s?).*^'"$setting_name_to_change"'\1'"$setting_value_to_change"'^' $1 + sed -i '\^\['"$current_section_name"'\]^,\^'"$setting_name_to_change"'.*^s^'"$setting_name_to_change"' = \".*\"^'"$setting_name_to_change"' = \"'"$setting_value_to_change"'\"^' $1 fi ;; + "dolphin" | "duckstation" | "pcsx2" | "ppsspp" | "xemu" ) + if [[ -z $current_section_name ]]; then + sed -i 's^'"$setting_name_to_change"' =.*^'"$setting_name_to_change"' = '"$setting_value_to_change"'^' $1 + else + sed -i '\^\['"$current_section_name"'\]^,\^'"$setting_name_to_change"'.*^s^'"$setting_name_to_change"' =.*^'"$setting_name_to_change"' = '"$setting_value_to_change"'^' $1 + fi + ;; + + "rpcs3" ) # This does not currently work for settings with a $ in them + if [[ -z $current_section_name ]]; then + sed -i 's^'"$setting_name_to_change"': .*^'"$setting_name_to_change"': '"$setting_value_to_change"'^' $1 + else + sed -i '\^\['"$current_section_name"'\]^,\^'"$setting_name_to_change"'.*^s^'"$setting_name_to_change"': .*^'"$setting_name_to_change"': '"$setting_value_to_change"'^' $1 + fi + ;; + + "emulationstation" ) + sed -i "s%$setting_name_to_change\" \" value=\".*\"%$setting_name_to_change\" \" value=\"$setting_value_to_change\"" $1 + ;; + esac } @@ -124,7 +148,6 @@ get_setting_name() { ;; "rpcs3" ) - #echo "$current_setting_line" | grep -o -P "^\s*?.*?(?=\s?:\s?)" | sed -e 's%\\\\%\\%g' | sed -e 's/^[ \t]*//' echo "$current_setting_line" | grep -o -P "^\s*?.*?(?=\s?:\s?)" | sed -e 's/^[ \t]*//;s^\\ ^ ^g' ;; @@ -144,25 +167,41 @@ get_setting_value() { case $3 in + "retrodeck" | "citra" | "melonds" | "yuzu" ) # For files with this syntax - setting_name=setting_value + if [[ -z $current_section_name ]]; then + echo $(grep -o -P "(?<=^$current_setting_name=).*" $1) + else + sed -n '\^\['"$section_name"'\]^,\^'"$current_setting_name"'^{ \^\['"$section_name"'\]^! { \^'"$current_setting_name"'^ p } }' $1 | grep -o -P "(?<=^$current_setting_name=).*" + fi + ;; + + "retroarch" ) # For files with this syntax - setting_name = "setting_value" + if [[ -z $current_section_name ]]; then + echo $(grep -o -P "(?<=^$current_setting_name = \").*(?=\")" $1) + else + sed -n '\^\['"$section_name"'\]^,\^'"$current_setting_name"'^{ \^\['"$section_name"'\]^! { \^'"$current_setting_name"'^ p } }' $1 | grep -o -P "(?<=^$current_setting_name = \").*(?=\")" + fi + ;; + + "dolphin" | "duckstation" | "pcsx2" | "ppsspp" | "xemu" ) # For files with this syntax - setting_name = setting_value + if [[ -z $current_section_name ]]; then + echo $(grep -o -P "(?<=^$current_setting_name = ).*" $1) + else + sed -n '\^\['"$section_name"'\]^,\^'"$current_setting_name"'^{ \^\['"$section_name"'\]^! { \^'"$current_setting_name"'^ p } }' $1 | grep -o -P "(?<=^$current_setting_name = ).*" + fi + ;; + + "rpcs3" ) # For files with this syntax - setting_name: setting_value + if [[ -z $current_section_name ]]; then + echo $(grep -o -P "(?<=$current_setting_name: ).*" $1) + else + sed -n '\^\['"$section_name"'\]^,\^'"$current_setting_name"'^{ \^\['"$section_name"'\]^! { \^'"$current_setting_name"'^ p } }' $1 | grep -o -P "(?<=$current_setting_name: ).*" + fi + ;; + "emulationstation" ) echo $(grep -o -P "(?<=^$current_setting_name\" value=\").*(?=\")" $1) - ;; - - rpcs3 ) - if [[ -z $current_section_name ]]; then - sed -n -E 's^\s*\b'"$current_setting_name"'\s?:\s?(.*)^\1^p' $1 - else - sed -n -E '\^\b'"$current_section"':$^,\^'"$current_setting_name"'^{ \^\b'"$current_section"':$^! { \^\b'"$current_setting_name"'^ p } }' $1 | sed -n -E 's^\s*\b.*\s?:\s?(.*)$^\1^p' - fi - ;; - - * ) - if [[ -z $current_section_name ]]; then - sed -n -E 's^\s*\b'"$current_setting_name"'\s?=\s?(.*)^\1^p' $1 - else - sed -n -E '\^\['"$current_section_name"'\]^,\^\b'"$current_setting_name"'^{ \^\['"$current_section_name"'\]^! { \^\b'"$current_setting_name"'^ p } }' $1 | sed -n -E 's^\s*\b.*\s?=\s?(.*)^\1^p' - fi - ;; + ;; esac } diff --git a/tools/configurator.sh b/tools/configurator.sh index 7c2e5075..0eb2600e 100644 --- a/tools/configurator.sh +++ b/tools/configurator.sh @@ -168,20 +168,20 @@ configurator_retroachivement_dialog() { --add-entry="Username" \ --add-password="Password") - if [ $? == 1 ] # Cancel button clicked - then + if [ $? == 0 ]; then # OK button clicked + arrIN=(${login//=SEP=/ }) + user=${arrIN[0]} + pass=${arrIN[1]} + + set_setting_value $raconf cheevos_enable true retroarch + set_setting_value $raconf cheevos_username $user retroarch + set_setting_value $raconf cheevos_password $pass retroarch + + configurator_process_complete_dialog "logging in to RetroArch RetroAchievements" + else configurator_welcome_dialog fi - arrIN=(${login//=SEP=/ }) - user=${arrIN[0]} - pass=${arrIN[1]} - - set_setting_value $raconf cheevos_enable true retroarch - set_setting_value $raconf cheevos_username $user retroarch - set_setting_value $raconf cheevos_password $pass retroarch - - configurator_process_complete_dialog "logging in to RetroArch RetroAchievements" } configurator_update_dialog() { @@ -194,80 +194,79 @@ configurator_power_user_changes_dialog() { --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ --text="Making manual changes to an emulators configuration may create serious issues,\nand some settings may be overwitten during RetroDECK updates.\n\nSome standalone emulator functions may not work properly outside of Desktop mode.\n\nPlease continue only if you know what you're doing.\n\nDo you want to continue?" - if [ $? == 1 ] # Cancel button clicked - then - configurator_options_dialog - fi + if [ $? == 0 ]; then # OK button clicked + emulator=$(zenity --list \ + --title "RetroDECK Configurator Utility - Power User Options" --cancel-label="Back" \ + --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ + --text="Which emulator do you want to configure?" \ + --hide-header \ + --column=emulator \ + "RetroArch" \ + "Citra" \ + "Dolphin" \ + "Duckstation" \ + "MelonDS" \ + "PCSX2-QT" \ + "PCSX2-Legacy" \ + "PPSSPP" \ + "RPCS3" \ + "XEMU" \ + "Yuzu") - emulator=$(zenity --list \ - --title "RetroDECK Configurator Utility - Power User Options" --cancel-label="Back" \ - --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ - --text="Which emulator do you want to configure?" \ - --hide-header \ - --column=emulator \ - "RetroArch" \ - "Citra" \ - "Dolphin" \ - "Duckstation" \ - "MelonDS" \ - "PCSX2-QT" \ - "PCSX2-Legacy" \ - "PPSSPP" \ - "RPCS3" \ - "XEMU" \ - "Yuzu") + case $emulator in - case $emulator in - - "RetroArch" ) - retroarch - ;; - - "Citra" ) - citra-qt - ;; - - "Dolphin" ) - dolphin-emu - ;; - - "Duckstation" ) - duckstation-qt - ;; - - "MelonDS" ) - melonDS - ;; - - "PCSX2-QT" ) - pcsx2-qt - ;; - - "PCSX2-Legacy" ) - pcsx2 - ;; - - "PPSSPP" ) - PPSSPPSDL - ;; - - "RPCS3" ) - rpcs3 - ;; - - "XEMU" ) - xemu - ;; - - "Yuzu" ) - yuzu + "RetroArch" ) + retroarch ;; - "" ) # No selection made or Back button clicked - configurator_options_dialog - ;; + "Citra" ) + citra-qt + ;; - esac + "Dolphin" ) + dolphin-emu + ;; + + "Duckstation" ) + duckstation-qt + ;; + + "MelonDS" ) + melonDS + ;; + + "PCSX2-QT" ) + pcsx2-qt + ;; + + "PCSX2-Legacy" ) + pcsx2 + ;; + + "PPSSPP" ) + PPSSPPSDL + ;; + + "RPCS3" ) + rpcs3 + ;; + + "XEMU" ) + xemu + ;; + + "Yuzu" ) + yuzu + ;; + + "" ) # No selection made or Back button clicked + configurator_options_dialog + ;; + + esac + else + configurator_options_dialog + fi } configurator_retroarch_rewind_dialog() { @@ -279,8 +278,8 @@ configurator_retroarch_rewind_dialog() { if [ $? == 0 ] then - set_setting_value $raconf rewind_enable true retroarch - configurator_process_complete_dialog "enabling Rewind" + set_setting_value $raconf "rewind_enable" "false" retroarch + configurator_process_complete_dialog "disabling Rewind" else configurator_options_dialog fi @@ -292,8 +291,8 @@ configurator_retroarch_rewind_dialog() { if [ $? == 0 ] then - set_setting_value $raconf rewind_enable false retroarch - configurator_process_complete_dialog "disabling Rewind" + set_setting_value $raconf "rewind_enable" "true" retroarch + configurator_process_complete_dialog "enabling Rewind" else configurator_options_dialog fi