import os
import uuid
import json
# 生成随机标识符
def generate_random_hex_id():
return "".join([f"{byte:02x}" for byte in os.urandom(32)])
def generate_uuid():
return str(uuid.uuid4()) # 生成标准UUID
def change(mode):
user_name = os.getenv("USERNAME")
if mode == "1":
file_path = rf"C:\Users\{user_name}\AppData\Roaming\Cursor\User\globalStorage\storage.json"
else:
file_path = rf"C:\Users\{user_name}\AppData\Roaming\Windsurf\User\globalStorage\storage.json"
print(file_path)
with open(file_path, "r") as f:
data = f.read()
data_info = json.loads(data)
if "telemetry.sqmId" in data_info:
data_info["telemetry.sqmId"] = f"{{{generate_uuid().upper()}}}"
if "telemetry.machineId" in data_info:
data_info["telemetry.machineId"] = generate_random_hex_id()
if "telemetry.macMachineId" in data_info:
data_info["telemetry.macMachineId"] = generate_random_hex_id()
if "telemetry.devDeviceId" in data_info:
data_info["telemetry.devDeviceId"] = generate_uuid()
with open(file_path, "w") as f:
json.dump(data_info, f, ensure_ascii=False, indent=4)
print(f"{'cursor' if mode == '1' else 'windsurf'}修改成功")
if __name__ == "__main__":
mode = ""
while True:
mode = input("cursor 输入1 windsurf输入2\nmode:")
if mode not in ["1", "2"]:
print("输入错误")
continue
break
change(mode)