feat: easily install multiple variants (#20)
* feat: easily install multiple variants * fix: filter only dirs that have patches
This commit is contained in:
@@ -676,6 +676,48 @@ function mod_install() {
|
||||
[[ ! -f "$file" ]] && { echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2; exit 1; }
|
||||
done
|
||||
|
||||
# check for mod variants and handle
|
||||
# if the mod directory contains more than 1 directory, it means there are multiple variants for the mod
|
||||
# prompt the user to choose which variant to install, or install multiple
|
||||
readarray -d '' all_dirs < <(find "$mod_dir" -mindepth 1 -type d -print0)
|
||||
|
||||
# filter so that we only have dirs that have *.patch_* files inside them
|
||||
filtered_dirs=()
|
||||
for dir in "${all_dirs[@]}"; do
|
||||
if find "$dir" -maxdepth 1 -type f -name "*.patch_*" -print -quit | grep -q .; then
|
||||
filtered_dirs+=("$dir")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#filtered_dirs[@]} -gt 1 ]]; then
|
||||
echo -e "Multiple mod variants found for mod ${mod_name}." >&2
|
||||
for i in "${!filtered_dirs[@]}"; do
|
||||
echo "$((i + 1)). ${filtered_dirs[$i]}"
|
||||
done
|
||||
|
||||
# prompt user to choose
|
||||
echo -ne "Enter the number of the variant(s) to install (separated by space) or press Enter to install all: " >&2
|
||||
read -a variant_indices
|
||||
if [[ -n "${variant_indices[0]}" ]]; then
|
||||
# clear mod_files
|
||||
mod_files=()
|
||||
|
||||
# get the files from the chosen variant
|
||||
for index in "${variant_indices[@]}"; do
|
||||
[[ ! "$index" =~ ^[0-9]+$ ]] && { echo -e "${RED}Error${NC}: Invalid variant index." >&2; exit 1; }
|
||||
[[ $index -lt 1 || $index -gt ${#filtered_dirs[@]} ]] && { echo -e "${RED}Error${NC}: Variant index out of range." >&2; exit 1; }
|
||||
|
||||
readarray -d '' variant_files < <(find "${filtered_dirs[$((index - 1))]}" -type f -name "*.patch_*" -print0)
|
||||
|
||||
# update mod_name to contain the variant name
|
||||
mod_name="${mod_name} [$(basename "${filtered_dirs[$((index - 1))]}")]"
|
||||
|
||||
# add the files to the mod_files array
|
||||
mod_files+=("${variant_files[@]}")
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
# hash table - in case multiple named files are needed for 1 mod install, store the patch count
|
||||
declare -A patch_count
|
||||
# store the target files so we can put them in the database later
|
||||
|
||||
Reference in New Issue
Block a user