1
- # 设置输出编码为 UTF-8
1
+ # Set output encoding to UTF-8
2
2
$OutputEncoding = [System.Text.Encoding ]::UTF8
3
3
[Console ]::OutputEncoding = [System.Text.Encoding ]::UTF8
4
4
5
- # 颜色定义
5
+ # Color definitions
6
6
$RED = " `e [31m"
7
7
$GREEN = " `e [32m"
8
8
$YELLOW = " `e [33m"
9
9
$BLUE = " `e [34m"
10
10
$NC = " `e [0m"
11
11
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"
15
15
16
- # 检查管理员权限
16
+ # Check administrator privileges
17
17
function Test-Administrator {
18
18
$user = [Security.Principal.WindowsIdentity ]::GetCurrent()
19
19
$principal = New-Object Security.Principal.WindowsPrincipal($user )
20
20
return $principal.IsInRole ([Security.Principal.WindowsBuiltInRole ]::Administrator)
21
21
}
22
22
23
23
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 "
27
27
exit 1
28
28
}
29
29
30
- # 显示 Logo
30
+ # Display Logo
31
31
Clear-Host
32
32
Write-Host @"
33
33
34
- ██████╗██╗ ██╗ ██████╗ ██ █████╗ ██████╗ ██████╗
35
- ██╔════╝██║ ██║██╔══██╗██╔════╝██╔═ ══██╗██╔══██╗
36
- ██ ║ ██║ ██║██████╔╝███████╗██ ║ ██║██████╔╝
37
- ██║ ██║ ██║██╔══██╗╚════██ ║██║ ██║██╔══██╗
38
- ╚ ██████╗╚██████╔╝██ ║ ██║ ███████║╚██████ ╔╝██║ ██║
39
- ╚═════╝ ╚═ ════╝ ╚═╝ ╚═╝╚══════ ╝ ╚═════╝ ╚═╝ ╚═╝
34
+ ███████╗ ██ ███╗ ██╗ ██╗ █████╗ ██████╗ ██████╗
35
+ ██╔════╝██╔══██╗ ██ ║ ██║██╔══██╗██╔══██╗██╔══██╗
36
+ ███████╗███████ ║ ██║ ██║███████║██ ║ ██║██║ ██║
37
+ ╚════ ██║██╔══██║ ██║ ██║██╔══██║██║ ██║██║ ██║
38
+ ███████║██║ ██ ║ ██ █████╗ ██║██║ ██║██████ ╔╝██████╔╝
39
+ ╚══════╝╚═╝ ╚═╝ ╚ ══════╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═════╝
40
40
41
41
"@
42
42
Write-Host " $BLUE ================================$NC "
43
- Write-Host " $GREEN Cursor ID 修改工具 $NC "
43
+ Write-Host " $GREEN SAJJAD ID Modifier $NC "
44
44
Write-Host " $BLUE ================================$NC "
45
45
Write-Host " "
46
46
47
- # 检查并关闭 Cursor 进程
48
- Write-Host " $GREEN [信息 ]$NC 检查 Cursor 进程 ..."
47
+ # Check and close SAJJAD processes
48
+ Write-Host " $GREEN [INFO ]$NC Checking SAJJAD processes ..."
49
49
50
50
function Get-ProcessDetails {
51
51
param ($processName )
52
- Write-Host " $BLUE [调试 ]$NC 正在获取 $processName 进程详细信息: "
52
+ Write-Host " $BLUE [DEBUG ]$NC Getting details for $processName processes: "
53
53
Get-WmiObject Win32_Process - Filter " name='$processName '" |
54
54
Select-Object ProcessId, ExecutablePath, CommandLine |
55
55
Format-List
56
56
}
57
57
58
- # 定义最大重试次数和等待时间
58
+ # Process closing parameters
59
59
$MAX_RETRIES = 5
60
60
$WAIT_TIME = 1
61
61
62
- # 处理进程关闭
63
- function Close-CursorProcess {
62
+ # Process closing function
63
+ function Close-SAJJADProcess {
64
64
param ($processName )
65
65
66
66
$process = Get-Process - Name $processName - ErrorAction SilentlyContinue
67
67
if ($process ) {
68
- Write-Host " $YELLOW [警告 ]$NC 发现 $processName 正在运行 "
68
+ Write-Host " $YELLOW [WARNING ]$NC Found running $processName process "
69
69
Get-ProcessDetails $processName
70
70
71
- Write-Host " $YELLOW [警告 ]$NC 尝试关闭 $processName ..."
71
+ Write-Host " $YELLOW [WARNING ]$NC Attempting to close $processName ..."
72
72
Stop-Process - Name $processName - Force
73
73
74
74
$retryCount = 0
@@ -78,43 +78,40 @@ function Close-CursorProcess {
78
78
79
79
$retryCount ++
80
80
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 "
82
82
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 "
85
85
exit 1
86
86
}
87
- Write-Host " $YELLOW [警告 ]$NC 等待进程关闭,尝试 $retryCount /$MAX_RETRIES ..."
87
+ Write-Host " $YELLOW [WARNING ]$NC Waiting for process termination, attempt $retryCount /$MAX_RETRIES ..."
88
88
Start-Sleep - Seconds $WAIT_TIME
89
89
}
90
- Write-Host " $GREEN [信息 ]$NC $processName 已成功关闭 "
90
+ Write-Host " $GREEN [INFO ]$NC Successfully closed $processName "
91
91
}
92
92
}
93
93
94
- # 关闭所有 Cursor 进程
95
- Close-CursorProcess " Cursor "
96
- Close-CursorProcess " cursor "
94
+ # Close all SAJJAD processes
95
+ Close-SAJJADProcess " SAJJAD "
96
+ Close-SAJJADProcess " sajjad "
97
97
98
- # 创建备份目录
98
+ # Create backup directory
99
99
if (-not (Test-Path $BACKUP_DIR )) {
100
100
New-Item - ItemType Directory - Path $BACKUP_DIR | Out-Null
101
101
}
102
102
103
- # 备份现有配置
103
+ # Backup existing configuration
104
104
if (Test-Path $STORAGE_FILE ) {
105
- Write-Host " $GREEN [信息 ]$NC 正在备份配置文件 ..."
105
+ Write-Host " $GREEN [INFO ]$NC Creating configuration backup ..."
106
106
$backupName = " storage.json.backup_$ ( Get-Date - Format ' yyyyMMdd_HHmmss' ) "
107
107
Copy-Item $STORAGE_FILE " $BACKUP_DIR \$backupName "
108
108
}
109
109
110
- # 生成新的 ID
111
- Write-Host " $GREEN [信息 ]$NC 正在生成新的 ID..."
110
+ # Generate new ID
111
+ Write-Host " $GREEN [INFO ]$NC Generating new ID..."
112
112
113
- # 生成随机字节数组并转换为十六进制字符串的函数
114
113
function Get-RandomHex {
115
- param (
116
- [int ]$length
117
- )
114
+ param ([int ]$length )
118
115
$bytes = New-Object byte[] $length
119
116
$rng = [System.Security.Cryptography.RNGCryptoServiceProvider ]::new()
120
117
$rng.GetBytes ($bytes )
@@ -123,58 +120,48 @@ function Get-RandomHex {
123
120
}
124
121
125
122
$UUID = [System.Guid ]::NewGuid().ToString()
126
- # 将 auth0|user_ 转换为字节数组的十六进制
127
123
$prefixBytes = [System.Text.Encoding ]::UTF8.GetBytes(" auth0|user_" )
128
124
$prefixHex = -join ($prefixBytes | ForEach-Object { ' {0:x2}' -f $_ })
129
- # 生成32字节(64个十六进制字符)的随机数作为 machineId 的随机部分
130
125
$randomPart = Get-RandomHex - length 32
131
126
$MACHINE_ID = " $prefixHex$randomPart "
132
127
$MAC_MACHINE_ID = Get-RandomHex - length 32
133
128
$SQM_ID = " {$ ( [System.Guid ]::NewGuid().ToString().ToUpper()) }"
134
129
135
- # 创建或更新配置文件
136
- Write-Host " $GREEN [信息 ]$NC 正在更新配置 ..."
130
+ # Update configuration
131
+ Write-Host " $GREEN [INFO ]$NC Updating configuration ..."
137
132
138
133
try {
139
- # 确保目录存在
140
134
$storageDir = Split-Path $STORAGE_FILE - Parent
141
135
if (-not (Test-Path $storageDir )) {
142
136
New-Item - ItemType Directory - Path $storageDir - Force | Out-Null
143
137
}
144
138
145
- # 写入配置
146
139
$config = @ {
147
140
' telemetry.machineId' = $MACHINE_ID
148
141
' telemetry.macMachineId' = $MAC_MACHINE_ID
149
142
' telemetry.devDeviceId' = $UUID
150
143
' telemetry.sqmId' = $SQM_ID
151
144
}
152
145
153
- # 使用 System.IO.File 方法写入文件
154
146
try {
155
147
$jsonContent = $config | ConvertTo-Json
156
148
[System.IO.File ]::WriteAllText(
157
149
[System.IO.Path ]::GetFullPath($STORAGE_FILE ),
158
150
$jsonContent ,
159
151
[System.Text.Encoding ]::UTF8
160
152
)
161
- Write-Host " $GREEN [信息 ]$NC 成功写入配置文件 "
153
+ Write-Host " $GREEN [INFO ]$NC Configuration file updated successfully "
162
154
} catch {
163
- throw " 写入文件失败 : $_ "
155
+ throw " File write failed : $_ "
164
156
}
165
157
166
- # 尝试设置文件权限
167
158
try {
168
- # 使用当前用户名和域名
169
159
$currentUser = [System.Security.Principal.WindowsIdentity ]::GetCurrent()
170
160
$userAccount = " $ ( $env: USERDOMAIN ) \$ ( $env: USERNAME ) "
171
161
172
- # 创建新的访问控制列表
173
162
$acl = New-Object System.Security.AccessControl.FileSecurity
174
-
175
- # 添加当前用户的完全控制权限
176
163
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
177
- $userAccount , # 使用域名\用户名格式
164
+ $userAccount ,
178
165
[System.Security.AccessControl.FileSystemRights ]::FullControl,
179
166
[System.Security.AccessControl.InheritanceFlags ]::None,
180
167
[System.Security.AccessControl.PropagationFlags ]::None,
@@ -184,128 +171,104 @@ try {
184
171
try {
185
172
$acl.AddAccessRule ($accessRule )
186
173
Set-Acl - Path $STORAGE_FILE - AclObject $acl - ErrorAction Stop
187
- Write-Host " $GREEN [信息 ]$NC 成功设置文件权限 "
174
+ Write-Host " $GREEN [INFO ]$NC File permissions set successfully "
188
175
} catch {
189
- # 如果第一种方法失败,尝试使用 icacls
190
- Write-Host " $YELLOW [警告]$NC 使用备选方法设置权限..."
176
+ Write-Host " $YELLOW [WARNING]$NC Using fallback permission method..."
191
177
$result = Start-Process " icacls.exe" - ArgumentList " `" $STORAGE_FILE `" /grant `" $ ( $env: USERNAME ) :(F)`" " - Wait - NoNewWindow - PassThru
192
178
if ($result.ExitCode -eq 0 ) {
193
- Write-Host " $GREEN [信息 ]$NC 成功使用 icacls 设置文件权限 "
179
+ Write-Host " $GREEN [INFO ]$NC Permissions set using icacls "
194
180
} else {
195
- Write-Host " $YELLOW [警告 ]$NC 设置文件权限失败,但文件已写入成功 "
181
+ Write-Host " $YELLOW [WARNING ]$NC File permissions failed but write succeeded "
196
182
}
197
183
}
198
184
} 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: $_ "
211
186
}
212
187
213
188
} catch {
214
- Write-Host " $RED [错误]$NC 主要操作失败: $_ "
215
- Write-Host " $YELLOW [尝试]$NC 使用备选方法..."
189
+ Write-Host " $RED [ERROR]$NC Main operation failed: $_ "
216
190
217
191
try {
218
- # 备选方法:使用 Add-Content
219
192
$tempFile = [System.IO.Path ]::GetTempFileName()
220
193
$config | ConvertTo-Json | Set-Content - Path $tempFile - Encoding UTF8
221
194
Copy-Item - Path $tempFile - Destination $STORAGE_FILE - Force
222
195
Remove-Item - Path $tempFile
223
- Write-Host " $GREEN [信息 ]$NC 使用备选方法成功写入配置 "
196
+ Write-Host " $GREEN [INFO ]$NC Configuration updated using fallback method "
224
197
} 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"
230
202
exit 1
231
203
}
232
204
}
233
205
234
- # 显示结果
206
+ # Display results
235
207
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 "
241
213
242
- # 显示文件树结构
214
+ # Display file structure
243
215
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 "
246
218
Write-Host " ├── globalStorage"
247
- Write-Host " │ ├── storage.json (已修改 )"
219
+ Write-Host " │ ├── storage.json (modified )"
248
220
Write-Host " │ └── backups"
249
221
250
- # 列出备份文件
222
+ # List backup files
251
223
$backupFiles = Get-ChildItem " $BACKUP_DIR \*" - ErrorAction SilentlyContinue
252
224
if ($backupFiles ) {
253
225
foreach ($file in $backupFiles ) {
254
226
Write-Host " │ └── $ ( $file.Name ) "
255
227
}
256
228
} else {
257
- Write-Host " │ └── (空 )"
229
+ Write-Host " │ └── (empty )"
258
230
}
259
231
260
- # 显示公众号信息
232
+ # Final instructions
261
233
Write-Host " "
262
234
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"
267
236
Write-Host " "
268
237
269
- # 询问是否要禁用自动更新
238
+ # Disable auto-update prompt
270
239
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 )"
275
244
276
245
if ($choice -eq " 1" ) {
277
246
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"
280
249
281
250
if (Test-Path $updaterPath ) {
282
251
try {
283
- # 强制删除目录
284
252
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"
288
254
New-Item - Path $updaterPath - ItemType File - Force | Out-Null
289
- Write-Host " $GREEN [信息 ]$NC 成功创建阻止文件 "
255
+ Write-Host " $GREEN [INFO ]$NC Created update blocker file "
290
256
}
291
257
catch {
292
- Write-Host " $RED [错误 ]$NC 处理 cursor-updater 时出错 : $_ "
258
+ Write-Host " $RED [ERROR ]$NC Update handling failed : $_ "
293
259
}
294
260
}
295
261
else {
296
- # 直接创建阻止文件
297
262
New-Item - Path $updaterPath - ItemType File - Force | Out-Null
298
- Write-Host " $GREEN [信息 ]$NC 成功创建阻止文件 "
263
+ Write-Host " $GREEN [INFO ]$NC Created update blocker file "
299
264
}
300
265
}
301
266
elseif ($choice -ne " " ) {
302
- Write-Host " $YELLOW [信息 ]$NC 保持默认设置,不进行更改 "
267
+ Write-Host " $YELLOW [INFO ]$NC Keeping default settings "
303
268
}
304
269
else {
305
- Write-Host " $YELLOW [信息 ]$NC 保持默认设置,不进行更改 "
270
+ Write-Host " $YELLOW [INFO ]$NC Keeping default settings "
306
271
}
307
272
308
-
309
-
310
- Read-Host " 按回车键退出"
311
- exit 0
273
+ Read-Host " Press Enter to exit"
274
+ exit 0
0 commit comments