Skip to content

Commit

Permalink
Update compression process logging
Browse files Browse the repository at this point in the history
  • Loading branch information
icenine451 committed Apr 8, 2024
1 parent baea3b2 commit 9cb238a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
55 changes: 27 additions & 28 deletions functions/compression.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,44 +55,43 @@ validate_for_chd() {
local file="$1"
local normalized_filename=$(echo "$file" | tr '[:upper:]' '[:lower:]')
local file_validated="false"
chd_validation_log_file="compression_$(basename "$file").log"
echo "Validating file:" "$file" > "$logs_folder/$chd_validation_log_file"
log i "Validating file: $file"
if echo "$normalized_filename" | grep -qE '\.iso|\.cue|\.gdi'; then
echo ".cue/.iso/.gdi file detected" >> "$logs_folder/$chd_validation_log_file"
log i ".cue/.iso/.gdi file detected"
local file_path=$(dirname "$(realpath "$file")")
local file_base_name=$(basename "$file")
local file_name=${file_base_name%.*}
if [[ "$normalized_filename" == *".cue" ]]; then # Validate .cue file
if [[ ! "$file_path" == *"dreamcast"* ]]; then # .bin/.cue compression may not work for Dreamcast, only GDI or ISO # TODO: verify
echo "Validating .cue associated .bin files" >> "$logs_folder/$chd_validation_log_file"
log i "Validating .cue associated .bin files"
local cue_bin_files=$(grep -o -P "(?<=FILE \").*(?=\".*$)" "$file")
echo "Associated bin files read:" >> "$logs_folder/$chd_validation_log_file"
printf '%s\n' "$cue_bin_files" >> "$logs_folder/$chd_validation_log_file"
log i "Associated bin files read:"
log i $(printf '%s\n' "$cue_bin_files")
if [[ ! -z "$cue_bin_files" ]]; then
while IFS= read -r line
do
echo "looking for $file_path/$line" >> "$logs_folder/$chd_validation_log_file"
log i "Looking for $file_path/$line"
if [[ -f "$file_path/$line" ]]; then
echo ".bin file found at $file_path/$line" >> "$logs_folder/$chd_validation_log_file"
log i ".bin file found at $file_path/$line"
file_validated="true"
else
echo ".bin file NOT found at $file_path/$line" >> "$logs_folder/$chd_validation_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/$chd_validation_log_file"
log e ".bin file NOT found at $file_path/$line"
log e ".cue file could not be validated. Please verify your .cue file contains the correct corresponding .bin file information and retry."
file_validated="false"
break
fi
done < <(printf '%s\n' "$cue_bin_files")
fi
else
echo ".cue files not compatible with Dreamcast CHD compression" >> "$logs_folder/$chd_validation_log_file"
log w ".cue files not compatible with CHD compression"
fi
echo $file_validated
else # If file is a .iso or .gdi
file_validated="true"
echo $file_validated
fi
else
echo "File type not recognized. Supported file types are .cue, .gdi and .iso" >> "$logs_folder/$chd_validation_log_file"
log w "File type not recognized. Supported file types are .cue, .gdi and .iso"
echo $file_validated
fi
}
Expand All @@ -108,7 +107,7 @@ cli_compress_single_game() {
local system=$(echo "$file" | grep -oE "$roms_folder/[^/]+" | grep -oE "[^/]+$")
local compatible_compression_format=$(find_compatible_compression_format "$file")
if [[ ! $compatible_compression_format == "none" ]]; then
echo "$(basename "$file") can be compressed to $compatible_compression_format"
log i "$(basename "$file") can be compressed to $compatible_compression_format"
compress_game "$compatible_compression_format" "$file" "$system"
if [[ $post_compression_cleanup == [yY] ]]; then # Remove file(s) if requested
if [[ -f "${file%.*}.$compatible_compression_format" ]]; then
Expand All @@ -117,27 +116,27 @@ cli_compress_single_game() {
local file_path=$(dirname "$(realpath "$file")")
while IFS= read -r line
do # Remove associated .bin files
echo "Removing original file "$file_path/$line""
log i "Removing original file "$file_path/$line""
rm -f "$file_path/$line"
done < <(printf '%s\n' "$cue_bin_files") # Remove original .cue file
echo "Removing original file $(basename "$file")"
log i "Removing original file $(basename "$file")"
rm -f "$file"
else
echo "Removing original file $(basename "$file")"
log i "Removing original file $(basename "$file")"
rm -f "$file"
fi
else
echo "Compressed version of $(basename "$file") not found, skipping deletion."
log w "Compressed version of $(basename "$file") not found, skipping deletion."
fi
fi
else
echo "$(basename "$file") does not have any compatible compression formats."
log w "$(basename "$file") does not have any compatible compression formats."
fi
else
echo "File not found, please specify the full path to the file to be compressed."
log w "File not found, please specify the full path to the file to be compressed."
fi
else
echo "Please use this command format \"--compress-one <path to file to compress>\""
log i "Please use this command format \"--compress-one <path to file to compress>\""
fi
}

Expand Down Expand Up @@ -165,12 +164,12 @@ cli_compress_all_games() {
do
local compression_candidates=$(find "$roms_folder/$system" -type f -not -iname "*.txt")
if [[ ! -z "$compression_candidates" ]]; then
echo "Checking files for $system"
log i "Checking files for $system"
while IFS= read -r file
do
local compatible_compression_format=$(find_compatible_compression_format "$file")
if [[ ! "$compatible_compression_format" == "none" ]]; then
echo "$(basename "$file") can be compressed to $compatible_compression_format"
log i "$(basename "$file") can be compressed to $compatible_compression_format"
compress_game "$compatible_compression_format" "$file" "$system"
if [[ $post_compression_cleanup == [yY] ]]; then # Remove file(s) if requested
if [[ -f "${file%.*}.$compatible_compression_format" ]]; then
Expand All @@ -179,25 +178,25 @@ cli_compress_all_games() {
local file_path=$(dirname "$(realpath "$file")")
while IFS= read -r line
do # Remove associated .bin files
echo "Removing original file "$file_path/$line""
log i "Removing original file "$file_path/$line""
rm -f "$file_path/$line"
done < <(printf '%s\n' "$cue_bin_files") # Remove original .cue file
echo "Removing original file "$file""
log i "Removing original file "$file""
rm -f $(realpath "$file")
else
echo "Removing original file "$file""
log i "Removing original file "$file""
rm -f $(realpath "$file")
fi
else
echo "Compressed version of $(basename "$file") not found, skipping deletion."
log w "Compressed version of $(basename "$file") not found, skipping deletion."
fi
fi
else
echo "No compatible compression format found for $(basename "$file")"
log w "No compatible compression format found for $(basename "$file")"
fi
done < <(printf '%s\n' "$compression_candidates")
else
echo "No compatible files found for compression in $system"
log w "No compatible files found for compression in $system"
fi
done < <(printf '%s\n' "$compressable_systems_list")
}
14 changes: 13 additions & 1 deletion tools/configurator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -790,22 +790,28 @@ configurator_compress_single_game_dialog() {
if [[ ! $compatible_compression_format == "none" ]]; then
local post_compression_cleanup=$(configurator_compression_cleanup_dialog)
(
echo "# Compressing $(basename "$file") to $compatible_compression_format format"
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
Expand Down Expand Up @@ -909,9 +915,11 @@ configurator_compress_multiple_games_dialog() {
local system=$(echo "$file" | grep -oE "$roms_folder/[^/]+" | grep -oE "[^/]+$")
local compression_format=$(find_compatible_compression_format "$file")
echo "# Compressing $(basename "$file") into $compression_format format" # Update Zenity dialog text
log i "Compressing $(basename "$file") into $compression_format format"
progress=$(( 100 - (( 100 / "$total_games_to_compress" ) * "$games_left_to_compress" )))
echo $progress
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
Expand All @@ -920,13 +928,17 @@ configurator_compress_multiple_games_dialog() {
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
Expand Down

0 comments on commit 9cb238a

Please sign in to comment.