diff --git a/README.md b/README.md index bde45bb..4343925 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,6 @@ h2mm install -n "Example mod" mod.patch_0 mod.patch_0.stream # -n is mandatory w h2mm install -n "Example mod" mod* # using a wildcard to include all files ``` -> [!NOTE] -> If the mod has more than 1 variant, you need to install the one you want by unarchiving it separately and providing the directory. - #### Uninstall a mod ```bash diff --git a/h2mm b/h2mm index ec4337d..cc83779 100755 --- a/h2mm +++ b/h2mm @@ -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 diff --git a/version b/version index 449d7e7..0f82685 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.3.6 +0.3.7