fix: directory checking in wrong place

This commit is contained in:
v4n
2025-03-02 15:38:07 +02:00
parent 0d8f22a2d0
commit 56bb73784e
2 changed files with 45 additions and 45 deletions
+44 -44
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
VERSION="0.3.8"
VERSION="0.3.9"
# --- Globals ---
@@ -57,7 +57,7 @@ function get_mod_name_and_index() {
entry=$(grep "^${mod_index}," "$DB_FILE")
mod_name=$(echo "$entry" | awk -F, '{print $3}')
elif [[ -n "$mod_name" ]]; then # if mod name exists
entry=$(grep ",$mod_name," "$DB_FILE")
entry=$(grep -F ",$mod_name," "$DB_FILE")
mod_index=$(echo "$entry" | awk -F, '{print $1}' | head -1)
fi
@@ -662,6 +662,48 @@ function mod_install() {
if [[ -z "$mod_name" ]]; then
mod_name=$(echo "$mod_dir" | sed 's:/*$::' | awk -F/ '{print $NF}' | sed -E 's/-[0-9]+-.*//')
fi
# 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)). $(basename "${filtered_dirs[$i]}")" >&2
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
fi
# verify minimum information required
@@ -676,48 +718,6 @@ 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)). $(basename "${filtered_dirs[$i]}")" >&2
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
+1 -1
View File
@@ -1 +1 @@
0.3.8
0.3.9