LOGGER: populating functions

This commit is contained in:
XargonWan 2024-02-28 18:13:33 +01:00
parent c09e5aba1c
commit a7f3866e96
15 changed files with 43 additions and 44 deletions

View file

@ -4,7 +4,6 @@
# This script is getting the latest release notes from the wiki and add them to the appdata
source automation_tools/version_extractor.sh
source /app/libexec/logger.sh
# Fetch appdata version
appdata_version=$(fetch_appdata_version)

View file

@ -1,7 +1,5 @@
#!/bin/bash
source /app/libexec/logger.sh
# Define the IWAD files list
IWAD_FILES=("DOOM1.WAD" "DOOM.WAD" "DOOM2.WAD" "DOOM2F.WAD" "DOOM64.WAD" "TNT.WAD"
"PLUTONIA.WAD" "HERETIC1.WAD" "HERETIC.WAD" "HEXEN.WAD" "HEXDD.WAD"

View file

@ -1,7 +1,5 @@
#!/bin/bash
source /app/libexec/logger.sh
save_migration() {
# Finding existing ROMs folder
if [ -d "$default_sd/retrodeck" ]

View file

@ -1,7 +1,5 @@
#!/bin/bash
source /app/libexec/logger.sh
check_network_connectivity() {
# This function will do a basic check for network availability and return "true" if it is working.
# USAGE: if [[ $(check_network_connectivity) == "true" ]]; then

View file

@ -1,7 +1,5 @@
#!/bin/bash
source /app/libexec/logger.sh
compress_game() {
# Function for compressing one or more files to .chd format
# USAGE: compress_game $format $full_path_to_input_file $system(optional)

View file

@ -162,6 +162,8 @@ changelog_dialog() {
# The function also accepts "all" as a version, and will print the entire changelog
# USAGE: changelog_dialog "version"
log d "Showing changelog dialog"
if [[ "$1" == "all" ]]; then
xml sel -t -m "//release" -v "concat('RetroDECK version: ', @version)" -n -v "description" -n $rd_appdata | awk '{$1=$1;print}' | sed -e '/./b' -e :n -e 'N;s/\n$//;tn' > "/var/config/retrodeck/changelog.txt"
@ -186,6 +188,8 @@ get_cheevos_token_dialog() {
# This function will return a RetroAchvievements token from a valid username and password, will return "login failed" otherwise
# USAGE: get_cheevos_token_dialog
log d "Opening RetroAchievements dialog"
local cheevos_info=$(zenity --forms --title="Cheevos" \
--text="Username and password." \
--separator="^" \
@ -211,15 +215,20 @@ desktop_mode_warning() {
# USAGE: desktop_mode_warning
if [[ $(check_desktop_mode) == "true" && $desktop_mode_warning == "true" ]]; then
local message='You appear to be running RetroDECK in the Steam Deck'\''s Desktop mode!\n\nSome functions of RetroDECK may not work properly in Desktop mode, such as the Steam Deck'\''s normal controls.\n\nRetroDECK is best enjoyed in Game mode!\n\nDo you still want to proceed?'
log i "Showing message:\n$message"
choice=$(zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --ok-label="Yes" --extra-button="No" --extra-button="Never show this again" \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Desktop Mode Warning" \
--text="You appear to be running RetroDECK in the Steam Deck's Desktop mode!\n\nSome functions of RetroDECK may not work properly in Desktop mode, such as the Steam Deck's normal controls.\n\nRetroDECK is best enjoyed in Game mode!\n\nDo you still want to proceed?")
--text="$message")
rc=$? # Capture return code, as "Yes" button has no text value
if [[ $rc == "1" ]]; then # If any button other than "Yes" was clicked
log i "Selected: \"Yes\""
if [[ $choice == "No" ]]; then
log i "Selected: \"No\""
exit 1
elif [[ $choice == "Never show this again" ]]; then
log i "Selected: \"Never show this again\""
set_setting_value $rd_conf "desktop_mode_warning" "false" retrodeck "options" # Store desktop mode warning variable for future checks
fi
fi
@ -233,13 +242,17 @@ low_space_warning() {
if [[ $low_space_warning == "true" ]]; then
local used_percent=$(df --output=pcent "$HOME" | tail -1 | tr -d " " | tr -d "%")
if [[ "$used_percent" -ge 90 && -d "$HOME/retrodeck" ]]; then # If there is any RetroDECK data on the main drive to move
local message='Your main drive is over 90% full!\n\nIf your drive fills completely this can lead to data loss or system crash.\n\nPlease consider moving some RetroDECK folders to other storage locations using the Configurator.'
log i "Showing message:\n$message"
choice=$(zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --ok-label="OK" --extra-button="Never show this again" \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Low Space Warning" \
--text="Your main drive is over 90% full!\n\nIf your drive fills completely this can lead to data loss or system crash.\n\nPlease consider moving some RetroDECK folders to other storage locations using the Configurator.")
--text="$message")
if [[ $choice == "Never show this again" ]]; then
set_setting_value $rd_conf "low_space_warning" "false" retrodeck "options" # Store low space warning variable for future checks
log i "Selected: \"Never show this again\""
set_setting_value $rd_conf "low_space_warning" "false" retrodeck "options" # Store low space warning variable for future checks
fi
fi
log i "Selected: \"OK\""
fi
}

View file

@ -1,7 +1,5 @@
#!/bin/bash
source /app/libexec/logger.sh
directory_browse() {
# This function browses for a directory and returns the path chosen
# USAGE: path_to_be_browsed_for=$(directory_browse $action_text)
@ -657,10 +655,10 @@ manage_ryujinx_keys() {
echo "Created symlink: \"$symlink\""
done
else
log w "No files found in $bios_folder/switch/keys. Continuing"
log w "No files found in $bios_folder/switch/keys. Continuing..."
fi
else
log w "Directory $bios_folder/switch/keys does not exist. Maybe Ryujinx was never run. Continuing"
log w "Directory $bios_folder/switch/keys does not exist. Maybe Ryujinx was never run. Continuing..."
fi
}

View file

@ -164,8 +164,7 @@ if [[ ! -f "$rd_conf" ]]; then
log i "Setting config file permissions"
chmod +rw $rd_conf
log i "RetroDECK config file initialized. Contents:\n"
log i "$(cat "$rd_conf")"
log i "RetroDECK config file initialized. Contents:\n\n$(cat $rd_conf\n)"
conf_read # Load new variables into memory
tmplog_merger
@ -201,4 +200,4 @@ else
multi_user_data_folder="$rdhome/multi-user-data" # The default location of multi-user environment profiles
fi
logs_folder="$rdhome/retrodeck/logs" # The path of the logs folder, here we collect all the logs
logs_folder="$rdhome/logs" # The path of the logs folder, here we collect all the logs

View file

@ -7,12 +7,12 @@
# log e "bar" -> logs an error with message bar in the default log file retrodeck/logs/retrodeck.log
# log i "par" rekku.log -> logs an information with message in the specified log file inside the logs folder retrodeck/logs/rekku.log
if [ "${log_init:-false}" = false ]; then
logs_folder=${logs_folder:-"/tmp"}
touch "$logs_folder/retrodeck.log"
# exec > >(tee "$logs_folder/retrodeck.log") 2>&1 # this is broken, creates strange artifacts and corrupts the log file
log_init=true
fi
# if [ "${log_init:-false}" = false ]; then
# logs_folder=${logs_folder:-"/tmp"}
# touch "$logs_folder/retrodeck.log"
# # exec > >(tee "$logs_folder/retrodeck.log") 2>&1 # this is broken, creates strange artifacts and corrupts the log file
# log_init=true
# fi
log() {
@ -89,6 +89,10 @@ log() {
echo -e "$colored_message"
# Write the log message to the log file
if [ ! -f "$logfile" ]; then
echo "$timestamp [WARN] Log file not found in \"$logfile\", creating it"
touch "$logfile"
fi
echo "$log_message" >> "$logfile"
}
@ -96,8 +100,10 @@ log() {
# This function is merging the temporary log file into the actual one
tmplog_merger() {
create_dir "$logs_folder"
# Check if /tmp/retrodeck.log exists
if [ -e "/tmp/retrodeck.log" ]; then
if [ -e "/tmp/retrodeck.log" ] && [ -e "$logs_folder/retrodeck.log" ]; then
# Sort both temporary and existing log files by timestamp
sort -k1,1n -k2,2M -k3,3n -k4,4n -k5,5n "/tmp/retrodeck.log" "$logs_folder/retrodeck.log" > "$logs_folder/merged_logs.tmp"
@ -108,14 +114,13 @@ tmplog_merger() {
# Remove the temporary file
rm "/tmp/retrodeck.log"
fi
}
ESDE_source_logs="/var/config/emulationstation/.emulationstation/es_log.txt"
# Check if the source file exists
if [ -e "$ESDE_source_logs" ]; then
# Create the symlink in the logs folder
ln -sf "$source_file" "$logs_folder/ES-DE.log"
log i "ES-DE log file linked to \"$logs_folder/ES-DE.log\""
else
echo "ES-DE log file not found, not linked"
fi
local ESDE_source_logs="/var/config/ES-DE/logs/es_log.txt"
# Check if the source file exists
if [ -e "$ESDE_source_logs" ]; then
# Create the symlink in the logs folder
ln -sf "$ESDE_source_logs" "$logs_folder/ES-DE.log"
log i "ES-DE log file linked to \"$logs_folder/ES-DE.log\""
fi
}

View file

@ -1,7 +1,5 @@
#!/bin/bash
source /app/libexec/logger.sh
multi_user_set_default_dialog() {
chosen_user="$1"
choice=$(zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --ok-label="Yes" --extra-button="No" --extra-button="No and don't ask again" \

View file

@ -1,7 +1,5 @@
#!/bin/bash
source /app/libexec/logger.sh
set_setting_value() {
# Function for editing settings
# USAGE: set_setting_value "$setting_file" "$setting_name" "$new_setting_value" "$system" "$section_name(optional)"

View file

@ -239,7 +239,7 @@ post_update() {
# - Remove RetroDECK controller profile from existing template location
# - Change section name in retrodeck.cfg for ABXY button swap preset
# - Force disable global rewind in RA in prep for preset system
if [[ -f "$HOME/.steam/steam/controller_base/templates/RetroDECK_controller_config.vdf"]]; then # Only remove if file had been previously installed
if [[ -f "$HOME/.steam/steam/controller_base/templates/RetroDECK_controller_config.vdf" ]]; then # Only remove if file had been previously installed
rm -f "$HOME/.steam/steam/controller_base/templates/RetroDECK_controller_config.vdf"
fi
sed -i 's^nintendo_button_layout^abxy_button_swap^' "$rd_conf" # This is a one-off sed statement as there are no functions for replacing section names

View file

@ -1,7 +1,6 @@
#!/bin/bash
source /app/libexec/global.sh
source /app/libexec/logger.sh
# Arguments section

View file

@ -3,7 +3,6 @@
# VARIABLES SECTION
source /app/libexec/global.sh
source /app/libexec/logger.sh
# DIALOG SECTION

View file

@ -4,7 +4,6 @@
# USAGE: /bin/bash retrodeck_function_wrapper.sh <function_name> <arg1> <arg2> ...
source /app/libexec/global.sh
source /app/libexec/logger.sh
# Check if a function was specified
if [[ $# -lt 1 ]]; then