From 0c52882a9eb004cca89b2ab7251f79ddae751786 Mon Sep 17 00:00:00 2001 From: chengchongzhen <15939054361@163.com> Date: Wed, 15 Jan 2025 14:27:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=87=8D=E7=BD=AE=E6=9C=BA=E5=99=A8id;?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E6=8F=90=E7=A4=BA=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=A4=87=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reset_machine.py | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/reset_machine.py b/reset_machine.py index fea4233f..ddb9039b 100644 --- a/reset_machine.py +++ b/reset_machine.py @@ -30,17 +30,19 @@ def __init__(self): self.db_path = os.path.join( appdata, "Cursor", "User", "globalStorage", "storage.json" ) - elif sys.platform == "darwin": # macOS - self.db_path = os.path.abspath(os.path.expanduser( - "~/Library/Application Support/Cursor/User/globalStorage/storage.json" - )) - elif sys.platform == "linux": # Linux 和其他类Unix系统 - self.db_path = os.path.abspath(os.path.expanduser( - "~/.config/Cursor/User/globalStorage/storage.json" - )) + elif sys.platform == "darwin": # macOS + self.db_path = os.path.abspath( + os.path.expanduser( + "~/Library/Application Support/Cursor/User/globalStorage/storage.json" + ) + ) + elif sys.platform == "linux": # Linux 和其他类Unix系统 + self.db_path = os.path.abspath( + os.path.expanduser("~/.config/Cursor/User/globalStorage/storage.json") + ) else: raise NotImplementedError(f"不支持的操作系统: {sys.platform}") - + def generate_new_ids(self): """生成新的机器ID""" # 生成新的UUID @@ -79,6 +81,9 @@ def reset_machine_ids(self): print( f"{Fore.RED}{EMOJI['ERROR']} 无法读写配置文件,请检查文件权限!{Style.RESET_ALL}" ) + print( + f"{Fore.RED}{EMOJI['ERROR']} 如果你使用过 go-cursor-help 来修改 ID; 请修改文件只读权限 {self.db_path} {Style.RESET_ALL}" + ) return False # 读取现有配置 @@ -86,18 +91,6 @@ def reset_machine_ids(self): with open(self.db_path, "r", encoding="utf-8") as f: config = json.load(f) - # 只在没有备份文件时创建备份 - backup_path = self.db_path + ".bak" - if not os.path.exists(backup_path): - print( - f"{Fore.YELLOW}{EMOJI['BACKUP']} 创建配置备份: {backup_path}{Style.RESET_ALL}" - ) - shutil.copy2(self.db_path, backup_path) - else: - print( - f"{Fore.YELLOW}{EMOJI['INFO']} 已存在备份文件,跳过备份步骤{Style.RESET_ALL}" - ) - # 生成新的ID print(f"{Fore.CYAN}{EMOJI['RESET']} 生成新的机器标识...{Style.RESET_ALL}") new_ids = self.generate_new_ids() @@ -125,6 +118,7 @@ def reset_machine_ids(self): return False except Exception as e: print(f"{Fore.RED}{EMOJI['ERROR']} 重置过程出错: {str(e)}{Style.RESET_ALL}") + return False