diff --git a/functions/configurator_functions.sh b/functions/configurator_functions.sh index a9e138fb..b654105e 100644 --- a/functions/configurator_functions.sh +++ b/functions/configurator_functions.sh @@ -31,3 +31,34 @@ check_bios_files() { fi done < $bios_checklist } + +find_empty_rom_folders() { + # This function will build an array of all the system subfolders in $roms_folder which are either empty or contain only systeminfo.txt for easy removal + + if [[ -f "$godot_empty_roms_folders" ]]; then + rm -f "$godot_empty_roms_folders" # Godot data transfer temp files + fi + touch "$godot_empty_roms_folders" + + empty_rom_folders_list=() + all_empty_folders=() + + for system in $(find "$roms_folder" -mindepth 1 -maxdepth 1 -type d -printf '%f\n') + do + local dir="$roms_folder/$system" + local files=$(ls -A1 "$dir") + local count=$(ls -A "$dir" | wc -l) + + if [[ $count -eq 0 ]]; then + # Directory is empty + empty_rom_folders_list=("${empty_rom_folders_list[@]}" "false" "$(realpath $dir)") + all_empty_folders=("${all_empty_folders[@]}" "$(realpath $dir)") + echo "$(realpath $dir)" >> "$godot_empty_roms_folders" # Godot data transfer temp file + elif [[ $count -eq 1 ]] && [[ "$(basename "${files[0]}")" == "systeminfo.txt" ]]; then + # Directory contains only systeminfo.txt + empty_rom_folders_list=("${empty_rom_folders_list[@]}" "false" "$(realpath $dir)") + all_empty_folders=("${all_empty_folders[@]}" "$(realpath $dir)") + echo "$(realpath $dir)" >> "$godot_empty_roms_folders" # Godot data transfer temp file + fi + done +} diff --git a/functions/global.sh b/functions/global.sh index e2b0257b..5ae8c08d 100644 --- a/functions/global.sh +++ b/functions/global.sh @@ -55,6 +55,7 @@ pretty_system_names_reference_list="$emuconfigs/defaults/retrodeck/reference_lis godot_bios_files_checked="/var/config/retrodeck/godot/godot_bios_files_checked.tmp" godot_current_preset_settings="/var/config/retrodeck/godot/godot_current_preset_settings.tmp" godot_compression_compatible_games="/var/config/retrodeck/godot/godot_compression_compatible_games.tmp" +godot_empty_roms_folders="/var/config/retrodeck/godot/godot_empty_roms_folders.tmp" # Config files for emulators with single config files diff --git a/tools/configurator.sh b/tools/configurator.sh index 7a0bb1be..04ee365e 100644 --- a/tools/configurator.sh +++ b/tools/configurator.sh @@ -52,6 +52,7 @@ source /app/libexec/global.sh # - Move Screenshots folder # - Move Mods folder # - Move Texture Packs folder +# - Tool: Remove Empty ROM Folders # - Tool: Compress Games # - Compress Single Game # - Compress Multiple Games - CHD @@ -559,6 +560,7 @@ configurator_retrodeck_tools_dialog() { local choices=( "Tool: Move Folders" "Move RetroDECK folders between internal/SD card or to a custom location" + "Tool: Remove Empty ROM Folders" "Remove some or all of the empty ROM folders" "Tool: Compress Games" "Compress games for systems that support it" "Install: RetroDECK Controller Layouts" "Install the custom RetroDECK controller layouts on Steam" "Install: PS3 Firmware" "Download and install PS3 firmware for use with the RPCS3 emulator" @@ -585,6 +587,34 @@ configurator_retrodeck_tools_dialog() { configurator_retrodeck_move_tool_dialog ;; + "Tool: Remove Empty ROM Folders" ) + log i "Configurator: opening \"$choice\" menu" + find_empty_rom_folders + + choice=$(zenity \ + --list --width=1200 --height=720 --title "RetroDECK Configurator - RetroDECK: Remove Empty ROM Folders" \ + --checklist --hide-column=3 --ok-label="Remove Selected" --extra-button="Remove All" \ + --separator="," --print-column=2 \ + --text="Choose which ROM folders to remove:" \ + --column "Remove?" \ + --column "System" \ + "${empty_rom_folders_list[@]}") + + local rc=$? + if [[ $rc == "0" && ! -z $choice ]]; then # User clicked "Remove Selected" with at least one system selected + IFS="," read -ra folders_to_remove <<< "$choice" + for folder in "${folders_to_remove[@]}"; do + log i "Removing empty folder $folder" + rm -f "$folder" + done + elif [[ ! -z $choice ]]; then # User clicked "Remove All" + for folder in "${all_empty_folders[@]}"; do + log i "Removing empty folder $folder" + rm -f "$folder" + done + fi + ;; + "Tool: Compress Games" ) log i "Configurator: opening \"$choice\" menu" configurator_generic_dialog "RetroDECK Configurator - Compression Tool" "Depending on your library and compression choices, the process can sometimes take a long time.\nPlease be patient once it is started!"