From fea3a3e3c2eaa80d38a48f3c8a7e34bf0294258d Mon Sep 17 00:00:00 2001 From: icenine451 Date: Thu, 13 Mar 2025 14:53:05 -0400 Subject: [PATCH] Add repair_paths function to fix paths that cannot be found without needing a full reset --- functions/other_functions.sh | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/functions/other_functions.sh b/functions/other_functions.sh index d78f30ec..e8231f83 100644 --- a/functions/other_functions.sh +++ b/functions/other_functions.sh @@ -1128,3 +1128,50 @@ add_retrodeck_to_steam(){ log i "RetroDECK has been added to Steam" } + +repair_paths() { + # This function will verify that all folders defined in the [paths] section of retrodeck.cfg exist + # If a folder doesn't exist and is defined outside of rdhome, it will check in rdhome first and have the user browse for them manually if it isn't there either + # USAGE: repair_paths + + invalid_path_found="false" + + log i "Checking that all RetroDECK paths are valid" + while read -r config_line; do + local current_setting_name=$(get_setting_name "$config_line" "retrodeck") + if [[ ! $current_setting_name =~ (rdhome|sdcard) ]]; then # Ignore these locations + local current_setting_value=$(get_setting_value "$rd_conf" "$current_setting_name" "retrodeck" "paths") + if [[ ! -d "$current_setting_value" ]]; then # If the folder doesn't exist as defined + log i "$current_setting_name does not exist as defined, config is incorrect" + if [[ ! -d "$rdhome/${current_setting_value#*retrodeck/}" ]]; then # If the folder doesn't exist within defined rdhome path + if [[ ! -d "$sdcard/${current_setting_value#*retrodeck/}" ]]; then # If the folder doesn't exist within defined sdcard path + log i "$current_setting_name cannot be found at any expected location, having user locate it manually" + configurator_generic_dialog "RetroDECK Path Repair" "The RetroDECK $current_setting_name was not found in the expected location.\nThis may happen when the folder is moved manually.\n\nPlease browse to the current location of the $current_setting_name." + new_path=$(directory_browse "RetroDECK $current_setting_name location") + set_setting_value "$rd_conf" "$current_setting_name" "$new_path" retrodeck "paths" + invalid_path_found="true" + else # Folder does exist within defined sdcard path, update accordingly + log i "$current_setting_name found in $sdcard/retrodeck, correcting path config" + new_path="$sdcard/retrodeck/${current_setting_value#*retrodeck/}" + set_setting_value "$rd_conf" "$current_setting_name" "$new_path" retrodeck "paths" + invalid_path_found="true" + fi + else # Folder does exist within defined rdhome path, update accordingly + log i "$current_setting_name found in $rdhome, correcting path config" + new_path="$rdhome/${current_setting_value#*retrodeck/}" + set_setting_value "$rd_conf" "$current_setting_name" "$new_path" retrodeck "paths" + invalid_path_found="true" + fi + fi + fi + done < <(grep -v '^\s*$' $rd_conf | awk '/^\[paths\]/{f=1;next} /^\[/{f=0} f') + + if [[ $invalid_path_found == "true" ]]; then + log i "One or more invalid paths repaired, fixing internal RetroDECK structures" + conf_read + dir_prep "$logs_folder" "$rd_logs_folder" + prepare_component "postmove" "all" + else + log i "All folders were found at their expected locations" + fi +}