更新: 1. 优化程序关闭逻辑,解决临时文件清理问题 2. 更新程序版本到 3.0.4

This commit is contained in:
huangzhenpc
2025-02-12 10:49:07 +08:00
parent 039cd06e43
commit 0435e586ab
3 changed files with 92 additions and 14 deletions

View File

@@ -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]:
"""激活并切换账号