From 2afcf2ead46aa9cfa2940e2f23cc10b347914470 Mon Sep 17 00:00:00 2001 From: icenine451 Date: Thu, 30 May 2024 11:35:42 -0400 Subject: [PATCH] Move post-compression file cleanup to compress_game function to avoid repetition --- functions/compression.sh | 23 +++++++++++++++++++++ tools/configurator.sh | 43 ---------------------------------------- 2 files changed, 23 insertions(+), 43 deletions(-) diff --git a/functions/compression.sh b/functions/compression.sh index 9616a2c3..fc726d80 100644 --- a/functions/compression.sh +++ b/functions/compression.sh @@ -26,6 +26,29 @@ compress_game() { elif [[ "$1" == "rvz" ]]; then dolphin-tool convert -f rvz -b 131072 -c zstd -l 5 -i "$source_file" -o "$dest_file.rvz" fi + + if [[ $post_compression_cleanup == "true" ]]; then # Remove file(s) if requested + if [[ -f "${file%.*}.$compatible_compression_format" ]]; then + log i "Performing post-compression file cleanup" + if [[ "$file" == *".cue" ]]; then + local cue_bin_files=$(grep -o -P "(?<=FILE \").*(?=\".*$)" "$file") + local file_path=$(dirname "$(realpath "$file")") + while IFS= read -r line + do + log i "Removing file $file_path/$line" + rm -f "$file_path/$line" + done < <(printf '%s\n' "$cue_bin_files") + log i "Removing file $(realpath $file)" + rm -f $(realpath "$file") + else + log i "Removing file $(realpath $file)" + rm -f "$(realpath "$file")" + fi + else + log i "Compressed file ${file%.*}.$compatible_compression_format not found, skipping original file deletion" + configurator_generic_dialog "RetroDECK Configurator - RetroDECK: Compression Tool" "A compressed version of the file was not found, skipping deletion." + fi + fi } find_compatible_compression_format() { diff --git a/tools/configurator.sh b/tools/configurator.sh index 1808ea8a..73588a07 100644 --- a/tools/configurator.sh +++ b/tools/configurator.sh @@ -794,28 +794,6 @@ configurator_compress_single_game_dialog() { echo "# Compressing $(basename "$file") to $compatible_compression_format format" # This updates the Zenity dialog log i "Compressing $(basename "$file") to $compatible_compression_format format" compress_game "$compatible_compression_format" "$file" "$system" - if [[ $post_compression_cleanup == "true" ]]; then # Remove file(s) if requested - if [[ -f "${file%.*}.$compatible_compression_format" ]]; then - log i "Performing post-compression file cleanup" - if [[ "$file" == *".cue" ]]; then - local cue_bin_files=$(grep -o -P "(?<=FILE \").*(?=\".*$)" "$file") - local file_path=$(dirname "$(realpath "$file")") - while IFS= read -r line - do - log i "Removing file $file_path/$line" - rm -f "$file_path/$line" - done < <(printf '%s\n' "$cue_bin_files") - log i "Removing file $(realpath $file)" - rm -f $(realpath "$file") - else - log i "Removing file $(realpath $file)" - rm -f "$(realpath "$file")" - fi - else - log i "Compressed file ${file%.*}.$compatible_compression_format not found, skipping original file deletion" - configurator_generic_dialog "RetroDECK Configurator - RetroDECK: Compression Tool" "A compressed version of the file was not found, skipping deletion." - fi - fi ) | zenity --icon-name=net.retrodeck.retrodeck --progress --no-cancel --pulsate --auto-close \ --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ @@ -922,27 +900,6 @@ configurator_compress_multiple_games_dialog() { games_left_to_compress=$((games_left_to_compress-1)) log i "Games left to compress: $games_left_to_compress" compress_game "$compression_format" "$file" "$system" - if [[ $post_compression_cleanup == "true" ]]; then # Remove file(s) if requested - if [[ -f "${file%.*}.$compatible_compression_format" ]]; then - if [[ "$file" == *".cue" ]]; then - local cue_bin_files=$(grep -o -P "(?<=FILE \").*(?=\".*$)" "$file") - local file_path=$(dirname "$(realpath "$file")") - while IFS= read -r line - do - log i "Removing file $file_path/$line" - rm -f "$file_path/$line" - done < <(printf '%s\n' "$cue_bin_files") - log i "Removing file $(realpath $file)" - rm -f $(realpath "$file") - else - log i "Removing file $(realpath $file)" - rm -f "$(realpath "$file")" - fi - else - log i "Compressed file ${file%.*}.$compatible_compression_format not found, skipping original file deletion" - configurator_generic_dialog "RetroDECK Configurator - RetroDECK: Compression Tool" "Compression of $(basename $file) failed, skipping deletion." - fi - fi done ) | zenity --icon-name=net.retrodeck.retrodeck --progress --no-cancel --auto-close \