Updated Download function.
This commit is contained in:
parent
232c6b4dd9
commit
93f5f9177a
@ -192,45 +192,63 @@ clear_cache() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
download() {
|
download() {
|
||||||
local source=($@)
|
local source=($@)
|
||||||
for i in "${source[@]}" ; do
|
for i in "${source[@]}" ; do
|
||||||
local dest="${i##*/}"
|
local dest="${i##*/}"
|
||||||
dest="${dest//%20/ }"
|
dest="${dest//%20/ }"
|
||||||
dest="${dest#*\?filename=}"
|
dest="${dest#*\?filename=}"
|
||||||
dest="${dest%\?*}"
|
dest="${dest%\?*}"
|
||||||
# Remove the destination file if it is empty.
|
# Remove the destination file if it is empty.
|
||||||
test -s "${cache}/${dest}" || rm -f "${cache}/${dest}" 2> /dev/null
|
test -s "${cache}/${dest}" || rm -f "${cache}/${dest}" 2> /dev/null
|
||||||
if [[ "${redownload}" == "true" ]] && [[ -e "${cache}/${dest}" ]]; then
|
if [[ "${redownload}" == "true" ]] && [[ -e "${cache}/${dest}" ]]; then
|
||||||
rm -v "${cache}/${dest}"
|
rm -v "${cache}/${dest}"
|
||||||
fi
|
fi
|
||||||
# Skip if the item is in cache.
|
# Skip if the item is in cache.
|
||||||
test -e "${cache}/${dest}" && continue
|
test -e "${cache}/${dest}" && continue
|
||||||
{ if ! curl -L4 --output "${cache}/${dest}" "${i}" ; then
|
{ if ! curl -L4 -C - --retry 10 --output "${cache}/${dest}" "${i}" ; then
|
||||||
echo "Could not download \"$i\"..."
|
echo "Could not download \"$i\"..."
|
||||||
exit 1
|
exit 1
|
||||||
fi; } | dialog --backtitle "Linux Game Manager" \
|
fi; } | dialog --backtitle "Linux Game Manager" \
|
||||||
--progressbox "Downloading \"$dest\" from \"$i\"" -1 -1
|
--progressbox "Downloading \"$dest\" from \"$i\"" -1 -1
|
||||||
local downloadError=1
|
local downloadError=1
|
||||||
case "${dest##*.}" in
|
case "${dest##*.}" in
|
||||||
"pk3"|"zip")
|
"pk3"|"zip")
|
||||||
unzip -tq "${cache}/${dest}" | dialog --backtitle "Linux Game Manager" \
|
unzip -tq "${cache}/${dest}" | dialog --backtitle "Linux Game Manager" \
|
||||||
--progressbox "Validating ${dest##*.} file" -1 -1 --stdout
|
--progressbox "Validating ${dest##*.} file" -1 -1 --stdout
|
||||||
downloadError= $?
|
downloadError=$?
|
||||||
;;
|
;;
|
||||||
"wad")
|
"7z")
|
||||||
if [[ "$(file -b --mime-type "${cache}/${dest}")" != "application/octet-stream" ]]; then
|
7z t "${cache}/${dest}" | dialog --backtitle "Linux Game Manager" \
|
||||||
downloadError=0
|
--progressbox "Validating 7z file" -1 -1 --stdout
|
||||||
fi
|
downloadError=$?
|
||||||
;;
|
;;
|
||||||
esac
|
"exe")
|
||||||
if [[ $downloadError -eq 0 ]]; then
|
# Check if it's a valid Windows executable by looking at the MZ header
|
||||||
rm -fv "${cache}/${dest}"
|
if ! hexdump -n 2 -v -e '/1 "%02X"' "${cache}/${dest}" | grep -q "4D5A"; then
|
||||||
dialog --backtitle "Linux Game Manager" \
|
downloadError=0
|
||||||
--infobox "Error downloading \"${dest}\". Installation cannot continue." -1 -1 --stdout
|
fi
|
||||||
alert
|
;;
|
||||||
exit 1
|
"wad")
|
||||||
fi
|
if [[ "$(file -b --mime-type "${cache}/${dest}")" != "application/octet-stream" ]]; then
|
||||||
done
|
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=0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
if [[ $downloadError -eq 0 ]]; then
|
||||||
|
rm -fv "${cache}/${dest}"
|
||||||
|
dialog --backtitle "Linux Game Manager" \
|
||||||
|
--infobox "Error downloading \"${dest}\". Installation cannot continue." -1 -1 --stdout
|
||||||
|
alert
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
download_named() {
|
download_named() {
|
||||||
|
Loading…
Reference in New Issue
Block a user