@echo off
title WanFengTool 启动器
setlocal
set "WFT_DIR=%~dp0"
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; try { Write-Host ''; Write-Host '====================================' -ForegroundColor DarkCyan; Write-Host '     WanFengTool 在线启动器' -ForegroundColor Cyan; Write-Host '====================================' -ForegroundColor DarkCyan; Write-Host ''; Write-Host '[1/3] 正在获取最新版本信息...' -ForegroundColor Yellow; $html = (& curl.exe -s -L --retry 3 --retry-delay 2 'https://new.wanfengtool.cn') -join ' '; if ($LASTEXITCODE -ne 0 -or -not $html) { throw '获取网页内容失败，请检查网络连接' }; $m = [regex]::Match($html, 'https://new\.wanfengtool\.cn/assets/WanFengTool_V[\d.]+\.exe'); if (-not $m.Success) { throw '未能从网页中匹配到下载链接，请稍后重试' }; $url = $m.Value; $fn = [IO.Path]::GetFileName($url); $sp = Join-Path $env:WFT_DIR $fn; Write-Host ('      链接: ' + $url) -ForegroundColor Green; Write-Host ('      保存: ' + $sp) -ForegroundColor Green; Write-Host ''; Write-Host '[2/3] 正在下载，请稍候...' -ForegroundColor Yellow; & curl.exe -L --retry 3 --retry-delay 2 --fail -o $sp $url; if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath $sp)) { throw ('文件下载失败 (curl 退出码: ' + $LASTEXITCODE + ')') }; $size = [math]::Round((Get-Item -LiteralPath $sp).Length / 1MB, 2); Write-Host ''; Write-Host ('      下载完成，文件大小: ' + $size + ' MB') -ForegroundColor Green; Write-Host ''; Write-Host '[3/3] 正在启动程序...' -ForegroundColor Yellow; Start-Process -FilePath $sp -WorkingDirectory $env:WFT_DIR; Write-Host '      启动成功，启动器即将退出。' -ForegroundColor Green; Start-Sleep -Milliseconds 800 } catch { Write-Host ''; Write-Host ('[错误] ' + $_.Exception.Message) -ForegroundColor Red; Write-Host ''; Read-Host '按回车键关闭'; exit 1 }"

if errorlevel 1 (
    endlocal
    exit /b 1
)
endlocal
(goto) 2>nul & del "%~f0"