Refactor download_select_install() function

This commit is contained in:
the-sane 2022-10-15 14:24:31 -04:00
parent 1ae94e9b50
commit 142e09800f

View File

@ -1209,7 +1209,7 @@ download_select_install() {
# To add new sources, handle them here, in the if statement # To add new sources, handle them here, in the if statement
# just above, and the download_install function above # just above, and the download_install function above
if [ "$download_url_type" = "github" ]; then if [ "$download_url_type" = "github" ]; then
download_versions=($(curl -s "$contributor_url" | awk '/browser_download_url/ {print $2}' | grep -vE "*.sha512sum" | xargs basename -a)) download_versions=($(curl -s "$contributor_url" | awk '/browser_download_url/ {print $2}' | xargs basename -a))
else else
debug_print exit "Script error: Unknown api/url format in ${download_type}_sources array. Aborting." debug_print exit "Script error: Unknown api/url format in ${download_type}_sources array. Aborting."
fi fi
@ -1232,9 +1232,13 @@ download_select_install() {
# and add them to the menu options # and add them to the menu options
# To add new file extensions, handle them here and in # To add new file extensions, handle them here and in
# the download_install function above # the download_install function above
for (( i=0; i<"$max_download_items" && i<"${#download_versions[@]}"; i++ )); do for (( i=0,num_download_items=0; i<"${#download_versions[@]}" && "$num_download_items"<"$max_download_items"; i++ )); do
# Get the file name minus the extension # Get the file name minus the extension
case "${download_versions[i]}" in case "${download_versions[i]}" in
*.sha*sum | *.ini | proton*)
# Ignore hashes, configs, and proton downloads
continue
;;
*.tar.gz) *.tar.gz)
download_name="$(basename "${download_versions[i]}" .tar.gz)" download_name="$(basename "${download_versions[i]}" .tar.gz)"
;; ;;
@ -1248,20 +1252,22 @@ download_select_install() {
download_name="$(basename "${download_versions[i]}" .tar.zst)" download_name="$(basename "${download_versions[i]}" .tar.zst)"
;; ;;
*) *)
download_name="skip" # Print a warning and move on to the next item
debug_print continue "Unknown archive filetype in download_select_install function. Offending String: ${download_versions[i]}" debug_print continue "Warning: Unknown archive filetype in download_select_install() function. Offending String: ${download_versions[i]}"
continue
;; ;;
esac esac
# Add the file names to the menu # Add the file names to the menu
if [[ "$download_name" = "skip" ]] || [[ "${download_versions[i]}" = "proton"* ]] ; then # filter out other file types or proton-downloads (needed for TKG) if [ -d "$download_dir/$download_name" ]; then
continue
elif [ -d "$download_dir/$download_name" ]; then
menu_options+=("$download_name [installed]") menu_options+=("$download_name [installed]")
else else
menu_options+=("$download_name") menu_options+=("$download_name")
fi fi
menu_actions+=("download_install $i") menu_actions+=("download_install $i")
# Increment the added items counter
num_download_items="$(($num_download_items+1))"
done done
# Complete the menu by adding the option to go back to the previous menu # Complete the menu by adding the option to go back to the previous menu