mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2025-06-08 04:22:06 +08:00
Update README files and scripts to clarify Cursor version support
- Added important notices in both English and Chinese README files regarding supported Cursor versions: v0.44.11 and below are supported, while the latest 0.45.x versions are temporarily unsupported. - Enhanced error handling in the cursor ID modifier scripts for Linux, macOS, and Windows to check for the existence of the configuration file before proceeding. - Improved user feedback by including warnings about the required Cursor version in the script outputs. - Streamlined the configuration update process in the scripts to ensure clarity and robustness.
This commit is contained in:
parent
7568d9f423
commit
f7345eae36
@ -12,6 +12,14 @@
|
||||
|
||||
</div>
|
||||
|
||||
> ⚠️ **IMPORTANT NOTICE**
|
||||
>
|
||||
> This tool currently supports:
|
||||
> - ✅ Cursor v0.44.11 and below
|
||||
> - ❌ Latest 0.45.x versions (temporarily unsupported)
|
||||
>
|
||||
> Please check your Cursor version before using this tool.
|
||||
|
||||
---
|
||||
|
||||
### 📝 Description
|
||||
|
@ -12,6 +12,14 @@
|
||||
|
||||
</div>
|
||||
|
||||
> ⚠️ **重要提示**
|
||||
>
|
||||
> 本工具当前支持版本:
|
||||
> - ✅ Cursor v0.44.11 及以下版本
|
||||
> - ❌ 最新的 0.45.x 版本(暂不支持)
|
||||
>
|
||||
> 使用前请确认您的 Cursor 版本。
|
||||
|
||||
---
|
||||
|
||||
### 📝 问题描述
|
||||
|
@ -161,39 +161,29 @@ generate_new_config() {
|
||||
if ! command -v uuidgen &> /dev/null; then
|
||||
log_error "未找到 uuidgen 命令,请安装 uuidgen"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 确保目录存在
|
||||
mkdir -p "$(dirname "$STORAGE_FILE")"
|
||||
# 检查配置文件是否存在
|
||||
if [ ! -f "$STORAGE_FILE" ]; then
|
||||
log_error "未找到配置文件: $STORAGE_FILE"
|
||||
log_warn "请先安装并运行一次 Cursor 后再使用此脚本"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 将 auth0|user_ 转换为字节数组的十六进制
|
||||
local prefix_hex=$(echo -n "auth0|user_" | xxd -p)
|
||||
# 生成随机部分
|
||||
local random_part=$(generate_random_id)
|
||||
# 拼接前缀的十六进制和随机部分
|
||||
local machine_id="${prefix_hex}${random_part}"
|
||||
|
||||
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 "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
|
||||
# 创建新文件
|
||||
cat > "$STORAGE_FILE" << EOF
|
||||
{
|
||||
"telemetry.machineId": "$machine_id",
|
||||
"telemetry.macMachineId": "$mac_machine_id",
|
||||
"telemetry.devDeviceId": "$device_id",
|
||||
"telemetry.sqmId": "$sqm_id"
|
||||
}
|
||||
EOF
|
||||
fi
|
||||
|
||||
chmod 644 "$STORAGE_FILE"
|
||||
chown "$CURRENT_USER:$CURRENT_USER" "$STORAGE_FILE"
|
||||
@ -257,6 +247,9 @@ main() {
|
||||
echo -e "${GREEN} Cursor ID 修改工具${NC}"
|
||||
echo -e "${BLUE}================================${NC}"
|
||||
echo
|
||||
echo -e "${YELLOW}[重要提示]${NC} 本工具仅支持 Cursor v0.44.11 及以下版本"
|
||||
echo -e "${YELLOW}[重要提示]${NC} 最新的 0.45.x 版本暂不支持"
|
||||
echo
|
||||
|
||||
check_permissions
|
||||
check_and_kill_cursor
|
||||
|
@ -139,32 +139,27 @@ generate_uuid() {
|
||||
|
||||
# 生成新的配置
|
||||
generate_new_config() {
|
||||
# 检查配置文件是否存在
|
||||
if [ ! -f "$STORAGE_FILE" ]; then
|
||||
log_error "未找到配置文件: $STORAGE_FILE"
|
||||
log_warn "请先安装并运行一次 Cursor 后再使用此脚本"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 将 auth0|user_ 转换为字节数组的十六进制
|
||||
local prefix_hex=$(echo -n "auth0|user_" | xxd -p)
|
||||
# 生成随机部分
|
||||
local random_part=$(generate_random_id)
|
||||
# 拼接前缀的十六进制和随机部分
|
||||
local machine_id="${prefix_hex}${random_part}"
|
||||
|
||||
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"
|
||||
@ -228,6 +223,9 @@ main() {
|
||||
echo -e "${GREEN} Cursor ID 修改工具 ${NC}"
|
||||
echo -e "${BLUE}================================${NC}"
|
||||
echo
|
||||
echo -e "${YELLOW}[重要提示]${NC} 本工具仅支持 Cursor v0.44.11 及以下版本"
|
||||
echo -e "${YELLOW}[重要提示]${NC} 最新的 0.45.x 版本暂不支持"
|
||||
echo
|
||||
|
||||
check_permissions
|
||||
check_and_kill_cursor
|
||||
|
@ -43,6 +43,9 @@ Write-Host "$BLUE================================$NC"
|
||||
Write-Host "$GREEN Cursor ID 修改工具 $NC"
|
||||
Write-Host "$BLUE================================$NC"
|
||||
Write-Host ""
|
||||
Write-Host "$YELLOW[重要提示]$NC 本工具仅支持 Cursor v0.44.11 及以下版本"
|
||||
Write-Host "$YELLOW[重要提示]$NC 最新的 0.45.x 版本暂不支持"
|
||||
Write-Host ""
|
||||
|
||||
# 检查并关闭 Cursor 进程
|
||||
Write-Host "$GREEN[信息]$NC 检查 Cursor 进程..."
|
||||
@ -136,31 +139,53 @@ $SQM_ID = "{$([System.Guid]::NewGuid().ToString().ToUpper())}"
|
||||
Write-Host "$GREEN[信息]$NC 正在更新配置..."
|
||||
|
||||
try {
|
||||
# 确保目录存在
|
||||
$storageDir = Split-Path $STORAGE_FILE -Parent
|
||||
if (-not (Test-Path $storageDir)) {
|
||||
New-Item -ItemType Directory -Path $storageDir -Force | Out-Null
|
||||
# 检查配置文件是否存在
|
||||
if (-not (Test-Path $STORAGE_FILE)) {
|
||||
Write-Host "$RED[错误]$NC 未找到配置文件: $STORAGE_FILE"
|
||||
Write-Host "$YELLOW[提示]$NC 请先安装并运行一次 Cursor 后再使用此脚本"
|
||||
Read-Host "按回车键退出"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 写入配置
|
||||
$config = @{
|
||||
'telemetry.machineId' = $MACHINE_ID
|
||||
'telemetry.macMachineId' = $MAC_MACHINE_ID
|
||||
'telemetry.devDeviceId' = $UUID
|
||||
'telemetry.sqmId' = $SQM_ID
|
||||
}
|
||||
|
||||
# 使用 System.IO.File 方法写入文件
|
||||
# 读取现有配置文件
|
||||
try {
|
||||
$jsonContent = $config | ConvertTo-Json
|
||||
$originalContent = Get-Content $STORAGE_FILE -Raw -Encoding UTF8
|
||||
|
||||
# 将 JSON 字符串转换为 PowerShell 对象
|
||||
$config = $originalContent | ConvertFrom-Json
|
||||
|
||||
# 备份当前值
|
||||
$oldValues = @{
|
||||
'machineId' = $config.'telemetry.machineId'
|
||||
'macMachineId' = $config.'telemetry.macMachineId'
|
||||
'devDeviceId' = $config.'telemetry.devDeviceId'
|
||||
'sqmId' = $config.'telemetry.sqmId'
|
||||
}
|
||||
|
||||
# 更新特定的值
|
||||
$config.'telemetry.machineId' = $MACHINE_ID
|
||||
$config.'telemetry.macMachineId' = $MAC_MACHINE_ID
|
||||
$config.'telemetry.devDeviceId' = $UUID
|
||||
$config.'telemetry.sqmId' = $SQM_ID
|
||||
|
||||
# 将更新后的对象转换回 JSON 并保存
|
||||
$updatedJson = $config | ConvertTo-Json -Depth 10
|
||||
[System.IO.File]::WriteAllText(
|
||||
[System.IO.Path]::GetFullPath($STORAGE_FILE),
|
||||
$jsonContent,
|
||||
$updatedJson,
|
||||
[System.Text.Encoding]::UTF8
|
||||
)
|
||||
Write-Host "$GREEN[信息]$NC 成功写入配置文件"
|
||||
Write-Host "$GREEN[信息]$NC 成功更新配置文件"
|
||||
} catch {
|
||||
throw "写入文件失败: $_"
|
||||
# 如果出错,尝试恢复原始内容
|
||||
if ($originalContent) {
|
||||
[System.IO.File]::WriteAllText(
|
||||
[System.IO.Path]::GetFullPath($STORAGE_FILE),
|
||||
$originalContent,
|
||||
[System.Text.Encoding]::UTF8
|
||||
)
|
||||
}
|
||||
throw "处理 JSON 失败: $_"
|
||||
}
|
||||
|
||||
# 尝试设置文件权限
|
||||
|
Loading…
x
Reference in New Issue
Block a user