Add comment and blank line handling to reference-file-reading functions

This commit is contained in:
icenine451 2024-06-29 15:31:05 -04:00
parent 88893a3c1b
commit 2e44842458
5 changed files with 172 additions and 164 deletions

View file

@ -158,9 +158,11 @@ check_for_version_update() {
validate_input() { validate_input() {
while IFS="^" read -r input action || [[ -n "$input" ]]; while IFS="^" read -r input action || [[ -n "$input" ]];
do do
if [[ "$input" == "$1" ]]; then if [[ ! $input == "#"* ]] && [[ ! -z "$input" ]]; then
eval "$action" if [[ "$input" == "$1" ]]; then
input_validated="true" eval "$action"
input_validated="true"
fi
fi fi
done < $input_validation done < $input_validation
} }

View file

@ -12,22 +12,24 @@ check_bios_files() {
while IFS="^" read -r bios_file bios_subdir bios_hash bios_system bios_desc || [[ -n "$bios_file" ]]; while IFS="^" read -r bios_file bios_subdir bios_hash bios_system bios_desc || [[ -n "$bios_file" ]];
do do
bios_file_found="No" if [[ ! $bios_file == "#"* ]] && [[ ! -z "$bios_file" ]]; then
bios_hash_matched="No" bios_file_found="No"
if [[ -f "$bios_folder/$bios_subdir$bios_file" ]]; then bios_hash_matched="No"
bios_file_found="Yes" if [[ -f "$bios_folder/$bios_subdir$bios_file" ]]; then
if [[ $bios_hash == "Unknown" ]]; then bios_file_found="Yes"
bios_hash_matched="Unknown" if [[ $bios_hash == "Unknown" ]]; then
elif [[ $(md5sum "$bios_folder/$bios_subdir$bios_file" | awk '{ print $1 }') == "$bios_hash" ]]; then bios_hash_matched="Unknown"
bios_hash_matched="Yes" elif [[ $(md5sum "$bios_folder/$bios_subdir$bios_file" | awk '{ print $1 }') == "$bios_hash" ]]; then
bios_hash_matched="Yes"
fi
fi
if [[ "$1" == "basic" ]]; then
bios_checked_list=("${bios_checked_list[@]}" "$bios_file" "$bios_system" "$bios_file_found" "$bios_hash_matched" "$bios_desc")
echo "$bios_file"^"$bios_system"^"$bios_file_found"^"$bios_hash_matched"^"$bios_desc" >> "$godot_bios_files_checked" # Godot data transfer temp file
else
bios_checked_list=("${bios_checked_list[@]}" "$bios_file" "$bios_system" "$bios_file_found" "$bios_hash_matched" "$bios_desc" "$bios_subdir" "$bios_hash")
echo "$bios_file"^"$bios_system"^"$bios_file_found"^"$bios_hash_matched"^"$bios_desc"^"$bios_subdir"^"$bios_hash" >> "$godot_bios_files_checked" # Godot data transfer temp file
fi fi
fi
if [[ "$1" == "basic" ]]; then
bios_checked_list=("${bios_checked_list[@]}" "$bios_file" "$bios_system" "$bios_file_found" "$bios_hash_matched" "$bios_desc")
echo "$bios_file"^"$bios_system"^"$bios_file_found"^"$bios_hash_matched"^"$bios_desc" >> "$godot_bios_files_checked" # Godot data transfer temp file
else
bios_checked_list=("${bios_checked_list[@]}" "$bios_file" "$bios_system" "$bios_file_found" "$bios_hash_matched" "$bios_desc" "$bios_subdir" "$bios_hash")
echo "$bios_file"^"$bios_system"^"$bios_file_found"^"$bios_hash_matched"^"$bios_desc"^"$bios_subdir"^"$bios_hash" >> "$godot_bios_files_checked" # Godot data transfer temp file
fi fi
done < $bios_checklist done < $bios_checklist
} }

View file

@ -412,45 +412,42 @@ cp -fv "$1" "$3" # Create a copy of the original file to be patched
while IFS="^" read -r action current_section setting_name setting_value system_name || [[ -n "$action" ]]; while IFS="^" read -r action current_section setting_name setting_value system_name || [[ -n "$action" ]];
do do
if [[ ! $action == "#"* ]] && [[ ! -z "$action" ]]; then
case $action in
case $action in "disable_file" )
eval disable_file "$setting_name"
;;
"disable_file" ) "enable_file" )
eval disable_file "$setting_name" eval enable_file "$setting_name"
;; ;;
"enable_file" ) "add_setting_line" )
eval enable_file "$setting_name" add_setting_line "$3" "$setting_name" "$system_name" "$current_section"
;; ;;
"add_setting_line" ) "disable_setting" )
add_setting_line "$3" "$setting_name" "$system_name" "$current_section" disable_setting "$3" "$setting_name" "$system_name" "$current_section"
;; ;;
"disable_setting" ) "enable_setting" )
disable_setting "$3" "$setting_name" "$system_name" "$current_section" enable_setting "$3" "$setting_name" "$system_name" "$current_section"
;; ;;
"enable_setting" ) "change" )
enable_setting "$3" "$setting_name" "$system_name" "$current_section" if [[ "$setting_value" = \$* ]]; then # If patch setting value is a reference to an internal variable name
;; eval setting_value="$setting_value"
fi
set_setting_value "$3" "$setting_name" "$setting_value" "$system_name" "$current_section"
;;
"change" ) * )
if [[ "$setting_value" = \$* ]]; then # If patch setting value is a reference to an internal variable name log e "Config line malformed: $action"
eval setting_value="$setting_value" ;;
fi
set_setting_value "$3" "$setting_name" "$setting_value" "$system_name" "$current_section"
;;
*"#"* ) esac
# Comment line in patch file fi
;;
* )
echo "Config line malformed: $action"
;;
esac
done < "$2" done < "$2"
} }
@ -463,58 +460,56 @@ deploy_multi_patch() {
while IFS="^" read -r action current_section setting_name setting_value system_name config_file || [[ -n "$action" ]]; while IFS="^" read -r action current_section setting_name setting_value system_name config_file || [[ -n "$action" ]];
do do
case $action in if [[ ! $action == "#"* ]] && [[ ! -z "$action" ]]; then
case $action in
"disable_file" ) "disable_file" )
if [[ "$config_file" = \$* ]]; then # If patch setting value is a reference to an internal variable name if [[ "$config_file" = \$* ]]; then # If patch setting value is a reference to an internal variable name
eval config_file="$config_file" eval config_file="$config_file"
fi fi
disable_file "$config_file" disable_file "$config_file"
;; ;;
"enable_file" ) "enable_file" )
if [[ "$config_file" = \$* ]]; then # If patch setting value is a reference to an internal variable name if [[ "$config_file" = \$* ]]; then # If patch setting value is a reference to an internal variable name
eval config_file="$config_file" eval config_file="$config_file"
fi fi
enable_file "$config_file" enable_file "$config_file"
;; ;;
"add_setting_line" ) "add_setting_line" )
if [[ "$config_file" = \$* ]]; then # If patch setting value is a reference to an internal variable name if [[ "$config_file" = \$* ]]; then # If patch setting value is a reference to an internal variable name
eval config_file="$config_file" eval config_file="$config_file"
fi fi
add_setting_line "$config_file" "$setting_name" "$system_name" "$current_section" add_setting_line "$config_file" "$setting_name" "$system_name" "$current_section"
;; ;;
"disable_setting" ) "disable_setting" )
if [[ "$config_file" = \$* ]]; then # If patch setting value is a reference to an internal variable name if [[ "$config_file" = \$* ]]; then # If patch setting value is a reference to an internal variable name
eval config_file="$config_file" eval config_file="$config_file"
fi fi
disable_setting "$config_file" "$setting_name" "$system_name" "$current_section" disable_setting "$config_file" "$setting_name" "$system_name" "$current_section"
;; ;;
"enable_setting" ) "enable_setting" )
if [[ "$config_file" = \$* ]]; then # If patch setting value is a reference to an internal variable name if [[ "$config_file" = \$* ]]; then # If patch setting value is a reference to an internal variable name
eval config_file="$config_file" eval config_file="$config_file"
fi fi
enable_setting "$config_file" "$setting_name" "$system_name" "$current_section" enable_setting "$config_file" "$setting_name" "$system_name" "$current_section"
;; ;;
"change" ) "change" )
if [[ "$setting_value" = \$* ]]; then # If patch setting value is a reference to an internal variable name if [[ "$setting_value" = \$* ]]; then # If patch setting value is a reference to an internal variable name
eval setting_value="$setting_value" eval setting_value="$setting_value"
fi fi
set_setting_value "$config_file" "$setting_name" "$setting_value" "$system_name" "$current_section" set_setting_value "$config_file" "$setting_name" "$setting_value" "$system_name" "$current_section"
;; ;;
*"#"* ) * )
# Comment line in patch file log e "Config line malformed: $action"
;; ;;
* ) esac
echo "Config line malformed: $action" fi
;;
esac
done < "$1" done < "$1"
} }

View file

@ -363,7 +363,9 @@ finit_user_options_dialog() {
while IFS="^" read -r enabled option_name option_desc option_tag || [[ -n "$enabled" ]]; while IFS="^" read -r enabled option_name option_desc option_tag || [[ -n "$enabled" ]];
do do
finit_available_options=("${finit_available_options[@]}" "$enabled" "$option_name" "$option_desc" "$option_tag") if [[ ! $enabled == "#"* ]] && [[ ! -z "$enabled" ]]; then
finit_available_options=("${finit_available_options[@]}" "$enabled" "$option_name" "$option_desc" "$option_tag")
fi
done < $finit_options_list done < $finit_options_list
@ -581,11 +583,13 @@ easter_eggs() {
if [[ ! -z $(cat $easter_egg_checklist) ]]; then if [[ ! -z $(cat $easter_egg_checklist) ]]; then
while IFS="^" read -r start_date end_date start_time end_time splash_file || [[ -n "$start_date" ]]; # Read Easter Egg checklist file and separate values while IFS="^" read -r start_date end_date start_time end_time splash_file || [[ -n "$start_date" ]]; # Read Easter Egg checklist file and separate values
do do
if [[ "$((10#$current_day))" -ge "$((10#$start_date))" && "$((10#$current_day))" -le "$((10#$end_date))" && "$((10#$current_time))" -ge "$((10#$start_time))" && "$((10#$current_time))" -le "$((10#$end_time))" ]]; then # If current line specified date/time matches current date/time, set $splash_file to be deployed if [[ ! $start_date == "#"* ]] && [[ ! -z "$start_date" ]]; then
new_splash_file="$splashscreen_dir/$splash_file" if [[ "$((10#$current_day))" -ge "$((10#$start_date))" && "$((10#$current_day))" -le "$((10#$end_date))" && "$((10#$current_time))" -ge "$((10#$start_time))" && "$((10#$current_time))" -le "$((10#$end_time))" ]]; then # If current line specified date/time matches current date/time, set $splash_file to be deployed
break new_splash_file="$splashscreen_dir/$splash_file"
else # When there are no matches, the default splash screen is set to deploy break
new_splash_file="$default_splash_file" else # When there are no matches, the default splash screen is set to deploy
new_splash_file="$default_splash_file"
fi
fi fi
done < $easter_egg_checklist done < $easter_egg_checklist
else else

View file

@ -79,11 +79,14 @@ make_preset_changes() {
fi fi
set_setting_value "$rd_conf" "$emulator" "true" "retrodeck" "$preset" set_setting_value "$rd_conf" "$emulator" "true" "retrodeck" "$preset"
# Check for conflicting presets for this system # Check for conflicting presets for this system
while IFS=: read -r preset_being_checked known_incompatible_preset; do while IFS=: read -r preset_being_checked known_incompatible_preset || [[ -n "$preset_being_checked" ]];
if [[ "$preset" == "$preset_being_checked" ]]; then do
if [[ $(get_setting_value "$rd_conf" "$emulator" "retrodeck" "$known_incompatible_preset") == "true" ]]; then if [[ ! $preset_being_checked == "#"* ]] && [[ ! -z "$preset_being_checked" ]]; then
changed_presets=("${changed_presets[@]}" "$known_incompatible_preset") if [[ "$preset" == "$preset_being_checked" ]]; then
set_setting_value "$rd_conf" "$emulator" "false" "retrodeck" "$known_incompatible_preset" if [[ $(get_setting_value "$rd_conf" "$emulator" "retrodeck" "$known_incompatible_preset") == "true" ]]; then
changed_presets=("${changed_presets[@]}" "$known_incompatible_preset")
set_setting_value "$rd_conf" "$emulator" "false" "retrodeck" "$known_incompatible_preset"
fi
fi fi
fi fi
done < "$incompatible_presets_reference_list" done < "$incompatible_presets_reference_list"
@ -118,79 +121,81 @@ build_preset_config() {
local read_system_enabled=$(get_setting_value "$rd_conf" "$read_system_name" "retrodeck" "$current_preset") local read_system_enabled=$(get_setting_value "$rd_conf" "$read_system_name" "retrodeck" "$current_preset")
while IFS='^' read -r action read_preset read_setting_name new_setting_value section target_file defaults_file || [[ -n "$action" ]]; while IFS='^' read -r action read_preset read_setting_name new_setting_value section target_file defaults_file || [[ -n "$action" ]];
do do
case "$action" in if [[ ! $action == "#"* ]] && [[ ! -z "$action" ]]; then
case "$action" in
"config_file_format" ) "config_file_format" )
if [[ "$read_preset" == "retroarch-all" ]]; then if [[ "$read_preset" == "retroarch-all" ]]; then
local retroarch_all="true" local retroarch_all="true"
local read_config_format="retroarch" local read_config_format="retroarch"
else else
local read_config_format="$read_preset" local read_config_format="$read_preset"
fi fi
;; ;;
"change" ) "change" )
if [[ "$read_preset" == "$current_preset" ]]; then if [[ "$read_preset" == "$current_preset" ]]; then
if [[ "$target_file" = \$* ]]; then # Read current target file and resolve if it is a variable if [[ "$target_file" = \$* ]]; then # Read current target file and resolve if it is a variable
eval target_file=$target_file eval target_file=$target_file
fi
local read_target_file="$target_file"
if [[ "$defaults_file" = \$* ]]; then #Read current defaults file and resolve if it is a variable
eval defaults_file=$defaults_file
fi
local read_defaults_file="$defaults_file"
if [[ "$read_system_enabled" == "true" ]]; then
if [[ "$new_setting_value" = \$* ]]; then
eval new_setting_value=$new_setting_value
fi fi
if [[ "$read_config_format" == "retroarch" && ! "$retroarch_all" == "true" ]]; then # If this is a RetroArch core, generate the override file local read_target_file="$target_file"
if [[ ! -f "$read_target_file" ]]; then if [[ "$defaults_file" = \$* ]]; then #Read current defaults file and resolve if it is a variable
create_dir "$(realpath "$(dirname "$read_target_file")")" eval defaults_file=$defaults_file
echo "$read_setting_name = \""$new_setting_value"\"" > "$read_target_file" fi
else local read_defaults_file="$defaults_file"
if [[ -z $(grep -o -P "^$read_setting_name\b" "$read_target_file") ]]; then if [[ "$read_system_enabled" == "true" ]]; then
add_setting "$read_target_file" "$read_setting_name" "$new_setting_value" "$read_config_format" "$section" if [[ "$new_setting_value" = \$* ]]; then
eval new_setting_value=$new_setting_value
fi
if [[ "$read_config_format" == "retroarch" && ! "$retroarch_all" == "true" ]]; then # If this is a RetroArch core, generate the override file
if [[ ! -f "$read_target_file" ]]; then
create_dir "$(realpath "$(dirname "$read_target_file")")"
echo "$read_setting_name = \""$new_setting_value"\"" > "$read_target_file"
else else
set_setting_value "$read_target_file" "$read_setting_name" "$new_setting_value" "$read_config_format" "$section" if [[ -z $(grep -o -P "^$read_setting_name\b" "$read_target_file") ]]; then
add_setting "$read_target_file" "$read_setting_name" "$new_setting_value" "$read_config_format" "$section"
else
set_setting_value "$read_target_file" "$read_setting_name" "$new_setting_value" "$read_config_format" "$section"
fi
fi fi
else
set_setting_value "$read_target_file" "$read_setting_name" "$new_setting_value" "$read_config_format" "$section"
fi fi
else else
set_setting_value "$read_target_file" "$read_setting_name" "$new_setting_value" "$read_config_format" "$section" if [[ "$read_config_format" == "retroarch" && ! "$retroarch_all" == "true" ]]; then
fi if [[ -f "$read_target_file" ]]; then
else delete_setting "$read_target_file" "$read_setting_name" "$read_config_format" "$section"
if [[ "$read_config_format" == "retroarch" && ! "$retroarch_all" == "true" ]]; then if [[ -z $(cat "$read_target_file") ]]; then # If the override file is empty
if [[ -f "$read_target_file" ]]; then rm -f "$read_target_file"
delete_setting "$read_target_file" "$read_setting_name" "$read_config_format" "$section" fi
if [[ -z $(cat "$read_target_file") ]]; then # If the override file is empty if [[ -z $(ls -1 "$(dirname "$read_target_file")") ]]; then # If the override folder is empty
rm -f "$read_target_file" rmdir "$(realpath "$(dirname "$read_target_file")")"
fi fi
if [[ -z $(ls -1 "$(dirname "$read_target_file")") ]]; then # If the override folder is empty
rmdir "$(realpath "$(dirname "$read_target_file")")"
fi fi
else
local default_setting_value=$(get_setting_value "$read_defaults_file" "$read_setting_name" "$read_config_format" "$section")
set_setting_value "$read_target_file" "$read_setting_name" "$default_setting_value" "$read_config_format" "$section"
fi fi
else
local default_setting_value=$(get_setting_value "$read_defaults_file" "$read_setting_name" "$read_config_format" "$section")
set_setting_value "$read_target_file" "$read_setting_name" "$default_setting_value" "$read_config_format" "$section"
fi fi
fi fi
fi ;;
;;
"enable" ) "enable" )
if [[ "$read_preset" == "$current_preset" ]]; then if [[ "$read_preset" == "$current_preset" ]]; then
if [[ "$read_system_enabled" == "true" ]]; then if [[ "$read_system_enabled" == "true" ]]; then
enable_file "$read_setting_name" enable_file "$read_setting_name"
else else
disable_file "$read_setting_name" disable_file "$read_setting_name"
fi
fi fi
fi ;;
;;
* ) * )
echo "Other data: $action $read_preset $read_setting_name $new_setting_value $section" # DEBUG echo "Other data: $action $read_preset $read_setting_name $new_setting_value $section" # DEBUG
;; ;;
esac esac
fi
done < <(cat "$presets_dir/$read_system_name"_presets.cfg) done < <(cat "$presets_dir/$read_system_name"_presets.cfg)
fi fi
done < <(printf '%s\n' "$preset_section") done < <(printf '%s\n' "$preset_section")