Refactor download_dirs array into single download_dir string variable.

Remnant of lutris support where items would have to be installed for both flatpak and native lutris in two different locations.
This commit is contained in:
the-sane
2025-10-06 18:03:03 -04:00
parent 5acbb6e1df
commit c2ed743a75

View File

@@ -1157,8 +1157,8 @@ filelimit_confirm() {
# of items to download. It should be pointed to the appropriate # of items to download. It should be pointed to the appropriate
# array set at the top of the script using indirect expansion. # array set at the top of the script using indirect expansion.
# See runner_sources at the top and runner_manage() for examples. # See runner_sources at the top and runner_manage() for examples.
# - The array download_dirs should contain the locations the downloaded item # - The string download_dir should contain the location where the
# will be installed to. Must be formatted in pairs of ("[type]" "[directory]") # downloaded item will be installed to.
# - The string "download_menu_heading" should contain the type of item # - The string "download_menu_heading" should contain the type of item
# being downloaded. It will appear in the menu heading. # being downloaded. It will appear in the menu heading.
# - The string "download_menu_description" should contain a description of # - The string "download_menu_description" should contain a description of
@@ -1178,8 +1178,8 @@ download_manage() {
# Sanity checks # Sanity checks
if [ -z "$download_sources" ]; then if [ -z "$download_sources" ]; then
debug_print exit "Script error: The string 'download_sources' was not set before calling the download_manage function. Aborting." debug_print exit "Script error: The string 'download_sources' was not set before calling the download_manage function. Aborting."
elif [ "${#download_dirs[@]}" -eq 0 ]; then elif [ -z "$download_dir" ]; then
debug_print exit "Script error: The array 'download_dirs' was not set before calling the download_manage function. Aborting." debug_print exit "Script error: The string 'download_dir' was not set before calling the download_manage function. Aborting."
elif [ -z "$download_menu_heading" ]; then elif [ -z "$download_menu_heading" ]; then
debug_print exit "Script error: The string 'download_menu_heading' was not set before calling the download_manage function. Aborting." debug_print exit "Script error: The string 'download_menu_heading' was not set before calling the download_manage function. Aborting."
elif [ -z "$download_menu_description" ]; then elif [ -z "$download_menu_description" ]; then
@@ -1258,10 +1258,7 @@ runner_manage() {
getdirs getdirs
# Set the download directory for wine runners # Set the download directory for wine runners
# Only installing to one directory is supported download_dir="$wine_prefix/runners"
# Do not include multiple download destinations in this array
# Must be formatted in pairs of ("[type]" "[directory]")
download_dirs=("wine" "$wine_prefix/runners")
# Configure the text displayed in the menus # Configure the text displayed in the menus
download_menu_heading="Wine Runners" download_menu_heading="Wine Runners"
@@ -1289,7 +1286,7 @@ runner_manage() {
# The following variables are expected to be set before calling this function: # The following variables are expected to be set before calling this function:
# - download_sources (array) # - download_sources (array)
# - download_type (string) # - download_type (string)
# - download_dirs (array) # - download_dir (string)
download_select_install() { download_select_install() {
# This function expects an element number for the sources array to be passed in as an argument # This function expects an element number for the sources array to be passed in as an argument
if [ -z "$1" ]; then if [ -z "$1" ]; then
@@ -1301,8 +1298,8 @@ download_select_install() {
debug_print exit "Script error: The array 'download_sources' was not set before calling the download_select_install function. Aborting." debug_print exit "Script error: The array 'download_sources' was not set before calling the download_select_install function. Aborting."
elif [ -z "$download_type" ]; then elif [ -z "$download_type" ]; then
debug_print exit "Script error: The string 'download_type' was not set before calling the download_select_install function. Aborting." debug_print exit "Script error: The string 'download_type' was not set before calling the download_select_install function. Aborting."
elif [ "${#download_dirs[@]}" -eq 0 ]; then elif [ -z "$download_dir" ]; then
debug_print exit "Script error: The array 'download_dirs' was not set before calling the download_select_install function. Aborting." debug_print exit "Script error: The string 'download_dir' was not set before calling the download_select_install function. Aborting."
fi fi
# Store info from the selected contributor # Store info from the selected contributor
@@ -1435,42 +1432,15 @@ download_select_install() {
;; ;;
esac esac
# Create a list of locations where the file is already installed
unset installed_types
for (( j=0; j<"${#download_dirs[@]}"; j=j+2 )); do
# Loop through all download destinations to get installed types
# Even numbered elements will contain the download destination type (ie. native/flatpak for lutris)
if [ -d "${download_dirs[j+1]}/$download_basename" ]; then
installed_types+=("${download_dirs[j]}")
fi
done
# Build the menu item # Build the menu item
unset menu_option_text unset menu_option_text
if [ "${#download_dirs[@]}" -eq 2 ]; then if [ -d "${download_dir}/${download_basename}" ]; then
# We're only installing to one location menu_option_text="$download_basename [installed]"
if [ -d "${download_dirs[1]}/$download_basename" ]; then
menu_option_text="$download_basename [installed]"
else
# The file is not installed
menu_option_text="$download_basename"
fi
else else
# We're installing to multiple locations # The file is not installed
if [ "${#installed_types[@]}" -gt 0 ]; then menu_option_text="$download_basename"
# The file is already installed
menu_option_text="$download_basename [installed:"
for (( j=0; j<"${#installed_types[@]}"; j++ )); do
# Add labels for each installed location
menu_option_text="$menu_option_text ${installed_types[j]}"
done
# Complete the menu text
menu_option_text="$menu_option_text]"
else
# The file is not installed
menu_option_text="$download_basename"
fi
fi fi
# Add the file names to the menu # Add the file names to the menu
menu_options+=("$menu_option_text") menu_options+=("$menu_option_text")
menu_actions+=("download_install $i") menu_actions+=("download_install $i")
@@ -1509,7 +1479,7 @@ download_select_install() {
# - contributor_url (string) # - contributor_url (string)
# - download_url_type (string) # - download_url_type (string)
# - download_type (string) # - download_type (string)
# - download_dirs (array) # - download_dir (string)
download_install() { download_install() {
# This function expects an index number for the array # This function expects an index number for the array
# download_versions to be passed in as an argument # download_versions to be passed in as an argument
@@ -1526,8 +1496,8 @@ download_install() {
debug_print exit "Script error: The string 'download_url_type' was not set before calling the download_install function. Aborting." debug_print exit "Script error: The string 'download_url_type' was not set before calling the download_install function. Aborting."
elif [ -z "$download_type" ]; then elif [ -z "$download_type" ]; then
debug_print exit "Script error: The string 'download_type' was not set before calling the download_install function. Aborting." debug_print exit "Script error: The string 'download_type' was not set before calling the download_install function. Aborting."
elif [ "${#download_dirs[@]}" -eq 0 ]; then elif [ -z "$download_dir" ]; then
debug_print exit "Script error: The array 'download_dirs' was not set before calling the download_install function. Aborting." debug_print exit "Script error: The string 'download_dir' was not set before calling the download_install function. Aborting."
fi fi
# Get the filename including file extension # Get the filename including file extension
@@ -1635,21 +1605,17 @@ download_install() {
# If the archive contains only one directory, install that directory # If the archive contains only one directory, install that directory
# We rename it to the name of the archive in case it is different # We rename it to the name of the archive in case it is different
# so we can easily detect installed items in download_select_install() # so we can easily detect installed items in download_select_install()
for (( i=1; i<"${#download_dirs[@]}"; i=i+2 )); do if [ -d "${download_dir}/${download_basename}" ]; then
# Loop through all download destinations, installing to each one # This item has already been installed. Delete it before reinstalling
# Odd numbered elements will contain the download destination's path debug_print continue "$download_type exists, deleting ${download_dir}/${download_basename}..."
if [ -d "${download_dirs[i]}/$download_basename" ]; then rm -r --interactive=never "${download_dir:?}/${download_basename}"
# This item has already been installed. Delete it before reinstalling debug_print continue "Reinstalling $download_type into ${download_dir}/${download_basename}..."
debug_print continue "$download_type exists, deleting ${download_dirs[i]}/$download_basename..." else
rm -r --interactive=never "${download_dirs[i]:?}/$download_basename" debug_print continue "Installing $download_type into ${download_dir}/${download_basename}..."
debug_print continue "Reinstalling $download_type into ${download_dirs[i]}/$download_basename..." fi
else
debug_print continue "Installing $download_type into ${download_dirs[i]}/$download_basename..."
fi
# Copy the directory to the destination # Copy the directory to the destination
mkdir -p "${download_dirs[i]}" && cp -r "$tmp_dir/$download_basename/$extracted_dir" "${download_dirs[i]}/$download_basename" mkdir -p "$download_dir" && cp -r "${tmp_dir}/${download_basename}/${extracted_dir}" "${download_dir}/${download_basename}"
done
# Store the final name of the downloaded item # Store the final name of the downloaded item
downloaded_item_name="$download_basename" downloaded_item_name="$download_basename"
@@ -1658,21 +1624,17 @@ download_install() {
elif [ "$num_dirs" -gt 1 ] || [ "$num_files" -gt 0 ]; then elif [ "$num_dirs" -gt 1 ] || [ "$num_files" -gt 0 ]; then
# If the archive contains more than one directory or # If the archive contains more than one directory or
# one or more files, we must create a subdirectory # one or more files, we must create a subdirectory
for (( i=1; i<"${#download_dirs[@]}"; i=i+2 )); do if [ -d "${download_dir}/${download_basename}" ]; then
# Loop through all download destinations, installing to each one # This item has already been installed. Delete it before reinstalling
# Odd numbered elements will contain the download destination's path debug_print continue "$download_type exists, deleting ${download_dir}/${download_basename}..."
if [ -d "${download_dirs[i]}/$download_basename" ]; then rm -r --interactive=never "${download_dir:?}/${download_basename}"
# This item has already been installed. Delete it before reinstalling debug_print continue "Reinstalling $download_type into ${download_dir}/${download_basename}..."
debug_print continue "$download_type exists, deleting ${download_dirs[i]}/$download_basename..." else
rm -r --interactive=never "${download_dirs[i]:?}/$download_basename" debug_print continue "Installing $download_type into ${download_dir}/${download_basename}..."
debug_print continue "Reinstalling $download_type into ${download_dirs[i]}/$download_basename..." fi
else
debug_print continue "Installing $download_type into ${download_dirs[i]}/$download_basename..."
fi
# Copy the directory to the destination # Copy the directory to the destination
mkdir -p "${download_dirs[i]}/$download_basename" && cp -r "$tmp_dir"/"$download_basename"/* "${download_dirs[i]}"/"$download_basename" mkdir -p "${download_dir}/${download_basename}" && cp -r "$tmp_dir"/"$download_basename"/* "$download_dir"/"$download_basename"
done
# Store the final name of the downloaded item # Store the final name of the downloaded item
downloaded_item_name="$download_basename" downloaded_item_name="$download_basename"
@@ -1686,9 +1648,9 @@ download_install() {
progress_bar stop # Stop the zenity progress window progress_bar stop # Stop the zenity progress window
# Cleanup tmp download # Cleanup tmp download
debug_print continue "Cleaning up $tmp_dir/$download_filename..." debug_print continue "Cleaning up ${tmp_dir}/${download_filename}..."
rm --interactive=never "${tmp_dir:?}/$download_filename" rm --interactive=never "${tmp_dir:?}/${download_filename}"
rm -r --interactive=never "${tmp_dir:?}/$download_basename" rm -r --interactive=never "${tmp_dir:?}/${download_basename}"
return 0 return 0
} }
@@ -1698,13 +1660,13 @@ download_install() {
# #
# The following variables are expected to be set before calling this function: # The following variables are expected to be set before calling this function:
# - download_type (string) # - download_type (string)
# - download_dirs (array) # - download_dir (string)
download_select_delete() { download_select_delete() {
# Sanity checks # Sanity checks
if [ -z "$download_type" ]; then if [ -z "$download_type" ]; then
debug_print exit "Script error: The string 'download_type' was not set before calling the download_select_delete function. Aborting." debug_print exit "Script error: The string 'download_type' was not set before calling the download_select_delete function. Aborting."
elif [ "${#download_dirs[@]}" -eq 0 ]; then elif [ -z "$download_dir" ]; then
debug_print exit "Script error: The array 'download_dirs' was not set before calling the download_select_delete function. Aborting." debug_print exit "Script error: The string 'download_dir' was not set before calling the download_select_delete function. Aborting."
fi fi
# Configure the menu # Configure the menu
@@ -1718,27 +1680,15 @@ download_select_delete() {
unset menu_options unset menu_options
unset menu_actions unset menu_actions
# Find all installed items in the download destinations # Find all installed items in the download destination
for (( i=1; i<"${#download_dirs[@]}"; i=i+2 )); do if [ -d "$download_dir" ]; then
# Skip if the directory doesn't exist for item in "$download_dir"/*; do
if [ ! -d "${download_dirs[i]}" ]; then
continue
fi
# Loop through all download destinations
# Odd numbered elements will contain the download destination's path
for item in "${download_dirs[i]}"/*; do
if [ -d "$item" ]; then if [ -d "$item" ]; then
if [ "${#download_dirs[@]}" -eq 2 ]; then installed_item_names+=("$(basename "$item")")
# We're deleting from one location
installed_item_names+=("$(basename "$item")")
else
# We're deleting from multiple locations so label each one
installed_item_names+=("$(basename "$item [${download_dirs[i-1]}]")")
fi
installed_items+=("$item") installed_items+=("$item")
fi fi
done done
done fi
# Create menu options for the installed items # Create menu options for the installed items
for (( i=0; i<"${#installed_items[@]}"; i++ )); do for (( i=0; i<"${#installed_items[@]}"; i++ )); do
@@ -2336,7 +2286,7 @@ install_game() {
debug_print continue "Installing a custom wine runner..." debug_print continue "Installing a custom wine runner..."
download_dirs=("wine" "$install_dir/runners") download_dir="$install_dir/runners"
# Install the default wine runner into the prefix # Install the default wine runner into the prefix
download_wine download_wine
@@ -2506,10 +2456,10 @@ Exec=\"$installed_launch_script\"" > "$prefix_desktop_file"
# MARK: download_wine() # MARK: download_wine()
# Download a default wine runner for use by the installer # Download a default wine runner for use by the installer
# Expects download_dirs to be set before calling # Expects download_dir to be set before calling
download_wine() { download_wine() {
if [ "${#download_dirs[@]}" -eq 0 ]; then if [ -z "$download_dir" ]; then
debug_print exit "Script error: The array 'download_dirs' was not set before calling the download_wine function. Aborting." debug_print exit "Script error: The string 'download_dir' was not set before calling the download_wine function. Aborting."
fi fi
# Set up variables needed for the download functions, quick and dirty # Set up variables needed for the download functions, quick and dirty