From fb3b96b6424ba9d633965f25ea44715649cfdaad Mon Sep 17 00:00:00 2001 From: icenine451 Date: Mon, 6 Mar 2023 12:50:25 -0500 Subject: [PATCH] Add CHD compression argument and functions --- functions.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ retrodeck.sh | 21 +++++++++++++++++---- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/functions.sh b/functions.sh index d9f760f0..d5d7feaf 100644 --- a/functions.sh +++ b/functions.sh @@ -86,6 +86,49 @@ move() { fi } +compress_to_chd () { + # Function for compressing one or more files to .chd format + # USAGE: compress_to_chd $full_path_to_input_file $full_path_to_output_file + + echo "Compressing file $1 to $2.chd" + /app/bin/chdman createcd -i $1 -o $2.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 + if [[ "$file" == *".cue" ]] || [[ "$file" == *".gdi" ]] || [[ "$file" == *".iso" ]]; then + echo ".cue/.iso/.gdi file detected" + 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) + 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 + 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" + fi + else + compress_to_chd "$file_path/$file_base_name" "$file_path/$file_name" + fi + else + echo "File type not recognized. Supported file types are .cue, .gdi and .iso" + fi +} + set_setting_value() { # Function for editing settings # USAGE: set_setting_value $setting_file "$setting_name" "$new_setting_value" $system $section_name(optional) diff --git a/retrodeck.sh b/retrodeck.sh index fd0d4925..1214b3c9 100644 --- a/retrodeck.sh +++ b/retrodeck.sh @@ -18,6 +18,7 @@ Arguments: -v, --version Print RetroDECK version --info-msg Print paths and config informations --configure Starts the RetroDECK Configurator + --compress Compresses target file to .chd format. Supports .cue, .iso and .gdi formats. --reset-all Starts the initial RetroDECK installer (backup your data first!) --reset-ra Resets RetroArch's config to the default values --reset-sa Reset all standalone emulator configs to the default values @@ -42,6 +43,22 @@ https://retrodeck.net cat $rd_conf exit ;; + --compress*) + if [[ ! -z $2 ]]; then + if [[ -f $2 ]]; then + validate_for_chd $2 + 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 + shift + ;; + --configure*) + sh /var/config/retrodeck/tools/configurator.sh + shift + ;; --reset-ra*) ra_init shift # past argument with no value @@ -58,10 +75,6 @@ https://retrodeck.net rm -f "$lockfile" shift # past argument with no value ;; - --configure*) - sh /var/config/retrodeck/tools/configurator.sh - shift # past argument with no value - ;; -*|--*) echo "Unknown option $i" exit 1