From 0435e586ab9c94668fe0e9292922e3fd0da104e3 Mon Sep 17 00:00:00 2001 From: huangzhenpc Date: Wed, 12 Feb 2025 10:49:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0:=201.=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=85=B3=E9=97=AD=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6=E6=B8=85?= =?UTF-8?q?=E7=90=86=E9=97=AE=E9=A2=98=202.=20=E6=9B=B4=E6=96=B0=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E7=89=88=E6=9C=AC=E5=88=B0=203.0.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account_switcher.py | 75 +++++++++++++++++++++++++++++++++++++++------ gui/main_window.py | 29 ++++++++++++++++-- version.txt | 2 +- 3 files changed, 92 insertions(+), 14 deletions(-) diff --git a/account_switcher.py b/account_switcher.py index ec09585..c0ef5f8 100644 --- a/account_switcher.py +++ b/account_switcher.py @@ -257,25 +257,80 @@ class AccountSwitcher: def reset_machine_id(self) -> bool: """重置机器码""" try: - # 读取package.json - with open(self.package_json, "r", encoding="utf-8") as f: - data = json.load(f) + # 1. 先关闭所有Cursor进程 + if sys.platform == "win32": + os.system("taskkill /f /im Cursor.exe >nul 2>&1") + time.sleep(2) - # 删除machineId - if "machineId" in data: - del data["machineId"] - - # 保存文件 - with open(self.package_json, "w", encoding="utf-8") as f: - json.dump(data, f, indent=2) + # 2. 删除 package.json 中的 machineId + if self.package_json.exists(): + with open(self.package_json, "r", encoding="utf-8") as f: + data = json.load(f) + if "machineId" in data: + del data["machineId"] + + with open(self.package_json, "w", encoding="utf-8") as f: + json.dump(data, f, indent=2) + + # 3. 清理特定的配置文件 + local_app_data = Path(os.getenv('LOCALAPPDATA')) + cursor_path = local_app_data / "Cursor" + + config_files = [ + cursor_path / "User" / "globalStorage" / "storage.json", + cursor_path / "User" / "globalStorage" / "state.json", + self.app_path / "config.json", + self.app_path / "state.json", + self.app_path / "settings.json" + ] + + for file_path in config_files: + if file_path.exists(): + try: + os.remove(file_path) + logging.info(f"删除配置文件成功: {file_path}") + except Exception as e: + logging.warning(f"删除配置文件失败: {file_path}, 错误: {str(e)}") + + # 4. 刷新注册表 + if not self.registry.refresh_registry(): + logging.warning("注册表刷新失败") + + # 5. 重启Cursor + cursor_exe = self.cursor_path / "Cursor.exe" + if cursor_exe.exists(): + os.startfile(str(cursor_exe)) + logging.info("Cursor重启成功") + logging.info("机器码重置完成") return True except Exception as e: logging.error(f"重置机器码失败: {str(e)}") return False + + def bypass_version_limit(self) -> Tuple[bool, str]: + """突破Cursor版本限制""" + try: + # 1. 先关闭所有Cursor进程 + if sys.platform == "win32": + os.system("taskkill /f /im Cursor.exe >nul 2>&1") + time.sleep(2) + # 2. 重置机器码 + if not self.reset_machine_id(): + return False, "重置机器码失败" + + # 3. 等待Cursor启动 + time.sleep(3) + + return True, "突破版本限制成功,Cursor已重启" + + except Exception as e: + logging.error(f"突破版本限制失败: {str(e)}") + return False, f"突破失败: {str(e)}" + def activate_and_switch(self, activation_code: str) -> Tuple[bool, str]: """激活并切换账号 diff --git a/gui/main_window.py b/gui/main_window.py index d2e8d80..7c4b08d 100644 --- a/gui/main_window.py +++ b/gui/main_window.py @@ -5,6 +5,7 @@ from pathlib import Path import logging import os from PIL import Image, ImageTk +import time sys.path.append(str(Path(__file__).parent.parent)) from utils.config import Config @@ -276,22 +277,44 @@ class MainWindow: """窗口关闭处理""" try: logging.info("正在关闭程序...") + # 先退出主循环 self.root.quit() + # 等待一小段时间确保资源释放 + time.sleep(0.5) except Exception as e: logging.error(f"关闭程序时出错: {str(e)}") finally: - self.root.destroy() + try: + # 销毁窗口 + self.root.destroy() + # 再等待一小段时间 + time.sleep(0.5) + # 强制结束进程 + if sys.platform == "win32": + import os + os._exit(0) + except: + # 如果还是无法正常关闭,直接强制退出 + os._exit(0) def run(self): """运行程序""" self.root.mainloop() def dummy_function(self): - """占位函数""" + """突破版本限制""" # 先检查状态 if not self.check_status(): return - messagebox.showinfo("提示", "此功能暂未实现") + + try: + success, message = self.switcher.bypass_version_limit() + if success: + messagebox.showinfo("成功", message) + else: + messagebox.showerror("错误", message) + except Exception as e: + messagebox.showerror("错误", f"操作失败: {str(e)}") def reset_machine_id(self): """刷新Cursor编辑器授权""" diff --git a/version.txt b/version.txt index d9c62ed..b38ebbf 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -3.0.2 \ No newline at end of file +3.0.4 \ No newline at end of file