Update compression process logging

This commit is contained in:
icenine451 2024-04-08 09:34:21 -04:00
parent baea3b284e
commit 9cb238a9df
2 changed files with 40 additions and 29 deletions

View file

@ -55,36 +55,35 @@ validate_for_chd() {
local file="$1" local file="$1"
local normalized_filename=$(echo "$file" | tr '[:upper:]' '[:lower:]') local normalized_filename=$(echo "$file" | tr '[:upper:]' '[:lower:]')
local file_validated="false" local file_validated="false"
chd_validation_log_file="compression_$(basename "$file").log" log i "Validating file: $file"
echo "Validating file:" "$file" > "$logs_folder/$chd_validation_log_file"
if echo "$normalized_filename" | grep -qE '\.iso|\.cue|\.gdi'; then 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_path=$(dirname "$(realpath "$file")")
local file_base_name=$(basename "$file") local file_base_name=$(basename "$file")
local file_name=${file_base_name%.*} local file_name=${file_base_name%.*}
if [[ "$normalized_filename" == *".cue" ]]; then # Validate .cue file 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 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") local cue_bin_files=$(grep -o -P "(?<=FILE \").*(?=\".*$)" "$file")
echo "Associated bin files read:" >> "$logs_folder/$chd_validation_log_file" log i "Associated bin files read:"
printf '%s\n' "$cue_bin_files" >> "$logs_folder/$chd_validation_log_file" log i $(printf '%s\n' "$cue_bin_files")
if [[ ! -z "$cue_bin_files" ]]; then if [[ ! -z "$cue_bin_files" ]]; then
while IFS= read -r line while IFS= read -r line
do 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 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" file_validated="true"
else else
echo ".bin file NOT found at $file_path/$line" >> "$logs_folder/$chd_validation_log_file" log e ".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." >> "$logs_folder/$chd_validation_log_file" 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" file_validated="false"
break break
fi fi
done < <(printf '%s\n' "$cue_bin_files") done < <(printf '%s\n' "$cue_bin_files")
fi fi
else 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 fi
echo $file_validated echo $file_validated
else # If file is a .iso or .gdi else # If file is a .iso or .gdi
@ -92,7 +91,7 @@ validate_for_chd() {
echo $file_validated echo $file_validated
fi fi
else 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 echo $file_validated
fi fi
} }
@ -108,7 +107,7 @@ cli_compress_single_game() {
local system=$(echo "$file" | grep -oE "$roms_folder/[^/]+" | grep -oE "[^/]+$") local system=$(echo "$file" | grep -oE "$roms_folder/[^/]+" | grep -oE "[^/]+$")
local compatible_compression_format=$(find_compatible_compression_format "$file") local compatible_compression_format=$(find_compatible_compression_format "$file")
if [[ ! $compatible_compression_format == "none" ]]; then 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" compress_game "$compatible_compression_format" "$file" "$system"
if [[ $post_compression_cleanup == [yY] ]]; then # Remove file(s) if requested if [[ $post_compression_cleanup == [yY] ]]; then # Remove file(s) if requested
if [[ -f "${file%.*}.$compatible_compression_format" ]]; then if [[ -f "${file%.*}.$compatible_compression_format" ]]; then
@ -117,27 +116,27 @@ cli_compress_single_game() {
local file_path=$(dirname "$(realpath "$file")") local file_path=$(dirname "$(realpath "$file")")
while IFS= read -r line while IFS= read -r line
do # Remove associated .bin files 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" rm -f "$file_path/$line"
done < <(printf '%s\n' "$cue_bin_files") # Remove original .cue file 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" rm -f "$file"
else else
echo "Removing original file $(basename "$file")" log i "Removing original file $(basename "$file")"
rm -f "$file" rm -f "$file"
fi fi
else else
echo "Compressed version of $(basename "$file") not found, skipping deletion." log w "Compressed version of $(basename "$file") not found, skipping deletion."
fi fi
fi fi
else else
echo "$(basename "$file") does not have any compatible compression formats." log w "$(basename "$file") does not have any compatible compression formats."
fi fi
else 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 fi
else 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 fi
} }
@ -165,12 +164,12 @@ cli_compress_all_games() {
do do
local compression_candidates=$(find "$roms_folder/$system" -type f -not -iname "*.txt") local compression_candidates=$(find "$roms_folder/$system" -type f -not -iname "*.txt")
if [[ ! -z "$compression_candidates" ]]; then if [[ ! -z "$compression_candidates" ]]; then
echo "Checking files for $system" log i "Checking files for $system"
while IFS= read -r file while IFS= read -r file
do do
local compatible_compression_format=$(find_compatible_compression_format "$file") local compatible_compression_format=$(find_compatible_compression_format "$file")
if [[ ! "$compatible_compression_format" == "none" ]]; then 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" compress_game "$compatible_compression_format" "$file" "$system"
if [[ $post_compression_cleanup == [yY] ]]; then # Remove file(s) if requested if [[ $post_compression_cleanup == [yY] ]]; then # Remove file(s) if requested
if [[ -f "${file%.*}.$compatible_compression_format" ]]; then if [[ -f "${file%.*}.$compatible_compression_format" ]]; then
@ -179,25 +178,25 @@ cli_compress_all_games() {
local file_path=$(dirname "$(realpath "$file")") local file_path=$(dirname "$(realpath "$file")")
while IFS= read -r line while IFS= read -r line
do # Remove associated .bin files 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" rm -f "$file_path/$line"
done < <(printf '%s\n' "$cue_bin_files") # Remove original .cue file 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") rm -f $(realpath "$file")
else else
echo "Removing original file "$file"" log i "Removing original file "$file""
rm -f $(realpath "$file") rm -f $(realpath "$file")
fi fi
else else
echo "Compressed version of $(basename "$file") not found, skipping deletion." log w "Compressed version of $(basename "$file") not found, skipping deletion."
fi fi
fi fi
else else
echo "No compatible compression format found for $(basename "$file")" log w "No compatible compression format found for $(basename "$file")"
fi fi
done < <(printf '%s\n' "$compression_candidates") done < <(printf '%s\n' "$compression_candidates")
else else
echo "No compatible files found for compression in $system" log w "No compatible files found for compression in $system"
fi fi
done < <(printf '%s\n' "$compressable_systems_list") done < <(printf '%s\n' "$compressable_systems_list")
} }

View file

@ -790,22 +790,28 @@ configurator_compress_single_game_dialog() {
if [[ ! $compatible_compression_format == "none" ]]; then if [[ ! $compatible_compression_format == "none" ]]; then
local post_compression_cleanup=$(configurator_compression_cleanup_dialog) 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" compress_game "$compatible_compression_format" "$file" "$system"
if [[ $post_compression_cleanup == "true" ]]; then # Remove file(s) if requested if [[ $post_compression_cleanup == "true" ]]; then # Remove file(s) if requested
if [[ -f "${file%.*}.$compatible_compression_format" ]]; then if [[ -f "${file%.*}.$compatible_compression_format" ]]; then
log i "Performing post-compression file cleanup"
if [[ "$file" == *".cue" ]]; then if [[ "$file" == *".cue" ]]; then
local cue_bin_files=$(grep -o -P "(?<=FILE \").*(?=\".*$)" "$file") local cue_bin_files=$(grep -o -P "(?<=FILE \").*(?=\".*$)" "$file")
local file_path=$(dirname "$(realpath "$file")") local file_path=$(dirname "$(realpath "$file")")
while IFS= read -r line while IFS= read -r line
do do
log i "Removing file $file_path/$line"
rm -f "$file_path/$line" rm -f "$file_path/$line"
done < <(printf '%s\n' "$cue_bin_files") done < <(printf '%s\n' "$cue_bin_files")
log i "Removing file $(realpath $file)"
rm -f $(realpath "$file") rm -f $(realpath "$file")
else else
log i "Removing file $(realpath $file)"
rm -f "$(realpath "$file")" rm -f "$(realpath "$file")"
fi fi
else 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." configurator_generic_dialog "RetroDECK Configurator - RetroDECK: Compression Tool" "A compressed version of the file was not found, skipping deletion."
fi fi
fi fi
@ -909,9 +915,11 @@ configurator_compress_multiple_games_dialog() {
local system=$(echo "$file" | grep -oE "$roms_folder/[^/]+" | grep -oE "[^/]+$") local system=$(echo "$file" | grep -oE "$roms_folder/[^/]+" | grep -oE "[^/]+$")
local compression_format=$(find_compatible_compression_format "$file") local compression_format=$(find_compatible_compression_format "$file")
echo "# Compressing $(basename "$file") into $compression_format format" # Update Zenity dialog text 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" ))) progress=$(( 100 - (( 100 / "$total_games_to_compress" ) * "$games_left_to_compress" )))
echo $progress echo $progress
games_left_to_compress=$((games_left_to_compress-1)) 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" compress_game "$compression_format" "$file" "$system"
if [[ $post_compression_cleanup == "true" ]]; then # Remove file(s) if requested if [[ $post_compression_cleanup == "true" ]]; then # Remove file(s) if requested
if [[ -f "${file%.*}.$compatible_compression_format" ]]; then if [[ -f "${file%.*}.$compatible_compression_format" ]]; then
@ -920,13 +928,17 @@ configurator_compress_multiple_games_dialog() {
local file_path=$(dirname "$(realpath "$file")") local file_path=$(dirname "$(realpath "$file")")
while IFS= read -r line while IFS= read -r line
do do
log i "Removing file $file_path/$line"
rm -f "$file_path/$line" rm -f "$file_path/$line"
done < <(printf '%s\n' "$cue_bin_files") done < <(printf '%s\n' "$cue_bin_files")
log i "Removing file $(realpath $file)"
rm -f $(realpath "$file") rm -f $(realpath "$file")
else else
log i "Removing file $(realpath $file)"
rm -f "$(realpath "$file")" rm -f "$(realpath "$file")"
fi fi
else 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." configurator_generic_dialog "RetroDECK Configurator - RetroDECK: Compression Tool" "Compression of $(basename $file) failed, skipping deletion."
fi fi
fi fi