-
Notifications
You must be signed in to change notification settings - Fork 45
/
reset.py
75 lines (59 loc) · 2.25 KB
/
reset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
'''
Cursor Trial Reset Tool
This script resets the device IDs in Cursor's configuration file to generate a new random device ID.
Repository: https://github.com/ultrasev/cursor-reset
Author: @ultrasev
Created: 10/Dec/2024
'''
import json
import os
import shutil
import uuid
from datetime import datetime
from pathlib import Path
import platform
def backup_file(file_path: str):
"""Create a timestamped backup of the given file."""
if os.path.exists(file_path):
backup_path = f"{file_path}.backup_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
shutil.copy2(file_path, backup_path)
def get_storage_file():
"""Determine the storage file location based on the operating system."""
system = platform.system()
if system == "Windows":
return Path(os.getenv("APPDATA")) / "Cursor" / "User" / "globalStorage" / "storage.json"
elif system == "Darwin": # macOS
return Path(os.path.expanduser("~")) / "Library" / "Application Support" / "Cursor" / "User" / "globalStorage" / "storage.json"
elif system == "Linux":
return Path(os.path.expanduser("~")) / ".config" / "Cursor" / "User" / "globalStorage" / "storage.json"
else:
raise OSError(f"Unsupported operating system: {system}")
def reset_cursor_id():
storage_file = get_storage_file()
storage_file.parent.mkdir(parents=True, exist_ok=True)
backup_file(storage_file)
if not storage_file.exists():
data = {}
else:
with open(storage_file, 'r', encoding='utf-8') as f:
data = json.load(f)
machine_id = os.urandom(32).hex()
mac_machine_id = os.urandom(32).hex()
dev_device_id = str(uuid.uuid4())
data["telemetry.machineId"] = machine_id
data["telemetry.macMachineId"] = mac_machine_id
data["telemetry.devDeviceId"] = dev_device_id
with open(storage_file, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2)
print("🎉 Device IDs have been successfully reset. The new device IDs are: \n")
print(
json.dumps(
{
"machineId": machine_id,
"macMachineId": mac_machine_id,
"devDeviceId": dev_device_id,
},
indent=2))
if __name__ == "__main__":
reset_cursor_id()