mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2025-08-02 22:07:36 +08:00
新增重启Cursor并等待配置文件生成的功能,提升机器码配置修改的可靠性。同时,更新了相关脚本以确保在修改机器码配置时能够正确处理Cursor进程,增强用户体验。
This commit is contained in:
parent
e282b95c8a
commit
ab6db7d431
@ -130,6 +130,127 @@ remove_cursor_trial_folders() {
|
|||||||
echo
|
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() {
|
check_permissions() {
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
@ -139,13 +260,16 @@ check_permissions() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 检查并关闭 Cursor 进程
|
# 检查并关闭 Cursor 进程(保存进程信息)
|
||||||
check_and_kill_cursor() {
|
check_and_kill_cursor() {
|
||||||
log_info "检查 Cursor 进程..."
|
log_info "🔍 [检查] 检查 Cursor 进程..."
|
||||||
|
|
||||||
local attempt=1
|
local attempt=1
|
||||||
local max_attempts=5
|
local max_attempts=5
|
||||||
|
|
||||||
|
# 💾 保存Cursor进程路径
|
||||||
|
CURSOR_PROCESS_PATH="/Applications/Cursor.app/Contents/MacOS/Cursor"
|
||||||
|
|
||||||
# 函数:获取进程详细信息
|
# 函数:获取进程详细信息
|
||||||
get_process_details() {
|
get_process_details() {
|
||||||
local process_name="$1"
|
local process_name="$1"
|
||||||
@ -158,17 +282,25 @@ check_and_kill_cursor() {
|
|||||||
CURSOR_PIDS=$(ps aux | grep -i "/Applications/Cursor.app" | grep -v grep | awk '{print $2}')
|
CURSOR_PIDS=$(ps aux | grep -i "/Applications/Cursor.app" | grep -v grep | awk '{print $2}')
|
||||||
|
|
||||||
if [ -z "$CURSOR_PIDS" ]; then
|
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
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_warn "发现 Cursor 进程正在运行"
|
log_warn "⚠️ [警告] 发现 Cursor 进程正在运行"
|
||||||
|
# 💾 保存进程信息
|
||||||
|
log_info "💾 [保存] 已保存Cursor路径: $CURSOR_PROCESS_PATH"
|
||||||
get_process_details "cursor"
|
get_process_details "cursor"
|
||||||
|
|
||||||
log_warn "尝试关闭 Cursor 进程..."
|
log_warn "🔄 [操作] 尝试关闭 Cursor 进程..."
|
||||||
|
|
||||||
if [ $attempt -eq $max_attempts ]; then
|
if [ $attempt -eq $max_attempts ]; then
|
||||||
log_warn "尝试强制终止进程..."
|
log_warn "💥 [强制] 尝试强制终止进程..."
|
||||||
kill -9 $CURSOR_PIDS 2>/dev/null || true
|
kill -9 $CURSOR_PIDS 2>/dev/null || true
|
||||||
else
|
else
|
||||||
kill $CURSOR_PIDS 2>/dev/null || true
|
kill $CURSOR_PIDS 2>/dev/null || true
|
||||||
@ -178,17 +310,17 @@ check_and_kill_cursor() {
|
|||||||
|
|
||||||
# 同样使用更精确的匹配来检查进程是否还在运行
|
# 同样使用更精确的匹配来检查进程是否还在运行
|
||||||
if ! ps aux | grep -i "/Applications/Cursor.app" | grep -v grep > /dev/null; then
|
if ! ps aux | grep -i "/Applications/Cursor.app" | grep -v grep > /dev/null; then
|
||||||
log_info "Cursor 进程已成功关闭"
|
log_info "✅ [成功] Cursor 进程已成功关闭"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_warn "等待进程关闭,尝试 $attempt/$max_attempts..."
|
log_warn "⏳ [等待] 等待进程关闭,尝试 $attempt/$max_attempts..."
|
||||||
((attempt++))
|
((attempt++))
|
||||||
done
|
done
|
||||||
|
|
||||||
log_error "在 $max_attempts 次尝试后仍无法关闭 Cursor 进程"
|
log_error "❌ [错误] 在 $max_attempts 次尝试后仍无法关闭 Cursor 进程"
|
||||||
get_process_details "cursor"
|
get_process_details "cursor"
|
||||||
log_error "请手动关闭进程后重试"
|
log_error "💥 [错误] 请手动关闭进程后重试"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1084,12 +1216,11 @@ main() {
|
|||||||
log_info "🚀 [开始] 开始执行核心功能..."
|
log_info "🚀 [开始] 开始执行核心功能..."
|
||||||
remove_cursor_trial_folders
|
remove_cursor_trial_folders
|
||||||
|
|
||||||
# 🚫 以下功能已暂时屏蔽
|
# 🔄 重启Cursor让其重新生成配置文件
|
||||||
log_warn "⚠️ [提示] 以下功能已暂时屏蔽:"
|
restart_cursor_and_wait
|
||||||
log_info "📋 [说明] - 配置文件备份和修改"
|
|
||||||
log_info "📋 [说明] - 主程序文件修改"
|
# 🛠️ 修改机器码配置
|
||||||
log_info "📋 [说明] 当前版本专注于删除文件夹功能"
|
modify_machine_code_config
|
||||||
echo
|
|
||||||
|
|
||||||
# 🎉 显示操作完成信息
|
# 🎉 显示操作完成信息
|
||||||
echo
|
echo
|
||||||
|
@ -108,6 +108,127 @@ remove_cursor_trial_folders() {
|
|||||||
echo
|
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 初始化函数(已暂时禁用)
|
||||||
cursor_initialize_cleanup_disabled() {
|
cursor_initialize_cleanup_disabled() {
|
||||||
log_warn "⚠️ [提示] 原有的机器码修改功能已暂时禁用"
|
log_warn "⚠️ [提示] 原有的机器码修改功能已暂时禁用"
|
||||||
@ -304,13 +425,16 @@ check_permissions() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 检查并关闭 Cursor 进程
|
# 检查并关闭 Cursor 进程(保存进程信息)
|
||||||
check_and_kill_cursor() {
|
check_and_kill_cursor() {
|
||||||
log_info "检查 Cursor 进程..."
|
log_info "🔍 [检查] 检查 Cursor 进程..."
|
||||||
|
|
||||||
local attempt=1
|
local attempt=1
|
||||||
local max_attempts=5
|
local max_attempts=5
|
||||||
|
|
||||||
|
# 💾 保存Cursor进程路径
|
||||||
|
CURSOR_PROCESS_PATH="/Applications/Cursor.app/Contents/MacOS/Cursor"
|
||||||
|
|
||||||
# 函数:获取进程详细信息
|
# 函数:获取进程详细信息
|
||||||
get_process_details() {
|
get_process_details() {
|
||||||
local process_name="$1"
|
local process_name="$1"
|
||||||
@ -323,17 +447,25 @@ check_and_kill_cursor() {
|
|||||||
CURSOR_PIDS=$(ps aux | grep -i "/Applications/Cursor.app" | grep -v grep | awk '{print $2}')
|
CURSOR_PIDS=$(ps aux | grep -i "/Applications/Cursor.app" | grep -v grep | awk '{print $2}')
|
||||||
|
|
||||||
if [ -z "$CURSOR_PIDS" ]; then
|
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
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_warn "发现 Cursor 进程正在运行"
|
log_warn "⚠️ [警告] 发现 Cursor 进程正在运行"
|
||||||
|
# 💾 保存进程信息
|
||||||
|
log_info "💾 [保存] 已保存Cursor路径: $CURSOR_PROCESS_PATH"
|
||||||
get_process_details "cursor"
|
get_process_details "cursor"
|
||||||
|
|
||||||
log_warn "尝试关闭 Cursor 进程..."
|
log_warn "🔄 [操作] 尝试关闭 Cursor 进程..."
|
||||||
|
|
||||||
if [ $attempt -eq $max_attempts ]; then
|
if [ $attempt -eq $max_attempts ]; then
|
||||||
log_warn "尝试强制终止进程..."
|
log_warn "💥 [强制] 尝试强制终止进程..."
|
||||||
kill -9 $CURSOR_PIDS 2>/dev/null || true
|
kill -9 $CURSOR_PIDS 2>/dev/null || true
|
||||||
else
|
else
|
||||||
kill $CURSOR_PIDS 2>/dev/null || true
|
kill $CURSOR_PIDS 2>/dev/null || true
|
||||||
@ -343,17 +475,17 @@ check_and_kill_cursor() {
|
|||||||
|
|
||||||
# 同样使用更精确的匹配来检查进程是否还在运行
|
# 同样使用更精确的匹配来检查进程是否还在运行
|
||||||
if ! ps aux | grep -i "/Applications/Cursor.app" | grep -v grep > /dev/null; then
|
if ! ps aux | grep -i "/Applications/Cursor.app" | grep -v grep > /dev/null; then
|
||||||
log_info "Cursor 进程已成功关闭"
|
log_info "✅ [成功] Cursor 进程已成功关闭"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_warn "等待进程关闭,尝试 $attempt/$max_attempts..."
|
log_warn "⏳ [等待] 等待进程关闭,尝试 $attempt/$max_attempts..."
|
||||||
((attempt++))
|
((attempt++))
|
||||||
done
|
done
|
||||||
|
|
||||||
log_error "在 $max_attempts 次尝试后仍无法关闭 Cursor 进程"
|
log_error "❌ [错误] 在 $max_attempts 次尝试后仍无法关闭 Cursor 进程"
|
||||||
get_process_details "cursor"
|
get_process_details "cursor"
|
||||||
log_error "请手动关闭进程后重试"
|
log_error "💥 [错误] 请手动关闭进程后重试"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1319,13 +1451,13 @@ main() {
|
|||||||
log_info "🚀 [开始] 开始执行核心功能..."
|
log_info "🚀 [开始] 开始执行核心功能..."
|
||||||
remove_cursor_trial_folders
|
remove_cursor_trial_folders
|
||||||
|
|
||||||
# 🚫 以下功能已暂时屏蔽
|
# <EFBFBD> 重启Cursor让其重新生成配置文件
|
||||||
log_warn "⚠️ [提示] 以下功能已暂时屏蔽:"
|
restart_cursor_and_wait
|
||||||
log_info "📋 [说明] - 配置文件备份和修改"
|
|
||||||
log_info "📋 [说明] - 系统MAC地址修改"
|
# 🛠️ 修改机器码配置
|
||||||
log_info "📋 [说明] - 主程序文件修改"
|
modify_machine_code_config
|
||||||
log_info "📋 [说明] 当前版本专注于删除文件夹功能"
|
|
||||||
echo
|
|
||||||
|
|
||||||
# 🎉 显示操作完成信息
|
# 🎉 显示操作完成信息
|
||||||
echo
|
echo
|
||||||
|
@ -87,11 +87,134 @@ function Remove-CursorTrialFolders {
|
|||||||
Write-Host ""
|
Write-Host ""
|
||||||
}
|
}
|
||||||
|
|
||||||
# 📝 原有的 Cursor 初始化函数(已暂时禁用)
|
# 🔄 重启Cursor并等待配置文件生成
|
||||||
function Cursor-初始化-已禁用 {
|
function Restart-CursorAndWait {
|
||||||
Write-Host "$YELLOW⚠️ [提示]$NC 原有的机器码修改功能已暂时禁用"
|
|
||||||
Write-Host "$BLUE📋 [说明]$NC 当前版本专注于删除文件夹功能,机器码修改功能已屏蔽"
|
|
||||||
Write-Host ""
|
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
|
$MAX_RETRIES = 5
|
||||||
$WAIT_TIME = 1
|
$WAIT_TIME = 1
|
||||||
|
|
||||||
# 🔄 处理进程关闭
|
# 🔄 处理进程关闭并保存进程信息
|
||||||
function Close-CursorProcess {
|
function Close-CursorProcessAndSaveInfo {
|
||||||
param($processName)
|
param($processName)
|
||||||
|
|
||||||
|
$global:CursorProcessInfo = $null
|
||||||
|
|
||||||
$process = Get-Process -Name $processName -ErrorAction SilentlyContinue
|
$process = Get-Process -Name $processName -ErrorAction SilentlyContinue
|
||||||
if ($process) {
|
if ($process) {
|
||||||
Write-Host "$YELLOW⚠️ [警告]$NC 发现 $processName 正在运行"
|
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
|
Get-ProcessDetails $processName
|
||||||
|
|
||||||
Write-Host "$YELLOW🔄 [操作]$NC 尝试关闭 $processName..."
|
Write-Host "$YELLOW🔄 [操作]$NC 尝试关闭 $processName..."
|
||||||
@ -215,12 +349,43 @@ function Close-CursorProcess {
|
|||||||
Start-Sleep -Seconds $WAIT_TIME
|
Start-Sleep -Seconds $WAIT_TIME
|
||||||
}
|
}
|
||||||
Write-Host "$GREEN✅ [成功]$NC $processName 已成功关闭"
|
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 进程
|
# 🚀 关闭所有 Cursor 进程并保存信息
|
||||||
Close-CursorProcess "Cursor"
|
Close-CursorProcessAndSaveInfo "Cursor"
|
||||||
Close-CursorProcess "cursor"
|
if (-not $global:CursorProcessInfo) {
|
||||||
|
Close-CursorProcessAndSaveInfo "cursor"
|
||||||
|
}
|
||||||
|
|
||||||
# 🚨 重要警告提示
|
# 🚨 重要警告提示
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
@ -235,10 +400,11 @@ Write-Host ""
|
|||||||
Write-Host "$GREEN🚀 [开始]$NC 开始执行核心功能..."
|
Write-Host "$GREEN🚀 [开始]$NC 开始执行核心功能..."
|
||||||
Remove-CursorTrialFolders
|
Remove-CursorTrialFolders
|
||||||
|
|
||||||
# 📝 以下机器码修改相关功能已暂时屏蔽
|
# 🔄 重启Cursor让其重新生成配置文件
|
||||||
Write-Host "$YELLOW⚠️ [提示]$NC 机器码修改功能已暂时屏蔽,专注于文件夹删除功能"
|
Restart-CursorAndWait
|
||||||
Write-Host "$BLUE📋 [说明]$NC 如需恢复机器码修改功能,请联系开发者"
|
|
||||||
Write-Host ""
|
# 🛠️ 修改机器码配置
|
||||||
|
Modify-MachineCodeConfig
|
||||||
|
|
||||||
<#
|
<#
|
||||||
# 🚫 已屏蔽:创建备份目录
|
# 🚫 已屏蔽:创建备份目录
|
||||||
|
Loading…
x
Reference in New Issue
Block a user