From 9d1acba9bb1f777ee38b504b85b6d582bdbcd3a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=85=8E=E9=A5=BC=E6=9E=9C=E5=AD=90=E5=8D=B7=E9=B2=A8?= =?UTF-8?q?=E9=B1=BC=E8=BE=A3=E6=A4=92?= Date: Tue, 1 Jul 2025 17:01:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCursor=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E4=B8=AD=E7=9A=84=E8=B7=AF=E5=BE=84=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E5=92=8C=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=B8=BA=E7=A9=BA=E6=88=96=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E6=97=B6=E6=8F=90=E4=BE=9B=E5=A4=87=E7=94=A8=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E3=80=82=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=A2=9D=E5=A4=96?= =?UTF-8?q?=E7=9A=84=E7=AD=89=E5=BE=85=E6=97=B6=E9=97=B4=E4=BB=A5=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E5=86=99=E5=85=A5=EF=BC=8C=E5=B9=B6=E5=9C=A8=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=97=B6=E6=8F=90=E4=BE=9B=E6=9B=B4=E8=AF=A6?= =?UTF-8?q?=E7=BB=86=E7=9A=84=E8=B0=83=E8=AF=95=E4=BF=A1=E6=81=AF=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E5=8D=87=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C=E7=9A=84?= =?UTF-8?q?=E5=8F=AF=E9=9D=A0=E6=80=A7=E5=92=8C=E7=A8=B3=E5=AE=9A=E6=80=A7?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/run/cursor_win_id_modifier.ps1 | 70 ++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/scripts/run/cursor_win_id_modifier.ps1 b/scripts/run/cursor_win_id_modifier.ps1 index fef1462..394e489 100644 --- a/scripts/run/cursor_win_id_modifier.ps1 +++ b/scripts/run/cursor_win_id_modifier.ps1 @@ -118,23 +118,57 @@ function Restart-CursorAndWait { } $cursorPath = $global:CursorProcessInfo.Path + + # 修复:确保路径是字符串类型 + if ($cursorPath -is [array]) { + $cursorPath = $cursorPath[0] + } + + # 验证路径不为空 + if ([string]::IsNullOrEmpty($cursorPath)) { + Write-Host "$RED❌ [错误]$NC Cursor路径为空" + return $false + } + Write-Host "$BLUE📍 [路径]$NC 使用路径: $cursorPath" if (-not (Test-Path $cursorPath)) { Write-Host "$RED❌ [错误]$NC Cursor可执行文件不存在: $cursorPath" - return $false + + # 尝试使用备用路径 + $backupPaths = @( + "$env:LOCALAPPDATA\Programs\cursor\Cursor.exe", + "$env:PROGRAMFILES\Cursor\Cursor.exe", + "$env:PROGRAMFILES(X86)\Cursor\Cursor.exe" + ) + + $foundPath = $null + foreach ($backupPath in $backupPaths) { + if (Test-Path $backupPath) { + $foundPath = $backupPath + Write-Host "$GREEN💡 [发现]$NC 使用备用路径: $foundPath" + break + } + } + + if (-not $foundPath) { + Write-Host "$RED❌ [错误]$NC 无法找到有效的Cursor可执行文件" + return $false + } + + $cursorPath = $foundPath } try { Write-Host "$GREEN🚀 [启动]$NC 正在启动Cursor..." $process = Start-Process -FilePath $cursorPath -PassThru -WindowStyle Hidden - Write-Host "$YELLOW⏳ [等待]$NC 等待15秒让Cursor完全启动并生成配置文件..." - Start-Sleep -Seconds 15 + Write-Host "$YELLOW⏳ [等待]$NC 等待20秒让Cursor完全启动并生成配置文件..." + Start-Sleep -Seconds 20 # 检查配置文件是否生成 $configPath = "$env:APPDATA\Cursor\User\globalStorage\storage.json" - $maxWait = 30 + $maxWait = 45 $waited = 0 while (-not (Test-Path $configPath) -and $waited -lt $maxWait) { @@ -145,8 +179,13 @@ function Restart-CursorAndWait { if (Test-Path $configPath) { Write-Host "$GREEN✅ [成功]$NC 配置文件已生成: $configPath" + + # 额外等待确保文件完全写入 + Write-Host "$YELLOW⏳ [等待]$NC 等待5秒确保配置文件完全写入..." + Start-Sleep -Seconds 5 } else { - Write-Host "$YELLOW⚠️ [警告]$NC 配置文件未在预期时间内生成,继续执行..." + Write-Host "$YELLOW⚠️ [警告]$NC 配置文件未在预期时间内生成" + Write-Host "$BLUE💡 [提示]$NC 可能需要手动启动Cursor一次来生成配置文件" } # 强制关闭Cursor @@ -165,6 +204,7 @@ function Restart-CursorAndWait { } catch { Write-Host "$RED❌ [错误]$NC 重启Cursor失败: $($_.Exception.Message)" + Write-Host "$BLUE💡 [调试]$NC 错误详情: $($_.Exception.GetType().FullName)" return $false } } @@ -370,15 +410,23 @@ function Close-CursorProcessAndSaveInfo { $global:CursorProcessInfo = $null - $process = Get-Process -Name $processName -ErrorAction SilentlyContinue - if ($process) { + $processes = Get-Process -Name $processName -ErrorAction SilentlyContinue + if ($processes) { Write-Host "$YELLOW⚠️ [警告]$NC 发现 $processName 正在运行" - # 💾 保存进程信息用于后续重启 + # 💾 保存进程信息用于后续重启 - 修复:确保获取单个进程路径 + $firstProcess = if ($processes -is [array]) { $processes[0] } else { $processes } + $processPath = $firstProcess.Path + + # 确保路径是字符串而不是数组 + if ($processPath -is [array]) { + $processPath = $processPath[0] + } + $global:CursorProcessInfo = @{ - ProcessName = $process.ProcessName - Path = $process.Path - StartTime = $process.StartTime + ProcessName = $firstProcess.ProcessName + Path = $processPath + StartTime = $firstProcess.StartTime } Write-Host "$GREEN💾 [保存]$NC 已保存进程信息: $($global:CursorProcessInfo.Path)"