Refactor choose_runner_to_delete(). Untabify.

This commit is contained in:
the-sane 2020-12-25 11:24:10 -05:00 committed by GitHub
parent be533e842b
commit 6e27ae8449
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,8 +31,6 @@ wine_conf="winedir.conf"
game_conf="gamedir.conf"
backup_conf="backupdir.conf"
base_path="$HOME/.local/share/lutris/runners/wine" # Default location of Lutris wine runner
# Use the XDG config directory if defined
if [ -z "$XDG_CONFIG_HOME" ]; then
conf_dir="$HOME/.config"
@ -48,10 +46,14 @@ keybinds_export_path="Controls/Mappings"
dxvk_cache_file="StarCitizen.dxvk-cache"
#URLs for downloading runners from
raw_url="https://api.github.com/repos/rawfoxDE/raw-wine/releases"
# Lutris wine runners directory
lutris_dir="$HOME/.local/share/lutris/runners/wine"
# URLs for downloading Lutris runners
rawfox_url="https://api.github.com/repos/rawfoxDE/raw-wine/releases"
snatella_url="https://api.github.com/repos/snatella/wine-runner-sc/releases"
# Set a maximum number of runners
max_runners="20"
############################################################################
############################################################################
@ -86,7 +88,7 @@ message() {
;;
"question")
# question
# call format: message question "question to ask?"
# call format: if message question "question to ask?"; then...
margs=("--question" "--text=")
;;
*)
@ -119,7 +121,7 @@ message() {
;;
"question")
# question
# call format: message question "question to ask?"
# call format: if message question "question to ask?"; then...
clear
echo -e "$2"
while read -p "[y/n]: " yn; do
@ -520,8 +522,8 @@ mapcount_set() {
fi
# Configure the menu
menu_text_zenity="<b>This helper can change vm.max_map_count for you.</b>\n\nChoose from the following options:"
menu_text_terminal="This helper can change vm.max_map_count for you.\n\nChoose from the following options:"
menu_text_zenity="<b>This helper can change vm.max_map_count for you</b>\n\nChoose from the following options:"
menu_text_terminal="This helper can change vm.max_map_count for you\n\nChoose from the following options:"
menu_height="200"
# Configure the menu options
@ -652,14 +654,6 @@ quit() {
exit 0
}
delete_runner() {
remove_option="$1"
message question "Delete ${installed_versions[$remove_option]}?"
rm -rf "${installed_versions[$remove_option]}"
echo "removed ${installed_versions[$remove_option]}"
choose_runner_to_delete
}
restart_lutris() {
if [ "$( pgrep lutris )" != "" ]; then
echo "Restarting Lutris"
@ -674,29 +668,43 @@ mainmenu() {
echo "going back to menu"
}
delete_runner() {
remove_option="$1"
if message question "Are you sure you want to delete the following runner?\n\n${installed_runners[$remove_option]}"; then
rm -r "${installed_runners[$remove_option]}"
echo "Deleted ${installed_runners[$remove_option]}\n"
fi
}
choose_runner_to_delete() {
# Configure the menu
menu_text_zenity="Please select Version to delete:"
menu_text_terminal="Please select Version to delete:"
menu_text_zenity="Please select the Lutris runner you want to delete:"
menu_text_terminal="Please select the Lutris runner you want to delete:"
menu_height="300"
menu_options=()
menu_actions=()
goback="Return to the runner management menu"
unset installed_runners
unset menu_options
unset menu_actions
installed_versions=($(ls -d "$base_path"/*/)) # create an array with all directorys in the base_path
# Create an array containing all directories in the lutris_dir
for runner_dir in "$lutris_dir"/*; do
if [ -d "$runner_dir" ]; then
installed_runners+=("$runner_dir")
fi
done
# iterate through the installed versions and create the menu options for them
for((i=0;i<${#installed_versions[@]};i++)); do
inumber=$(("$i" + 1))
folder=$(echo "${installed_versions[i]}" | rev | cut -d/ -f2 | rev) #reverse the order, cut after the second / and reverse again to only have the runner folder instead of the whole path
menu_options+=("$inumber. $folder")
# Create menu options for the installed runners
for (( i=0; i<"${#installed_runners[@]}"; i++ )); do
menu_options+=("$(basename "${installed_runners[i]}")")
menu_actions+=("delete_runner $i")
done
menu_options+=("Back")
# Complete the menu by adding the option to go back to the previous menu
menu_options+=("$goback")
menu_actions+=("manage_runners")
# Call the menu function. It will use the options as configured above
menu
}
install_runner() {
@ -718,13 +726,13 @@ install_runner() {
# check if the installed runner is from Rawfox or snatella because rawfox has a subfolder in the archive
if test "$latest_url" = "$snatella_url" ; then
dest_path="$base_path/$version"
dest_path="$lutris_dir/$version"
[ -d "$dest_path" ] || {
mkdir "$dest_path"
echo [Info] Created "$dest_path"
}
else
dest_path="$base_path"
dest_path="$lutris_dir"
fi
# download and extract the runner
@ -740,9 +748,9 @@ install_runner() {
snatella="Download another runner from Molotov/Snatella"
delete="Delete an installed runner"
restart="Restart Lutris and got back to Mainmenu"
back="Back to Mainmenu"
goback="Return to the main menu"
# Set the options to be displayed in the menu
menu_options=("$rawfox" "$snatella" "$delete" "$restart" "$back")
menu_options=("$rawfox" "$snatella" "$delete" "$restart" "$goback")
# Set the corresponding functions to be called for each of the options
menu_actions=("choose_runner_version rawfox" "choose_runner_version snatella" "choose_runner_to_delete" "restart_lutris" "mainmenu")
@ -761,8 +769,8 @@ choose_runner_version() {
download_options=($(curl -s "$latest_url" | grep -E "browser_download_url.*tgz" | cut -d \" -f4 | cut -d / -f9))
;;
rawfox)
latest_url="$raw_url"
echo "searching $raw_url ..."
latest_url="$rawfox_url"
echo "searching $rawfox_url ..."
download_options=($(curl -s "$latest_url" | grep -E "browser_download_url.*tar.gz" | cut -d \" -f4 | cut -d / -f9 | cut -d . -f1-3))
;;
esac
@ -785,7 +793,7 @@ choose_runner_version() {
for((i=0;i<"$runner_count";i++)); do
number=$(("$i" + 1))
version=$(echo "${download_options[i]}" | sed 's/\.[^.]*$//')
if [ -d "$base_path"/"$version" ]; then
if [ -d "$lutris_dir"/"$version" ]; then
menu_options+=("$number. $version [installed]")
else
menu_options+=("$number. $version")
@ -800,17 +808,16 @@ choose_runner_version() {
manage_runners() {
max_runners=20
# Configure the menu
menu_text_zenity="<b>This helper can manage your runners for you</b>\n\nChoose what you want to do:"
menu_text_terminal="This helper can manage your runners for you<\n\nChoose what you want to do:"
menu_text_zenity="<b>This helper can manage your Lutris runners</b>\n\nChoose from the following options:"
menu_text_terminal="This helper can manage your Lutris runners<\n\nChoose from the following options:"
menu_height="200"
# Configure the menu options
rawfox="Download a runner from RawFox"
snatella="Download a runner from Molotov/Snatella"
rawfox="Install a runner from RawFox"
snatella="Install a runner from Molotov/Snatella"
delete="Delete an installed runner"
back="Back to Mainmenu"
back="Return to the main menu"
# Set the options to be displayed in the menu
menu_options=("$rawfox" "$snatella" "$delete" "$back")
# Set the corresponding functions to be called for each of the options
@ -839,22 +846,22 @@ while true; do
# Configure the menu
menu_text_zenity="<b><big>Welcome, fellow Penguin, to the Star Citizen LUG Helper!</big>\n\nThis helper is designed to help optimize your system for Star Citizen</b>\n\nYou may choose from the following options:"
menu_text_terminal="Welcome, fellow Penguin, to the Star Citizen Linux Users Group Helper!\n\nThis helper is designed to help optimize your system for Star Citizen\nYou may choose from the following options:"
menu_height="335"
menu_height="340"
# Configure the menu options
mapcount_msg="Check vm.max_map_count for optimal performance"
download_msg="Manage Lutris-Runners"
filelimit_msg="Check my open file descriptors limit"
runners_msg="Manage Lutris Runners"
sanitize_msg="Delete my Star Citizen USER folder and preserve my keybinds"
mapcount_msg="Check vm.max_map_count for optimal performance"
filelimit_msg="Check my open file descriptors limit"
shaders_msg="Delete my shaders only"
vidcache_msg="Delete my DXVK cache"
version_msg="Switch the helper between LIVE and PTU (default is LIVE)"
quit_msg="Quit"
# Set the options to be displayed in the menu
menu_options=("$mapcount_msg" "$download_msg" "$filelimit_msg" "$sanitize_msg" "$shaders_msg" "$vidcache_msg" "$version_msg" "$quit_msg")
menu_options=("$runners_msg" "$sanitize_msg" "$mapcount_msg" "$filelimit_msg" "$shaders_msg" "$vidcache_msg" "$version_msg" "$quit_msg")
# Set the corresponding functions to be called for each of the options
menu_actions=("mapcount_set" "manage_runners" "filelimit_set" "sanitize" "rm_shaders" "rm_vidcache" "set_version" "quit")
menu_actions=("manage_runners" "sanitize" "mapcount_set" "filelimit_set" "rm_shaders" "rm_vidcache" "set_version" "quit")
# Call the menu function. It will use the options as configured above
menu