mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-05 21:28:48 +00:00
D2r posix update (#531)
* Update d2r-loot-filters.sh * Update d2r-loot-filters.sh
This commit is contained in:
parent
b2ca03fe35
commit
fb883522aa
|
@ -2,42 +2,62 @@
|
||||||
|
|
||||||
. ../../common-script.sh
|
. ../../common-script.sh
|
||||||
|
|
||||||
|
# Check for required commands
|
||||||
|
for cmd in find curl unzip stty; do
|
||||||
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||||
|
printf "%s\n" "Error: $cmd is not installed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Search for possible Diablo II Resurrected folder locations
|
# Search for possible Diablo II Resurrected folder locations
|
||||||
printf "%b\n" "${YELLOW}Searching for Diablo II Resurrected folders...${RC}"
|
printf "%s\n" "Searching for Diablo II Resurrected folders..."
|
||||||
possible_paths=$(find $HOME -type d -path "*/drive_c/Program Files (x86)/Diablo II Resurrected" 2>/dev/null)
|
possible_paths=$(find "$HOME" -type d -path "*/drive_c/Program Files (x86)/Diablo II Resurrected" 2>/dev/null)
|
||||||
|
|
||||||
if [ -z "$possible_paths" ]; then
|
if [ -z "$possible_paths" ]; then
|
||||||
printf "%b\n" "${RED}Error: No Diablo II Resurrected folders found.${RC}"
|
printf "%s\n" "Error: No Diablo II Resurrected folders found."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Display possible paths and allow selection
|
# Display possible paths and allow selection
|
||||||
printf "%b\n" "${YELLOW}Possible Diablo II Resurrected folder locations:${RC}"
|
printf "%s\n" "Possible Diablo II Resurrected folder locations:"
|
||||||
mapfile -t paths_array <<< "$possible_paths"
|
paths_string=""
|
||||||
|
i=0
|
||||||
|
IFS='
|
||||||
|
'
|
||||||
|
for path in $possible_paths; do
|
||||||
|
paths_string="$paths_string|$path"
|
||||||
|
i=$((i + 1))
|
||||||
|
done
|
||||||
|
IFS=' '
|
||||||
|
paths_string="${paths_string#|}"
|
||||||
|
total=$i
|
||||||
selected=0
|
selected=0
|
||||||
total=${#paths_array[@]}
|
|
||||||
|
|
||||||
print_menu() {
|
print_menu() {
|
||||||
clear
|
command -v clear >/dev/null 2>&1 && clear
|
||||||
local max_display=$((total < 10 ? total : 10))
|
max_display=$((total < 10 ? total : 10))
|
||||||
local start=$((selected - max_display/2))
|
start=$((selected - max_display / 2))
|
||||||
if ((start < 0)); then start=0; fi
|
if [ $start -lt 0 ]; then start=0; fi
|
||||||
if ((start + max_display > total)); then start=$((total - max_display)); fi
|
if [ $((start + max_display)) -gt $total ]; then start=$((total - max_display)); fi
|
||||||
if ((start < 0)); then start=0; fi
|
if [ $start -lt 0 ]; then start=0; fi
|
||||||
|
|
||||||
printf "%b\n" "${YELLOW}Please select the Diablo II: Resurrected installation path:${RC}"
|
printf "%s\n" "Please select the Diablo II: Resurrected installation path:"
|
||||||
for i in $(seq 0 $((max_display - 1))); do
|
i=0
|
||||||
if ((i + start >= total)); then break; fi
|
echo "$paths_string" | tr '|' '\n' | while IFS= read -r path; do
|
||||||
if [ $((i + start)) -eq $selected ]; then
|
if [ $i -ge $start ] && [ $i -lt $((start + max_display)) ]; then
|
||||||
echo "> ${paths_array[$((i + start))]}"
|
if [ $i -eq $selected ]; then
|
||||||
|
printf "> %s\n" "$path"
|
||||||
else
|
else
|
||||||
echo " ${paths_array[$((i + start))]}"
|
printf " %s\n" "$path"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
i=$((i + 1))
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
select_path() {
|
select_path() {
|
||||||
local last_selected=-1
|
last_selected=-1
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
if [ $last_selected -ne $selected ]; then
|
if [ $last_selected -ne $selected ]; then
|
||||||
|
@ -45,31 +65,29 @@ select_path() {
|
||||||
last_selected=$selected
|
last_selected=$selected
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read -rsn1 key
|
stty -echo
|
||||||
|
key=$(dd bs=1 count=1 2>/dev/null)
|
||||||
|
stty echo
|
||||||
|
|
||||||
case "$key" in
|
case "$key" in
|
||||||
$'\x1B') # ESC key
|
$(printf '\033')A | k)
|
||||||
read -rsn2 key
|
if [ $selected -gt 0 ]; then
|
||||||
case "$key" in
|
selected=$((selected - 1))
|
||||||
'[A' | 'k')
|
|
||||||
if ((selected > 0)); then
|
|
||||||
((selected--))
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
'[B' | 'j')
|
$(printf '\033')B | j)
|
||||||
if ((selected < total - 1)); then
|
if [ $selected -lt $((total - 1)) ]; then
|
||||||
((selected++))
|
selected=$((selected + 1))
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
'')
|
||||||
;;
|
d2r_path=$(echo "$paths_string" | cut -d '|' -f $((selected + 1)))
|
||||||
'') # Enter key
|
|
||||||
d2r_path="${paths_array[$selected]}"
|
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
clear # Clear the screen after selection
|
command -v clear >/dev/null 2>&1 && clear
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use the select_path function
|
# Use the select_path function
|
||||||
|
@ -77,7 +95,7 @@ select_path
|
||||||
|
|
||||||
# Validate the path
|
# Validate the path
|
||||||
if [ ! -d "$d2r_path" ]; then
|
if [ ! -d "$d2r_path" ]; then
|
||||||
printf "%b\n" "${RED}Error: The specified path does not exist.${RC}"
|
printf "%s\n" "Error: The specified path does not exist."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -86,17 +104,23 @@ mods_path="$d2r_path/mods"
|
||||||
mkdir -p "$mods_path"
|
mkdir -p "$mods_path"
|
||||||
|
|
||||||
# Download the latest release
|
# Download the latest release
|
||||||
printf "%b\n" "${YELLOW}Downloading the latest loot filter...${RC}"
|
printf "%s\n" "Downloading the latest loot filter..."
|
||||||
curl -sSLo /tmp/lootfilter.zip https://github.com/ChrisTitusTech/d2r-loot-filter/releases/latest/download/lootfilter.zip
|
if ! curl -sSLo /tmp/lootfilter.zip https://github.com/ChrisTitusTech/d2r-loot-filter/releases/latest/download/lootfilter.zip; then
|
||||||
|
printf "%s\n" "Error: Failed to download the loot filter."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Extract the contents to the mods folder
|
# Extract the contents to the mods folder
|
||||||
printf "%b\n" "${YELLOW}Extracting loot filter to $mods_path...${RC}"
|
printf "%s\n" "Extracting loot filter to $mods_path..."
|
||||||
unzip -q -o /tmp/lootfilter.zip -d "$mods_path"
|
if ! unzip -q -o /tmp/lootfilter.zip -d "$mods_path"; then
|
||||||
|
printf "%s\n" "Error: Failed to extract the loot filter."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
rm /tmp/lootfilter.zip
|
rm /tmp/lootfilter.zip
|
||||||
|
|
||||||
printf "%b\n" "${GREEN}Loot filter installed successfully in $mods_path${RC}"
|
printf "%s\n" "Loot filter installed successfully in $mods_path"
|
||||||
|
|
||||||
printf "\nTo complete the setup, please follow these steps to add launch options in Battle.net:\n"
|
printf "\nTo complete the setup, please follow these steps to add launch options in Battle.net:\n"
|
||||||
printf "1. Open the Battle.net launcher\n"
|
printf "1. Open the Battle.net launcher\n"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user