# ========================================================= # MAX Windows Toolkit - 安装开发工具 # 中文界面,统一风格 # ========================================================= $Common = "C:\Setup\windows\lib\common.ps1" if (Test-Path $Common) { . $Common } Write-Header "安装开发工具" Show-AdminWarn $DevAppBaseUrl = "$Global:RepoBase/dev-apps" $LocalDevAppDir = "C:\Setup\dev-apps" try { New-Item -ItemType Directory -Path $LocalDevAppDir -Force -ErrorAction Stop | Out-Null } catch {} $DevTools = @( @{ Id = 1; Name = "Git"; FileName = "Git-Setup.exe"; Arguments = "/VERYSILENT /NORESTART"; KillProcesses = @("git-bash"); TimeoutSeconds = 600 } @{ Id = 2; Name = "Visual Studio Code"; FileName = "VSCode-Setup.exe"; Arguments = "/VERYSILENT /NORESTART /MERGETASKS=!runcode"; KillProcesses = @("Code"); TimeoutSeconds = 600 } @{ Id = 3; Name = "PowerShell 7"; FileName = "PowerShell7-Setup.msi"; Arguments = "/qn /norestart"; KillProcesses = @("pwsh"); TimeoutSeconds = 600 } @{ Id = 4; Name = "Docker Desktop"; FileName = "DockerDesktop-Setup.exe"; Arguments = "install --quiet"; KillProcesses = @("Docker Desktop"); TimeoutSeconds = 1200 } @{ Id = 5; Name = "FinalShell"; FileName = "FinalShell-Setup.exe"; Arguments = "/S"; KillProcesses = @("FinalShell"); TimeoutSeconds = 600 } @{ Id = 6; Name = "Everything"; FileName = "Everything-Setup.exe"; Arguments = "/S"; KillProcesses = @("Everything"); TimeoutSeconds = 300 } ) function Install-DevTool { param([hashtable]$Tool) $Name = $Tool.Name $FileName = $Tool.FileName $Arguments = $Tool.Arguments $TimeoutSeconds = $Tool.TimeoutSeconds $KillList = $Tool.KillProcesses $Url = "$DevAppBaseUrl/$FileName" $Installer = Join-Path $LocalDevAppDir $FileName Write-Section "正在安装: $Name" if (-not (Download-File -Url $Url -OutFile $Installer)) { Write-Err "$Name 跳过安装(下载失败)" return } try { if ($FileName -like "*.msi") { Write-Muted "msiexec.exe /i `"$Installer`" $Arguments" $Process = Start-Process msiexec.exe -ArgumentList "/i `"$Installer`" $Arguments" -PassThru } else { Write-Muted "`"$Installer`" $Arguments" $Process = Start-Process -FilePath $Installer -ArgumentList $Arguments -PassThru } $Exited = $Process.WaitForExit($TimeoutSeconds * 1000) if (-not $Exited) { Stop-Process -Id $Process.Id -Force -ErrorAction SilentlyContinue Write-Warn "$Name 安装超时,已终止" } Kill-Processes -ProcessNames $KillList Write-OK "$Name 安装完成" } catch { Write-Err "$Name 安装失败" Write-Muted $_.Exception.Message } } # 显示列表 foreach ($Tool in $DevTools) { Write-Info "$($Tool.Id). $($Tool.Name)" } Write-Info "" Write-Info "A. 安装全部" Write-Info "0. 退出" Write-Info "" $Choice = Read-Host "选择工具(如 1,2,3 或 A/0)" Write-Line if ($Choice -match '^[0]$') { exit 0 } if ($Choice -match '^[Aa]$') { foreach ($Tool in $DevTools) { Install-DevTool -Tool $Tool } Write-OK "所有开发工具安装完成" Write-Line exit 0 } $Ids = $Choice -split "," | ForEach-Object { $_.Trim() } | Where-Object { $_ -match '^\d+$' } | ForEach-Object { [int]$_ } foreach ($Id in $Ids) { $Tool = $DevTools | Where-Object { $_.Id -eq $Id } if ($Tool) { Install-DevTool -Tool $Tool } }