Skip to content
This repository was archived by the owner on Apr 20, 2025. It is now read-only.

Commit 0c52882

Browse files
committed
feat: 重置机器id; 增加提示删除备份
1 parent 7ce80bd commit 0c52882

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

Diff for: reset_machine.py

+15-21
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ def __init__(self):
3030
self.db_path = os.path.join(
3131
appdata, "Cursor", "User", "globalStorage", "storage.json"
3232
)
33-
elif sys.platform == "darwin": # macOS
34-
self.db_path = os.path.abspath(os.path.expanduser(
35-
"~/Library/Application Support/Cursor/User/globalStorage/storage.json"
36-
))
37-
elif sys.platform == "linux": # Linux 和其他类Unix系统
38-
self.db_path = os.path.abspath(os.path.expanduser(
39-
"~/.config/Cursor/User/globalStorage/storage.json"
40-
))
33+
elif sys.platform == "darwin": # macOS
34+
self.db_path = os.path.abspath(
35+
os.path.expanduser(
36+
"~/Library/Application Support/Cursor/User/globalStorage/storage.json"
37+
)
38+
)
39+
elif sys.platform == "linux": # Linux 和其他类Unix系统
40+
self.db_path = os.path.abspath(
41+
os.path.expanduser("~/.config/Cursor/User/globalStorage/storage.json")
42+
)
4143
else:
4244
raise NotImplementedError(f"不支持的操作系统: {sys.platform}")
43-
45+
4446
def generate_new_ids(self):
4547
"""生成新的机器ID"""
4648
# 生成新的UUID
@@ -79,25 +81,16 @@ def reset_machine_ids(self):
7981
print(
8082
f"{Fore.RED}{EMOJI['ERROR']} 无法读写配置文件,请检查文件权限!{Style.RESET_ALL}"
8183
)
84+
print(
85+
f"{Fore.RED}{EMOJI['ERROR']} 如果你使用过 go-cursor-help 来修改 ID; 请修改文件只读权限 {self.db_path} {Style.RESET_ALL}"
86+
)
8287
return False
8388

8489
# 读取现有配置
8590
print(f"{Fore.CYAN}{EMOJI['FILE']} 读取当前配置...{Style.RESET_ALL}")
8691
with open(self.db_path, "r", encoding="utf-8") as f:
8792
config = json.load(f)
8893

89-
# 只在没有备份文件时创建备份
90-
backup_path = self.db_path + ".bak"
91-
if not os.path.exists(backup_path):
92-
print(
93-
f"{Fore.YELLOW}{EMOJI['BACKUP']} 创建配置备份: {backup_path}{Style.RESET_ALL}"
94-
)
95-
shutil.copy2(self.db_path, backup_path)
96-
else:
97-
print(
98-
f"{Fore.YELLOW}{EMOJI['INFO']} 已存在备份文件,跳过备份步骤{Style.RESET_ALL}"
99-
)
100-
10194
# 生成新的ID
10295
print(f"{Fore.CYAN}{EMOJI['RESET']} 生成新的机器标识...{Style.RESET_ALL}")
10396
new_ids = self.generate_new_ids()
@@ -125,6 +118,7 @@ def reset_machine_ids(self):
125118
return False
126119
except Exception as e:
127120
print(f"{Fore.RED}{EMOJI['ERROR']} 重置过程出错: {str(e)}{Style.RESET_ALL}")
121+
128122
return False
129123

130124

0 commit comments

Comments
 (0)