每日签到奶昔超市点数市场奶昔访达
返回列表 发布新帖
查看: 311|回复: 8

无限免费试用 Cursor Pro:单账号避开设备限制

发表于 5 天前 来自手机 | 查看全部 |阅读模式

欢迎注册论坛,享受更多奶昔会员权益!

您需要 登录 才可以下载或查看,没有账号?注册

×
如何仅用一个账号无限免费试用 Cursor Pro,避免“此设备已使用过多免费试用账号”检测
爱生活,爱奶昔~
回复

使用道具 举报

发表于 5 天前 | 查看全部
nb,666666
爱生活,爱奶昔~
发表于 5 天前 | 查看全部
蚌,我还以为是教程,结果是求助
爱生活,爱奶昔~
发表于 5 天前 来自手机 | 查看全部
这个需要重置cursor机器码的,分别是两个系统的。。。
给个脚本,你自己重置
Windows:
  1. # 设置输出编码为 UTF-8
  2. $OutputEncoding = [System.Text.Encoding]::UTF8
  3. [Console]::OutputEncoding = [System.Text.Encoding]::UTF8

  4. # 颜色定义
  5. $RED = "`e[31m"
  6. $GREEN = "`e[32m"
  7. $YELLOW = "`e[33m"
  8. $BLUE = "`e[34m"
  9. $NC = "`e[0m"

  10. # 配置文件路径
  11. $STORAGE_FILE = "$env:APPDATA\Cursor\User\globalStorage\storage.json"
  12. $BACKUP_DIR = "$env:APPDATA\Cursor\User\globalStorage\backups"

  13. # 检查管理员权限
  14. function Test-Administrator {
  15.     $user = [Security.Principal.WindowsIdentity]::GetCurrent()
  16.     $principal = New-Object Security.Principal.WindowsPrincipal($user)
  17.     return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
  18. }

  19. if (-not (Test-Administrator)) {
  20.     Write-Host "$RED[错误]$NC 请以管理员身份运行此脚本"
  21.     Write-Host "请右键点击脚本,选择'以管理员身份运行'"
  22.     Read-Host "按回车键退出"
  23.     exit 1
  24. }

  25. # 显示 Logo
  26. Clear-Host
  27. Write-Host @"

  28.     ██████╗██╗   ██╗██████╗ ███████╗ ██████╗ ██████╗
  29.    ██╔════╝██║   ██║██╔══██╗██╔════╝██╔═══██╗██╔══██╗
  30.    ██║     ██║   ██║██████╔╝███████╗██║   ██║██████╔╝
  31.    ██║     ██║   ██║██╔══██╗╚════██║██║   ██║██╔══██╗
  32.    ╚██████╗╚██████╔╝██║  ██║███████║╚██████╔╝██║  ██║
  33.     ╚═════╝ ╚═════╝ ╚═╝  ╚═╝╚══════╝ ╚═════╝ ╚═╝  ╚═╝

  34. "@
  35. Write-Host "$BLUE================================$NC"
  36. Write-Host "$BLUE================================$NC"
  37. Write-Host ""

  38. # 获取并显示 Cursor 版本
  39. function Get-CursorVersion {
  40.     try {
  41.         # 主要检测路径
  42.         $packagePath = "$env:LOCALAPPDATA\Programs\cursor\resources\app\package.json"
  43.         
  44.         if (Test-Path $packagePath) {
  45.             $packageJson = Get-Content $packagePath -Raw | ConvertFrom-Json
  46.             if ($packageJson.version) {
  47.                 Write-Host "$GREEN[信息]$NC 当前安装的 Cursor 版本: v$($packageJson.version)"
  48.                 return $packageJson.version
  49.             }
  50.         }

  51.         # 备用路径检测
  52.         $altPath = "$env:LOCALAPPDATA\cursor\resources\app\package.json"
  53.         if (Test-Path $altPath) {
  54.             $packageJson = Get-Content $altPath -Raw | ConvertFrom-Json
  55.             if ($packageJson.version) {
  56.                 Write-Host "$GREEN[信息]$NC 当前安装的 Cursor 版本: v$($packageJson.version)"
  57.                 return $packageJson.version
  58.             }
  59.         }

  60.         Write-Host "$YELLOW[警告]$NC 无法检测到 Cursor 版本"
  61.         Write-Host "$YELLOW[提示]$NC 请确保 Cursor 已正确安装"
  62.         return $null
  63.     }
  64.     catch {
  65.         Write-Host "$RED[错误]$NC 获取 Cursor 版本失败: $_"
  66.         return $null
  67.     }
  68. }

  69. # 获取并显示版本信息
  70. $cursorVersion = Get-CursorVersion
  71. Write-Host ""

  72. Write-Host "$YELLOW[重要提示]$NC 最新的 0.49.x (以支持)"
  73. Write-Host ""

  74. # 检查并关闭 Cursor 进程
  75. Write-Host "$GREEN[信息]$NC 检查 Cursor 进程..."

  76. function Get-ProcessDetails {
  77.     param($processName)
  78.     Write-Host "$BLUE[调试]$NC 正在获取 $processName 进程详细信息:"
  79.     Get-WmiObject Win32_Process -Filter "name='$processName'" |
  80.         Select-Object ProcessId, ExecutablePath, CommandLine |
  81.         Format-List
  82. }

  83. # 定义最大重试次数和等待时间
  84. $MAX_RETRIES = 5
  85. $WAIT_TIME = 1

  86. # 处理进程关闭
  87. function Close-CursorProcess {
  88.     param($processName)
  89.    
  90.     $process = Get-Process -Name $processName -ErrorAction SilentlyContinue
  91.     if ($process) {
  92.         Write-Host "$YELLOW[警告]$NC 发现 $processName 正在运行"
  93.         Get-ProcessDetails $processName
  94.         
  95.         Write-Host "$YELLOW[警告]$NC 尝试关闭 $processName..."
  96.         Stop-Process -Name $processName -Force
  97.         
  98.         $retryCount = 0
  99.         while ($retryCount -lt $MAX_RETRIES) {
  100.             $process = Get-Process -Name $processName -ErrorAction SilentlyContinue
  101.             if (-not $process) { break }
  102.             
  103.             $retryCount++
  104.             if ($retryCount -ge $MAX_RETRIES) {
  105.                 Write-Host "$RED[错误]$NC 在 $MAX_RETRIES 次尝试后仍无法关闭 $processName"
  106.                 Get-ProcessDetails $processName
  107.                 Write-Host "$RED[错误]$NC 请手动关闭进程后重试"
  108.                 Read-Host "按回车键退出"
  109.                 exit 1
  110.             }
  111.             Write-Host "$YELLOW[警告]$NC 等待进程关闭,尝试 $retryCount/$MAX_RETRIES..."
  112.             Start-Sleep -Seconds $WAIT_TIME
  113.         }
  114.         Write-Host "$GREEN[信息]$NC $processName 已成功关闭"
  115.     }
  116. }

  117. # 关闭所有 Cursor 进程
  118. Close-CursorProcess "Cursor"
  119. Close-CursorProcess "cursor"

  120. # 创建备份目录
  121. if (-not (Test-Path $BACKUP_DIR)) {
  122.     New-Item -ItemType Directory -Path $BACKUP_DIR | Out-Null
  123. }

  124. # 备份现有配置
  125. if (Test-Path $STORAGE_FILE) {
  126.     Write-Host "$GREEN[信息]$NC 正在备份配置文件..."
  127.     $backupName = "storage.json.backup_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
  128.     Copy-Item $STORAGE_FILE "$BACKUP_DIR\$backupName"
  129. }

  130. # 生成新的 ID
  131. Write-Host "$GREEN[信息]$NC 正在生成新的 ID..."

  132. # 在颜色定义后添加此函数
  133. function Get-RandomHex {
  134.     param (
  135.         [int]$length
  136.     )
  137.    
  138.     $bytes = New-Object byte[] ($length)
  139.     $rng = [System.Security.Cryptography.RNGCryptoServiceProvider]::new()
  140.     $rng.GetBytes($bytes)
  141.     $hexString = [System.BitConverter]::ToString($bytes) -replace '-',''
  142.     $rng.Dispose()
  143.     return $hexString
  144. }

  145. # 改进 ID 生成函数
  146. function New-StandardMachineId {
  147.     $template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
  148.     $result = $template -replace '[xy]', {
  149.         param($match)
  150.         $r = [Random]::new().Next(16)
  151.         $v = if ($match.Value -eq "x") { $r } else { ($r -band 0x3) -bor 0x8 }
  152.         return $v.ToString("x")
  153.     }
  154.     return $result
  155. }

  156. # 在生成 ID 时使用新函数
  157. $MAC_MACHINE_ID = New-StandardMachineId
  158. $UUID = [System.Guid]::NewGuid().ToString()
  159. # 将 auth0|user_ 转换为字节数组的十六进制
  160. $prefixBytes = [System.Text.Encoding]::UTF8.GetBytes("auth0|user_")
  161. $prefixHex = -join ($prefixBytes | ForEach-Object { '{0:x2}' -f $_ })
  162. # 生成32字节(64个十六进制字符)的随机数作为 machineId 的随机部分
  163. $randomPart = Get-RandomHex -length 32
  164. $MACHINE_ID = "$prefixHex$randomPart"
  165. $SQM_ID = "{$([System.Guid]::NewGuid().ToString().ToUpper())}"

  166. # 在Update-MachineGuid函数前添加权限检查
  167. if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
  168.     Write-Host "$RED[错误]$NC 请使用管理员权限运行此脚本"
  169.     Start-Process powershell "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
  170.     exit
  171. }

  172. function Update-MachineGuid {
  173.     try {
  174.         # 检查注册表路径是否存在,不存在则创建
  175.         $registryPath = "HKLM:\SOFTWARE\Microsoft\Cryptography"
  176.         if (-not (Test-Path $registryPath)) {
  177.             Write-Host "$YELLOW[警告]$NC 注册表路径不存在: $registryPath,正在创建..."
  178.             New-Item -Path $registryPath -Force | Out-Null
  179.             Write-Host "$GREEN[信息]$NC 注册表路径创建成功"
  180.         }

  181.         # 获取当前的 MachineGuid,如果不存在则使用空字符串作为默认值
  182.         $originalGuid = ""
  183.         try {
  184.             $currentGuid = Get-ItemProperty -Path $registryPath -Name MachineGuid -ErrorAction SilentlyContinue
  185.             if ($currentGuid) {
  186.                 $originalGuid = $currentGuid.MachineGuid
  187.                 Write-Host "$GREEN[信息]$NC 当前注册表值:"
  188.                 Write-Host "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography"
  189.                 Write-Host "    MachineGuid    REG_SZ    $originalGuid"
  190.             } else {
  191.                 Write-Host "$YELLOW[警告]$NC MachineGuid 值不存在,将创建新值"
  192.             }
  193.         } catch {
  194.             Write-Host "$YELLOW[警告]$NC 获取 MachineGuid 失败: $($_.Exception.Message)"
  195.         }

  196.         # 创建备份目录(如果不存在)
  197.         if (-not (Test-Path $BACKUP_DIR)) {
  198.             New-Item -ItemType Directory -Path $BACKUP_DIR -Force | Out-Null
  199.         }

  200.         # 创建备份文件(仅当原始值存在时)
  201.         if ($originalGuid) {
  202.             $backupFile = "$BACKUP_DIR\MachineGuid_$(Get-Date -Format 'yyyyMMdd_HHmmss').reg"
  203.             $backupResult = Start-Process "reg.exe" -ArgumentList "export", "`"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography`"", "`"$backupFile`"" -NoNewWindow -Wait -PassThru
  204.             
  205.             if ($backupResult.ExitCode -eq 0) {
  206.                 Write-Host "$GREEN[信息]$NC 注册表项已备份到:$backupFile"
  207.             } else {
  208.                 Write-Host "$YELLOW[警告]$NC 备份创建失败,继续执行..."
  209.             }
  210.         }

  211.         # 生成新GUID
  212.         $newGuid = [System.Guid]::NewGuid().ToString()

  213.         # 更新或创建注册表值
  214.         Set-ItemProperty -Path $registryPath -Name MachineGuid -Value $newGuid -Force -ErrorAction Stop
  215.         
  216.         # 验证更新
  217.         $verifyGuid = (Get-ItemProperty -Path $registryPath -Name MachineGuid -ErrorAction Stop).MachineGuid
  218.         if ($verifyGuid -ne $newGuid) {
  219.             throw "注册表验证失败:更新后的值 ($verifyGuid) 与预期值 ($newGuid) 不匹配"
  220.         }

  221.         Write-Host "$GREEN[信息]$NC 注册表更新成功:"
  222.         Write-Host "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography"
  223.         Write-Host "    MachineGuid    REG_SZ    $newGuid"
  224.         return $true
  225.     }
  226.     catch {
  227.         Write-Host "$RED[错误]$NC 注册表操作失败:$($_.Exception.Message)"
  228.         
  229.         # 尝试恢复备份(如果存在)
  230.         if (($backupFile -ne $null) -and (Test-Path $backupFile)) {
  231.             Write-Host "$YELLOW[恢复]$NC 正在从备份恢复..."
  232.             $restoreResult = Start-Process "reg.exe" -ArgumentList "import", "`"$backupFile`"" -NoNewWindow -Wait -PassThru
  233.             
  234.             if ($restoreResult.ExitCode -eq 0) {
  235.                 Write-Host "$GREEN[恢复成功]$NC 已还原原始注册表值"
  236.             } else {
  237.                 Write-Host "$RED[错误]$NC 恢复失败,请手动导入备份文件:$backupFile"
  238.             }
  239.         } else {
  240.             Write-Host "$YELLOW[警告]$NC 未找到备份文件或备份创建失败,无法自动恢复"
  241.         }
  242.         return $false
  243.     }
  244. }

  245. # 创建或更新配置文件
  246. Write-Host "$GREEN[信息]$NC 正在更新配置..."

  247. try {
  248.     # 检查配置文件是否存在
  249.     if (-not (Test-Path $STORAGE_FILE)) {
  250.         Write-Host "$RED[错误]$NC 未找到配置文件: $STORAGE_FILE"
  251.         Write-Host "$YELLOW[提示]$NC 请先安装并运行一次 Cursor 后再使用此脚本"
  252.         Read-Host "按回车键退出"
  253.         exit 1
  254.     }

  255.     # 读取现有配置文件
  256.     try {
  257.         $originalContent = Get-Content $STORAGE_FILE -Raw -Encoding UTF8
  258.         
  259.         # 将 JSON 字符串转换为 PowerShell 对象
  260.         $config = $originalContent | ConvertFrom-Json

  261.         # 备份当前值
  262.         $oldValues = @{
  263.             'machineId' = $config.'telemetry.machineId'
  264.             'macMachineId' = $config.'telemetry.macMachineId'
  265.             'devDeviceId' = $config.'telemetry.devDeviceId'
  266.             'sqmId' = $config.'telemetry.sqmId'
  267.         }

  268.         # 更新特定的值
  269.         $config.'telemetry.machineId' = $MACHINE_ID
  270.         $config.'telemetry.macMachineId' = $MAC_MACHINE_ID
  271.         $config.'telemetry.devDeviceId' = $UUID
  272.         $config.'telemetry.sqmId' = $SQM_ID

  273.         # 将更新后的对象转换回 JSON 并保存
  274.         $updatedJson = $config | ConvertTo-Json -Depth 10
  275.         [System.IO.File]::WriteAllText(
  276.             [System.IO.Path]::GetFullPath($STORAGE_FILE),
  277.             $updatedJson,
  278.             [System.Text.Encoding]::UTF8
  279.         )
  280.         Write-Host "$GREEN[信息]$NC 成功更新配置文件"
  281.     } catch {
  282.         # 如果出错,尝试恢复原始内容
  283.         if ($originalContent) {
  284.             [System.IO.File]::WriteAllText(
  285.                 [System.IO.Path]::GetFullPath($STORAGE_FILE),
  286.                 $originalContent,
  287.                 [System.Text.Encoding]::UTF8
  288.             )
  289.         }
  290.         throw "处理 JSON 失败: $_"
  291.     }
  292.     # 直接执行更新 MachineGuid,不再询问
  293.     Update-MachineGuid
  294.     # 显示结果
  295.     Write-Host ""
  296.     Write-Host "$GREEN[信息]$NC 已更新配置:"
  297.     Write-Host "$BLUE[调试]$NC machineId: $MACHINE_ID"
  298.     Write-Host "$BLUE[调试]$NC macMachineId: $MAC_MACHINE_ID"
  299.     Write-Host "$BLUE[调试]$NC devDeviceId: $UUID"
  300.     Write-Host "$BLUE[调试]$NC sqmId: $SQM_ID"

  301.     # 显示文件树结构
  302.     Write-Host ""
  303.     Write-Host "$GREEN[信息]$NC 文件结构:"
  304.     Write-Host "$BLUE$env:APPDATA\Cursor\User$NC"
  305.     Write-Host "├── globalStorage"
  306.     Write-Host "│   ├── storage.json (已修改)"
  307.     Write-Host "│   └── backups"

  308.     # 列出备份文件
  309.     $backupFiles = Get-ChildItem "$BACKUP_DIR\*" -ErrorAction SilentlyContinue
  310.     if ($backupFiles) {
  311.         foreach ($file in $backupFiles) {
  312.             Write-Host "│       └── $($file.Name)"
  313.         }
  314.     } else {
  315.         Write-Host "│       └── (空)"
  316.     }

  317.     # 显示公众号信息
  318.     Write-Host ""
  319.     Write-Host "$GREEN================================$NC"
  320.     Write-Host "$GREEN================================$NC"
  321.     Write-Host ""
  322.     Write-Host "$GREEN[信息]$NC 请重启 Cursor 以应用新的配置"
  323.     Write-Host ""

  324.     # 询问是否要禁用自动更新
  325.     Write-Host ""
  326.     Write-Host "$YELLOW[询问]$NC 是否要禁用 Cursor 自动更新功能?"
  327.     Write-Host "0) 否 - 保持默认设置 (按回车键)"
  328.     Write-Host "1) 是 - 禁用自动更新"
  329.     $choice = Read-Host "请输入选项 (0)"

  330.     if ($choice -eq "1") {
  331.         Write-Host ""
  332.         Write-Host "$GREEN[信息]$NC 正在处理自动更新..."
  333.         $updaterPath = "$env:LOCALAPPDATA\cursor-updater"

  334.         # 定义手动设置教程
  335.         function Show-ManualGuide {
  336.             Write-Host ""
  337.             Write-Host "$YELLOW[警告]$NC 自动设置失败,请尝试手动操作:"
  338.             Write-Host "$YELLOW手动禁用更新步骤:$NC"
  339.             Write-Host "1. 以管理员身份打开 PowerShell"
  340.             Write-Host "2. 复制粘贴以下命令:"
  341.             Write-Host "$BLUE命令1 - 删除现有目录(如果存在):$NC"
  342.             Write-Host "Remove-Item -Path `"$updaterPath`" -Force -Recurse -ErrorAction SilentlyContinue"
  343.             Write-Host ""
  344.             Write-Host "$BLUE命令2 - 创建阻止文件:$NC"
  345.             Write-Host "New-Item -Path `"$updaterPath`" -ItemType File -Force | Out-Null"
  346.             Write-Host ""
  347.             Write-Host "$BLUE命令3 - 设置只读属性:$NC"
  348.             Write-Host "Set-ItemProperty -Path `"$updaterPath`" -Name IsReadOnly -Value `$true"
  349.             Write-Host ""
  350.             Write-Host "$BLUE命令4 - 设置权限(可选):$NC"
  351.             Write-Host "icacls `"$updaterPath`" /inheritance:r /grant:r `"`$($env:USERNAME):(R)`""
  352.             Write-Host ""
  353.             Write-Host "$YELLOW验证方法:$NC"
  354.             Write-Host "1. 运行命令:Get-ItemProperty `"$updaterPath`""
  355.             Write-Host "2. 确认 IsReadOnly 属性为 True"
  356.             Write-Host "3. 运行命令:icacls `"$updaterPath`""
  357.             Write-Host "4. 确认只有读取权限"
  358.             Write-Host ""
  359.             Write-Host "$YELLOW[提示]$NC 完成后请重启 Cursor"
  360.         }

  361.         try {
  362.             # 检查cursor-updater是否存在
  363.             if (Test-Path $updaterPath) {
  364.                 # 如果是文件,说明已经创建了阻止更新
  365.                 if ((Get-Item $updaterPath) -is [System.IO.FileInfo]) {
  366.                     Write-Host "$GREEN[信息]$NC 已创建阻止更新文件,无需再次阻止"
  367.                     return
  368.                 }
  369.                 # 如果是目录,尝试删除
  370.                 else {
  371.                     try {
  372.                         Remove-Item -Path $updaterPath -Force -Recurse -ErrorAction Stop
  373.                         Write-Host "$GREEN[信息]$NC 成功删除 cursor-updater 目录"
  374.                     }
  375.                     catch {
  376.                         Write-Host "$RED[错误]$NC 删除 cursor-updater 目录失败"
  377.                         Show-ManualGuide
  378.                         return
  379.                     }
  380.                 }
  381.             }

  382.             # 创建阻止文件
  383.             try {
  384.                 New-Item -Path $updaterPath -ItemType File -Force -ErrorAction Stop | Out-Null
  385.                 Write-Host "$GREEN[信息]$NC 成功创建阻止文件"
  386.             }
  387.             catch {
  388.                 Write-Host "$RED[错误]$NC 创建阻止文件失败"
  389.                 Show-ManualGuide
  390.                 return
  391.             }

  392.             # 设置文件权限
  393.             try {
  394.                 # 设置只读属性
  395.                 Set-ItemProperty -Path $updaterPath -Name IsReadOnly -Value $true -ErrorAction Stop
  396.                
  397.                 # 使用 icacls 设置权限
  398.                 $result = Start-Process "icacls.exe" -ArgumentList "`"$updaterPath`" /inheritance:r /grant:r `"$($env:USERNAME):(R)`"" -Wait -NoNewWindow -PassThru
  399.                 if ($result.ExitCode -ne 0) {
  400.                     throw "icacls 命令失败"
  401.                 }
  402.                
  403.                 Write-Host "$GREEN[信息]$NC 成功设置文件权限"
  404.             }
  405.             catch {
  406.                 Write-Host "$RED[错误]$NC 设置文件权限失败"
  407.                 Show-ManualGuide
  408.                 return
  409.             }

  410.             # 验证设置
  411.             try {
  412.                 $fileInfo = Get-ItemProperty $updaterPath
  413.                 if (-not $fileInfo.IsReadOnly) {
  414.                     Write-Host "$RED[错误]$NC 验证失败:文件权限设置可能未生效"
  415.                     Show-ManualGuide
  416.                     return
  417.                 }
  418.             }
  419.             catch {
  420.                 Write-Host "$RED[错误]$NC 验证设置失败"
  421.                 Show-ManualGuide
  422.                 return
  423.             }

  424.             Write-Host "$GREEN[信息]$NC 成功禁用自动更新"
  425.         }
  426.         catch {
  427.             Write-Host "$RED[错误]$NC 发生未知错误: $_"
  428.             Show-ManualGuide
  429.         }
  430.     }
  431.     else {
  432.         Write-Host "$GREEN[信息]$NC 保持默认设置,不进行更改"
  433.     }

  434.     # 保留有效的注册表更新
  435.     Update-MachineGuid

  436. } catch {
  437.     Write-Host "$RED[错误]$NC 主要操作失败: $_"
  438.     Write-Host "$YELLOW[尝试]$NC 使用备选方法..."
  439.    
  440.     try {
  441.         # 备选方法:使用 Add-Content
  442.         $tempFile = [System.IO.Path]::GetTempFileName()
  443.         $config | ConvertTo-Json | Set-Content -Path $tempFile -Encoding UTF8
  444.         Copy-Item -Path $tempFile -Destination $STORAGE_FILE -Force
  445.         Remove-Item -Path $tempFile
  446.         Write-Host "$GREEN[信息]$NC 使用备选方法成功写入配置"
  447.     } catch {
  448.         Write-Host "$RED[错误]$NC 所有尝试都失败了"
  449.         Write-Host "错误详情: $_"
  450.         Write-Host "目标文件: $STORAGE_FILE"
  451.         Write-Host "请确保您有足够的权限访问该文件"
  452.         Read-Host "按回车键退出"
  453.         exit 1
  454.     }
  455. }

  456. Write-Host ""
  457. Read-Host "按回车键退出"
  458. exit 0

  459. # 在文件写入部分修改
  460. function Write-ConfigFile {
  461.     param($config, $filePath)
  462.    
  463.     try {
  464.         # 使用 UTF8 无 BOM 编码
  465.         $utf8NoBom = New-Object System.Text.UTF8Encoding $false
  466.         $jsonContent = $config | ConvertTo-Json -Depth 10
  467.         
  468.         # 统一使用 LF 换行符
  469.         $jsonContent = $jsonContent.Replace("`r`n", "`n")
  470.         
  471.         [System.IO.File]::WriteAllText(
  472.             [System.IO.Path]::GetFullPath($filePath),
  473.             $jsonContent,
  474.             $utf8NoBom
  475.         )
  476.         
  477.         Write-Host "$GREEN[信息]$NC 成功写入配置文件(UTF8 无 BOM)"
  478.     }
  479.     catch {
  480.         throw "写入配置文件失败: $_"
  481.     }
  482. }

  483. # 获取并显示版本信息
  484. $cursorVersion = Get-CursorVersion
  485. Write-Host ""
  486. if ($cursorVersion) {
  487.     Write-Host "$GREEN[信息]$NC 检测到 Cursor 版本: $cursorVersion,继续执行..."
  488. } else {
  489.     Write-Host "$YELLOW[警告]$NC 无法检测版本,将继续执行..."
  490. }
复制代码
macOS:
  1. # --- Terminal Colors and Formatting ---
  2. RED='\033[0;31m'
  3. GREEN='\033[0;32m'
  4. YELLOW='\033[1;33m'
  5. BLUE='\033[0;34m'
  6. MAGENTA='\033[0;35m'
  7. CYAN='\033[0;36m'
  8. BOLD='\033[1m'
  9. DIM='\033[2m'
  10. NC='\033[0m' # No Color
  11. TICK="${GREEN}✓${NC}"
  12. CROSS="${RED}✗${NC}"
  13. INFO="${BLUE}ℹ${NC}"
  14. WARN="${YELLOW}⚠${NC}"

  15. # --- Spinner Animation ---
  16. spinner() {
  17.     local pid=$1
  18.     local delay=0.1
  19.     local spinstr='|/-\'
  20.     local msg="$2"
  21.     printf "${DIM}  %s" "$msg"
  22.     while kill -0 $pid 2>/dev/null; do
  23.         local temp=${spinstr#?}
  24.         printf "\r  ${CYAN}[%c]${NC} %s" "$spinstr" "$msg"
  25.         local spinstr=$temp${spinstr%"$temp"}
  26.         sleep $delay
  27.     done
  28.     printf "\r  ${TICK} %s\n" "$msg"
  29. }

  30. # --- Progress Bar ---
  31. progress_bar() {
  32.     local duration=$1
  33.     local msg="$2"
  34.     local width=40
  35.     local progress=0
  36.     local fill
  37.     local remain
  38.    
  39.     echo -ne "\n  ${msg}\n  "
  40.     while [ $progress -le 100 ]; do
  41.         let fill=($width*$progress/100)
  42.         let remain=$width-$fill
  43.         printf "\r  ${CYAN}[${NC}"
  44.         printf "%${fill}s" '' | tr ' ' '█'
  45.         printf "%${remain}s" '' | tr ' ' '░'
  46.         printf "${CYAN}]${NC} ${progress}%%"
  47.         progress=$((progress + 2))
  48.         sleep 0.06  # Adjusted for macOS
  49.     done
  50.     echo -e "\n"
  51. }

  52. # --- Fancy Print Functions ---
  53. print_header() {
  54.     clear
  55.     echo -e "\n${CYAN}════════════════════════════════════════════════════════════════════${NC}"
  56.     echo -e "${BOLD}${BLUE}         Cursor Cleaner & Identity Reset Script for macOS${NC}"
  57.     echo -e "${CYAN}════════════════════════════════════════════════════════════════════${NC}\n"
  58. }

  59. print_section() {
  60.     echo -e "\n${MAGENTA}▓▒░ ${BOLD}$1${NC} ${MAGENTA}░▒▓${NC}"
  61.     echo -e "${DIM}${MAGENTA}──────────────────────────────────────────${NC}\n"
  62. }

  63. print_warning() {
  64.     echo -e "  ${WARN} ${YELLOW}$1${NC}"
  65. }

  66. print_info() {
  67.     echo -e "  ${INFO} ${BLUE}$1${NC}"
  68. }

  69. print_success() {
  70.     echo -e "  ${TICK} ${GREEN}$1${NC}"
  71. }

  72. print_error() {
  73.     echo -e "  ${CROSS} ${RED}$1${NC}" >&2
  74. }

  75. # --- Function for running commands with sudo ---
  76. run_sudo() {
  77.     echo -e "  ${INFO} Running: ${CYAN}$@${NC}"
  78.     if ! sudo "$@"; then
  79.         print_error "Failed to execute sudo command: '$@'"
  80.     fi
  81. }

  82. # --- Initial Checks and Confirmation ---
  83. print_header

  84. # Check if running on macOS
  85. if [[ "$OSTYPE" != "darwin"* ]]; then
  86.     print_error "This script is designed for macOS only!"
  87.     exit 1
  88. fi

  89. # Display warnings
  90. print_section "IMPORTANT WARNINGS"
  91. print_warning "This script performs destructive operations that cannot be undone!"
  92. print_warning "All Cursor settings and data will be permanently deleted."
  93. print_warning "A system restart is recommended after completion."
  94. echo

  95. # Display actions
  96. print_section "ACTIONS TO BE PERFORMED"
  97. print_info "1. Stop running Cursor processes"
  98. print_info "2. Remove Cursor.app from Applications"
  99. print_info "3. Delete configuration and cache data"
  100. print_info "4. Clean up system preferences"
  101. print_info "5. Clear launch services database"
  102. print_info "6. Remove quarantine attributes"
  103. echo

  104. # Get confirmation
  105. echo -e "${YELLOW}${BOLD}Do you understand and accept the risks?${NC}"
  106. read -p "Type 'YES' in uppercase to confirm: " CONFIRMATION
  107. if [[ "$CONFIRMATION" != "YES" ]]; then
  108.     print_error "Operation cancelled by user"
  109.     exit 1
  110. fi

  111. # --- Main Operations ---
  112. print_section "STARTING CLEANUP PROCESS"

  113. # Stop Cursor Process
  114. print_info "Stopping Cursor processes..."
  115. (pkill -f "Cursor" 2>/dev/null || true) &
  116. spinner $! "Terminating running instances"

  117. # Wait a moment for processes to terminate
  118. sleep 2

  119. # Remove Application
  120. print_info "Removing Cursor application..."
  121. if [ -d "/Applications/Cursor.app" ]; then
  122.     (sudo rm -rf "/Applications/Cursor.app") &
  123.     spinner $! "Removing Cursor.app from Applications"
  124. else
  125.     print_info "Cursor.app not found in /Applications"
  126. fi

  127. # Check for app in user Applications folder
  128. if [ -d "$HOME/Applications/Cursor.app" ]; then
  129.     (rm -rf "$HOME/Applications/Cursor.app") &
  130.     spinner $! "Removing Cursor.app from user Applications"
  131. fi

  132. # Remove User Config/Data with progress simulation
  133. print_section "CLEANING USER DATA"

  134. # macOS specific directories
  135. CONFIG_DIRS=(
  136.     "$HOME/Library/Application Support/Cursor"
  137.     "$HOME/Library/Caches/Cursor"
  138.     "$HOME/Library/Caches/com.todesktop.230313mzl4w4u92"
  139.     "$HOME/Library/Preferences/com.todesktop.230313mzl4w4u92.plist"
  140.     "$HOME/Library/Preferences/cursor.plist"
  141.     "$HOME/Library/Saved Application State/com.todesktop.230313mzl4w4u92.savedState"
  142.     "$HOME/Library/WebKit/Cursor"
  143.     "$HOME/Library/HTTPStorages/com.todesktop.230313mzl4w4u92"
  144.     "$HOME/.cursor"
  145.     "$HOME/.cursor-server"
  146. )

  147. progress_bar 3 "Removing configuration directories..."
  148. for item in "${CONFIG_DIRS[@]}"; do
  149.     if [ -e "$item" ]; then
  150.         rm -rf "$item"
  151.         print_success "Removed: $(basename "$item")"
  152.     else
  153.         print_info "Skipped: $(basename "$item") (not found)"
  154.     fi
  155. done

  156. # Clean up LaunchAgents
  157. print_section "CLEANING LAUNCH AGENTS"
  158. LAUNCH_AGENTS=(
  159.     "$HOME/Library/LaunchAgents/com.todesktop.230313mzl4w4u92.plist"
  160.     "$HOME/Library/LaunchAgents/cursor.plist"
  161. )

  162. for agent in "${LAUNCH_AGENTS[@]}"; do
  163.     if [ -f "$agent" ]; then
  164.         launchctl unload "$agent" 2>/dev/null
  165.         rm -f "$agent"
  166.         print_success "Removed launch agent: $(basename "$agent")"
  167.     fi
  168. done

  169. # # Clear Quarantine Attributes
  170. # print_section "CLEARING SYSTEM ATTRIBUTES"
  171. # print_info "Removing quarantine attributes..."
  172. # sudo xattr -r -d com.apple.quarantine /Applications/Cursor.app 2>/dev/null || true

  173. # Reset Launch Services Database
  174. print_info "Resetting Launch Services database..."
  175. (
  176.     /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister \
  177.     -kill -r -domain local -domain system -domain user
  178. ) &
  179. spinner $! "Rebuilding Launch Services"

  180. # Clear DNS Cache (might help with online verification)
  181. print_section "CLEARING SYSTEM CACHES"
  182. print_info "Flushing DNS cache..."
  183. sudo dscacheutil -flushcache 2>/dev/null &
  184. spinner $! "Flushing DNS"

  185. # Clear Spotlight Index for Cursor
  186. # print_info "Clearing Spotlight index..."
  187. # sudo mdutil -E / 2>/dev/null || true

  188. # Clear Keychain entries
  189. print_section "CLEANING KEYCHAIN"
  190. print_info "Removing Cursor keychain entries..."
  191. security delete-generic-password -s "Cursor" 2>/dev/null || true
  192. security delete-generic-password -s "com.todesktop.230313mzl4w4u92" 2>/dev/null || true

  193. # System Information
  194. print_section "SYSTEM INFORMATION"
  195. echo -e "${CYAN}Hardware UUID:${NC}"
  196. system_profiler SPHardwareDataType | grep "Hardware UUID" | awk '{print $3}'
  197. echo -e "\n${DIM}Note: Hardware UUID cannot be changed without significant system modifications${NC}"

  198. # Final Cleanup
  199. print_section "FINAL CLEANUP"
  200. progress_bar 2 "Cleaning system caches..."

  201. # Empty Trash (optional - commented out for safety)
  202. # osascript -e 'tell application "Finder" to empty trash' 2>/dev/null || true

  203. # Final Instructions
  204. echo -e "\n${CYAN}════════════════════════════════════════════════════════════════════${NC}"
  205. echo -e "${GREEN}${BOLD}               ✨ CLEANUP COMPLETE! ✨${NC}"
  206. echo -e "${CYAN}════════════════════════════════════════════════════════════════════${NC}\n"

  207. print_warning "A SYSTEM RESTART IS RECOMMENDED TO COMPLETE THE PROCESS"
  208. print_info "Some changes may not take effect until after restart"
  209. echo -e "\n${BOLD}Would you like to restart now? ${NC}(y/N): "
  210. read -n 1 -r
  211. echo
  212. if [[ $REPLY =~ ^[Yy]$ ]]; then
  213.     echo -e "\n${YELLOW}System will restart in 10 seconds...${NC}"
  214.     echo -e "${DIM}Press Ctrl+C to cancel${NC}"
  215.     sleep 10
  216.     sudo shutdown -r now
  217. else
  218.     print_info "Please remember to restart your system manually"
  219.     print_info "You can restart using: ${CYAN}sudo shutdown -r now${NC}"
  220.     print_info "Or via Apple Menu > Restart"
  221. fi

  222. exit 0
复制代码
收起
爱生活,爱奶昔~
发表于 4 天前 来自手机 | 查看全部
还是求助啊?
爱生活,爱奶昔~
发表于 4 天前 | 查看全部
菊部地区小雨 发表于 2025-11-8 21:10
这个需要重置cursor机器码的,分别是两个系统的。。。
[fold=0,给个脚本,你自己重置]
Windows:macOS:

强的
爱生活,爱奶昔~
发表于 4 天前 | 查看全部
这必须得看!!
爱生活,爱奶昔~
发表于 3 天前 | 查看全部
666666
爱生活,爱奶昔~
发表于 3 天前 | 查看全部
菊部地区小雨 发表于 2025-11-8 21:10
这个需要重置cursor机器码的,分别是两个系统的。。。
[fold=0,给个脚本,你自己重置]
Windows:macOS:

谢谢
爱生活,爱奶昔~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

© 2025 Nyarime 沪ICP备13020230号-1|沪公网安备 31010702007642号手机版小黑屋RSS
返回顶部 关灯 在本版发帖
快速回复 返回顶部 返回列表