# Alerts, for when user needs to read something. alert() { play -qnV0 synth 3 pluck D3 pluck A3 pluck D4 pluck F4 pluck A4 delay 0 .1 .2 .3 .4 remix - chorus 0.9 0.9 38 0.75 0.3 0.5 -t echo read -rp "Press enter to continue." continue } check_requirements() { # Make sure the minimum of curl, sox, wine, and winetricks are installed or fex-emu on aarch64 if [[ "$(uname -m)" == "aarch64" ]]; then minimumDependencies=("FEXLoader") wine="FEXLoader -- /usr/bin/wine" else minimumDependencies=("curl" "sox" "wine") fi for i in "${minimumDependencies[@]}" ; do if ! command -v $i &> /dev/null ; then echo "Please install $i before continuing." return 1 fi done return 0 } download() { local source=($@) for i in "${source[@]}" ; do local dest="${i##*/}" dest="${dest//%20/ }" dest="${dest#*\?filename=}" dest="${dest%\?*}" # Remove the destination file if it is empty. [[ -s "${cache}/${dest}" ]] || rm -f "${cache}/${dest}" 2> /dev/null if [[ "${redownload}" == "true" ]] && [[ -e "${cache}/${dest}" ]]; then rm -v "${cache}/${dest}" fi # Skip if the item is in cache. [[ -e "${cache}/${dest}" ]] && continue { if ! curl -L4 -C - --retry 10 --output "${cache}/${dest}" "${i}" ; then echo "Could not download \"$i\"..." exit 1 fi; } | dialog --backtitle "Audio Game Manager" \ --progressbox "Downloading \"$dest\" from \"$i\"" -1 -1 local downloadError=1 case "${dest##*.}" in "pk3"|"zip") unzip -tq "${cache}/${dest}" | dialog --backtitle "Audio Game Manager" \ --progressbox "Validating ${dest##*.} file" -1 -1 --stdout downloadError=$? ;; "7z") 7z t "${cache}/${dest}" | dialog --backtitle "Audio Game Manager" \ --progressbox "Validating 7z file" -1 -1 --stdout downloadError=$? ;; "exe") # Check if it's a valid Windows executable by looking at the MZ header hexdump -n 2 -v -e '/1 "%02X"' "${cache}/${dest}" | grep -q "4D5A" downloadError=$? ;; "wad") if [[ "$(file -b --mime-type "${cache}/${dest}")" != "application/octet-stream" ]]; then downloadError=0 fi ;; *) # Add HTML check for other file types if file -b "${cache}/${dest}" | grep -q "HTML document" ; then echo "File not found: \"$i\" (HTML document probably 404)" downloadError=1 else downloadError=0 fi ;; esac if [[ $downloadError -ne 0 ]]; then rm -fv "${cache}/${dest}" dialog --backtitle "Audio Game Manager" \ --infobox "Error downloading \"${dest}\". Installation cannot continue." -1 -1 --stdout alert exit 1 fi done } # Function to open urls across OS. open_url() { if [[ "$(uname)" == "Darwin" ]]; then open "${*}" 2> /dev/null else xdg-open "${*}" 2> /dev/null fi }