From ab6db7d4318926829146663a7438239e5d1a31fd 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 11:25:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=87=8D=E5=90=AFCursor?= =?UTF-8?q?=E5=B9=B6=E7=AD=89=E5=BE=85=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E5=8D=87=E6=9C=BA=E5=99=A8=E7=A0=81=E9=85=8D=E7=BD=AE=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E7=9A=84=E5=8F=AF=E9=9D=A0=E6=80=A7=E3=80=82=E5=90=8C?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=9B=B4=E6=96=B0=E4=BA=86=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=BB=A5=E7=A1=AE=E4=BF=9D=E5=9C=A8=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=9C=BA=E5=99=A8=E7=A0=81=E9=85=8D=E7=BD=AE=E6=97=B6?= =?UTF-8?q?=E8=83=BD=E5=A4=9F=E6=AD=A3=E7=A1=AE=E5=A4=84=E7=90=86Cursor?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B=EF=BC=8C=E5=A2=9E=E5=BC=BA=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BD=93=E9=AA=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/run/cursor_mac_free_trial_reset.sh | 185 +++++++++++++++++--- scripts/run/cursor_mac_id_modifier.sh | 170 ++++++++++++++++-- scripts/run/cursor_win_id_modifier.ps1 | 192 +++++++++++++++++++-- 3 files changed, 488 insertions(+), 59 deletions(-) diff --git a/scripts/run/cursor_mac_free_trial_reset.sh b/scripts/run/cursor_mac_free_trial_reset.sh index 8dd52d8..3bcf7fb 100644 --- a/scripts/run/cursor_mac_free_trial_reset.sh +++ b/scripts/run/cursor_mac_free_trial_reset.sh @@ -130,6 +130,127 @@ remove_cursor_trial_folders() { echo } +# 🔄 重启Cursor并等待配置文件生成 +restart_cursor_and_wait() { + echo + log_info "🔄 [重启] 正在重启Cursor以重新生成配置文件..." + + if [ -z "$CURSOR_PROCESS_PATH" ]; then + log_error "❌ [错误] 未找到Cursor进程信息,无法重启" + return 1 + fi + + log_info "📍 [路径] 使用路径: $CURSOR_PROCESS_PATH" + + if [ ! -f "$CURSOR_PROCESS_PATH" ]; then + log_error "❌ [错误] Cursor可执行文件不存在: $CURSOR_PROCESS_PATH" + return 1 + fi + + # 启动Cursor + log_info "🚀 [启动] 正在启动Cursor..." + "$CURSOR_PROCESS_PATH" > /dev/null 2>&1 & + CURSOR_PID=$! + + log_info "⏳ [等待] 等待15秒让Cursor完全启动并生成配置文件..." + sleep 15 + + # 检查配置文件是否生成 + local config_path="$HOME/Library/Application Support/Cursor/User/globalStorage/storage.json" + local max_wait=30 + local waited=0 + + while [ ! -f "$config_path" ] && [ $waited -lt $max_wait ]; do + log_info "⏳ [等待] 等待配置文件生成... ($waited/$max_wait 秒)" + sleep 1 + waited=$((waited + 1)) + done + + if [ -f "$config_path" ]; then + log_info "✅ [成功] 配置文件已生成: $config_path" + else + log_warn "⚠️ [警告] 配置文件未在预期时间内生成,继续执行..." + fi + + # 强制关闭Cursor + log_info "🔄 [关闭] 正在关闭Cursor以进行配置修改..." + if [ ! -z "$CURSOR_PID" ]; then + kill $CURSOR_PID 2>/dev/null || true + fi + + # 确保所有Cursor进程都关闭 + pkill -f "Cursor" 2>/dev/null || true + + log_info "✅ [完成] Cursor重启流程完成" + return 0 +} + +# 🛠️ 修改机器码配置 +modify_machine_code_config() { + echo + log_info "🛠️ [配置] 正在修改机器码配置..." + + local config_path="$HOME/Library/Application Support/Cursor/User/globalStorage/storage.json" + + if [ ! -f "$config_path" ]; then + log_error "❌ [错误] 配置文件不存在: $config_path" + log_info "💡 [提示] 请手动启动Cursor一次,然后重新运行此脚本" + return 1 + fi + + # 生成新的ID + local MAC_MACHINE_ID=$(uuidgen | tr '[:upper:]' '[:lower:]') + local UUID=$(uuidgen | tr '[:upper:]' '[:lower:]') + local MACHINE_ID="auth0|user_$(openssl rand -hex 32)" + local SQM_ID="{$(uuidgen | tr '[:lower:]' '[:upper:]')}" + + log_info "🔧 [生成] 已生成新的设备标识符" + + # 备份原始配置 + local backup_dir="$HOME/Library/Application Support/Cursor/User/globalStorage/backups" + mkdir -p "$backup_dir" + + local backup_name="storage.json.backup_$(date +%Y%m%d_%H%M%S)" + cp "$config_path" "$backup_dir/$backup_name" + log_info "💾 [备份] 已备份原配置: $backup_name" + + # 使用Python修改JSON配置(更可靠) + python3 -c " +import json +import sys + +try: + with open('$config_path', 'r', encoding='utf-8') as f: + config = json.load(f) + + config['telemetry.machineId'] = '$MACHINE_ID' + config['telemetry.macMachineId'] = '$MAC_MACHINE_ID' + config['telemetry.devDeviceId'] = '$UUID' + config['telemetry.sqmId'] = '$SQM_ID' + + with open('$config_path', 'w', encoding='utf-8') as f: + json.dump(config, f, indent=2, ensure_ascii=False) + + print('SUCCESS') +except Exception as e: + print(f'ERROR: {e}') + sys.exit(1) +" 2>/dev/null + + if [ $? -eq 0 ]; then + log_info "✅ [成功] 机器码配置修改完成" + log_info "📋 [详情] 已更新以下标识符:" + echo " 🔹 machineId: ${MACHINE_ID:0:20}..." + echo " 🔹 macMachineId: $MAC_MACHINE_ID" + echo " 🔹 devDeviceId: $UUID" + echo " 🔹 sqmId: $SQM_ID" + return 0 + else + log_error "❌ [错误] 修改配置失败" + return 1 + fi +} + # 检查权限 check_permissions() { if [ "$EUID" -ne 0 ]; then @@ -139,56 +260,67 @@ check_permissions() { fi } -# 检查并关闭 Cursor 进程 +# 检查并关闭 Cursor 进程(保存进程信息) check_and_kill_cursor() { - log_info "检查 Cursor 进程..." - + log_info "🔍 [检查] 检查 Cursor 进程..." + local attempt=1 local max_attempts=5 - + + # 💾 保存Cursor进程路径 + CURSOR_PROCESS_PATH="/Applications/Cursor.app/Contents/MacOS/Cursor" + # 函数:获取进程详细信息 get_process_details() { local process_name="$1" log_debug "正在获取 $process_name 进程详细信息:" ps aux | grep -i "/Applications/Cursor.app" | grep -v grep } - + while [ $attempt -le $max_attempts ]; do # 使用更精确的匹配来获取 Cursor 进程 CURSOR_PIDS=$(ps aux | grep -i "/Applications/Cursor.app" | grep -v grep | awk '{print $2}') - + if [ -z "$CURSOR_PIDS" ]; then - log_info "未发现运行中的 Cursor 进程" + log_info "💡 [提示] 未发现运行中的 Cursor 进程" + # 确认Cursor应用路径存在 + if [ -f "$CURSOR_PROCESS_PATH" ]; then + log_info "💾 [保存] 已保存Cursor路径: $CURSOR_PROCESS_PATH" + else + log_warn "⚠️ [警告] 未找到Cursor应用,请确认已安装" + fi return 0 fi - - log_warn "发现 Cursor 进程正在运行" + + log_warn "⚠️ [警告] 发现 Cursor 进程正在运行" + # 💾 保存进程信息 + log_info "💾 [保存] 已保存Cursor路径: $CURSOR_PROCESS_PATH" get_process_details "cursor" - - log_warn "尝试关闭 Cursor 进程..." - + + log_warn "🔄 [操作] 尝试关闭 Cursor 进程..." + if [ $attempt -eq $max_attempts ]; then - log_warn "尝试强制终止进程..." + log_warn "💥 [强制] 尝试强制终止进程..." kill -9 $CURSOR_PIDS 2>/dev/null || true else kill $CURSOR_PIDS 2>/dev/null || true fi - + sleep 1 - + # 同样使用更精确的匹配来检查进程是否还在运行 if ! ps aux | grep -i "/Applications/Cursor.app" | grep -v grep > /dev/null; then - log_info "Cursor 进程已成功关闭" + log_info "✅ [成功] Cursor 进程已成功关闭" return 0 fi - - log_warn "等待进程关闭,尝试 $attempt/$max_attempts..." + + log_warn "⏳ [等待] 等待进程关闭,尝试 $attempt/$max_attempts..." ((attempt++)) done - - log_error "在 $max_attempts 次尝试后仍无法关闭 Cursor 进程" + + log_error "❌ [错误] 在 $max_attempts 次尝试后仍无法关闭 Cursor 进程" get_process_details "cursor" - log_error "请手动关闭进程后重试" + log_error "💥 [错误] 请手动关闭进程后重试" exit 1 } @@ -1084,12 +1216,11 @@ main() { log_info "🚀 [开始] 开始执行核心功能..." remove_cursor_trial_folders - # 🚫 以下功能已暂时屏蔽 - log_warn "⚠️ [提示] 以下功能已暂时屏蔽:" - log_info "📋 [说明] - 配置文件备份和修改" - log_info "📋 [说明] - 主程序文件修改" - log_info "📋 [说明] 当前版本专注于删除文件夹功能" - echo + # 🔄 重启Cursor让其重新生成配置文件 + restart_cursor_and_wait + + # 🛠️ 修改机器码配置 + modify_machine_code_config # 🎉 显示操作完成信息 echo diff --git a/scripts/run/cursor_mac_id_modifier.sh b/scripts/run/cursor_mac_id_modifier.sh index abb23ac..5ab2c32 100644 --- a/scripts/run/cursor_mac_id_modifier.sh +++ b/scripts/run/cursor_mac_id_modifier.sh @@ -108,6 +108,127 @@ remove_cursor_trial_folders() { echo } +# 🔄 重启Cursor并等待配置文件生成 +restart_cursor_and_wait() { + echo + log_info "🔄 [重启] 正在重启Cursor以重新生成配置文件..." + + if [ -z "$CURSOR_PROCESS_PATH" ]; then + log_error "❌ [错误] 未找到Cursor进程信息,无法重启" + return 1 + fi + + log_info "📍 [路径] 使用路径: $CURSOR_PROCESS_PATH" + + if [ ! -f "$CURSOR_PROCESS_PATH" ]; then + log_error "❌ [错误] Cursor可执行文件不存在: $CURSOR_PROCESS_PATH" + return 1 + fi + + # 启动Cursor + log_info "🚀 [启动] 正在启动Cursor..." + "$CURSOR_PROCESS_PATH" > /dev/null 2>&1 & + CURSOR_PID=$! + + log_info "⏳ [等待] 等待15秒让Cursor完全启动并生成配置文件..." + sleep 15 + + # 检查配置文件是否生成 + local config_path="$HOME/Library/Application Support/Cursor/User/globalStorage/storage.json" + local max_wait=30 + local waited=0 + + while [ ! -f "$config_path" ] && [ $waited -lt $max_wait ]; do + log_info "⏳ [等待] 等待配置文件生成... ($waited/$max_wait 秒)" + sleep 1 + waited=$((waited + 1)) + done + + if [ -f "$config_path" ]; then + log_info "✅ [成功] 配置文件已生成: $config_path" + else + log_warn "⚠️ [警告] 配置文件未在预期时间内生成,继续执行..." + fi + + # 强制关闭Cursor + log_info "🔄 [关闭] 正在关闭Cursor以进行配置修改..." + if [ ! -z "$CURSOR_PID" ]; then + kill $CURSOR_PID 2>/dev/null || true + fi + + # 确保所有Cursor进程都关闭 + pkill -f "Cursor" 2>/dev/null || true + + log_info "✅ [完成] Cursor重启流程完成" + return 0 +} + +# 🛠️ 修改机器码配置 +modify_machine_code_config() { + echo + log_info "🛠️ [配置] 正在修改机器码配置..." + + local config_path="$HOME/Library/Application Support/Cursor/User/globalStorage/storage.json" + + if [ ! -f "$config_path" ]; then + log_error "❌ [错误] 配置文件不存在: $config_path" + log_info "💡 [提示] 请手动启动Cursor一次,然后重新运行此脚本" + return 1 + fi + + # 生成新的ID + local MAC_MACHINE_ID=$(uuidgen | tr '[:upper:]' '[:lower:]') + local UUID=$(uuidgen | tr '[:upper:]' '[:lower:]') + local MACHINE_ID="auth0|user_$(openssl rand -hex 32)" + local SQM_ID="{$(uuidgen | tr '[:lower:]' '[:upper:]')}" + + log_info "🔧 [生成] 已生成新的设备标识符" + + # 备份原始配置 + local backup_dir="$HOME/Library/Application Support/Cursor/User/globalStorage/backups" + mkdir -p "$backup_dir" + + local backup_name="storage.json.backup_$(date +%Y%m%d_%H%M%S)" + cp "$config_path" "$backup_dir/$backup_name" + log_info "💾 [备份] 已备份原配置: $backup_name" + + # 使用Python修改JSON配置(更可靠) + python3 -c " +import json +import sys + +try: + with open('$config_path', 'r', encoding='utf-8') as f: + config = json.load(f) + + config['telemetry.machineId'] = '$MACHINE_ID' + config['telemetry.macMachineId'] = '$MAC_MACHINE_ID' + config['telemetry.devDeviceId'] = '$UUID' + config['telemetry.sqmId'] = '$SQM_ID' + + with open('$config_path', 'w', encoding='utf-8') as f: + json.dump(config, f, indent=2, ensure_ascii=False) + + print('SUCCESS') +except Exception as e: + print(f'ERROR: {e}') + sys.exit(1) +" 2>/dev/null + + if [ $? -eq 0 ]; then + log_info "✅ [成功] 机器码配置修改完成" + log_info "📋 [详情] 已更新以下标识符:" + echo " 🔹 machineId: ${MACHINE_ID:0:20}..." + echo " 🔹 macMachineId: $MAC_MACHINE_ID" + echo " 🔹 devDeviceId: $UUID" + echo " 🔹 sqmId: $SQM_ID" + return 0 + else + log_error "❌ [错误] 修改配置失败" + return 1 + fi +} + # 📝 原有的 Cursor 初始化函数(已暂时禁用) cursor_initialize_cleanup_disabled() { log_warn "⚠️ [提示] 原有的机器码修改功能已暂时禁用" @@ -304,13 +425,16 @@ check_permissions() { fi } -# 检查并关闭 Cursor 进程 +# 检查并关闭 Cursor 进程(保存进程信息) check_and_kill_cursor() { - log_info "检查 Cursor 进程..." + log_info "🔍 [检查] 检查 Cursor 进程..." local attempt=1 local max_attempts=5 + # 💾 保存Cursor进程路径 + CURSOR_PROCESS_PATH="/Applications/Cursor.app/Contents/MacOS/Cursor" + # 函数:获取进程详细信息 get_process_details() { local process_name="$1" @@ -323,37 +447,45 @@ check_and_kill_cursor() { CURSOR_PIDS=$(ps aux | grep -i "/Applications/Cursor.app" | grep -v grep | awk '{print $2}') if [ -z "$CURSOR_PIDS" ]; then - log_info "未发现运行中的 Cursor 进程" + log_info "💡 [提示] 未发现运行中的 Cursor 进程" + # 确认Cursor应用路径存在 + if [ -f "$CURSOR_PROCESS_PATH" ]; then + log_info "💾 [保存] 已保存Cursor路径: $CURSOR_PROCESS_PATH" + else + log_warn "⚠️ [警告] 未找到Cursor应用,请确认已安装" + fi return 0 fi - log_warn "发现 Cursor 进程正在运行" + log_warn "⚠️ [警告] 发现 Cursor 进程正在运行" + # 💾 保存进程信息 + log_info "💾 [保存] 已保存Cursor路径: $CURSOR_PROCESS_PATH" get_process_details "cursor" - log_warn "尝试关闭 Cursor 进程..." + log_warn "🔄 [操作] 尝试关闭 Cursor 进程..." if [ $attempt -eq $max_attempts ]; then - log_warn "尝试强制终止进程..." + log_warn "💥 [强制] 尝试强制终止进程..." kill -9 $CURSOR_PIDS 2>/dev/null || true else kill $CURSOR_PIDS 2>/dev/null || true fi - + sleep 3 - + # 同样使用更精确的匹配来检查进程是否还在运行 if ! ps aux | grep -i "/Applications/Cursor.app" | grep -v grep > /dev/null; then - log_info "Cursor 进程已成功关闭" + log_info "✅ [成功] Cursor 进程已成功关闭" return 0 fi - log_warn "等待进程关闭,尝试 $attempt/$max_attempts..." + log_warn "⏳ [等待] 等待进程关闭,尝试 $attempt/$max_attempts..." ((attempt++)) done - log_error "在 $max_attempts 次尝试后仍无法关闭 Cursor 进程" + log_error "❌ [错误] 在 $max_attempts 次尝试后仍无法关闭 Cursor 进程" get_process_details "cursor" - log_error "请手动关闭进程后重试" + log_error "💥 [错误] 请手动关闭进程后重试" exit 1 } @@ -1319,13 +1451,13 @@ main() { log_info "🚀 [开始] 开始执行核心功能..." remove_cursor_trial_folders - # 🚫 以下功能已暂时屏蔽 - log_warn "⚠️ [提示] 以下功能已暂时屏蔽:" - log_info "📋 [说明] - 配置文件备份和修改" - log_info "📋 [说明] - 系统MAC地址修改" - log_info "📋 [说明] - 主程序文件修改" - log_info "📋 [说明] 当前版本专注于删除文件夹功能" - echo + # � 重启Cursor让其重新生成配置文件 + restart_cursor_and_wait + + # 🛠️ 修改机器码配置 + modify_machine_code_config + + # 🎉 显示操作完成信息 echo diff --git a/scripts/run/cursor_win_id_modifier.ps1 b/scripts/run/cursor_win_id_modifier.ps1 index 0e5ec6a..8967bbc 100644 --- a/scripts/run/cursor_win_id_modifier.ps1 +++ b/scripts/run/cursor_win_id_modifier.ps1 @@ -87,11 +87,134 @@ function Remove-CursorTrialFolders { Write-Host "" } -# 📝 原有的 Cursor 初始化函数(已暂时禁用) -function Cursor-初始化-已禁用 { - Write-Host "$YELLOW⚠️ [提示]$NC 原有的机器码修改功能已暂时禁用" - Write-Host "$BLUE📋 [说明]$NC 当前版本专注于删除文件夹功能,机器码修改功能已屏蔽" +# 🔄 重启Cursor并等待配置文件生成 +function Restart-CursorAndWait { Write-Host "" + Write-Host "$GREEN🔄 [重启]$NC 正在重启Cursor以重新生成配置文件..." + + if (-not $global:CursorProcessInfo) { + Write-Host "$RED❌ [错误]$NC 未找到Cursor进程信息,无法重启" + return $false + } + + $cursorPath = $global:CursorProcessInfo.Path + Write-Host "$BLUE📍 [路径]$NC 使用路径: $cursorPath" + + if (-not (Test-Path $cursorPath)) { + Write-Host "$RED❌ [错误]$NC Cursor可执行文件不存在: $cursorPath" + return $false + } + + try { + Write-Host "$GREEN🚀 [启动]$NC 正在启动Cursor..." + $process = Start-Process -FilePath $cursorPath -PassThru -WindowStyle Hidden + + Write-Host "$YELLOW⏳ [等待]$NC 等待15秒让Cursor完全启动并生成配置文件..." + Start-Sleep -Seconds 15 + + # 检查配置文件是否生成 + $configPath = "$env:APPDATA\Cursor\User\globalStorage\storage.json" + $maxWait = 30 + $waited = 0 + + while (-not (Test-Path $configPath) -and $waited -lt $maxWait) { + Write-Host "$YELLOW⏳ [等待]$NC 等待配置文件生成... ($waited/$maxWait 秒)" + Start-Sleep -Seconds 1 + $waited++ + } + + if (Test-Path $configPath) { + Write-Host "$GREEN✅ [成功]$NC 配置文件已生成: $configPath" + } else { + Write-Host "$YELLOW⚠️ [警告]$NC 配置文件未在预期时间内生成,继续执行..." + } + + # 强制关闭Cursor + Write-Host "$YELLOW🔄 [关闭]$NC 正在关闭Cursor以进行配置修改..." + if ($process -and -not $process.HasExited) { + $process.Kill() + $process.WaitForExit(5000) + } + + # 确保所有Cursor进程都关闭 + Get-Process -Name "Cursor" -ErrorAction SilentlyContinue | Stop-Process -Force + Get-Process -Name "cursor" -ErrorAction SilentlyContinue | Stop-Process -Force + + Write-Host "$GREEN✅ [完成]$NC Cursor重启流程完成" + return $true + + } catch { + Write-Host "$RED❌ [错误]$NC 重启Cursor失败: $($_.Exception.Message)" + return $false + } +} + +# 🛠️ 修改机器码配置 +function Modify-MachineCodeConfig { + Write-Host "" + Write-Host "$GREEN🛠️ [配置]$NC 正在修改机器码配置..." + + $configPath = "$env:APPDATA\Cursor\User\globalStorage\storage.json" + + if (-not (Test-Path $configPath)) { + Write-Host "$RED❌ [错误]$NC 配置文件不存在: $configPath" + Write-Host "$YELLOW💡 [提示]$NC 请手动启动Cursor一次,然后重新运行此脚本" + return $false + } + + try { + # 生成新的ID + $MAC_MACHINE_ID = [System.Guid]::NewGuid().ToString() + $UUID = [System.Guid]::NewGuid().ToString() + $prefixBytes = [System.Text.Encoding]::UTF8.GetBytes("auth0|user_") + $prefixHex = -join ($prefixBytes | ForEach-Object { '{0:x2}' -f $_ }) + $randomBytes = New-Object byte[] 32 + $rng = [System.Security.Cryptography.RNGCryptoServiceProvider]::new() + $rng.GetBytes($randomBytes) + $randomPart = [System.BitConverter]::ToString($randomBytes) -replace '-','' + $rng.Dispose() + $MACHINE_ID = "$prefixHex$randomPart" + $SQM_ID = "{$([System.Guid]::NewGuid().ToString().ToUpper())}" + + Write-Host "$BLUE🔧 [生成]$NC 已生成新的设备标识符" + + # 读取并修改配置文件 + $originalContent = Get-Content $configPath -Raw -Encoding UTF8 + $config = $originalContent | ConvertFrom-Json + + # 备份原始值 + $backupDir = "$env:APPDATA\Cursor\User\globalStorage\backups" + if (-not (Test-Path $backupDir)) { + New-Item -ItemType Directory -Path $backupDir -Force | Out-Null + } + + $backupName = "storage.json.backup_$(Get-Date -Format 'yyyyMMdd_HHmmss')" + Copy-Item $configPath "$backupDir\$backupName" + Write-Host "$GREEN💾 [备份]$NC 已备份原配置: $backupName" + + # 更新配置值 + $config.'telemetry.machineId' = $MACHINE_ID + $config.'telemetry.macMachineId' = $MAC_MACHINE_ID + $config.'telemetry.devDeviceId' = $UUID + $config.'telemetry.sqmId' = $SQM_ID + + # 保存修改后的配置 + $updatedJson = $config | ConvertTo-Json -Depth 10 + [System.IO.File]::WriteAllText($configPath, $updatedJson, [System.Text.Encoding]::UTF8) + + Write-Host "$GREEN✅ [成功]$NC 机器码配置修改完成" + Write-Host "$BLUE📋 [详情]$NC 已更新以下标识符:" + Write-Host " 🔹 machineId: $($MACHINE_ID.Substring(0,20))..." + Write-Host " 🔹 macMachineId: $MAC_MACHINE_ID" + Write-Host " 🔹 devDeviceId: $UUID" + Write-Host " 🔹 sqmId: $SQM_ID" + + return $true + + } catch { + Write-Host "$RED❌ [错误]$NC 修改配置失败: $($_.Exception.Message)" + return $false + } } # 检查管理员权限 @@ -186,13 +309,24 @@ function Get-ProcessDetails { $MAX_RETRIES = 5 $WAIT_TIME = 1 -# 🔄 处理进程关闭 -function Close-CursorProcess { +# 🔄 处理进程关闭并保存进程信息 +function Close-CursorProcessAndSaveInfo { param($processName) + $global:CursorProcessInfo = $null + $process = Get-Process -Name $processName -ErrorAction SilentlyContinue if ($process) { Write-Host "$YELLOW⚠️ [警告]$NC 发现 $processName 正在运行" + + # 💾 保存进程信息用于后续重启 + $global:CursorProcessInfo = @{ + ProcessName = $process.ProcessName + Path = $process.Path + StartTime = $process.StartTime + } + Write-Host "$GREEN💾 [保存]$NC 已保存进程信息: $($global:CursorProcessInfo.Path)" + Get-ProcessDetails $processName Write-Host "$YELLOW🔄 [操作]$NC 尝试关闭 $processName..." @@ -215,12 +349,43 @@ function Close-CursorProcess { Start-Sleep -Seconds $WAIT_TIME } Write-Host "$GREEN✅ [成功]$NC $processName 已成功关闭" + } else { + Write-Host "$BLUE💡 [提示]$NC 未发现 $processName 进程运行" + # 尝试找到Cursor的安装路径 + $cursorPaths = @( + "$env:LOCALAPPDATA\Programs\cursor\Cursor.exe", + "$env:PROGRAMFILES\Cursor\Cursor.exe", + "$env:PROGRAMFILES(X86)\Cursor\Cursor.exe" + ) + + foreach ($path in $cursorPaths) { + if (Test-Path $path) { + $global:CursorProcessInfo = @{ + ProcessName = "Cursor" + Path = $path + StartTime = $null + } + Write-Host "$GREEN💾 [发现]$NC 找到Cursor安装路径: $path" + break + } + } + + if (-not $global:CursorProcessInfo) { + Write-Host "$YELLOW⚠️ [警告]$NC 未找到Cursor安装路径,将使用默认路径" + $global:CursorProcessInfo = @{ + ProcessName = "Cursor" + Path = "$env:LOCALAPPDATA\Programs\cursor\Cursor.exe" + StartTime = $null + } + } } } -# 🚀 关闭所有 Cursor 进程 -Close-CursorProcess "Cursor" -Close-CursorProcess "cursor" +# 🚀 关闭所有 Cursor 进程并保存信息 +Close-CursorProcessAndSaveInfo "Cursor" +if (-not $global:CursorProcessInfo) { + Close-CursorProcessAndSaveInfo "cursor" +} # 🚨 重要警告提示 Write-Host "" @@ -235,10 +400,11 @@ Write-Host "" Write-Host "$GREEN🚀 [开始]$NC 开始执行核心功能..." Remove-CursorTrialFolders -# 📝 以下机器码修改相关功能已暂时屏蔽 -Write-Host "$YELLOW⚠️ [提示]$NC 机器码修改功能已暂时屏蔽,专注于文件夹删除功能" -Write-Host "$BLUE📋 [说明]$NC 如需恢复机器码修改功能,请联系开发者" -Write-Host "" +# 🔄 重启Cursor让其重新生成配置文件 +Restart-CursorAndWait + +# 🛠️ 修改机器码配置 +Modify-MachineCodeConfig <# # 🚫 已屏蔽:创建备份目录