sed -i 's^\^'"$setting_name_to_change"'=.*^'"$setting_name_to_change"'='"$setting_value_to_change"'^'$1
else
sed -i '\^\['"$current_section_name"'\]^,\^\^'"$setting_name_to_change"'=^s^\^'"$setting_name_to_change"'=.*^'"$setting_name_to_change"'='"$setting_value_to_change"'^'$1
fi
if[["$4"=="retrodeck"&&("$current_section_name"==""||"$current_section_name"=="paths"||"$current_section_name"=="options")]];then# If a RetroDECK setting is being changed, also write it to memory for immediate use
sed -i 's^\^'"$setting_name_to_change"' =.*^'"$setting_name_to_change"' = '"$setting_value_to_change"'^'$1
else
sed -i '\^\['"$current_section_name"'\]^,\^\^'"$setting_name_to_change"' =^s^\^'"$setting_name_to_change"' =.*^'"$setting_name_to_change"' = '"$setting_value_to_change"'^'$1
fi
;;
"rpcs3")# This does not currently work for settings with a $ in them
if[[ -z $current_section_name]];then
sed -i 's^\^'"$setting_name_to_change"': .*^'"$setting_name_to_change"': '"$setting_value_to_change"'^'$1
else
sed -i '\^\['"$current_section_name"'\]^,\^\^'"$setting_name_to_change"'.*^s^\^'"$setting_name_to_change"': .*^'"$setting_name_to_change"': '"$setting_value_to_change"'^'$1
fi
;;
"es_settings")
sed -i 's^'"$setting_name_to_change"'" value=".*"^'"$setting_name_to_change"'" value="'"$setting_value_to_change"'"^'$1
;;
esac
}
get_setting_name(){
# Function for getting the setting name from a full setting line from a config file
# This function will add a setting line to a file. This is useful for dynamically generated config files where a setting line may not exist until the setting is changed from the default.
sed -i -E 's^(\s*?)'"$current_setting_line"'^\1#'"$current_setting_line"'^'$1
else
sed -i -E '\^\['"$current_section_name"'\]|\b'"$current_section_name"':$^,\^\s*?'"$current_setting_line"'^s^(\s*?)'"$current_setting_line"'^\1#'"$current_setting_line"'^'$1
fi
;;
esac
}
enable_setting(){
# This function will remove a '#' to the beginning of a defined setting line, enabling it.
sed -i -E 's^(\s*?)#'"$current_setting_line"'^\1'"$current_setting_line"'^'$1
else
sed -i -E '\^\['"$current_section_name"'\]|\b'"$current_section_name"':$^,\^\s*?#'"$current_setting_line"'^s^(\s*?)#'"$current_setting_line"'^\1'"$current_setting_line"'^'$1
fi
;;
esac
}
disable_file(){
# This function adds the suffix ".disabled" to the end of a file to prevent it from being used entirely.
# USAGE: disable_file $file_name
# NOTE: $filename can be a defined variable from global.sh or must have the full path to the file
mv $(realpath $1)$(realpath $1).disabled
}
enable_file(){
# This function removes the suffix ".disabled" to the end of a file to allow it to be used.
# USAGE: enable_file $file_name
# NOTE: $filename can be a defined variable from global.sh or must have the full path to the file and should not have ".disabled" as a suffix
mv $(realpath $1.disabled)$(realpath $(echo$1| sed -e 's/\.disabled//'))
if[[ -z $(sed -n -E '\^\['"$current_section"'\]|\b'"$current_section"':$^,\^\s*?'"$(sed -E 's/^[ \t]*//;'<<<"$escaped_setting_line")"'^{ \^\['"$current_section"'\]|\b'"$current_section"':$^! { \^\s*?'"$(sed -E 's/^[ \t]*//'<<<"$escaped_setting_line")"'^ p } }'"$modified_file")]];then# If disabled line is not disabled in new file...
elif[[ ! -z $(sed -n -E '\^\['"$current_section"'\]|\b'"$current_section"':$^,\^\s*?#'"$(sed -E 's/^[ \t]*//'<<<"$escaped_setting_line")"'^{ \^\['"$current_section"'\]|\b'"$current_section"':$^! { \^\s*?#'"$(sed -E 's/^[ \t]*//;'<<<"$escaped_setting_line")"'^ p } }'"$modified_file")]];then# Check if line is disabled in new file
if[[(-z $(sed -n -E '\^\['"$current_section"'\]|\b'"$current_section"':$^,\^\b'"$current_setting_name"'\s*?[:=]^{ \^\['"$current_section"'\]|\b'"$current_section"':$^! { \^\b'"$(sed -E 's/^[ \t]*//;'<<<"$escaped_setting_line")"'$^ p } }'"$modified_file"))]];then# If the same setting line is not found in the same section of the modified file...
if[[ ! -z $(sed -n -E '\^\['"$current_section"'\]|\b'"$current_section"':$^,\^\b'"$current_setting_name"'\s*?[:=]^{ \^\['"$current_section"'\]|\b'"$current_section"':$^! { \^\b'"$current_setting_name"'\s*?[:=]^ p } }'"$modified_file")]];then# But the setting exists in that section, only with a different value...
elif[[ ! -z $(sed -n -E '\^\s*?#'"$(sed -E 's/^[ \t]*//'<<<"$escaped_setting_line")"'$^p'"$modified_file")]];then# Check if line is disabled in new file
if[[(-z $(sed -n -E '\^\s*?\b'"$(sed -E 's/^[ \t]*//'<<<"$escaped_setting_line")"'$^p'"$modified_file"))]];then# If the same setting line is not found in the modified file...
if[[ -z $(sed -n -E '\^\['"$current_section"'\]|\b'"$current_section"':$^,\^\b'"$current_setting_name"'.*^{ \^\['"$current_section"'\]|\b'"$current_section"':$^! { \^\b'"$current_setting_name"'^p } }'$1)]];then# If setting name is not found in this section of the original file...
action="add_setting_line"# TODO: This should include the previous line, so that new lines can be inserted in the correct place rather than at the end.