Add low space check and warning

This commit is contained in:
icenine451 2023-05-08 16:54:35 -04:00
parent 519230c588
commit 13acb4199c
3 changed files with 48 additions and 21 deletions

View file

@ -18,6 +18,7 @@ sdcard=/run/media/mmcblk0p1
[options] [options]
power_user_warning=true power_user_warning=true
desktop_mode_warning=true desktop_mode_warning=true
low_space_warning=true
update_check=false update_check=false
update_repo=RetroDECK update_repo=RetroDECK
update_ignore= update_ignore=

View file

@ -159,25 +159,29 @@ validate_for_chd() {
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
echo "Validating .cue associated .bin files" >> "$logs_folder/$chd_validation_log_file" if [[ ! "$file_path" == *"dreamcast"* ]]; then # .bin/.cue compression may not work for Dreamcast, only GDI or ISO # TODO: verify
local cue_bin_files=$(grep -o -P "(?<=FILE \").*(?=\".*$)" "$file") echo "Validating .cue associated .bin files" >> "$logs_folder/$chd_validation_log_file"
echo "Associated bin files read:" >> "$logs_folder/$chd_validation_log_file" local cue_bin_files=$(grep -o -P "(?<=FILE \").*(?=\".*$)" "$file")
printf '%s\n' "$cue_bin_files" >> "$logs_folder/$chd_validation_log_file" echo "Associated bin files read:" >> "$logs_folder/$chd_validation_log_file"
if [[ ! -z "$cue_bin_files" ]]; then printf '%s\n' "$cue_bin_files" >> "$logs_folder/$chd_validation_log_file"
while IFS= read -r line if [[ ! -z "$cue_bin_files" ]]; then
do while IFS= read -r line
echo "looking for $file_path/$line" >> "$logs_folder/$chd_validation_log_file" do
if [[ -f "$file_path/$line" ]]; then echo "looking for $file_path/$line" >> "$logs_folder/$chd_validation_log_file"
echo ".bin file found at $file_path/$line" >> "$logs_folder/$chd_validation_log_file" if [[ -f "$file_path/$line" ]]; then
file_validated="true" echo ".bin file found at $file_path/$line" >> "$logs_folder/$chd_validation_log_file"
else file_validated="true"
echo ".bin file NOT found at $file_path/$line" >> "$logs_folder/$chd_validation_log_file" else
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" echo ".bin file NOT found at $file_path/$line" >> "$logs_folder/$chd_validation_log_file"
file_validated="false" 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"
break file_validated="false"
fi break
done < <(printf '%s\n' "$cue_bin_files") fi
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"
fi
echo $file_validated echo $file_validated
else # If file is a .iso or .gdi else # If file is a .iso or .gdi
file_validated="true" file_validated="true"
@ -290,6 +294,7 @@ desktop_mode_warning() {
# This function is a generic warning for issues that happen when running in desktop mode. # This function is a generic warning for issues that happen when running in desktop mode.
# Running in desktop mode can be verified with the following command: if [[ ! $XDG_CURRENT_DESKTOP == "gamescope" ]]; then # Running in desktop mode can be verified with the following command: if [[ ! $XDG_CURRENT_DESKTOP == "gamescope" ]]; then
# This function will check if desktop mode is currently being used and if the warning has not been disabled, and show it if needed. # This function will check if desktop mode is currently being used and if the warning has not been disabled, and show it if needed.
# USAGE: desktop_mode_warning
if [[ ! $XDG_CURRENT_DESKTOP == "gamescope" ]]; then if [[ ! $XDG_CURRENT_DESKTOP == "gamescope" ]]; then
if [[ $desktop_mode_warning == "true" ]]; then if [[ $desktop_mode_warning == "true" ]]; then
@ -302,13 +307,31 @@ desktop_mode_warning() {
if [[ $choice == "No" ]]; then if [[ $choice == "No" ]]; then
exit 1 exit 1
elif [[ $choice == "Never show this again" ]]; then elif [[ $choice == "Never show this again" ]]; then
set_setting_value $rd_conf "desktop_mode_warning" "false" retrodeck "options" # Store desktop mode warning variable for future checks set_setting_value $rd_conf "desktop_mode_warning" "false" retrodeck "options" # Store desktop mode warning variable for future checks
fi fi
fi fi
fi fi
fi fi
} }
low_space_warning() {
# This function will verify that the drive with the $HOME path on it has at least 10% space free, so the user can be warned before it fills up
# USAGE: 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
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.")
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
fi
fi
fi
}
set_setting_value() { set_setting_value() {
# Function for editing settings # Function for editing settings
# USAGE: set_setting_value $setting_file "$setting_name" "$new_setting_value" $system $section_name(optional) # USAGE: set_setting_value $setting_file "$setting_name" "$new_setting_value" $system $section_name(optional)
@ -2563,6 +2586,8 @@ get_cheevos_token_dialog() {
fi fi
} }
change_preset_dialog() { change_preset_dialog() {
# This function will build a list of all systems compatible with a given preset, their current enable/disabled state and allow the user to change one or more # This function will build a list of all systems compatible with a given preset, their current enable/disabled state and allow the user to change one or more
# USAGE: change_preset_dialog "$preset" # USAGE: change_preset_dialog "$preset"

View file

@ -154,9 +154,10 @@ if [[ $multi_user_mode == "true" ]]; then
multi_user_determine_current_user multi_user_determine_current_user
fi fi
# Check if running in Desktop mode and warn if true, unless desktop_mode_warning=false in retrodeck.cfg # Run optional startup checks
desktop_mode_warning desktop_mode_warning
low_space_warning
# Check if there is a new version of RetroDECK available, if update_check=true in retrodeck.cfg and there is network connectivity available. # Check if there is a new version of RetroDECK available, if update_check=true in retrodeck.cfg and there is network connectivity available.
if [[ $(check_network_connectivity) == "true" ]] && [[ $update_check == "true" ]]; then if [[ $(check_network_connectivity) == "true" ]] && [[ $update_check == "true" ]]; then