feat: export, reset functionality
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
# TODO:
|
# TODO:
|
||||||
# export mods
|
# export mods
|
||||||
# import mods
|
# import mods
|
||||||
# reset all
|
|
||||||
|
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
@@ -70,34 +69,32 @@ function display_help() {
|
|||||||
echo "Helldivers 2 Mod Manager"
|
echo "Helldivers 2 Mod Manager"
|
||||||
echo "Usage: h2mm [command] [options]"
|
echo "Usage: h2mm [command] [options]"
|
||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
echo " install -n \"<mod_name>\" <mod_files> Install a mod with a name and files."
|
echo " install Install a mod with files."
|
||||||
echo " uninstall -n \"<mod_name>\" Uninstall a mod by name."
|
echo " uninstall Uninstall a mod by name."
|
||||||
echo " list List all installed mods."
|
echo " list List all installed mods."
|
||||||
echo " export \"<zip_name>\" Export installed mods to a zip file (not yet implemented)."
|
echo " export <zip_name> Export installed mods to a zip file (not yet implemented)."
|
||||||
echo " import \"<zip_name>\" Import mods from a zip file (not yet implemented)."
|
echo " import <zip_name> Import mods from a zip file (not yet implemented)."
|
||||||
echo " reset Reset all installed mods (not yet implemented)."
|
echo " reset Reset all installed mods."
|
||||||
echo " help Display this help message."
|
echo " help Display this help message."
|
||||||
echo "For more information on usage, use h2mm [command] --help, available for install and uninstall."
|
echo "For more information on usage, use h2mm [command] --help, available for install and uninstall."
|
||||||
echo "Basic Usage:"
|
echo "Basic Usage:"
|
||||||
echo " h2mm install -n \"Example mod\" a5f2c029522e6714.patch_0 a5f2c029522e6714.patch_0.stream"
|
echo " h2mm install -z /path/to/mod.zip"
|
||||||
|
echo " h2mm install -d /path/to/mod/files"
|
||||||
echo " h2mm uninstall -n \"Example mod\""
|
echo " h2mm uninstall -n \"Example mod\""
|
||||||
echo "Advanced Usage:"
|
|
||||||
echo " Database of mods is stored in Steam/steamapps/common/Helldivers\ 2/data/mods.csv"
|
|
||||||
echo " You can rename, delete, or edit this file to manage mods manually."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function display_install_help() {
|
function display_install_help() {
|
||||||
echo "Usage: h2mm install -n \"<mod_name>\" [options] <mod_files>"
|
echo "Usage: h2mm install [options] <mod_files>"
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -n \"<mod_name>\" Name of the mod (MANDATORY), inside double quotes."
|
|
||||||
echo " -d <mod_dir> Directory containing mod files."
|
echo " -d <mod_dir> Directory containing mod files."
|
||||||
echo " -z <mod_zip> Zip file containing mod files (.zip only)."
|
echo " -z <mod_zip> Zip file containing mod files (.zip only)."
|
||||||
|
echo " -n \"<mod_name>\" Name the mod yourself, inside double quotes."
|
||||||
echo " <mod_files> List of mod files to install."
|
echo " <mod_files> List of mod files to install."
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
echo " h2mm install -n \"Example mod\" a5f2c029522e6714.patch_0 a5f2c029522e6714.patch_0.stream"
|
echo " h2mm install -z /path/to/mod.zip"
|
||||||
echo " h2mm install -n \"Example mod\" a5f* (using a wildcard to include all files)"
|
echo " h2mm install -d /path/to/mod/files"
|
||||||
echo " h2mm install -n \"Example mod\" -d /path/to/mod/files"
|
echo " h2mm install -n \"Example mod\" mod.patch_0 mod.patch_0.stream (-n is mandatory when using files)"
|
||||||
echo " h2mm install -n \"Example mod\" -z /path/to/mod.zip"
|
echo " h2mm install -n \"Example mod\" mod* (using a wildcard to include all files)"
|
||||||
}
|
}
|
||||||
|
|
||||||
function display_uninstall_help() {
|
function display_uninstall_help() {
|
||||||
@@ -110,6 +107,35 @@ function display_uninstall_help() {
|
|||||||
echo " h2mm uninstall -i 1"
|
echo " h2mm uninstall -i 1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function display_list_help() {
|
||||||
|
echo "Usage: h2mm list"
|
||||||
|
echo "List all installed mods."
|
||||||
|
echo " Database of mods is stored in Steam/steamapps/common/Helldivers\ 2/data/mods.csv"
|
||||||
|
echo " You can rename, delete, or edit this file to manage mods manually."
|
||||||
|
}
|
||||||
|
|
||||||
|
function display_reset_help() {
|
||||||
|
echo "Usage: h2mm reset"
|
||||||
|
echo "Reset all installed mods."
|
||||||
|
echo " Deletes all installed mods and the database file."
|
||||||
|
echo " Database of mods is stored in Steam/steamapps/common/Helldivers\ 2/data/mods.csv, along with the mods."
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||||
|
display_reset_help
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -p "Are you sure you want to reset all installed mods? (y/n): " confirm
|
||||||
|
if [[ "$confirm" == "y" ]]; then
|
||||||
|
rm -f "$MODS_DIR"/*.patch_*
|
||||||
|
rm -f "$DB_FILE"
|
||||||
|
rm -f "$H2PATH"
|
||||||
|
echo "Database file deleted."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function install_mod() {
|
function install_mod() {
|
||||||
local mod_name=""
|
local mod_name=""
|
||||||
local mod_files=()
|
local mod_files=()
|
||||||
@@ -135,7 +161,7 @@ function install_mod() {
|
|||||||
mod_zip="$2"
|
mod_zip="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--help)
|
--help|-h)
|
||||||
display_install_help
|
display_install_help
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
@@ -152,13 +178,27 @@ function install_mod() {
|
|||||||
echo -e "${RED}Error${NC}: unzip is not installed, please install the package and try again."
|
echo -e "${RED}Error${NC}: unzip is not installed, please install the package and try again."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [[ ! -f "$mod_zip" ]]; then
|
||||||
|
echo -e "${RED}Error${NC}: Zip file $mod_zip does not exist."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ -n "$mod_name" ]]; then
|
||||||
|
mod_name=$(basename "$mod_zip" | sed -E 's/\.zip//')
|
||||||
|
fi
|
||||||
mod_dir=$(mktemp -d)
|
mod_dir=$(mktemp -d)
|
||||||
unzip -qq "$mod_zip" -d "$mod_dir"
|
unzip -qq "$mod_zip" -d "$mod_dir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# directory containing mod files
|
# directory containing mod files
|
||||||
if [[ -n "$mod_dir" ]]; then
|
if [[ -n "$mod_dir" ]]; then
|
||||||
|
if [[ ! -d "$mod_dir" ]]; then
|
||||||
|
echo -e "${RED}Error${NC}: Directory $mod_dir does not exist."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
readarray -d '' mod_files < <(find "$mod_dir" -type f -name "*.patch_*" -print0)
|
readarray -d '' mod_files < <(find "$mod_dir" -type f -name "*.patch_*" -print0)
|
||||||
|
if [[ -n "$mod_name" ]]; then
|
||||||
|
mod_name=$($mod_dir | awk -F/ '{print $NF}')
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# verify minimum information required
|
# verify minimum information required
|
||||||
@@ -183,12 +223,18 @@ function install_mod() {
|
|||||||
count=$(ls "${patch_prefix}"* 2>/dev/null | grep -E '([0-9]+$)' 2>/dev/null | wc -l) # count installed patches
|
count=$(ls "${patch_prefix}"* 2>/dev/null | grep -E '([0-9]+$)' 2>/dev/null | wc -l) # count installed patches
|
||||||
|
|
||||||
# set patch count for file name
|
# set patch count for file name
|
||||||
if [[ -z "${patch_count[$base_name]+unset}" ]]; then
|
if [[ -z "${patch_count[$file]+unset}" ]]; then
|
||||||
patch_count["$base_name"]=$count
|
patch_count["$file"]=$count
|
||||||
fi
|
fi
|
||||||
|
patch_count["$base_name"]=$count
|
||||||
|
|
||||||
extension=$(echo "$file" | sed -E 's/.*patch_[0-9]+//')
|
extension=$(echo "$file" | sed -E 's/.*patch_[0-9]+//')
|
||||||
target_file="${base_name}.patch_${patch_count[$base_name]}${extension}"
|
if [[ -n "$extension" ]]; then
|
||||||
|
target_file="${base_name}.patch_$((patch_count[$base_name] - 1))${extension}"
|
||||||
|
else
|
||||||
|
target_file="${base_name}.patch_${patch_count[$file]}"
|
||||||
|
fi
|
||||||
|
|
||||||
target_files+=($target_file)
|
target_files+=($target_file)
|
||||||
|
|
||||||
cp "$file" "$MODS_DIR/$target_file"
|
cp "$file" "$MODS_DIR/$target_file"
|
||||||
@@ -202,12 +248,17 @@ function install_mod() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function list_mods() {
|
function list_mods() {
|
||||||
|
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||||
|
display_list_help
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! -s "$DB_FILE" ]]; then
|
if [[ ! -s "$DB_FILE" ]]; then
|
||||||
echo "No mods installed."
|
echo "No mods installed."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
awk -v color="$GREEN" -v nc="$NC" -F, '{ printf "%s. %s%s%s (%s)\n", $1, color, $2, nc, $3 }' "$DB_FILE"
|
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 uninstall_mod() {
|
||||||
@@ -222,21 +273,17 @@ function uninstall_mod() {
|
|||||||
# parse arguments
|
# parse arguments
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-n)
|
|
||||||
mod_name="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-i)
|
-i)
|
||||||
mod_index="$2"
|
mod_index="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--help)
|
--help|-h)
|
||||||
display_uninstall_help
|
display_uninstall_help
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "${RED}Error${NC}: Invalid argument $1."
|
mod_name="$1"
|
||||||
exit 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@@ -300,6 +347,24 @@ function uninstall_mod() {
|
|||||||
echo -e "Mod ${GREEN}uninstalled successfully${NC}."
|
echo -e "Mod ${GREEN}uninstalled successfully${NC}."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function export_mods() {
|
||||||
|
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||||
|
display_export_help
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
OUT_DIR=$(mktemp -d)
|
||||||
|
echo "$OUT_DIR"
|
||||||
|
cp "$DB_FILE" "$OUT_DIR"
|
||||||
|
ls "$MODS_DIR/" 2>/dev/null | grep -E 'patch_.*' | xargs -I {} cp "$MODS_DIR/{}" "$OUT_DIR"
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo -e "${RED}Error${NC}: Could not export mods. Possibly because no mods are present."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
read -p "Enter the name of the zip file to export to: " zip_name
|
||||||
|
zip -r "$zip_name" "$OUT_DIR/*"
|
||||||
|
}
|
||||||
|
|
||||||
# main
|
# main
|
||||||
if [[ $# -lt 1 ]]; then
|
if [[ $# -lt 1 ]]; then
|
||||||
display_help
|
display_help
|
||||||
@@ -314,24 +379,28 @@ initialize_directories
|
|||||||
case "$command" in
|
case "$command" in
|
||||||
install)
|
install)
|
||||||
install_mod "$@"
|
install_mod "$@"
|
||||||
echo "--- /// END /// ---"
|
|
||||||
;;
|
;;
|
||||||
list)
|
list)
|
||||||
list_mods
|
list_mods "$@"
|
||||||
echo "--- /// END /// ---"
|
|
||||||
;;
|
;;
|
||||||
uninstall)
|
uninstall)
|
||||||
uninstall_mod "$@"
|
uninstall_mod "$@"
|
||||||
echo "--- /// END /// ---"
|
|
||||||
;;
|
;;
|
||||||
export)
|
export)
|
||||||
echo "Exporting mods to a zip file is not yet implemented."
|
export_mods "$@"
|
||||||
;;
|
;;
|
||||||
import)
|
import)
|
||||||
echo "Importing mods from a zip file is not yet implemented."
|
echo "Importing mods from a zip file is not yet implemented."
|
||||||
;;
|
;;
|
||||||
|
reset)
|
||||||
|
reset "$@"
|
||||||
|
;;
|
||||||
|
help|--help|-h)
|
||||||
|
display_help
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
display_help
|
display_help
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
echo "--- /// END /// ---"
|
||||||
|
|||||||
Reference in New Issue
Block a user