Browse Source
chore: remove CHANGELOG.md and update README with proxy download instructions for domestic users
chore: remove CHANGELOG.md and update README with proxy download instructions for domestic users
- Deleted the CHANGELOG.md file as it is no longer needed for project documentation. - Updated the README.md to include proxy download instructions for Linux and macOS users in China. - Added similar instructions for Windows users to facilitate easier access to installation scripts.pull/122/head v0.0.38
5 changed files with 719 additions and 53 deletions
-
53CHANGELOG.md
-
15README.md
-
241scripts/run/cursor_linux_id_modifier.sh
-
239scripts/run/cursor_mac_id_modifier.sh
-
224scripts/run/cursor_win_id_modifier.bat
@ -1,53 +0,0 @@ |
|||
# 📝 Changelog |
|||
|
|||
All notable changes to this project will be documented in this file. |
|||
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), |
|||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
|||
|
|||
## [0.1.23] - 2024-12-29 🚀 |
|||
|
|||
### ✨ Features |
|||
- **Initial Release**: First public release of Cursor ID Modifier |
|||
- **Multi-Platform Support**: |
|||
- 🪟 Windows (x64, x86) |
|||
- 🍎 macOS (Intel & Apple Silicon) |
|||
- 🐧 Linux (x64, x86, ARM64) |
|||
- **Installation**: |
|||
- Automated installation scripts for all platforms |
|||
- One-line installation commands |
|||
- Secure download and verification |
|||
- **Core Functionality**: |
|||
- Telemetry ID modification for Cursor IDE |
|||
- Automatic process management |
|||
- Secure configuration handling |
|||
|
|||
### 🐛 Bug Fixes |
|||
- **Installation**: |
|||
- Fixed environment variable preservation in sudo operations |
|||
- Enhanced error handling during installation |
|||
- Improved binary download reliability |
|||
- **Process Management**: |
|||
- Improved Cursor process detection accuracy |
|||
- Enhanced process termination reliability |
|||
- Better handling of edge cases |
|||
- **User Experience**: |
|||
- Enhanced error messages and user feedback |
|||
- Improved progress indicators |
|||
- Better handling of system permissions |
|||
|
|||
### 🔧 Technical Improvements |
|||
- Optimized binary size with proper build flags |
|||
- Enhanced cross-platform compatibility |
|||
- Improved error handling and logging |
|||
- Better system resource management |
|||
|
|||
### 📚 Documentation |
|||
- Added comprehensive installation instructions |
|||
- Included platform-specific guidelines |
|||
- Enhanced error troubleshooting guide |
|||
|
|||
--- |
|||
*For more details about the changes, please refer to the [commit history](https://github.com/yuaotian/go-cursor-help/commits/main).* |
|||
|
|||
[0.1.22]: https://github.com/yuaotian/go-cursor-help/releases/tag/v0.1.23 |
@ -0,0 +1,241 @@ |
|||
#!/bin/bash |
|||
|
|||
# 设置错误处理 |
|||
set -e |
|||
|
|||
# 颜色定义 |
|||
RED='\033[0;31m' |
|||
GREEN='\033[0;32m' |
|||
YELLOW='\033[1;33m' |
|||
BLUE='\033[0;34m' |
|||
NC='\033[0m' # No Color |
|||
|
|||
# 日志函数 |
|||
log_info() { |
|||
echo -e "${GREEN}[INFO]${NC} $1" |
|||
} |
|||
|
|||
log_warn() { |
|||
echo -e "${YELLOW}[WARN]${NC} $1" |
|||
} |
|||
|
|||
log_error() { |
|||
echo -e "${RED}[ERROR]${NC} $1" |
|||
} |
|||
|
|||
log_debug() { |
|||
echo -e "${BLUE}[DEBUG]${NC} $1" |
|||
} |
|||
|
|||
# 获取当前用户 |
|||
get_current_user() { |
|||
if [ "$EUID" -eq 0 ]; then |
|||
echo "$SUDO_USER" |
|||
else |
|||
echo "$USER" |
|||
fi |
|||
} |
|||
|
|||
CURRENT_USER=$(get_current_user) |
|||
if [ -z "$CURRENT_USER" ]; then |
|||
log_error "无法获取用户名" |
|||
exit 1 |
|||
fi |
|||
|
|||
# 定义配置文件路径 (Linux 路径) |
|||
STORAGE_FILE="/home/$CURRENT_USER/.config/Cursor/User/globalStorage/storage.json" |
|||
BACKUP_DIR="/home/$CURRENT_USER/.config/Cursor/User/globalStorage/backups" |
|||
|
|||
# 检查权限 |
|||
check_permissions() { |
|||
if [ "$EUID" -ne 0 ]; then |
|||
log_error "请使用 sudo 运行此脚本" |
|||
echo "示例: sudo $0" |
|||
exit 1 |
|||
fi |
|||
} |
|||
|
|||
# 检查并关闭 Cursor 进程 |
|||
check_and_kill_cursor() { |
|||
log_info "检查 Cursor 进程..." |
|||
|
|||
local attempt=1 |
|||
local max_attempts=5 |
|||
|
|||
# 函数:获取进程详细信息 |
|||
get_process_details() { |
|||
local process_name="$1" |
|||
log_debug "正在获取 $process_name 进程详细信息:" |
|||
ps aux | grep -i "$process_name" | grep -v grep |
|||
} |
|||
|
|||
while [ $attempt -le $max_attempts ]; do |
|||
CURSOR_PIDS=$(pgrep -i "cursor" || true) |
|||
|
|||
if [ -z "$CURSOR_PIDS" ]; then |
|||
log_info "未发现运行中的 Cursor 进程" |
|||
return 0 |
|||
fi |
|||
|
|||
log_warn "发现 Cursor 进程正在运行" |
|||
get_process_details "cursor" |
|||
|
|||
log_warn "尝试关闭 Cursor 进程..." |
|||
|
|||
if [ $attempt -eq $max_attempts ]; then |
|||
log_warn "尝试强制终止进程..." |
|||
kill -9 $CURSOR_PIDS 2>/dev/null || true |
|||
else |
|||
kill $CURSOR_PIDS 2>/dev/null || true |
|||
fi |
|||
|
|||
sleep 1 |
|||
|
|||
if ! pgrep -i "cursor" > /dev/null; then |
|||
log_info "Cursor 进程已成功关闭" |
|||
return 0 |
|||
fi |
|||
|
|||
log_warn "等待进程关闭,尝试 $attempt/$max_attempts..." |
|||
((attempt++)) |
|||
done |
|||
|
|||
log_error "在 $max_attempts 次尝试后仍无法关闭 Cursor 进程" |
|||
get_process_details "cursor" |
|||
log_error "请手动关闭进程后重试" |
|||
exit 1 |
|||
} |
|||
|
|||
# 备份配置文件 |
|||
backup_config() { |
|||
if [ ! -f "$STORAGE_FILE" ]; then |
|||
log_warn "配置文件不存在,跳过备份" |
|||
return 0 |
|||
fi |
|||
|
|||
mkdir -p "$BACKUP_DIR" |
|||
local backup_file="$BACKUP_DIR/storage.json.backup_$(date +%Y%m%d_%H%M%S)" |
|||
|
|||
if cp "$STORAGE_FILE" "$backup_file"; then |
|||
chmod 644 "$backup_file" |
|||
chown "$CURRENT_USER:$CURRENT_USER" "$backup_file" |
|||
log_info "配置已备份到: $backup_file" |
|||
else |
|||
log_error "备份失败" |
|||
exit 1 |
|||
fi |
|||
} |
|||
|
|||
# 生成随机 ID |
|||
generate_random_id() { |
|||
# Linux 可以使用 /dev/urandom |
|||
head -c 32 /dev/urandom | xxd -p |
|||
} |
|||
|
|||
# 生成随机 UUID |
|||
generate_uuid() { |
|||
# Linux 使用 uuidgen 命令 |
|||
uuidgen | tr '[:upper:]' '[:lower:]' |
|||
} |
|||
|
|||
# 生成新的配置 |
|||
generate_new_config() { |
|||
local machine_id="auth0|user_$(generate_random_id)" |
|||
local mac_machine_id=$(generate_random_id) |
|||
local device_id=$(generate_uuid | tr '[:upper:]' '[:lower:]') |
|||
local sqm_id="{$(generate_uuid | tr '[:lower:]' '[:upper:]')}" |
|||
|
|||
if [ -f "$STORAGE_FILE" ]; then |
|||
# 直接修改现有文件 (Linux sed 不需要 '') |
|||
sed -i "s/\"telemetry\.machineId\":[[:space:]]*\"[^\"]*\"/\"telemetry.machineId\": \"$machine_id\"/" "$STORAGE_FILE" |
|||
sed -i "s/\"telemetry\.macMachineId\":[[:space:]]*\"[^\"]*\"/\"telemetry.macMachineId\": \"$mac_machine_id\"/" "$STORAGE_FILE" |
|||
sed -i "s/\"telemetry\.devDeviceId\":[[:space:]]*\"[^\"]*\"/\"telemetry.devDeviceId\": \"$device_id\"/" "$STORAGE_FILE" |
|||
sed -i "s/\"telemetry\.sqmId\":[[:space:]]*\"[^\"]*\"/\"telemetry.sqmId\": \"$sqm_id\"/" "$STORAGE_FILE" |
|||
else |
|||
# 创建新文件 |
|||
echo "{" > "$STORAGE_FILE" |
|||
echo " \"telemetry.machineId\": \"$machine_id\"," >> "$STORAGE_FILE" |
|||
echo " \"telemetry.macMachineId\": \"$mac_machine_id\"," >> "$STORAGE_FILE" |
|||
echo " \"telemetry.devDeviceId\": \"$device_id\"," >> "$STORAGE_FILE" |
|||
echo " \"telemetry.sqmId\": \"$sqm_id\"" >> "$STORAGE_FILE" |
|||
echo "}" >> "$STORAGE_FILE" |
|||
fi |
|||
|
|||
chmod 644 "$STORAGE_FILE" |
|||
chown "$CURRENT_USER:$CURRENT_USER" "$STORAGE_FILE" |
|||
|
|||
echo |
|||
log_info "已更新配置:" |
|||
log_debug "machineId: $machine_id" |
|||
log_debug "macMachineId: $mac_machine_id" |
|||
log_debug "devDeviceId: $device_id" |
|||
log_debug "sqmId: $sqm_id" |
|||
} |
|||
|
|||
# 显示文件树结构 |
|||
show_file_tree() { |
|||
local base_dir=$(dirname "$STORAGE_FILE") |
|||
echo |
|||
log_info "文件结构:" |
|||
echo -e "${BLUE}$base_dir${NC}" |
|||
echo "├── globalStorage" |
|||
echo "│ ├── storage.json (已修改)" |
|||
echo "│ └── backups" |
|||
|
|||
# 列出备份文件 |
|||
if [ -d "$BACKUP_DIR" ]; then |
|||
local backup_files=("$BACKUP_DIR"/*) |
|||
if [ ${#backup_files[@]} -gt 0 ]; then |
|||
for file in "${backup_files[@]}"; do |
|||
if [ -f "$file" ]; then |
|||
echo "│ └── $(basename "$file")" |
|||
fi |
|||
done |
|||
else |
|||
echo "│ └── (空)" |
|||
fi |
|||
fi |
|||
echo |
|||
} |
|||
|
|||
# 显示公众号信息 |
|||
show_follow_info() { |
|||
echo |
|||
echo -e "${GREEN}================================${NC}" |
|||
echo -e "${YELLOW} 关注公众号【煎饼果子AI】一起交流更多Cursor技巧和AI知识 ${NC}" |
|||
echo -e "${GREEN}================================${NC}" |
|||
echo |
|||
} |
|||
|
|||
# 主函数 |
|||
main() { |
|||
clear |
|||
# 显示 CURSOR Logo |
|||
echo -e " |
|||
██████╗██╗ ██╗██████╗ ███████╗ ██████╗ ██████╗ |
|||
██╔════╝██║ ██║██╔══██╗██╔════╝██╔═══██╗██╔══██╗ |
|||
██║ ██║ ██║██████╔╝███████╗██║ ██║██████╔╝ |
|||
██║ ██║ ██║██╔══██╗╚════██║██║ ██║██╔══██╗ |
|||
╚██████╗╚██████╔╝██║ ██║███████║╚██████╔╝██║ ██║ |
|||
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝ |
|||
" |
|||
echo -e "${BLUE}================================${NC}" |
|||
echo -e "${GREEN} Cursor ID 修改工具${NC}" |
|||
echo -e "${BLUE}================================${NC}" |
|||
echo |
|||
|
|||
check_permissions |
|||
check_and_kill_cursor |
|||
backup_config |
|||
generate_new_config |
|||
|
|||
echo |
|||
log_info "操作完成!" |
|||
show_follow_info |
|||
show_file_tree |
|||
log_info "请重启 Cursor 以应用新的配置" |
|||
echo |
|||
} |
|||
|
|||
# 执行主函数 |
|||
main |
@ -0,0 +1,239 @@ |
|||
#!/bin/bash |
|||
|
|||
# 设置错误处理 |
|||
set -e |
|||
|
|||
# 颜色定义 |
|||
RED='\033[0;31m' |
|||
GREEN='\033[0;32m' |
|||
YELLOW='\033[1;33m' |
|||
BLUE='\033[0;34m' |
|||
NC='\033[0m' # No Color |
|||
|
|||
# 日志函数 |
|||
log_info() { |
|||
echo -e "${GREEN}[INFO]${NC} $1" |
|||
} |
|||
|
|||
log_warn() { |
|||
echo -e "${YELLOW}[WARN]${NC} $1" |
|||
} |
|||
|
|||
log_error() { |
|||
echo -e "${RED}[ERROR]${NC} $1" |
|||
} |
|||
|
|||
log_debug() { |
|||
echo -e "${BLUE}[DEBUG]${NC} $1" |
|||
} |
|||
|
|||
# 获取当前用户 |
|||
get_current_user() { |
|||
if [ "$EUID" -eq 0 ]; then |
|||
echo "$SUDO_USER" |
|||
else |
|||
echo "$USER" |
|||
fi |
|||
} |
|||
|
|||
CURRENT_USER=$(get_current_user) |
|||
if [ -z "$CURRENT_USER" ]; then |
|||
log_error "无法获取用户名" |
|||
exit 1 |
|||
fi |
|||
|
|||
# 定义配置文件路径 |
|||
STORAGE_FILE="$HOME/Library/Application Support/Cursor/User/globalStorage/storage.json" |
|||
BACKUP_DIR="$HOME/Library/Application Support/Cursor/User/globalStorage/backups" |
|||
|
|||
# 检查权限 |
|||
check_permissions() { |
|||
if [ "$EUID" -ne 0 ]; then |
|||
log_error "请使用 sudo 运行此脚本" |
|||
echo "示例: sudo $0" |
|||
exit 1 |
|||
fi |
|||
} |
|||
|
|||
# 检查并关闭 Cursor 进程 |
|||
check_and_kill_cursor() { |
|||
log_info "检查 Cursor 进程..." |
|||
|
|||
local attempt=1 |
|||
local max_attempts=5 |
|||
|
|||
# 函数:获取进程详细信息 |
|||
get_process_details() { |
|||
local process_name="$1" |
|||
log_debug "正在获取 $process_name 进程详细信息:" |
|||
ps aux | grep -i "$process_name" | grep -v grep |
|||
} |
|||
|
|||
while [ $attempt -le $max_attempts ]; do |
|||
CURSOR_PIDS=$(pgrep -i "cursor" || true) |
|||
|
|||
if [ -z "$CURSOR_PIDS" ]; then |
|||
log_info "未发现运行中的 Cursor 进程" |
|||
return 0 |
|||
fi |
|||
|
|||
log_warn "发现 Cursor 进程正在运行" |
|||
get_process_details "cursor" |
|||
|
|||
log_warn "尝试关闭 Cursor 进程..." |
|||
|
|||
if [ $attempt -eq $max_attempts ]; then |
|||
log_warn "尝试强制终止进程..." |
|||
kill -9 $CURSOR_PIDS 2>/dev/null || true |
|||
else |
|||
kill $CURSOR_PIDS 2>/dev/null || true |
|||
fi |
|||
|
|||
sleep 1 |
|||
|
|||
if ! pgrep -i "cursor" > /dev/null; then |
|||
log_info "Cursor 进程已成功关闭" |
|||
return 0 |
|||
fi |
|||
|
|||
log_warn "等待进程关闭,尝试 $attempt/$max_attempts..." |
|||
((attempt++)) |
|||
done |
|||
|
|||
log_error "在 $max_attempts 次尝试后仍无法关闭 Cursor 进程" |
|||
get_process_details "cursor" |
|||
log_error "请手动关闭进程后重试" |
|||
exit 1 |
|||
} |
|||
|
|||
# 备份配置文件 |
|||
backup_config() { |
|||
if [ ! -f "$STORAGE_FILE" ]; then |
|||
log_warn "配置文件不存在,跳过备份" |
|||
return 0 |
|||
fi |
|||
|
|||
mkdir -p "$BACKUP_DIR" |
|||
local backup_file="$BACKUP_DIR/storage.json.backup_$(date +%Y%m%d_%H%M%S)" |
|||
|
|||
if cp "$STORAGE_FILE" "$backup_file"; then |
|||
chmod 644 "$backup_file" |
|||
chown "$CURRENT_USER" "$backup_file" |
|||
log_info "配置已备份到: $backup_file" |
|||
else |
|||
log_error "备份失败" |
|||
exit 1 |
|||
fi |
|||
} |
|||
|
|||
# 生成随机 ID |
|||
generate_random_id() { |
|||
openssl rand -hex 32 |
|||
} |
|||
|
|||
# 生成随机 UUID |
|||
generate_uuid() { |
|||
uuidgen | tr '[:upper:]' '[:lower:]' |
|||
} |
|||
|
|||
# 生成新的配置 |
|||
generate_new_config() { |
|||
local machine_id="auth0|user_$(generate_random_id)" |
|||
local mac_machine_id=$(generate_random_id) |
|||
local device_id=$(generate_uuid | tr '[:upper:]' '[:lower:]') |
|||
local sqm_id="{$(generate_uuid | tr '[:lower:]' '[:upper:]')}" |
|||
|
|||
if [ -f "$STORAGE_FILE" ]; then |
|||
# 直接修改现有文件 |
|||
sed -i '' -e "s/\"telemetry\.machineId\":[[:space:]]*\"[^\"]*\"/\"telemetry.machineId\": \"$machine_id\"/" "$STORAGE_FILE" |
|||
sed -i '' -e "s/\"telemetry\.macMachineId\":[[:space:]]*\"[^\"]*\"/\"telemetry.macMachineId\": \"$mac_machine_id\"/" "$STORAGE_FILE" |
|||
sed -i '' -e "s/\"telemetry\.devDeviceId\":[[:space:]]*\"[^\"]*\"/\"telemetry.devDeviceId\": \"$device_id\"/" "$STORAGE_FILE" |
|||
sed -i '' -e "s/\"telemetry\.sqmId\":[[:space:]]*\"[^\"]*\"/\"telemetry.sqmId\": \"$sqm_id\"/" "$STORAGE_FILE" |
|||
else |
|||
# 创建新文件 |
|||
echo "{" > "$STORAGE_FILE" |
|||
echo " \"telemetry.machineId\": \"$machine_id\"," >> "$STORAGE_FILE" |
|||
echo " \"telemetry.macMachineId\": \"$mac_machine_id\"," >> "$STORAGE_FILE" |
|||
echo " \"telemetry.devDeviceId\": \"$device_id\"," >> "$STORAGE_FILE" |
|||
echo " \"telemetry.sqmId\": \"$sqm_id\"" >> "$STORAGE_FILE" |
|||
echo "}" >> "$STORAGE_FILE" |
|||
fi |
|||
|
|||
chmod 644 "$STORAGE_FILE" |
|||
chown "$CURRENT_USER" "$STORAGE_FILE" |
|||
|
|||
echo |
|||
log_info "已更新配置:" |
|||
log_debug "machineId: $machine_id" |
|||
log_debug "macMachineId: $mac_machine_id" |
|||
log_debug "devDeviceId: $device_id" |
|||
log_debug "sqmId: $sqm_id" |
|||
} |
|||
|
|||
# 显示文件树结构 |
|||
show_file_tree() { |
|||
local base_dir=$(dirname "$STORAGE_FILE") |
|||
echo |
|||
log_info "文件结构:" |
|||
echo -e "${BLUE}$base_dir${NC}" |
|||
echo "├── globalStorage" |
|||
echo "│ ├── storage.json (已修改)" |
|||
echo "│ └── backups" |
|||
|
|||
# 列出备份文件 |
|||
if [ -d "$BACKUP_DIR" ]; then |
|||
local backup_files=("$BACKUP_DIR"/*) |
|||
if [ ${#backup_files[@]} -gt 0 ]; then |
|||
for file in "${backup_files[@]}"; do |
|||
if [ -f "$file" ]; then |
|||
echo "│ └── $(basename "$file")" |
|||
fi |
|||
done |
|||
else |
|||
echo "│ └── (空)" |
|||
fi |
|||
fi |
|||
echo |
|||
} |
|||
|
|||
# 显示公众号信息 |
|||
show_follow_info() { |
|||
echo |
|||
echo -e "${GREEN}================================${NC}" |
|||
echo -e "${YELLOW} 关注公众号【煎饼果子AI】一起交流更多Cursor技巧和AI知识 ${NC}" |
|||
echo -e "${GREEN}================================${NC}" |
|||
echo |
|||
} |
|||
|
|||
# 主函数 |
|||
main() { |
|||
clear |
|||
# 显示 CURSOR Logo |
|||
echo -e " |
|||
██████╗██╗ ██╗██████╗ ███████╗ ██████╗ ██████╗ |
|||
██╔════╝██║ ██║██╔══██╗██╔════╝██╔═══██╗██╔══██╗ |
|||
██║ ██║ ██║██████╔╝███████╗██║ ██║██████╔╝ |
|||
██║ ██║ ██║██╔══██╗╚════██║██║ ██║██╔══██╗ |
|||
╚██████╗╚██████╔╝██║ ██║███████║╚██████╔╝██║ ██║ |
|||
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝ |
|||
" |
|||
echo -e "${BLUE}================================${NC}" |
|||
echo -e "${GREEN} Cursor ID 修改工具${NC}" |
|||
echo -e "${BLUE}================================${NC}" |
|||
echo |
|||
|
|||
check_permissions |
|||
check_and_kill_cursor |
|||
backup_config |
|||
generate_new_config |
|||
|
|||
echo |
|||
log_info "操作完成!" |
|||
show_follow_info |
|||
show_file_tree |
|||
log_info "请重启 Cursor 以应用新的配置" |
|||
echo |
|||
} |
|||
|
|||
# 执行主函数 |
|||
main |
@ -0,0 +1,224 @@ |
|||
@echo off |
|||
chcp 65001 >nul |
|||
setlocal EnableDelayedExpansion |
|||
|
|||
:: 颜色定义 |
|||
set "RED=[31m" |
|||
set "GREEN=[32m" |
|||
set "YELLOW=[33m" |
|||
set "BLUE=[34m" |
|||
set "NC=[0m" |
|||
|
|||
:: 配置文件路径 |
|||
set "STORAGE_FILE=%APPDATA%\Cursor\User\globalStorage\storage.json" |
|||
set "BACKUP_DIR=%APPDATA%\Cursor\User\globalStorage\backups" |
|||
|
|||
:: 检查管理员权限 |
|||
net session >nul 2>&1 |
|||
if %errorLevel% neq 0 ( |
|||
echo %RED%[错误]%NC% 请以管理员身份运行此脚本 |
|||
echo 请右键点击脚本,选择"以管理员身份运行" |
|||
pause |
|||
exit /b 1 |
|||
) |
|||
|
|||
:: 显示 Logo |
|||
cls |
|||
echo. |
|||
echo ██████╗██╗ ██╗██████╗ ███████╗ ██████╗ ██████╗ |
|||
echo ██╔════╝██║ ██║██╔══██╗██╔════╝██╔═══██╗██╔══██╗ |
|||
echo ██║ ██║ ██║██████╔╝███████╗██║ ██║██████╔╝ |
|||
echo ██║ ██║ ██║██╔══██╗╚════██║██║ ██║██╔══██╗ |
|||
echo ╚██████╗╚██████╔╝██║ ██║███████║╚██████╔╝██║ ██║ |
|||
echo ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝ |
|||
echo. |
|||
echo %BLUE%================================%NC% |
|||
echo %GREEN% Cursor ID 修改工具%NC% |
|||
echo %BLUE%================================%NC% |
|||
echo. |
|||
|
|||
:: 检查并关闭 Cursor 进程 |
|||
:: 定义最大重试次数和等待时间 |
|||
set "MAX_RETRIES=5" |
|||
set "WAIT_TIME=1" |
|||
|
|||
echo %GREEN%[信息]%NC% 检查 Cursor 进程... |
|||
|
|||
goto :main |
|||
|
|||
:check_process |
|||
setlocal |
|||
set "process_name=%~1" |
|||
tasklist /FI "IMAGENAME eq %process_name%" 2>NUL | find /I "%process_name%" >NUL |
|||
endlocal & exit /b %ERRORLEVEL% |
|||
|
|||
:get_process_details |
|||
setlocal |
|||
set "process_name=%~1" |
|||
echo %BLUE%[调试]%NC% 正在获取 %process_name% 进程详细信息: |
|||
wmic process where "name='%process_name%'" get ProcessId,ExecutablePath,CommandLine /format:list |
|||
endlocal |
|||
exit /b |
|||
|
|||
:main |
|||
|
|||
:: 处理 Cursor.exe |
|||
call :check_process "Cursor.exe" |
|||
if %ERRORLEVEL% equ 0 ( |
|||
echo %YELLOW%[警告]%NC% 发现 Cursor.exe 正在运行 |
|||
call :get_process_details "Cursor.exe" |
|||
|
|||
echo %YELLOW%[警告]%NC% 尝试关闭 Cursor.exe... |
|||
taskkill /F /IM "Cursor.exe" >NUL 2>&1 |
|||
|
|||
:: 循环检测进程是否真正关闭 |
|||
set "retry_count=0" |
|||
:retry_cursor |
|||
call :check_process "Cursor.exe" |
|||
if %ERRORLEVEL% equ 0 ( |
|||
set /a "retry_count+=1" |
|||
if !retry_count! geq %MAX_RETRIES% ( |
|||
echo %RED%[错误]%NC% 在 %MAX_RETRIES% 次尝试后仍无法关闭 Cursor.exe |
|||
call :get_process_details "Cursor.exe" |
|||
echo %RED%[错误]%NC% 请手动关闭进程后重试 |
|||
pause |
|||
exit /b 1 |
|||
) |
|||
echo %YELLOW%[警告]%NC% 等待进程关闭,尝试 !retry_count!/%MAX_RETRIES%... |
|||
timeout /t %WAIT_TIME% /nobreak >NUL |
|||
goto retry_cursor |
|||
) |
|||
echo %GREEN%[信息]%NC% Cursor.exe 已成功关闭 |
|||
) |
|||
|
|||
:: 处理 cursor.exe |
|||
call :check_process "cursor.exe" |
|||
if %ERRORLEVEL% equ 0 ( |
|||
echo %YELLOW%[警告]%NC% 发现 cursor.exe 正在运行 |
|||
call :get_process_details "cursor.exe" |
|||
|
|||
echo %YELLOW%[警告]%NC% 尝试关闭 cursor.exe... |
|||
taskkill /F /IM "cursor.exe" >NUL 2>&1 |
|||
|
|||
:: 循环检测进程是否真正关闭 |
|||
set "retry_count=0" |
|||
:retry_cursor_lower |
|||
call :check_process "cursor.exe" |
|||
if %ERRORLEVEL% equ 0 ( |
|||
set /a "retry_count+=1" |
|||
if !retry_count! geq %MAX_RETRIES% ( |
|||
echo %RED%[错误]%NC% 在 %MAX_RETRIES% 次尝试后仍无法关闭 cursor.exe |
|||
call :get_process_details "cursor.exe" |
|||
echo %RED%[错误]%NC% 请手动关闭进程后重试 |
|||
pause |
|||
exit /b 1 |
|||
) |
|||
echo %YELLOW%[警告]%NC% 等待进程关闭,尝试 !retry_count!/%MAX_RETRIES%... |
|||
timeout /t %WAIT_TIME% /nobreak >NUL |
|||
goto retry_cursor_lower |
|||
) |
|||
echo %GREEN%[信息]%NC% cursor.exe 已成功关闭 |
|||
) |
|||
|
|||
:: 最终确认所有进程都已关闭 |
|||
echo %GREEN%[信息]%NC% 正在进行最终确认... |
|||
call :check_process "Cursor.exe" |
|||
if %ERRORLEVEL% equ 0 ( |
|||
echo %RED%[错误]%NC% 仍然检测到 Cursor.exe 进程 |
|||
call :get_process_details "Cursor.exe" |
|||
pause |
|||
exit /b 1 |
|||
) |
|||
call :check_process "cursor.exe" |
|||
if %ERRORLEVEL% equ 0 ( |
|||
echo %RED%[错误]%NC% 仍然检测到 cursor.exe 进程 |
|||
call :get_process_details "cursor.exe" |
|||
pause |
|||
exit /b 1 |
|||
) |
|||
|
|||
echo %GREEN%[信息]%NC% 所有 Cursor 进程已确认关闭 |
|||
|
|||
:: 创建备份目录 |
|||
if not exist "%BACKUP_DIR%" mkdir "%BACKUP_DIR%" |
|||
|
|||
:: 备份现有配置 |
|||
if exist "%STORAGE_FILE%" ( |
|||
echo %GREEN%[信息]%NC% 正在备份配置文件... |
|||
copy "%STORAGE_FILE%" "%BACKUP_DIR%\storage.json.backup_%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%" >NUL |
|||
if !errorlevel! neq 0 ( |
|||
echo %RED%[错误]%NC% 备份失败 |
|||
pause |
|||
exit /b 1 |
|||
) |
|||
) |
|||
|
|||
:: 生成新的 ID |
|||
echo %GREEN%[信息]%NC% 正在生成新的 ID... |
|||
|
|||
:: 生成随机 ID |
|||
for /f "delims=" %%a in ('powershell -Command "[System.Guid]::NewGuid().ToString()"') do set "UUID=%%a" |
|||
for /f "delims=" %%a in ('powershell -Command "$bytes = New-Object Byte[] 32; (New-Object Security.Cryptography.RNGCryptoServiceProvider).GetBytes($bytes); -join($bytes | ForEach-Object { $_.ToString('x2') })"') do set "MACHINE_ID=%%a" |
|||
for /f "delims=" %%a in ('powershell -Command "$bytes = New-Object Byte[] 32; (New-Object Security.Cryptography.RNGCryptoServiceProvider).GetBytes($bytes); -join($bytes | ForEach-Object { $_.ToString('x2') })"') do set "MAC_MACHINE_ID=%%a" |
|||
for /f "delims=" %%a in ('powershell -Command "[System.Guid]::NewGuid().ToString().ToUpper()"') do set "SQM_ID={%%a}" |
|||
|
|||
:: 创建或更新配置文件 |
|||
echo %GREEN%[信息]%NC% 正在更新配置... |
|||
|
|||
:: 直接更新 JSON 文件 |
|||
if not exist "%STORAGE_FILE%" ( |
|||
echo {> "%STORAGE_FILE%" |
|||
echo "telemetry.machineId": "%MACHINE_ID%",>> "%STORAGE_FILE%" |
|||
echo "telemetry.macMachineId": "%MAC_MACHINE_ID%",>> "%STORAGE_FILE%" |
|||
echo "telemetry.devDeviceId": "%UUID%",>> "%STORAGE_FILE%" |
|||
echo "telemetry.sqmId": "%SQM_ID%">> "%STORAGE_FILE%" |
|||
echo }>> "%STORAGE_FILE%" |
|||
) else ( |
|||
:: 使用 PowerShell 更新现有 JSON 文件 |
|||
powershell -Command "$json = Get-Content '%STORAGE_FILE%' | ConvertFrom-Json; $json.'telemetry.machineId' = '%MACHINE_ID%'; $json.'telemetry.macMachineId' = '%MAC_MACHINE_ID%'; $json.'telemetry.devDeviceId' = '%UUID%'; $json.'telemetry.sqmId' = '%SQM_ID%'; $json | ConvertTo-Json -Depth 10 | Set-Content '%STORAGE_FILE%'" |
|||
) |
|||
|
|||
:: 设置文件权限 |
|||
icacls "%STORAGE_FILE%" /grant:r "%USERNAME%":F >NUL |
|||
|
|||
:: 显示结果 |
|||
echo. |
|||
echo %GREEN%[信息]%NC% 已更新配置: |
|||
echo %BLUE%[调试]%NC% machineId: %MACHINE_ID% |
|||
echo %BLUE%[调试]%NC% macMachineId: %MAC_MACHINE_ID% |
|||
echo %BLUE%[调试]%NC% devDeviceId: %UUID% |
|||
echo %BLUE%[调试]%NC% sqmId: %SQM_ID% |
|||
echo. |
|||
echo %GREEN%[信息]%NC% 操作完成! |
|||
|
|||
:: 显示公众号信息 |
|||
echo. |
|||
echo %GREEN%================================%NC% |
|||
echo %YELLOW% 关注公众号【煎饼果子AI】一起交流更多Cursor技巧和AI知识 %NC% |
|||
echo %GREEN%================================%NC% |
|||
echo. |
|||
|
|||
:: 显示文件树结构 |
|||
echo. |
|||
echo %GREEN%[信息]%NC% 文件结构: |
|||
echo %BLUE%%APPDATA%\Cursor\User%NC% |
|||
echo ├── globalStorage |
|||
echo │ ├── storage.json (已修改) |
|||
echo │ └── backups |
|||
|
|||
:: 列出备份文件 |
|||
if exist "%BACKUP_DIR%\*" ( |
|||
for %%F in ("%BACKUP_DIR%\*") do ( |
|||
echo │ └── %%~nxF |
|||
) |
|||
) else ( |
|||
echo │ └── (空) |
|||
) |
|||
echo. |
|||
|
|||
echo %GREEN%[信息]%NC% 请重启 Cursor 以应用新的配置 |
|||
|
|||
echo. |
|||
|
|||
pause |
|||
exit /b 0 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue