# PanTool 启动脚本 # 用法:irm https://get.808855.xyz | iex # # 逻辑: # 1. 检查本地 exe 版本 # 2. 版本不对或不存在 → 从 Gitee 下载(不耗服务器流量) # 3. 启动 exe → 自动打开浏览器 $ErrorActionPreference = "Stop" # ── 配置(发布新版本时只改这两行)────────────── $VERSION = "1.0.0" $EXE_URL = "https://gitee.com/你的用户名/pantool/releases/download/v$VERSION/PanTool.exe" # ──────────────────────────────────────────────── $TOOL_DIR = "$env:APPDATA\PanTool" $TOOL_PATH = "$TOOL_DIR\PanTool.exe" $VERSION_FILE = "$TOOL_DIR\version.txt" function Write-Color($text, $color = "White") { Write-Host $text -ForegroundColor $color } Write-Color "" Write-Color " ██████╗ █████╗ ███╗ ██╗████████╗ ██████╗ ██████╗ ██╗" "Cyan" Write-Color " ██╔══██╗██╔══██╗████╗ ██║╚══██╔══╝██╔═══██╗██╔═══██╗██║" "Cyan" Write-Color " ██████╔╝███████║██╔██╗██║ ██║ ██║ ██║██║ ██║██║" "Cyan" Write-Color " ██╔═══╝ ██╔══██║██║╚████║ ██║ ██║ ██║██║ ██║██║" "Cyan" Write-Color " ██║ ██║ ██║██║ ╚███║ ██║ ╚██████╔╝╚██████╔╝███████╗" "Cyan" Write-Color " ╚═╝ ╚═╝ ╚═╝╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝" "Cyan" Write-Color " 网盘批处理工具 v$VERSION" "DarkCyan" Write-Color "" # 创建目录 if (!(Test-Path $TOOL_DIR)) { New-Item -ItemType Directory -Path $TOOL_DIR -Force | Out-Null } # 判断是否需要下载 $needDownload = $true if ((Test-Path $TOOL_PATH) -and (Test-Path $VERSION_FILE)) { $localVer = (Get-Content $VERSION_FILE -Raw -ErrorAction SilentlyContinue).Trim() if ($localVer -eq $VERSION) { $needDownload = $false Write-Color " ✓ 已是最新版本 v$VERSION" "Green" } else { Write-Color " ↑ 发现新版本 v$VERSION(当前 v$localVer),正在更新..." "Yellow" } } # 下载 if ($needDownload) { Write-Color " ↓ 正在下载 PanTool.exe..." "Cyan" try { # 显示进度 $webClient = New-Object System.Net.WebClient $webClient.DownloadProgressChanged += { param($s, $e) Write-Progress -Activity "下载 PanTool" ` -Status "$($e.ProgressPercentage)% ($([math]::Round($e.BytesReceived/1MB,1)) MB)" ` -PercentComplete $e.ProgressPercentage } $webClient.DownloadFileTaskAsync($EXE_URL, $TOOL_PATH).Wait() Write-Progress -Activity "下载 PanTool" -Completed Set-Content -Path $VERSION_FILE -Value $VERSION -Encoding UTF8 Write-Color " ✓ 下载完成!" "Green" } catch { Write-Color " ✗ 下载失败:$($_.Exception.Message)" "Red" if (Test-Path $TOOL_PATH) { Write-Color " → 使用本地已有版本继续..." "Yellow" } else { Write-Color " 请手动下载:$EXE_URL" "Yellow" Write-Color " 保存到:$TOOL_PATH" "Yellow" Read-Host " 按 Enter 退出" exit 1 } } } # 检查端口是否已占用(已经在运行) $portInUse = $false try { $conn = New-Object System.Net.Sockets.TcpClient $conn.Connect("127.0.0.1", 8080) $conn.Close() $portInUse = $true } catch {} if ($portInUse) { Write-Color " ✓ PanTool 已在运行,打开浏览器..." "Green" Start-Process "http://localhost:8080" } else { Write-Color " → 启动 PanTool,浏览器将自动打开..." "Cyan" Start-Process -FilePath $TOOL_PATH -WindowStyle Hidden } Write-Color "" Write-Color " 如浏览器未自动打开,请访问:http://localhost:8080" "DarkGray" Write-Color ""