Skip to content

Commit 201555f

Browse files
Update run.ps1
1 parent e5930d9 commit 201555f

File tree

1 file changed

+84
-121
lines changed

1 file changed

+84
-121
lines changed

run.ps1

Lines changed: 84 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,74 @@
1-
# 设置输出编码为 UTF-8
1+
# Set output encoding to UTF-8
22
$OutputEncoding = [System.Text.Encoding]::UTF8
33
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
44

5-
# 颜色定义
5+
# Color definitions
66
$RED = "`e[31m"
77
$GREEN = "`e[32m"
88
$YELLOW = "`e[33m"
99
$BLUE = "`e[34m"
1010
$NC = "`e[0m"
1111

12-
# 配置文件路径
13-
$STORAGE_FILE = "$env:APPDATA\Cursor\User\globalStorage\storage.json"
14-
$BACKUP_DIR = "$env:APPDATA\Cursor\User\globalStorage\backups"
12+
# Configuration file paths
13+
$STORAGE_FILE = "$env:APPDATA\SAJJAD\User\globalStorage\storage.json"
14+
$BACKUP_DIR = "$env:APPDATA\SAJJAD\User\globalStorage\backups"
1515

16-
# 检查管理员权限
16+
# Check administrator privileges
1717
function Test-Administrator {
1818
$user = [Security.Principal.WindowsIdentity]::GetCurrent()
1919
$principal = New-Object Security.Principal.WindowsPrincipal($user)
2020
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
2121
}
2222

2323
if (-not (Test-Administrator)) {
24-
Write-Host "$RED[错误]$NC 请以管理员身份运行此脚本"
25-
Write-Host "请右键点击脚本,选择'以管理员身份运行'"
26-
Read-Host "按回车键退出"
24+
Write-Host "$RED[ERROR]$NC Please run this script as Administrator"
25+
Write-Host "Right-click the script and select 'Run as Administrator'"
26+
Read-Host "Press Enter to exit"
2727
exit 1
2828
}
2929

30-
# 显示 Logo
30+
# Display Logo
3131
Clear-Host
3232
Write-Host @"
3333
34-
██████╗██╗ ██╗██████╗ ███████╗ ██████╗ ██████╗
35-
██╔════╝██║ ██║██╔══██╗██╔════╝██╔═══██╗██╔══██╗
36-
██ ██║ ██║██████╔╝███████╗██ ██║██████╔╝
37-
██║ ██║ ██║██╔══██╗╚════██║██║ ██║██╔══██╗
38-
██████╗╚██████╔╝████║███████║╚██████╔╝██║ ██║
39-
╚═════╝ ╚═════╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝
34+
███████╗ █████╗ ██╗ ██╗ █████╗ ██████╗ ██████╗
35+
██╔════╝██╔══██╗ ██ ██║██╔══██╗██╔══██╗██╔══██╗
36+
███████╗███████║ ██║ ██║███████║██║ ██║██║ ██║
37+
╚════██║██╔══██║ ██║ ██║██╔══██║██║ ██║██║ ██║
38+
███████║██║ ██ █████████║██║ ██║██████╔╝██████╔╝
39+
╚══════╝╚═╝ ╚═╝ ╚══════╝╚═╝╚═╝ ╚═╝╚═════╝ ╚═════╝
4040
4141
"@
4242
Write-Host "$BLUE================================$NC"
43-
Write-Host "$GREEN Cursor ID 修改工具 $NC"
43+
Write-Host "$GREEN SAJJAD ID Modifier $NC"
4444
Write-Host "$BLUE================================$NC"
4545
Write-Host ""
4646

47-
# 检查并关闭 Cursor 进程
48-
Write-Host "$GREEN[信息]$NC 检查 Cursor 进程..."
47+
# Check and close SAJJAD processes
48+
Write-Host "$GREEN[INFO]$NC Checking SAJJAD processes..."
4949

5050
function Get-ProcessDetails {
5151
param($processName)
52-
Write-Host "$BLUE[调试]$NC 正在获取 $processName 进程详细信息:"
52+
Write-Host "$BLUE[DEBUG]$NC Getting details for $processName processes:"
5353
Get-WmiObject Win32_Process -Filter "name='$processName'" |
5454
Select-Object ProcessId, ExecutablePath, CommandLine |
5555
Format-List
5656
}
5757

58-
# 定义最大重试次数和等待时间
58+
# Process closing parameters
5959
$MAX_RETRIES = 5
6060
$WAIT_TIME = 1
6161

62-
# 处理进程关闭
63-
function Close-CursorProcess {
62+
# Process closing function
63+
function Close-SAJJADProcess {
6464
param($processName)
6565

6666
$process = Get-Process -Name $processName -ErrorAction SilentlyContinue
6767
if ($process) {
68-
Write-Host "$YELLOW[警告]$NC 发现 $processName 正在运行"
68+
Write-Host "$YELLOW[WARNING]$NC Found running $processName process"
6969
Get-ProcessDetails $processName
7070

71-
Write-Host "$YELLOW[警告]$NC 尝试关闭 $processName..."
71+
Write-Host "$YELLOW[WARNING]$NC Attempting to close $processName..."
7272
Stop-Process -Name $processName -Force
7373

7474
$retryCount = 0
@@ -78,43 +78,40 @@ function Close-CursorProcess {
7878

7979
$retryCount++
8080
if ($retryCount -ge $MAX_RETRIES) {
81-
Write-Host "$RED[错误]$NC $MAX_RETRIES 次尝试后仍无法关闭 $processName"
81+
Write-Host "$RED[ERROR]$NC Failed to close $processName after $MAX_RETRIES attempts"
8282
Get-ProcessDetails $processName
83-
Write-Host "$RED[错误]$NC 请手动关闭进程后重试"
84-
Read-Host "按回车键退出"
83+
Write-Host "$RED[ERROR]$NC Please close the process manually and try again"
84+
Read-Host "Press Enter to exit"
8585
exit 1
8686
}
87-
Write-Host "$YELLOW[警告]$NC 等待进程关闭,尝试 $retryCount/$MAX_RETRIES..."
87+
Write-Host "$YELLOW[WARNING]$NC Waiting for process termination, attempt $retryCount/$MAX_RETRIES..."
8888
Start-Sleep -Seconds $WAIT_TIME
8989
}
90-
Write-Host "$GREEN[信息]$NC $processName 已成功关闭"
90+
Write-Host "$GREEN[INFO]$NC Successfully closed $processName"
9191
}
9292
}
9393

94-
# 关闭所有 Cursor 进程
95-
Close-CursorProcess "Cursor"
96-
Close-CursorProcess "cursor"
94+
# Close all SAJJAD processes
95+
Close-SAJJADProcess "SAJJAD"
96+
Close-SAJJADProcess "sajjad"
9797

98-
# 创建备份目录
98+
# Create backup directory
9999
if (-not (Test-Path $BACKUP_DIR)) {
100100
New-Item -ItemType Directory -Path $BACKUP_DIR | Out-Null
101101
}
102102

103-
# 备份现有配置
103+
# Backup existing configuration
104104
if (Test-Path $STORAGE_FILE) {
105-
Write-Host "$GREEN[信息]$NC 正在备份配置文件..."
105+
Write-Host "$GREEN[INFO]$NC Creating configuration backup..."
106106
$backupName = "storage.json.backup_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
107107
Copy-Item $STORAGE_FILE "$BACKUP_DIR\$backupName"
108108
}
109109

110-
# 生成新的 ID
111-
Write-Host "$GREEN[信息]$NC 正在生成新的 ID..."
110+
# Generate new ID
111+
Write-Host "$GREEN[INFO]$NC Generating new ID..."
112112

113-
# 生成随机字节数组并转换为十六进制字符串的函数
114113
function Get-RandomHex {
115-
param (
116-
[int]$length
117-
)
114+
param ([int]$length)
118115
$bytes = New-Object byte[] $length
119116
$rng = [System.Security.Cryptography.RNGCryptoServiceProvider]::new()
120117
$rng.GetBytes($bytes)
@@ -123,58 +120,48 @@ function Get-RandomHex {
123120
}
124121

125122
$UUID = [System.Guid]::NewGuid().ToString()
126-
# 将 auth0|user_ 转换为字节数组的十六进制
127123
$prefixBytes = [System.Text.Encoding]::UTF8.GetBytes("auth0|user_")
128124
$prefixHex = -join ($prefixBytes | ForEach-Object { '{0:x2}' -f $_ })
129-
# 生成32字节(64个十六进制字符)的随机数作为 machineId 的随机部分
130125
$randomPart = Get-RandomHex -length 32
131126
$MACHINE_ID = "$prefixHex$randomPart"
132127
$MAC_MACHINE_ID = Get-RandomHex -length 32
133128
$SQM_ID = "{$([System.Guid]::NewGuid().ToString().ToUpper())}"
134129

135-
# 创建或更新配置文件
136-
Write-Host "$GREEN[信息]$NC 正在更新配置..."
130+
# Update configuration
131+
Write-Host "$GREEN[INFO]$NC Updating configuration..."
137132

138133
try {
139-
# 确保目录存在
140134
$storageDir = Split-Path $STORAGE_FILE -Parent
141135
if (-not (Test-Path $storageDir)) {
142136
New-Item -ItemType Directory -Path $storageDir -Force | Out-Null
143137
}
144138

145-
# 写入配置
146139
$config = @{
147140
'telemetry.machineId' = $MACHINE_ID
148141
'telemetry.macMachineId' = $MAC_MACHINE_ID
149142
'telemetry.devDeviceId' = $UUID
150143
'telemetry.sqmId' = $SQM_ID
151144
}
152145

153-
# 使用 System.IO.File 方法写入文件
154146
try {
155147
$jsonContent = $config | ConvertTo-Json
156148
[System.IO.File]::WriteAllText(
157149
[System.IO.Path]::GetFullPath($STORAGE_FILE),
158150
$jsonContent,
159151
[System.Text.Encoding]::UTF8
160152
)
161-
Write-Host "$GREEN[信息]$NC 成功写入配置文件"
153+
Write-Host "$GREEN[INFO]$NC Configuration file updated successfully"
162154
} catch {
163-
throw "写入文件失败: $_"
155+
throw "File write failed: $_"
164156
}
165157

166-
# 尝试设置文件权限
167158
try {
168-
# 使用当前用户名和域名
169159
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
170160
$userAccount = "$($env:USERDOMAIN)\$($env:USERNAME)"
171161

172-
# 创建新的访问控制列表
173162
$acl = New-Object System.Security.AccessControl.FileSecurity
174-
175-
# 添加当前用户的完全控制权限
176163
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
177-
$userAccount, # 使用域名\用户名格式
164+
$userAccount,
178165
[System.Security.AccessControl.FileSystemRights]::FullControl,
179166
[System.Security.AccessControl.InheritanceFlags]::None,
180167
[System.Security.AccessControl.PropagationFlags]::None,
@@ -184,128 +171,104 @@ try {
184171
try {
185172
$acl.AddAccessRule($accessRule)
186173
Set-Acl -Path $STORAGE_FILE -AclObject $acl -ErrorAction Stop
187-
Write-Host "$GREEN[信息]$NC 成功设置文件权限"
174+
Write-Host "$GREEN[INFO]$NC File permissions set successfully"
188175
} catch {
189-
# 如果第一种方法失败,尝试使用 icacls
190-
Write-Host "$YELLOW[警告]$NC 使用备选方法设置权限..."
176+
Write-Host "$YELLOW[WARNING]$NC Using fallback permission method..."
191177
$result = Start-Process "icacls.exe" -ArgumentList "`"$STORAGE_FILE`" /grant `"$($env:USERNAME):(F)`"" -Wait -NoNewWindow -PassThru
192178
if ($result.ExitCode -eq 0) {
193-
Write-Host "$GREEN[信息]$NC 成功使用 icacls 设置文件权限"
179+
Write-Host "$GREEN[INFO]$NC Permissions set using icacls"
194180
} else {
195-
Write-Host "$YELLOW[警告]$NC 设置文件权限失败,但文件已写入成功"
181+
Write-Host "$YELLOW[WARNING]$NC File permissions failed but write succeeded"
196182
}
197183
}
198184
} catch {
199-
Write-Host "$YELLOW[警告]$NC 设置文件权限失败: $_"
200-
Write-Host "$YELLOW[警告]$NC 尝试使用 icacls 命令..."
201-
try {
202-
$result = Start-Process "icacls.exe" -ArgumentList "`"$STORAGE_FILE`" /grant `"$($env:USERNAME):(F)`"" -Wait -NoNewWindow -PassThru
203-
if ($result.ExitCode -eq 0) {
204-
Write-Host "$GREEN[信息]$NC 成功使用 icacls 设置文件权限"
205-
} else {
206-
Write-Host "$YELLOW[警告]$NC 所有权限设置方法都失败,但文件已写入成功"
207-
}
208-
} catch {
209-
Write-Host "$YELLOW[警告]$NC icacls 命令失败: $_"
210-
}
185+
Write-Host "$YELLOW[WARNING]$NC Permission setting failed: $_"
211186
}
212187

213188
} catch {
214-
Write-Host "$RED[错误]$NC 主要操作失败: $_"
215-
Write-Host "$YELLOW[尝试]$NC 使用备选方法..."
189+
Write-Host "$RED[ERROR]$NC Main operation failed: $_"
216190

217191
try {
218-
# 备选方法:使用 Add-Content
219192
$tempFile = [System.IO.Path]::GetTempFileName()
220193
$config | ConvertTo-Json | Set-Content -Path $tempFile -Encoding UTF8
221194
Copy-Item -Path $tempFile -Destination $STORAGE_FILE -Force
222195
Remove-Item -Path $tempFile
223-
Write-Host "$GREEN[信息]$NC 使用备选方法成功写入配置"
196+
Write-Host "$GREEN[INFO]$NC Configuration updated using fallback method"
224197
} catch {
225-
Write-Host "$RED[错误]$NC 所有尝试都失败了"
226-
Write-Host "错误详情: $_"
227-
Write-Host "目标文件: $STORAGE_FILE"
228-
Write-Host "请确保您有足够的权限访问该文件"
229-
Read-Host "按回车键退出"
198+
Write-Host "$RED[ERROR]$NC All methods failed"
199+
Write-Host "Error details: $_"
200+
Write-Host "Target file: $STORAGE_FILE"
201+
Read-Host "Press Enter to exit"
230202
exit 1
231203
}
232204
}
233205

234-
# 显示结果
206+
# Display results
235207
Write-Host ""
236-
Write-Host "$GREEN[信息]$NC 已更新配置:"
237-
Write-Host "$BLUE[调试]$NC machineId: $MACHINE_ID"
238-
Write-Host "$BLUE[调试]$NC macMachineId: $MAC_MACHINE_ID"
239-
Write-Host "$BLUE[调试]$NC devDeviceId: $UUID"
240-
Write-Host "$BLUE[调试]$NC sqmId: $SQM_ID"
208+
Write-Host "$GREEN[INFO]$NC Updated configuration:"
209+
Write-Host "$BLUE[DEBUG]$NC machineId: $MACHINE_ID"
210+
Write-Host "$BLUE[DEBUG]$NC macMachineId: $MAC_MACHINE_ID"
211+
Write-Host "$BLUE[DEBUG]$NC devDeviceId: $UUID"
212+
Write-Host "$BLUE[DEBUG]$NC sqmId: $SQM_ID"
241213

242-
# 显示文件树结构
214+
# Display file structure
243215
Write-Host ""
244-
Write-Host "$GREEN[信息]$NC 文件结构:"
245-
Write-Host "$BLUE$env:APPDATA\Cursor\User$NC"
216+
Write-Host "$GREEN[INFO]$NC File structure:"
217+
Write-Host "$BLUE$env:APPDATA\SAJJAD\User$NC"
246218
Write-Host "├── globalStorage"
247-
Write-Host "│ ├── storage.json (已修改)"
219+
Write-Host "│ ├── storage.json (modified)"
248220
Write-Host "│ └── backups"
249221

250-
# 列出备份文件
222+
# List backup files
251223
$backupFiles = Get-ChildItem "$BACKUP_DIR\*" -ErrorAction SilentlyContinue
252224
if ($backupFiles) {
253225
foreach ($file in $backupFiles) {
254226
Write-Host "│ └── $($file.Name)"
255227
}
256228
} else {
257-
Write-Host "│ └── ()"
229+
Write-Host "│ └── (empty)"
258230
}
259231

260-
# 显示公众号信息
232+
# Final instructions
261233
Write-Host ""
262234
Write-Host "$GREEN================================$NC"
263-
Write-Host "$YELLOW 关注公众号【煎饼果子卷AI】一起交流更多Cursor技巧和AI知识 $NC"
264-
Write-Host "$GREEN================================$NC"
265-
Write-Host ""
266-
Write-Host "$GREEN[信息]$NC 请重启 Cursor 以应用新的配置"
235+
Write-Host "$GREEN[INFO]$NC Please restart SAJJAD to apply changes"
267236
Write-Host ""
268237

269-
# 询问是否要禁用自动更新
238+
# Disable auto-update prompt
270239
Write-Host ""
271-
Write-Host "$YELLOW[询问]$NC 是否要禁用 Cursor 自动更新功能?"
272-
Write-Host "0) - 保持默认设置 (按回车键)"
273-
Write-Host "1) - 禁用自动更新"
274-
$choice = Read-Host "请输入选项 (1 或直接回车)"
240+
Write-Host "$YELLOW[PROMPT]$NC Disable automatic updates?"
241+
Write-Host "0) No - Keep default settings (press Enter)"
242+
Write-Host "1) Yes - Disable auto-updates"
243+
$choice = Read-Host "Enter choice (1 or press Enter)"
275244

276245
if ($choice -eq "1") {
277246
Write-Host ""
278-
Write-Host "$GREEN[信息]$NC 正在处理自动更新..."
279-
$updaterPath = "$env:LOCALAPPDATA\cursor-updater"
247+
Write-Host "$GREEN[INFO]$NC Handling auto-updates..."
248+
$updaterPath = "$env:LOCALAPPDATA\sajjad-updater"
280249

281250
if (Test-Path $updaterPath) {
282251
try {
283-
# 强制删除目录
284252
Remove-Item -Path $updaterPath -Force -Recurse -ErrorAction Stop
285-
Write-Host "$GREEN[信息]$NC 成功删除 cursor-updater 目录"
286-
287-
# 创建同名文件
253+
Write-Host "$GREEN[INFO]$NC Removed updater directory"
288254
New-Item -Path $updaterPath -ItemType File -Force | Out-Null
289-
Write-Host "$GREEN[信息]$NC 成功创建阻止文件"
255+
Write-Host "$GREEN[INFO]$NC Created update blocker file"
290256
}
291257
catch {
292-
Write-Host "$RED[错误]$NC 处理 cursor-updater 时出错: $_"
258+
Write-Host "$RED[ERROR]$NC Update handling failed: $_"
293259
}
294260
}
295261
else {
296-
# 直接创建阻止文件
297262
New-Item -Path $updaterPath -ItemType File -Force | Out-Null
298-
Write-Host "$GREEN[信息]$NC 成功创建阻止文件"
263+
Write-Host "$GREEN[INFO]$NC Created update blocker file"
299264
}
300265
}
301266
elseif ($choice -ne "") {
302-
Write-Host "$YELLOW[信息]$NC 保持默认设置,不进行更改"
267+
Write-Host "$YELLOW[INFO]$NC Keeping default settings"
303268
}
304269
else {
305-
Write-Host "$YELLOW[信息]$NC 保持默认设置,不进行更改"
270+
Write-Host "$YELLOW[INFO]$NC Keeping default settings"
306271
}
307272

308-
309-
310-
Read-Host "按回车键退出"
311-
exit 0
273+
Read-Host "Press Enter to exit"
274+
exit 0

0 commit comments

Comments
 (0)