fix: directories stop counting as files
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# --- Globals ---
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
ORANGE='\033[0;33m'
|
||||
@@ -9,8 +11,14 @@ H2PATH="./h2path"
|
||||
MODS_DIR=""
|
||||
DB_FILE=""
|
||||
|
||||
# --- Utility Functions ---
|
||||
|
||||
function get_filename_without_path() {
|
||||
echo $(echo "$1" | awk -F/ '{print $NF}')
|
||||
}
|
||||
|
||||
function get_basename() {
|
||||
base_name=$(echo "$1" | awk -F/ '{print $NF}' | sed -E 's/\.+.*//')
|
||||
echo $(get_filename_without_path "$1" | sed -E 's/\.+.*//')
|
||||
}
|
||||
|
||||
function find_game_directory() {
|
||||
@@ -61,6 +69,8 @@ function initialize_directories() {
|
||||
echo "--- /// MAIN /// ---" >&2
|
||||
}
|
||||
|
||||
# --- Help Functions ---
|
||||
|
||||
function display_help() {
|
||||
echo "Helldivers 2 Mod Manager"
|
||||
echo "Usage: h2mm [command] [options]"
|
||||
@@ -128,7 +138,9 @@ function display_import_help() {
|
||||
echo "Import mods and database from a zip file (coming from h2mm)."
|
||||
}
|
||||
|
||||
function reset() {
|
||||
# --- Main Functions ---
|
||||
|
||||
function mod_reset() {
|
||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||
display_reset_help
|
||||
exit 0
|
||||
@@ -143,7 +155,7 @@ function reset() {
|
||||
fi
|
||||
}
|
||||
|
||||
function install_mod() {
|
||||
function mod_install() {
|
||||
local mod_name=""
|
||||
local mod_files=()
|
||||
local mod_dir=""
|
||||
@@ -214,18 +226,22 @@ function install_mod() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# verify mod files exist
|
||||
# verify mod files exist and is not directory
|
||||
for file in "${mod_files[@]}"; do
|
||||
if [[ ! -f "$file" ]]; then
|
||||
if [[ ! -d "$file" ]]; then
|
||||
echo -e "${RED}Error${NC}: File $file does not exist."
|
||||
exit 1
|
||||
else
|
||||
mod_files=(${mod_files[@]/$file})
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
declare -A patch_count # hash table - in case multiple named files are needed for 1 mod install, store the patch count
|
||||
target_files=()
|
||||
for file in "${mod_files[@]}"; do
|
||||
get_basename "$file"
|
||||
base_name=$(get_basename "$file")
|
||||
patch_prefix="$MODS_DIR/${base_name}.patch_"
|
||||
count=$(ls "${patch_prefix}"* 2>/dev/null | grep -E '([0-9]+$)' 2>/dev/null | wc -l) # count installed patches
|
||||
|
||||
@@ -254,7 +270,7 @@ function install_mod() {
|
||||
echo -e "Mod $mod_name ($base_name) ${GREEN}installed successfully${NC}."
|
||||
}
|
||||
|
||||
function list_mods() {
|
||||
function mod_list() {
|
||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||
display_list_help
|
||||
exit 0
|
||||
@@ -268,7 +284,7 @@ function list_mods() {
|
||||
awk -F, '{ if (length($3) > 150) $3 = substr($3, 1, 147) "..."; printf "%2s. %s (%s)\n", $1, $2, $3 }' "$DB_FILE"
|
||||
}
|
||||
|
||||
function uninstall_mod() {
|
||||
function mod_uninstall() {
|
||||
local mod_name=""
|
||||
local mod_index=""
|
||||
|
||||
@@ -321,7 +337,7 @@ function uninstall_mod() {
|
||||
echo -e "Removing ${ORANGE}\$MODS_DIR/$file${NC}."
|
||||
rm -f "$MODS_DIR/$file"
|
||||
|
||||
get_basename "$file"
|
||||
base_name=$(get_basename "$file")
|
||||
current_version=$(echo $file | grep -oP '(?<=patch_)\d+')
|
||||
downgrades["$base_name"]=current_version
|
||||
done
|
||||
@@ -329,7 +345,7 @@ function uninstall_mod() {
|
||||
# downgrade any necessary mods
|
||||
for file in "${!downgrades[@]}"; do
|
||||
# find all files that have the same base name, and are greater than the current version, and downgrade them
|
||||
get_basename "$file"
|
||||
base_name=$(get_basename "$file")
|
||||
same_patches=$(ls "$MODS_DIR/${base_name}.patch_"* 2>/dev/null | grep -Eo "$base_name.*")
|
||||
|
||||
for patch in $same_patches; do
|
||||
@@ -354,7 +370,7 @@ function uninstall_mod() {
|
||||
echo -e "Mod ${GREEN}uninstalled successfully${NC}."
|
||||
}
|
||||
|
||||
function export_mods() {
|
||||
function mod_export() {
|
||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||
display_export_help
|
||||
exit 0
|
||||
@@ -383,7 +399,7 @@ function export_mods() {
|
||||
fi
|
||||
}
|
||||
|
||||
function import_mods() {
|
||||
function mod_import() {
|
||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||
display_import_help
|
||||
exit 0
|
||||
@@ -418,7 +434,9 @@ function import_mods() {
|
||||
echo -e "Mods imported ${GREEN}successfully${NC}."
|
||||
}
|
||||
|
||||
# main
|
||||
# --- Main ---
|
||||
|
||||
function main() {
|
||||
if [[ $# -lt 1 ]]; then
|
||||
display_help
|
||||
exit 1
|
||||
@@ -426,27 +444,26 @@ fi
|
||||
|
||||
command="$1"
|
||||
shift
|
||||
|
||||
initialize_directories
|
||||
|
||||
case "$command" in
|
||||
install|i)
|
||||
install_mod "$@"
|
||||
mod_install "$@"
|
||||
;;
|
||||
list|l)
|
||||
list_mods "$@"
|
||||
mod_list "$@"
|
||||
;;
|
||||
uninstall|u)
|
||||
uninstall_mod "$@"
|
||||
mod_uninstall "$@"
|
||||
;;
|
||||
export|ex)
|
||||
export_mods "$@"
|
||||
mod_export "$@"
|
||||
;;
|
||||
import|im)
|
||||
import_mods "$@"
|
||||
mod_import "$@"
|
||||
;;
|
||||
reset|rr)
|
||||
reset "$@"
|
||||
mod_reset "$@"
|
||||
;;
|
||||
help|--help|-h|h)
|
||||
display_help
|
||||
@@ -457,3 +474,6 @@ case "$command" in
|
||||
esac
|
||||
|
||||
echo "--- /// END /// ---"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user