Rework CHD compression process

This commit is contained in:
icenine451 2023-03-08 10:33:38 -05:00
parent 8d81ac9858
commit 96ee4ddc8b
3 changed files with 37 additions and 50 deletions

View file

@ -128,34 +128,39 @@ 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
}

View file

@ -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 <file> Compresses target file to .chd format. Supports .cue, .iso and .gdi formats
--reset-emulator <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 <full path to cue/gdi/iso file>\""
echo "Please use this command format \"--compress <cue/gdi/iso file to compress>\""
fi
exit
;;
--configure*)
--configurator*)
sh /var/config/retrodeck/tools/configurator.sh
exit
;;

View file

@ -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