Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions scripts/setup/install_deps_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,30 @@ function Install-VCPKG {
& "$vcpkgPath\bootstrap-vcpkg.bat"
}
}
function Install-VCPKG-Dependency {
$vcpkgPath = "C:\Dev\vcpkg\vcpkg.exe"
$depsList = @(
# ToDo: Add dependencies here
)
function Install-VCPKG-Dependency {
$vcpkgExe = "$script:vcpkgPath\vcpkg.exe"
$jsonPath = Join-Path $PSScriptRoot "..\..\vcpkg.json"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [路径处理] 相对路径 ..\..\vcpkg.json 假设脚本始终位于 scripts/setup/ 目录。建议使用 (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) 显式获取仓库根目录,避免因脚本调用位置不同导致路径解析失败。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emmm,如果需求健壮性,我其实比较喜欢C#,并且……这玩意是内置在用户手册里的,so……如果用户根本看不懂文件放在哪里,到时候咱俩都得遭殃


if (-not (Test-Path $jsonPath)) {
Write-Error "vcpkg.json not found at $jsonPath"
return
}


$json = Get-Content $jsonPath -Raw | ConvertFrom-Json

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 [错误处理] 建议添加 try-catch 块包裹 JSON 解析,防止文件格式错误时抛出未处理异常:

try {
    $json = Get-Content $jsonPath -Raw | ConvertFrom-Json
} catch {
    Write-Error "Failed to parse vcpkg.json: $_"
    return
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emmm,对哦,OK,下个版本改

$depsList = $json.dependencies

if ($depsList.Count -eq 0) {
Write-Output "No dependencies listed in vcpkg.json"
return
}

foreach ($dep in $depsList) {
Write-Output "Installing $dep via vcpkg..."
& "$vcpkgPath" install "$dep"
& $vcpkgExe install $dep

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 [安全性] 建议验证 $dep 格式后再执行,防止潜在的命令注入(尽管 vcpkg 包名通常受限):

if ($dep -notmatch '^[\w\-\.]+$') {
    Write-Warning "Invalid dependency name format: $dep"
    continue
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你的意思是不信任Coredev们喽,你这是指桑骂槐,有反叛之心啊

if ($LASTEXITCODE -ne 0) {
Write-Warning "Failed to install $dep"
}
}
}
function Get-Admin{
Expand Down
Loading