RetroDECK/tools/configurator.sh

578 lines
17 KiB
Bash
Raw Normal View History

#!/bin/bash
2022-10-07 17:46:48 +00:00
# VARIABLES SECTION
source /app/bin/global.sh # Grab global variables
source /app/libexec/functions.sh # Source global functions
# Config files for emulators with single config files
citraconf="/var/config/citra-emu/qt-config.ini"
melondsconf="/var/config/melonDS/melonDS.ini"
rpcs3conf="/var/config/rpcs3/config.yml"
yuzuconf="/var/config/yuzu/qt-config.ini"
2022-10-07 20:28:36 +00:00
source $rd_conf
2022-10-07 17:46:48 +00:00
2022-10-10 16:46:35 +00:00
# ES-DE config files
es_settings="/var/config/emulationstation/.emulationstation/es_settings.xml"
# RetroArch config files
raconf="/var/config/retroarch/retroarch.cfg"
ra_core_conf="/var/config/retroarch/retroarch-core-options.cfg"
2022-10-07 17:46:48 +00:00
# Dolphin config files
dolphinconf="/var/config/dolphin-emu/Dolphin.ini"
dolphingcpadconf="/var/config/dolphin-emu/GCPadNew.ini"
dolphingfxconf="/var/config/dolphin-emu/GFX.ini"
dolphinhkconf="/var/config/dolphin-emu/Hotkeys.ini"
dolphinqtconf="/var/config/dolphin-emu/Qt.ini"
# PCSX2 config files
pcsx2conf="/var/config/PCSX2/inis/GS.ini"
pcsx2uiconf="/var/config/PCSX2/inis/PCSX2_ui.ini"
pcsx2vmconf="/var/config/PCSX2/inis/PCSX2_vm.ini"
# FUNCTION SECTION
browse() {
2022-10-11 20:19:35 +00:00
# This function browses for a directory and returns the path chosen
# USAGE: path_to_be_browsed_for=$(browse $source/destination_text $action_text)
2022-10-07 17:46:48 +00:00
2022-10-11 20:19:35 +00:00
path_selected=false
2022-10-07 17:46:48 +00:00
2022-10-11 20:19:35 +00:00
while [ $path_selected == false ]
2022-10-07 17:46:48 +00:00
do
2022-10-11 20:19:35 +00:00
target="$(zenity --file-selection --title="Choose $1 location to $2" --directory)"
2022-10-07 17:46:48 +00:00
echo "Path chosen: $target, answer=$?"
if [ $? == 0 ] #yes
then
2022-10-11 20:19:35 +00:00
zenity --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label="No" --ok-label "Yes" \
--text="Directory $target chosen, is this correct?"
if [ $? == 0 ]
then
path_selected=true
echo $target
break
else
fi
2022-10-07 17:46:48 +00:00
else
2022-10-11 20:19:35 +00:00
zenity --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label="No" --ok-label "Yes" \
--text="No directory selected. Do you want to return to the main menu?"
if [ $? == 1 ]
2022-10-07 17:46:48 +00:00
then
2022-10-11 20:19:35 +00:00
configurator_welcome_dialog
2022-10-07 17:46:48 +00:00
fi
fi
done
}
2022-10-11 20:19:35 +00:00
verify_space() {
# Function used for verifying adequate space before moving directories around
# USAGE: verify_space $source_dir $dest_dir
# Function returns "true" if there is enough space, "false" if there is not
source_size=$(du -sk /home/deck/retrodeck | awk '{print $1}')
source_size=$((source_size+(source_size/10))) # Add 10% to source size for safety
dest_avail=$(df -k --output=avail $2 | tail -1)
if [[ $source_size -ge $dest_avail ]]; then
echo "false"
else
echo "true"
fi
}
2022-10-07 17:46:48 +00:00
move() {
2022-10-11 20:19:35 +00:00
# Function to move a directory from one parent to another
# USAGE: move $source_dir $dest_dir
if [[ verify_space $1 $2 ]]; then
(
echo "mv -v -t $2 $1"
) |
zenity --icon-name=net.retrodeck.retrodeck --progress --no-cancel --pulsate --auto-close \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Configurator Utility - Move in Progress" \
--text="Moving directory $1 to new location of $2, please wait."
2022-10-07 17:46:48 +00:00
2022-10-11 20:19:35 +00:00
else
zenity --icon-name=net.retrodeck.retrodeck --error --no-wrap \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Configurator Utility - Move Directories" \
--text="The destination directory you have selected does not have enough free space for the files you are trying to move.\n\nPlease select a new destination or free up some space."
configurator_move_dialog
fi
2022-10-07 17:46:48 +00:00
}
2022-10-07 20:28:36 +00:00
set_setting() {
2022-10-07 17:46:48 +00:00
# Function for editing settings
2022-10-11 20:19:35 +00:00
# USAGE: set_setting $setting_file $setting_name $new_setting_value $system (needed as different systems use different config file syntax)
2022-10-07 17:46:48 +00:00
2022-10-07 20:28:36 +00:00
case $4 in
2022-10-07 17:46:48 +00:00
2022-10-07 20:28:36 +00:00
"retrodeck" )
2022-10-10 21:01:19 +00:00
sed -i "s%$2=.*%$2=$3%" $1
;;
2022-10-07 20:28:36 +00:00
"retroarch" )
2022-10-10 21:01:19 +00:00
sed -i "s%$2 = \".*\"%$2 = \"$3\"%" $1
;;
2022-10-07 17:46:48 +00:00
2022-10-07 20:28:36 +00:00
"dolphin" )
2022-10-10 21:01:19 +00:00
sed -i "s%$2 = .*%$2 = $3%" $1
;;
2022-10-07 17:46:48 +00:00
2022-10-07 20:28:36 +00:00
"duckstation" )
2022-10-10 21:01:19 +00:00
sed -i "s%$2 = .*%$2 = $3%" $1
;;
2022-10-07 17:46:48 +00:00
2022-10-07 20:28:36 +00:00
"pcsx2" )
2022-10-10 21:01:19 +00:00
sed -i "s%$2 = .*%$2 = $3%" $1
;;
2022-10-07 20:28:36 +00:00
"ppsspp" )
2022-10-10 21:01:19 +00:00
sed -i "s%$2 = .*%$2 = $3%" $1
;;
2022-10-07 20:28:36 +00:00
2022-10-10 21:01:19 +00:00
"rpcs3" ) # This does not currently work for settings with a $ in them
sed -i "s%$2: .*%$2: $3%" $1
;;
2022-10-07 20:28:36 +00:00
"yuzu" )
2022-10-10 21:01:19 +00:00
#sed -i "s%$2=.*%$2=$3%" $1
;;
2022-10-07 17:46:48 +00:00
2022-10-07 20:28:36 +00:00
"citra" )
2022-10-10 21:01:19 +00:00
#sed -i "s%$2=.*%$2=$3%" $1
;;
2022-10-07 17:46:48 +00:00
2022-10-07 20:28:36 +00:00
"melonds" )
2022-10-10 21:01:19 +00:00
sed -i "s%$2=.*%$2=$3%" $1
;;
2022-10-07 20:28:36 +00:00
"xemu" )
2022-10-10 21:01:19 +00:00
sed -i "s%$2 = .*%$2 = $3%" $1
;;
2022-10-07 20:28:36 +00:00
2022-10-10 16:46:35 +00:00
"emulationstation" )
2022-10-10 21:01:19 +00:00
sed -i "s%$2\" \" value=\".*\"%$2\" \" value=\"$3\"" $1
;;
2022-10-07 20:28:36 +00:00
esac
}
get_setting() {
# Function for getting the current value of a setting from a config file
2022-10-11 20:19:35 +00:00
# USAGE: get_setting $setting_file $setting_name $system (needed as different systems use different config file syntax)
2022-10-07 20:28:36 +00:00
case $3 in
"retrodeck" )
2022-10-10 21:01:19 +00:00
echo $(grep "$2" $1 | grep -o -P "(?<=$2=).*")
;;
2022-10-10 16:46:35 +00:00
2022-10-07 20:28:36 +00:00
"retroarch" )
2022-10-10 21:01:19 +00:00
echo $(grep "$2" $1 | grep -o -P "(?<=$2 = \").*(?=\")")
;;
2022-10-07 17:46:48 +00:00
2022-10-10 16:46:35 +00:00
"dolphin" ) # Use quotes when passing setting_name, as this config file contains special characters
2022-10-10 21:01:19 +00:00
echo $(grep "$2" $1 | grep -o -P "(?<=$2 = ).*")
;;
2022-10-07 17:46:48 +00:00
"duckstation" )
2022-10-10 21:01:19 +00:00
echo $(grep "$2" $1 | grep -o -P "(?<=$2 = ).*")
;;
2022-10-07 17:46:48 +00:00
"pcsx2" )
2022-10-10 21:01:19 +00:00
echo $(grep "$2" $1 | grep -o -P "(?<=$2 = ).*")
;;
2022-10-07 17:46:48 +00:00
2022-10-10 21:01:19 +00:00
"ppsspp" ) # Use quotes when passing setting_name, as this config file contains spaces
echo $(grep "$2" $1 | grep -o -P "(?<=$2 = ).*")
;;
2022-10-07 17:46:48 +00:00
2022-10-10 16:46:35 +00:00
"rpcs3" ) # Use quotes when passing setting_name, as this config file contains special characters and spaces
2022-10-10 21:01:19 +00:00
echo $(grep "$2" $1 | grep -o -P "(?<=$2: ).*")
;;
2022-10-07 17:46:48 +00:00
2022-10-10 16:46:35 +00:00
"yuzu" ) # Use quotes when passing setting_name, as this config file contains special characters
2022-10-10 21:01:19 +00:00
yuzu_setting=$(sed -e 's%\\%\\\\%g' <<< "$2") # Accomodate for backslashes in setting names
echo $(grep "$yuzu_setting" $1 | grep -o -P "(?<=$yuzu_setting=).*")
;;
2022-10-10 16:46:35 +00:00
"citra" ) # Use quotes when passing setting_name, as this config file contains special characters
2022-10-10 21:01:19 +00:00
citra_setting=$(sed -e 's%\\%\\\\%g' <<< "$2") # Accomodate for backslashes in setting names
echo $(grep "$citra_setting" $1 | grep -o -P "(?<=$citra_setting=).*")
;;
2022-10-07 17:46:48 +00:00
"melonds" )
2022-10-10 21:01:19 +00:00
echo $(grep "$2" $1 | grep -o -P "(?<=$2=).*")
;;
2022-10-07 17:46:48 +00:00
"xemu" )
2022-10-10 21:01:19 +00:00
echo $(grep "$2" $1 | grep -o -P "(?<=$2 = ).*")
;;
2022-10-10 16:46:35 +00:00
"emulationstation" )
2022-10-10 21:01:19 +00:00
echo $(grep "$2" $1 | grep -o -P "(?<=$2\" value=\").*(?=\")")
;;
2022-10-07 17:46:48 +00:00
esac
}
# DIALOG SECTION
# Configurator Option Tree
# Welcome
# - Move Directories
2022-10-07 17:46:48 +00:00
# - Migrate ROM directory
# - Migrate downloaded_media
# - Migrate BIOS directory
# - Change Emulator Options
# - RetroArch
# - Change Rewind Setting
# - Add or Update Files
# - Add specific cores
# - Grab all missing cores
# - Update all cores to nightly
# - RetroAchivement login
2022-10-07 17:46:48 +00:00
# - Login prompt
# - Reset RetroDECK
2022-10-07 17:46:48 +00:00
# - Reset RetroArch
# - Reset Standalone Emulators
# - Reset Tools
# - Reset All
2022-10-07 17:46:48 +00:00
# Code for the menus should be put in reverse order, so functions for sub-menus exists before it is called by the parent menu
2022-10-07 17:46:48 +00:00
configurator_process_complete_dialog() {
2022-10-11 20:19:35 +00:00
# This dialog shows when a process is complete.
# USAGE: configurator_process_complete_dialog "process text"
2022-10-07 17:46:48 +00:00
zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Configurator Utility - Process Complete" \
2022-10-10 21:01:19 +00:00
--text="The process of $1 is now complete.\n\nYou may need to quit and restart RetroDECK for your changes to take effect\n\nClick OK to return to the Main Menu or Quit to return to RetroDECK."
2022-10-11 20:19:35 +00:00
2022-10-10 21:01:19 +00:00
if [ $? == 0 ] # OK button clicked
then
configurator_welcome_dialog
fi
}
2022-10-07 17:46:48 +00:00
configurator_reset_dialog() {
choice=$(zenity --list --title="RetroDECK Configurator Utility - Reset Options" --cancel-label="Back" \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--column="Choice" --column="Action" \
"Reset RetroArch" "Reset RetroArch to default settings" \
"Reset Standalones" "Reset standalone emulators to default settings" \
"Reset Tools" "Reset Tools menu entries" \
"Reset All" "Reset RetroDECK to default settings" )
2022-10-07 17:46:48 +00:00
case $choice in
"Reset RetroArch" )
ra_init
configurator_process_complete_dialog "resetting RetroArch"
;;
"Reset Standalones" )
standalones_init
configurator_process_complete_dialog "resetting standalone emulators"
;;
"Reset Tools" )
tools_init
configurator_process_complete_dialog "resetting the tools menu"
;;
"Reset All" )
zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Configurator Utility - Reset RetroDECK" \
--text="You are resetting RetroDECK to its default state.\n\nAfter the process is complete you will need to exit RetroDECK and run it again."
rm -f "$lockfile"
configurator_process_complete_dialog "resetting RetroDECK"
;;
"" ) # No selection made or Back button clicked
configurator_welcome_dialog
;;
esac
}
configurator_retroachivement_dialog() {
login=$(zenity --forms --title="RetroDECK Configurator Utility - RetroAchievements Login" --cancel-label="Back" \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--text="Enter your RetroAchievements Account details.\n\nBe aware that this tool cannot verify your login details.\nFor registration and more info visit\nhttps://retroachievements.org/\n" \
--separator="=SEP=" \
--add-entry="Username" \
--add-password="Password")
if [ $? == 1 ] # Cancel button clicked
then
configurator_welcome_dialog
fi
arrIN=(${login//=SEP=/ })
user=${arrIN[0]}
pass=${arrIN[1]}
sed -i "s%cheevos_enable =.*%cheevos_enable = \"true\"%" $raconf
sed -i "s%cheevos_username =.*%cheevos_username = \"$user\"%" $raconf
sed -i "s%cheevos_password =.*%cheevos_password = \"$pass\"%" $raconf
2022-10-10 21:01:19 +00:00
configurator_process_complete_dialog "logging in to RetroAchievements"
}
configurator_update_dialog() {
}
2022-10-07 17:46:48 +00:00
configurator_power_user_changes_dialog() {
zenity --title "RetroDECK Configurator Utility - Power User Options" --question --no-wrap --cancel-label="Back" \
--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\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
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
"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
;;
"" ) # No selection made or Back button clicked
configurator_options_dialog
;;
2022-10-07 17:46:48 +00:00
esac
}
2022-10-07 20:28:36 +00:00
configurator_retroarch_rewind_dialog() {
if [[ $(get_setting $raconf rewind_enable retroarch) == "true" ]]; then
zenity --question \
--no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Configurator - Rewind" \
--text="Rewind is currently enabled. Do you want to disable it?."
2022-10-07 17:46:48 +00:00
2022-10-07 20:28:36 +00:00
if [ $? == 0 ]
then
set_setting $raconf rewind_enable true retroarch
2022-10-10 21:01:19 +00:00
configurator_process_complete_dialog "enabling Rewind"
2022-10-07 20:28:36 +00:00
else
configurator_options_dialog
fi
else
zenity --question \
--no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Configurator - Rewind" \
--text="Rewind is currently disabled, do you want to enable it?\n\nNOTE:\nThis may impact performance expecially on the latest systems."
if [ $? == 0 ]
then
set_setting $raconf rewind_enable false retroarch
2022-10-10 21:01:19 +00:00
configurator_process_complete_dialog "disabling Rewind"
2022-10-07 20:28:36 +00:00
else
configurator_options_dialog
fi
2022-10-07 17:46:48 +00:00
fi
}
2022-10-07 20:28:36 +00:00
configurator_retroarch_options_dialog() {
choice=$(zenity --list --title="RetroDECK Configurator Utility - RetroArch Options" --cancel-label="Back" \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--column="Choice" --column="Action" \
"Change Rewind Setting" "Enable or disable the Rewind function in RetroArch" )
case $choice in
"Change Rewind Setting" )
configurator_retroarch_rewind_dialog
;;
"" ) # No selection made or Back button clicked
configurator_options_dialog
;;
esac
}
2022-10-07 17:46:48 +00:00
configurator_options_dialog() {
choice=$(zenity --list --title="RetroDECK Configurator Utility - Change Options" --cancel-label="Back" \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--column="Choice" --column="Action" \
2022-10-07 20:28:36 +00:00
"Change RetroArch Settings" "Change settings specific to RetroArch" \
2022-10-07 17:46:48 +00:00
"Power User Changes" "Make changes directly in an emulator" )
case $choice in
2022-10-07 20:28:36 +00:00
"Change RetroArch Settings" )
configurator_retroarch_options_dialog
2022-10-07 17:46:48 +00:00
;;
"Power User Changes" )
configurator_power_user_changes_dialog
;;
"" ) # No selection made or Back button clicked
configurator_welcome_dialog
;;
esac
}
2022-10-10 21:01:19 +00:00
configurator_move_dialog() {
choice=$(zenity --list --title="RetroDECK Configurator Utility - Move Directories" --cancel-label="Back" \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--column="Choice" --column="Action" \
"Move ROMs" "Move your ROMs directory to a new location" \
"Move BIOS" "Move your BIOS directory to a new location" \
"Move Downloaded Media" "Move your downloaded media directory to a new location" \
"Move Saves and States" "Move your save and state directories to a new location" )
case $choice in
"Move ROMs" )
;;
"Move BIOS" )
2022-10-11 20:19:35 +00:00
2022-10-10 21:01:19 +00:00
;;
"Move Downloaded Media" )
;;
"Move Saves and States" )
;;
"" ) # No selection made or Back button clicked
configurator_welcome_dialog
;;
esac
2022-10-07 17:46:48 +00:00
}
configurator_welcome_dialog() {
# Clear the variables
2022-10-10 21:01:19 +00:00
source=
destination=
2022-10-07 17:46:48 +00:00
action=
2022-10-10 21:01:19 +00:00
setting=
2022-10-07 17:46:48 +00:00
setting_value=
choice=$(zenity --list --title="RetroDECK Configurator Utility" --cancel-label="Quit" \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--column="Choice" --column="Action" \
"Move Files" "Move files between internal/SD card or to custom locations" \
"Change Options" "Adjust how RetroDECK behaves" \
"Upgrade" "Upgrade parts of RetroDECK" \
"RetroAchivements" "Log in to RetroAchievements" \
"Reset" "Reset parts of RetroDECK" )
case $choice in
"Move Files" )
2022-10-10 21:01:19 +00:00
configurator_move_dialog
2022-10-07 17:46:48 +00:00
;;
"Change Options" )
configurator_options_dialog
;;
"Upgrade" )
configurator_update_dialog
;;
"RetroAchivements" )
configurator_retroachivement_dialog
;;
"Reset" )
configurator_reset_dialog
;;
2022-10-10 21:01:19 +00:00
"" )
;;
2022-10-07 17:46:48 +00:00
esac
}
# START THE CONFIGURATOR
2022-10-07 17:46:48 +00:00
configurator_welcome_dialog