mirror of
https://github.com/dockur/windows.git
synced 2024-11-17 02:01:49 +00:00
feat: Refactor download code
This commit is contained in:
parent
d664bd0cf7
commit
bcae60c9ec
1 changed files with 62 additions and 0 deletions
62
src/mido.sh
62
src/mido.sh
|
@ -195,4 +195,66 @@ downloadFile() {
|
|||
return 1
|
||||
}
|
||||
|
||||
downloadImage() {
|
||||
|
||||
local iso="$1"
|
||||
local version="$2"
|
||||
local tried="n"
|
||||
local url sum size base desc
|
||||
|
||||
if [[ "${version,,}" == "http"* ]]; then
|
||||
base=$(basename "$iso")
|
||||
desc=$(fromFile "$base")
|
||||
downloadFile "$iso" "$version" "" "" "$desc" && return 0
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! validVersion "$version"; then
|
||||
error "Invalid VERSION specified, value \"$version\" is not recognized!" && return 1
|
||||
fi
|
||||
|
||||
desc=$(printVersion "$version" "")
|
||||
|
||||
if isMido "$version"; then
|
||||
tried="y"
|
||||
doMido "$iso" "$version" "$desc" && return 0
|
||||
fi
|
||||
|
||||
switchEdition "$version"
|
||||
|
||||
if isESD "$version"; then
|
||||
|
||||
if [[ "$tried" != "n" ]]; then
|
||||
info "Failed to download $desc using Mido, will try a diferent method now..."
|
||||
fi
|
||||
|
||||
tried="y"
|
||||
|
||||
if getESD "$TMP/esd" "$version"; then
|
||||
ISO="${ISO%.*}.esd"
|
||||
downloadFile "$ISO" "$ESD" "$ESD_SUM" "$ESD_SIZE" "$desc" && return 0
|
||||
ISO="$iso"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
for ((i=1;i<=MIRRORS;i++)); do
|
||||
|
||||
url=$(getLink "$i" "$version")
|
||||
|
||||
if [ -n "$url" ]; then
|
||||
if [[ "$tried" != "n" ]]; then
|
||||
info "Failed to download $desc, will try another mirror now..."
|
||||
fi
|
||||
tried="y"
|
||||
size=$(getSize "$i" "$version")
|
||||
sum=$(getHash "$i" "$version")
|
||||
downloadFile "$iso" "$url" "$sum" "$size" "$desc" && return 0
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
|
|
Loading…
Reference in a new issue