v3.2.6 稳定版本备份
This commit is contained in:
@@ -105,8 +105,9 @@ class AccountSwitcher:
|
||||
Tuple[bool, str, Optional[Dict]]: (是否成功, 提示消息, 账号信息)
|
||||
"""
|
||||
try:
|
||||
# 获取当前状态
|
||||
# 获取当前状态和历史记录
|
||||
member_info = self.config.load_member_info()
|
||||
activation_history = member_info.get("activation_records", []) if member_info else []
|
||||
|
||||
# 分割多个激活码
|
||||
codes = [c.strip() for c in code.split(',')]
|
||||
@@ -182,16 +183,27 @@ class AccountSwitcher:
|
||||
# 使用最后一次激活的结果作为最终状态
|
||||
final_result = activation_results[-1]
|
||||
|
||||
# 保存会员信息
|
||||
# 合并历史记录
|
||||
new_activation_records = final_result.get("activation_records", [])
|
||||
if activation_history:
|
||||
# 保留旧的激活记录,避免重复
|
||||
existing_codes = {record.get("code") for record in activation_history}
|
||||
for record in new_activation_records:
|
||||
if record.get("code") not in existing_codes:
|
||||
activation_history.append(record)
|
||||
else:
|
||||
activation_history = new_activation_records
|
||||
|
||||
# 保存会员信息,包含完整的历史记录
|
||||
member_info = {
|
||||
"hardware_id": final_result.get("machine_id", self.hardware_id),
|
||||
"expire_time": final_result.get("expire_time", ""),
|
||||
"days_left": final_result.get("days_left", 0), # 使用days_left
|
||||
"total_days": final_result.get("total_days", 0), # 使用total_days
|
||||
"days_left": final_result.get("days_left", 0),
|
||||
"total_days": final_result.get("total_days", 0),
|
||||
"status": final_result.get("status", "inactive"),
|
||||
"device_info": final_result.get("device_info", device_info),
|
||||
"activation_time": final_result.get("activation_time", ""),
|
||||
"activation_records": final_result.get("activation_records", []) # 保存激活记录
|
||||
"activation_records": activation_history # 使用合并后的历史记录
|
||||
}
|
||||
self.config.save_member_info(member_info)
|
||||
|
||||
@@ -201,8 +213,7 @@ class AccountSwitcher:
|
||||
# 显示每个成功激活码的信息
|
||||
for i, result in enumerate(activation_results, 1):
|
||||
message += f"\n第{i}个激活码:\n"
|
||||
message += f"- 新增天数: {result.get('added_days', 0)}天\n" # 使用added_days显示本次新增天数
|
||||
# 格式化时间显示
|
||||
message += f"- 新增天数: {result.get('added_days', 0)}天\n"
|
||||
activation_time = result.get('activation_time', '')
|
||||
if activation_time:
|
||||
try:
|
||||
@@ -214,8 +225,8 @@ class AccountSwitcher:
|
||||
message += f"- 激活时间: {activation_time}\n"
|
||||
|
||||
message += f"\n最终状态:"
|
||||
message += f"\n- 总天数: {final_result.get('total_days', 0)}天" # 累计总天数
|
||||
message += f"\n- 剩余天数: {final_result.get('days_left', 0)}天" # 剩余天数
|
||||
message += f"\n- 总天数: {final_result.get('total_days', 0)}天"
|
||||
message += f"\n- 剩余天数: {final_result.get('days_left', 0)}天"
|
||||
|
||||
# 格式化到期时间显示
|
||||
expire_time = final_result.get('expire_time', '')
|
||||
@@ -227,9 +238,9 @@ class AccountSwitcher:
|
||||
pass
|
||||
message += f"\n- 到期时间: {expire_time}"
|
||||
|
||||
# 显示激活记录历史
|
||||
# 显示完整的激活记录历史
|
||||
message += "\n\n历史激活记录:"
|
||||
for record in final_result.get('activation_records', []):
|
||||
for record in activation_history:
|
||||
activation_time = record.get('activation_time', '')
|
||||
if activation_time:
|
||||
try:
|
||||
@@ -248,11 +259,11 @@ class AccountSwitcher:
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"处理激活结果时出错: {str(e)}")
|
||||
return False, f"处理激活结果失败: {str(e)}", None
|
||||
return False, f"处理激活结果时出错: {str(e)}", None
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"激活码验证过程出错: {str(e)}")
|
||||
return False, f"激活失败: {str(e)}", None
|
||||
logging.error(f"验证激活码时出错: {str(e)}")
|
||||
return False, f"验证激活码时出错: {str(e)}", None
|
||||
|
||||
def reset_machine_id(self) -> bool:
|
||||
"""重置机器码"""
|
||||
@@ -262,7 +273,15 @@ class AccountSwitcher:
|
||||
os.system("taskkill /f /im Cursor.exe >nul 2>&1")
|
||||
time.sleep(2)
|
||||
|
||||
# 2. 删除 package.json 中的 machineId
|
||||
# 2. 清理注册表(包括更新系统 MachineGuid)
|
||||
if not self.registry.clean_registry():
|
||||
logging.warning("注册表清理失败")
|
||||
|
||||
# 3. 清理文件(包括备份 storage.json)
|
||||
if not self.registry.clean_cursor_files():
|
||||
logging.warning("文件清理失败")
|
||||
|
||||
# 4. 修改 package.json 中的 machineId
|
||||
if self.package_json.exists():
|
||||
with open(self.package_json, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
@@ -273,67 +292,20 @@ class AccountSwitcher:
|
||||
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"
|
||||
|
||||
# 需要清理的目录
|
||||
cache_dirs = [
|
||||
cursor_path / "Cache",
|
||||
cursor_path / "Code Cache",
|
||||
cursor_path / "GPUCache",
|
||||
cursor_path / "Local Storage" / "leveldb"
|
||||
]
|
||||
|
||||
# 需要删除的配置文件
|
||||
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 dir_path in cache_dirs:
|
||||
if dir_path.exists():
|
||||
try:
|
||||
import shutil
|
||||
shutil.rmtree(str(dir_path))
|
||||
logging.info(f"清理目录成功: {dir_path}")
|
||||
except Exception as e:
|
||||
logging.warning(f"清理目录失败: {dir_path}, 错误: {str(e)}")
|
||||
|
||||
# 删除配置文件
|
||||
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. 删除卸载注册表项
|
||||
try:
|
||||
import winreg
|
||||
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Uninstall", 0, winreg.KEY_ALL_ACCESS) as key:
|
||||
# 遍历所有子键,找到Cursor相关的
|
||||
i = 0
|
||||
while True:
|
||||
try:
|
||||
subkey_name = winreg.EnumKey(key, i)
|
||||
if "Cursor" in subkey_name:
|
||||
winreg.DeleteKey(key, subkey_name)
|
||||
logging.info(f"删除注册表项成功: {subkey_name}")
|
||||
i += 1
|
||||
except WindowsError:
|
||||
break
|
||||
except Exception as e:
|
||||
logging.warning(f"删除注册表项失败: {str(e)}")
|
||||
# 5. 修改 storage.json 中的遥测 ID
|
||||
storage_path = Path(os.getenv('APPDATA')) / "Cursor" / "User" / "globalStorage" / "storage.json"
|
||||
if storage_path.exists():
|
||||
with open(storage_path, "r", encoding="utf-8") as f:
|
||||
storage_data = json.load(f)
|
||||
|
||||
# 只修改 machineId,保持其他遥测 ID 不变
|
||||
if "telemetry.machineId" in storage_data:
|
||||
# 生成新的 machineId(使用与 GitHub 脚本类似的格式)
|
||||
new_machine_id = hashlib.sha256(str(uuid.uuid4()).encode()).hexdigest()
|
||||
storage_data["telemetry.machineId"] = new_machine_id
|
||||
|
||||
with open(storage_path, "w", encoding="utf-8") as f:
|
||||
json.dump(storage_data, f, indent=2)
|
||||
|
||||
# 6. 重启Cursor
|
||||
cursor_exe = self.cursor_path / "Cursor.exe"
|
||||
@@ -523,7 +495,12 @@ class AccountSwitcher:
|
||||
Tuple[bool, str]: (是否成功, 提示消息)
|
||||
"""
|
||||
try:
|
||||
# 获取未使用的账号
|
||||
# 1. 先关闭所有Cursor进程
|
||||
if sys.platform == "win32":
|
||||
os.system("taskkill /f /im Cursor.exe >nul 2>&1")
|
||||
time.sleep(2)
|
||||
|
||||
# 2. 获取未使用的账号
|
||||
endpoint = "https://cursorapi.nosqli.com/admin/api.account/getUnused"
|
||||
data = {
|
||||
"machine_id": self.hardware_id
|
||||
@@ -559,26 +536,14 @@ class AccountSwitcher:
|
||||
if not all([email, access_token, refresh_token]):
|
||||
return False, "获取账号信息不完整"
|
||||
|
||||
# 更新Cursor认证信息
|
||||
# 3. 更新Cursor认证信息
|
||||
if not self.auth_manager.update_auth(email, access_token, refresh_token):
|
||||
return False, "更新Cursor认证信息失败"
|
||||
|
||||
# 重置机器码
|
||||
# 4. 重置机器码(包含了清理注册表、文件和重启操作)
|
||||
if not self.reset_machine_id():
|
||||
return False, "重置机器码失败"
|
||||
|
||||
# 刷新注册表
|
||||
if not self.registry.refresh_registry():
|
||||
logging.warning("注册表刷新失败,但不影响主要功能")
|
||||
|
||||
# 重启Cursor
|
||||
if not self.auth_manager.restart_cursor():
|
||||
return False, "重启Cursor失败"
|
||||
# 重启Cursor
|
||||
# if not self.restart_cursor():
|
||||
# logging.warning("Cursor重启失败,请手动重启")
|
||||
# return True, f"授权刷新成功,请手动重启Cursor编辑器\n邮箱: {email}\n到期时间: {expire_time}\n剩余天数: {days_left}天"
|
||||
|
||||
return True, f"授权刷新成功,Cursor编辑器已重启\n邮箱: {email}\n"
|
||||
|
||||
elif response_data.get("code") == 404:
|
||||
|
||||
Reference in New Issue
Block a user