From 96ee4ddc8b426b70a97efdcd6e6dc5e8f1e446af Mon Sep 17 00:00:00 2001 From: icenine451 Date: Wed, 8 Mar 2023 10:33:38 -0500 Subject: [PATCH] Rework CHD compression process --- functions.sh | 23 +++++++++++++--------- retrodeck.sh | 18 ++++++++++++----- tools/configurator.sh | 46 ++++++++++--------------------------------- 3 files changed, 37 insertions(+), 50 deletions(-) diff --git a/functions.sh b/functions.sh index fd180350..a9882341 100644 --- a/functions.sh +++ b/functions.sh @@ -127,35 +127,40 @@ compress_to_chd () { validate_for_chd () { # Function for validating chd compression candidates, and compresses if validation passes. Supports .cue, .iso and .gdi formats ONLY # USAGE: validate_for_chd $input_file - -local file=$1 + + local file=$1 + current_run_log_file="chd_compression_"$(date +"%Y_%m_%d_%I_%M_%p").log"" + echo "Validating file:" $file > "$logs_folder/$current_run_log_file" if [[ "$file" == *".cue" ]] || [[ "$file" == *".gdi" ]] || [[ "$file" == *".iso" ]]; then - echo ".cue/.iso/.gdi file detected" + echo ".cue/.iso/.gdi file detected" >> $logs_folder/$current_run_log_file local file_path=$(dirname $(realpath $file)) local file_base_name=$(basename $file) local file_name=${file_base_name%.*} - if [[ "$file" == *".cue" ]]; then # Validate .cue file correctly maps existing .bin file(s) + echo "File base path:" $file_path >> "$logs_folder/$current_run_log_file" + echo "File base name:" $file_name >> "$logs_folder/$current_run_log_file" + if [[ "$file" == *".cue" ]]; then # Validate .cue file local cue_bin_files=$(grep -o -P "(?<=FILE \").*(?=\".*$)" $file) local cue_validated="false" for line in $cue_bin_files do if [[ -f "$file_path/$line" ]]; then + echo ".bin file found at $file_path/$line" >> "$logs_folder/$current_run_log_file" cue_validated="true" else - echo ".bin file NOT found at $file_path/$line" - echo ".cue file could not be validated. Please verify your .cue file contains the correct corresponding .bin file information and retry." + echo ".bin file NOT found at $file_path/$line" >> "$logs_folder/$current_run_log_file" + echo ".cue file could not be validated. Please verify your .cue file contains the correct corresponding .bin file information and retry." >> "$logs_folder/$current_run_log_file" cue_validated="false" break fi done if [[ $cue_validated == "true" ]]; then - compress_to_chd "$file_path/$file_base_name" "$file_path/$file_name" + echo $cue_validated fi else - compress_to_chd "$file_path/$file_base_name" "$file_path/$file_name" + echo $cue_validated fi else - echo "File type not recognized. Supported file types are .cue, .gdi and .iso" + echo "File type not recognized. Supported file types are .cue, .gdi and .iso" >> "$logs_folder/$current_run_log_file" fi } diff --git a/retrodeck.sh b/retrodeck.sh index 864116f0..b9c8e015 100644 --- a/retrodeck.sh +++ b/retrodeck.sh @@ -17,7 +17,7 @@ Arguments: -h, --help Print this help -v, --version Print RetroDECK version --info-msg Print paths and config informations - --configure Starts the RetroDECK Configurator + --configurator Starts the RetroDECK Configurator --compress Compresses target file to .chd format. Supports .cue, .iso and .gdi formats --reset-emulator Reset one or more emulator configs to the default values --reset-tools Reset the RetroDECK Tools section @@ -44,16 +44,24 @@ https://retrodeck.net read -p "RetroDECK will now attempt to compress your selected game. The original game will still exist and will need to be removed manually after the process completes. Press any key to continue..." if [[ ! -z $2 ]]; then if [[ -f $2 ]]; then - validate_for_chd $2 + current_run_log_file="chd_compression_"$(date +"%Y_%m_%d_%I_%M_%p").log"" + if [[ $(validate_for_chd $2) == "true" ]]; then + filename_no_path=$(basename $2) + filename_no_extension=${filename_no_path%.*} + compress_to_chd $(dirname $(realpath $2))/$(basename $2) $(dirname $(realpath $2))/$filename_no_extension + else + printf "An error occured during the compression process. Please see the following log entries for details:\n\n" + cat $logs_folder/$current_run_log_file + fi else echo "File not found, please specify the full path to the file to be compressed." fi else - echo "Please use this command format \"--compress \"" - fi + echo "Please use this command format \"--compress \"" + fi exit ;; - --configure*) + --configurator*) sh /var/config/retrodeck/tools/configurator.sh exit ;; diff --git a/tools/configurator.sh b/tools/configurator.sh index 2c765e86..55429fac 100644 --- a/tools/configurator.sh +++ b/tools/configurator.sh @@ -346,42 +346,16 @@ configurator_options_dialog() { configurator_compress_single_game_dialog() { file_to_compress=$(file_browse "Game to compress") if [[ ! -z $file_to_compress ]]; then - if [[ "$file_to_compress" == *".cue" ]] || [[ "$file_to_compress" == *".gdi" ]] || [[ "$file_to_compress" == *".iso" ]]; then - local file_path=$(dirname $(realpath $file_to_compress)) - local file_base_name=$(basename $file_to_compress) - local file_name=${file_base_name%.*} - if [[ "$file_to_compress" == *".cue" ]]; then # Validate .cue file correctly maps existing .bin file(s) - local cue_bin_files=$(grep -o -P "(?<=FILE \").*(?=\".*$)" $file_to_compress) - local cue_validated="false" - for line in $cue_bin_files - do - if [[ -f "$file_path/$line" ]]; then - cue_validated="true" - else - echo ".bin file NOT found at $file_path/$line" - echo ".cue file could not be validated. Please verify your .cue file contains the correct corresponding .bin file information and retry." - cue_validated="false" - break - fi - done - if [[ $cue_validated == "true" ]]; then - ( - compress_to_chd "$file_path/$file_base_name" "$file_path/$file_name" - ) | - 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 - Compression in Progress" \ - --text="Compressing game $file_base_name, please wait." - fi - else - ( - compress_to_chd "$file_path/$file_base_name" "$file_path/$file_name" - ) | - 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 - Compression in Progress" \ - --text="Compressing game $file_base_name, please wait." - fi + if [[ $(validate_for_chd $file_to_compress) == "true" ]]; then + ( + filename_no_path=$(basename $file_to_compress) + filename_no_extension=${filename_no_path%.*} + compress_to_chd $(dirname $(realpath $file_to_compress))/$(basename $file_to_compress) $(dirname $(realpath $file_to_compress))/$filename_no_extension + ) | + 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 - Compression in Progress" \ + --text="Compressing game $filename_no_path, please wait." else configurator_generic_dialog "File type not recognized. Supported file types are .cue, .gdi and .iso" configurator_compress_single_game_dialog