From 56bb73784eab47fdfdedaf5bdeb884a5d279cdf7 Mon Sep 17 00:00:00 2001 From: v4n <105587619+v4n00@users.noreply.github.com> Date: Sun, 2 Mar 2025 15:38:07 +0200 Subject: [PATCH] fix: directory checking in wrong place --- h2mm | 88 ++++++++++++++++++++++++++++----------------------------- version | 2 +- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/h2mm b/h2mm index 20c5ac5..72a875c 100755 --- a/h2mm +++ b/h2mm @@ -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 diff --git a/version b/version index 6678432..940ac09 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.3.8 +0.3.9