42 lines
1.4 KiB
PowerShell
42 lines
1.4 KiB
PowerShell
$scriptDir = $PSScriptRoot
|
|
if ([string]::IsNullOrWhiteSpace($scriptDir)) {
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
}
|
|
Set-Location -LiteralPath $scriptDir
|
|
$exe = Join-Path $scriptDir "mihomo-windows-amd64-v3-go125.exe"
|
|
$configDir = Join-Path $scriptDir "config"
|
|
$configFile = Join-Path $configDir "config.yaml"
|
|
if (!(Test-Path -LiteralPath $exe)) {
|
|
Write-Host "mihomo 程序不存在:$exe" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
if (!(Test-Path -LiteralPath $configFile)) {
|
|
Write-Host "配置文件不存在:$configFile" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
$timeout = 180
|
|
$interval = 3
|
|
$elapsed = 0
|
|
Write-Host "等待网络连接..."
|
|
while ($elapsed -lt $timeout) {
|
|
ping.exe -4 -n 1 -w 1000 www.baidu.com | Out-Null
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host "网络已连接。" -ForegroundColor Green
|
|
break
|
|
}
|
|
Start-Sleep -Seconds $interval
|
|
$elapsed += $interval
|
|
}
|
|
if ($elapsed -ge $timeout) {
|
|
Write-Host "等待网络超时,已停止启动。" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
Write-Host "正在检查配置格式..."
|
|
& $exe -d $configDir -f $configFile -t
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "配置格式检查失败,已停止启动。" -ForegroundColor Red
|
|
exit $LASTEXITCODE
|
|
}
|
|
Write-Host "配置格式检查成功!" -ForegroundColor Green
|
|
Write-Host "正在启动 mihomo..."
|
|
& $exe -d $configDir -f $configFile |