From b8f30dcc9f5f81d21e9f24e21e1bd644f9a302bc Mon Sep 17 00:00:00 2001 From: SkyJourney Date: Sun, 16 Aug 2026 13:50:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20install.ps1=20=E5=9C=A8=20?= =?UTF-8?q?Windows=20PowerShell=205.1=20=E4=B8=8B=E7=9A=84=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E5=85=BC=E5=AE=B9=E6=80=A7=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ConvertFrom-Json 不支持 -Depth 参数(该参数只存在于 ConvertTo-Json), 5.1 下三处调用会直接报错终止,已实测复现并修复。 - 文件缺少 UTF-8 BOM,导致 5.1 用 -File 加载脚本时按系统代码页误读 中文/emoji 字符串,解析失败;PS7 默认按 UTF-8 解析不受影响。已加 BOM 修复。 已在本机 PowerShell 5.1 和 PowerShell 7 上分别实测通过(脚本解析 + test-fixtures 三种 profile 场景的 JSON 读写逻辑 + 幂等性)。 Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01XBPAN7bzFphM8eMDwACmxs --- install.ps1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/install.ps1 b/install.ps1 index 5525076..f32ae57 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1,4 +1,4 @@ -# 强制启用 Chrome 中的 Gemini(Project Glic)(PowerShell 版本) +# 强制启用 Chrome 中的 Gemini(Project Glic)(PowerShell 版本) # 通过修补 Chrome 的 Local State 配置文件,绕过地区资格限制 # 支持系统:Windows # @@ -56,8 +56,10 @@ if (-not $chromeVersion) { Write-Host "⚠️ 未能自动探测 Chrome 版本号,variations_permanent_consistency_country 的版本位会留空" -ForegroundColor Yellow } -# 读取并解析 JSON(-Depth 需要给够,避免嵌套结构在读取阶段被截断) -$json = Get-Content -Path $chromeStatePath -Raw -Encoding UTF8 | ConvertFrom-Json -Depth 100 +# 读取并解析 JSON +# 注意:ConvertFrom-Json 不接受 -Depth 参数(该参数只存在于 ConvertTo-Json; +# Windows PowerShell 5.1 下传了会直接报"找不到与参数名"Depth"匹配的参数"并终止执行) +$json = Get-Content -Path $chromeStatePath -Raw -Encoding UTF8 | ConvertFrom-Json # 对可能不存在的属性做"存在则改、不存在则插入"的统一封装, # 因为 PSCustomObject 对不存在的属性不能直接用 `=` 赋值 @@ -97,7 +99,7 @@ $tmpPath = "$chromeStatePath.tmp" # 校验写回的内容仍是合法 JSON,且目标字段确实生效;不合法就回滚、不覆盖原文件 try { - $verify = Get-Content -Path $tmpPath -Raw -Encoding UTF8 | ConvertFrom-Json -Depth 100 + $verify = Get-Content -Path $tmpPath -Raw -Encoding UTF8 | ConvertFrom-Json if ($verify.variations_country -ne "us") { throw "variations_country 未生效" } @@ -111,7 +113,7 @@ try { # 汇报结果 Write-Host "" $errors = 0 -$final = Get-Content -Path $chromeStatePath -Raw -Encoding UTF8 | ConvertFrom-Json -Depth 100 +$final = Get-Content -Path $chromeStatePath -Raw -Encoding UTF8 | ConvertFrom-Json if ($final.variations_country -eq "us") { Write-Host "✓ variations_country 已设为 us" -ForegroundColor Green } else {