Files
Shigure/Tools/Download-WowIcons.ps1
waynebian01 e17975d4be 配置与宏
2026-07-28 20:31:34 +08:00

40 lines
1.2 KiB
PowerShell

param(
[switch]$Force
)
$repoRoot = Split-Path -Parent $PSScriptRoot
$assetRoot = Join-Path $repoRoot "Assets"
$manifestPath = Join-Path $assetRoot "IconManifest.json"
$manifest = Get-Content -LiteralPath $manifestPath -Raw | ConvertFrom-Json
$downloaded = 0
$skipped = 0
foreach ($icon in $manifest.icons) {
$target = Join-Path $assetRoot $icon.target
if ((Test-Path -LiteralPath $target) -and -not $Force) {
$skipped++
continue
}
$directory = Split-Path -Parent $target
New-Item -ItemType Directory -Path $directory -Force | Out-Null
$uri = "$($manifest.source.imageBaseUrl)$($icon.slug).jpg"
$temporary = "$target.download"
try {
Invoke-WebRequest -Uri $uri -OutFile $temporary -UseBasicParsing
if ((Get-Item -LiteralPath $temporary).Length -lt 512) {
throw "Downloaded file is unexpectedly small."
}
Move-Item -LiteralPath $temporary -Destination $target -Force
$downloaded++
}
finally {
if (Test-Path -LiteralPath $temporary) {
Remove-Item -LiteralPath $temporary -Force
}
}
}
Write-Output "Downloaded: $downloaded; skipped existing: $skipped; total: $($manifest.icons.Count)"