Browse Source

增强机器码配置修改功能,新增配置文件格式验证及现有遥测属性显示,确保用户在执行过程中获得详细反馈。优化了属性更新和验证逻辑,提升了脚本的可靠性和用户体验。

master v0.0.178
煎饼果子卷鲨鱼辣椒 3 weeks ago
parent
commit
7e566bc768
  1. 73
      scripts/run/cursor_mac_id_modifier.sh
  2. 72
      scripts/run/cursor_win_id_modifier.ps1

73
scripts/run/cursor_mac_id_modifier.sh

@ -460,7 +460,7 @@ modify_machine_code_config() {
return 1
fi
# 验证配置文件格式
# 验证配置文件格式并显示结构
log_info "🔍 [验证] 检查配置文件格式..."
if ! python3 -c "import json; json.load(open('$config_path'))" 2>/dev/null; then
log_error "❌ [错误] 配置文件格式错误或损坏"
@ -469,6 +469,27 @@ modify_machine_code_config() {
fi
log_info "✅ [验证] 配置文件格式正确"
# 显示当前配置文件中的相关属性
log_info "📋 [当前配置] 检查现有的遥测属性:"
python3 -c "
import json
try:
with open('$config_path', 'r', encoding='utf-8') as f:
config = json.load(f)
properties = ['telemetry.machineId', 'telemetry.macMachineId', 'telemetry.devDeviceId', 'telemetry.sqmId']
for prop in properties:
if prop in config:
value = config[prop]
display_value = value[:20] + '...' if len(value) > 20 else value
print(f' ✓ {prop} = {display_value}')
else:
print(f' - {prop} (不存在,将创建)')
except Exception as e:
print(f'Error reading config: {e}')
"
echo
# 显示操作进度
log_info "⏳ [进度] 1/5 - 生成新的设备标识符..."
@ -514,7 +535,7 @@ modify_machine_code_config() {
log_info "⏳ [进度] 4/5 - 更新配置文件..."
# 使用Python修改JSON配置(更可靠)
# 使用Python修改JSON配置(更可靠,安全方式
local python_result=$(python3 -c "
import json
import sys
@ -523,10 +544,20 @@ 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'
# 安全更新配置,确保属性存在
properties_to_update = {
'telemetry.machineId': '$MACHINE_ID',
'telemetry.macMachineId': '$MAC_MACHINE_ID',
'telemetry.devDeviceId': '$UUID',
'telemetry.sqmId': '$SQM_ID'
}
for key, value in properties_to_update.items():
if key in config:
print(f' ✓ 更新属性: {key}')
else:
print(f' + 添加属性: {key}')
config[key] = value
with open('$config_path', 'w', encoding='utf-8') as f:
json.dump(config, f, indent=2, ensure_ascii=False)
@ -547,14 +578,23 @@ try:
with open('$config_path', 'r', encoding='utf-8') as f:
config = json.load(f)
checks = [
config.get('telemetry.machineId') == '$MACHINE_ID',
config.get('telemetry.macMachineId') == '$MAC_MACHINE_ID',
config.get('telemetry.devDeviceId') == '$UUID',
config.get('telemetry.sqmId') == '$SQM_ID'
]
properties_to_check = {
'telemetry.machineId': '$MACHINE_ID',
'telemetry.macMachineId': '$MAC_MACHINE_ID',
'telemetry.devDeviceId': '$UUID',
'telemetry.sqmId': '$SQM_ID'
}
verification_passed = True
for key, expected_value in properties_to_check.items():
actual_value = config.get(key)
if actual_value == expected_value:
print(f'✓ {key}: 验证通过')
else:
print(f'✗ {key}: 验证失败 (期望: {expected_value}, 实际: {actual_value})')
verification_passed = False
if all(checks):
if verification_passed:
print('VERIFICATION_SUCCESS')
else:
print('VERIFICATION_FAILED')
@ -598,12 +638,7 @@ except Exception as e:
fi
}
# 📝 原有的 Cursor 初始化函数(已暂时禁用)
cursor_initialize_cleanup_disabled() {
log_warn "⚠️ [提示] 原有的机器码修改功能已暂时禁用"
log_info "📋 [说明] 当前版本专注于删除文件夹功能,机器码修改功能已屏蔽"
echo
}
# 获取当前用户
get_current_user() {

72
scripts/run/cursor_win_id_modifier.ps1

@ -309,12 +309,26 @@ function Modify-MachineCodeConfig {
return $false
}
# 验证配置文件格式
# 验证配置文件格式并显示结构
try {
Write-Host "$BLUE🔍 [验证]$NC 检查配置文件格式..."
$originalContent = Get-Content $configPath -Raw -Encoding UTF8 -ErrorAction Stop
$config = $originalContent | ConvertFrom-Json -ErrorAction Stop
Write-Host "$GREEN✅ [验证]$NC 配置文件格式正确"
# 显示当前配置文件中的相关属性
Write-Host "$BLUE📋 [当前配置]$NC 检查现有的遥测属性:"
$telemetryProperties = @('telemetry.machineId', 'telemetry.macMachineId', 'telemetry.devDeviceId', 'telemetry.sqmId')
foreach ($prop in $telemetryProperties) {
if ($config.PSObject.Properties[$prop]) {
$value = $config.$prop
$displayValue = if ($value.Length -gt 20) { "$($value.Substring(0,20))..." } else { $value }
Write-Host "$GREEN ✓ $prop$NC = $displayValue"
} else {
Write-Host "$YELLOW - $prop$NC (不存在,将创建)"
}
}
Write-Host ""
} catch {
Write-Host "$RED❌ [错误]$NC 配置文件格式错误: $($_.Exception.Message)"
Write-Host "$YELLOW💡 [建议]$NC 配置文件可能已损坏,建议选择'重置环境+修改机器码'选项"
@ -369,11 +383,30 @@ function Modify-MachineCodeConfig {
Write-Host "$BLUE⏳ [进度]$NC 4/5 - 更新配置文件..."
# 更新配置值
$config.'telemetry.machineId' = $MACHINE_ID
$config.'telemetry.macMachineId' = $MAC_MACHINE_ID
$config.'telemetry.devDeviceId' = $UUID
$config.'telemetry.sqmId' = $SQM_ID
# 更新配置值(安全方式,确保属性存在)
# 检查并创建属性(如果不存在)
$propertiesToUpdate = @{
'telemetry.machineId' = $MACHINE_ID
'telemetry.macMachineId' = $MAC_MACHINE_ID
'telemetry.devDeviceId' = $UUID
'telemetry.sqmId' = $SQM_ID
}
foreach ($property in $propertiesToUpdate.GetEnumerator()) {
$key = $property.Key
$value = $property.Value
# 使用 Add-Member 或直接赋值的安全方式
if ($config.PSObject.Properties[$key]) {
# 属性存在,直接更新
$config.$key = $value
Write-Host "$BLUE ✓ 更新属性: $key$NC"
} else {
# 属性不存在,添加新属性
$config | Add-Member -MemberType NoteProperty -Name $key -Value $value -Force
Write-Host "$BLUE + 添加属性: $key$NC"
}
}
# 保存修改后的配置
$updatedJson = $config | ConvertTo-Json -Depth 10
@ -387,10 +420,27 @@ function Modify-MachineCodeConfig {
$verifyConfig = $verifyContent | ConvertFrom-Json
$verificationPassed = $true
if ($verifyConfig.'telemetry.machineId' -ne $MACHINE_ID) { $verificationPassed = $false }
if ($verifyConfig.'telemetry.macMachineId' -ne $MAC_MACHINE_ID) { $verificationPassed = $false }
if ($verifyConfig.'telemetry.devDeviceId' -ne $UUID) { $verificationPassed = $false }
if ($verifyConfig.'telemetry.sqmId' -ne $SQM_ID) { $verificationPassed = $false }
$verificationResults = @()
# 安全验证每个属性
foreach ($property in $propertiesToUpdate.GetEnumerator()) {
$key = $property.Key
$expectedValue = $property.Value
$actualValue = $verifyConfig.$key
if ($actualValue -eq $expectedValue) {
$verificationResults += "$key: 验证通过"
} else {
$verificationResults += "$key: 验证失败 (期望: $expectedValue, 实际: $actualValue)"
$verificationPassed = $false
}
}
# 显示验证结果
Write-Host "$BLUE📋 [验证详情]$NC"
foreach ($result in $verificationResults) {
Write-Host " $result"
}
if ($verificationPassed) {
Write-Host "$GREEN✅ [进度]$NC 5/5 - 修改验证成功"
@ -660,7 +710,7 @@ $cursorVersion = Get-CursorVersion
Write-Host ""
Write-Host "$YELLOW💡 [重要提示]$NC 最新的 1.0.x 版本已支持"
Write-Host "$BLUE📋 [功能说明]$NC 本工具专注于删除Cursor试用相关文件夹,暂时屏蔽机器码修改功能"
Write-Host ""
# 🔍 检查并关闭 Cursor 进程

Loading…
Cancel
Save