更新: 1. 优化未激活状态下的购买信息提示框 2. 添加一键复制功能 3. 更新版本到3.0.9
This commit is contained in:
@@ -273,10 +273,19 @@ class AccountSwitcher:
|
|||||||
with open(self.package_json, "w", encoding="utf-8") as f:
|
with open(self.package_json, "w", encoding="utf-8") as f:
|
||||||
json.dump(data, f, indent=2)
|
json.dump(data, f, indent=2)
|
||||||
|
|
||||||
# 3. 清理特定的配置文件
|
# 3. 清理特定的配置文件和缓存
|
||||||
local_app_data = Path(os.getenv('LOCALAPPDATA'))
|
local_app_data = Path(os.getenv('LOCALAPPDATA'))
|
||||||
cursor_path = local_app_data / "Cursor"
|
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 = [
|
config_files = [
|
||||||
cursor_path / "User" / "globalStorage" / "storage.json",
|
cursor_path / "User" / "globalStorage" / "storage.json",
|
||||||
cursor_path / "User" / "globalStorage" / "state.json",
|
cursor_path / "User" / "globalStorage" / "state.json",
|
||||||
@@ -285,6 +294,17 @@ class AccountSwitcher:
|
|||||||
self.app_path / "settings.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:
|
for file_path in config_files:
|
||||||
if file_path.exists():
|
if file_path.exists():
|
||||||
try:
|
try:
|
||||||
@@ -297,7 +317,25 @@ class AccountSwitcher:
|
|||||||
if not self.registry.refresh_registry():
|
if not self.registry.refresh_registry():
|
||||||
logging.warning("注册表刷新失败")
|
logging.warning("注册表刷新失败")
|
||||||
|
|
||||||
# 5. 重启Cursor
|
# 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)}")
|
||||||
|
|
||||||
|
# 6. 重启Cursor
|
||||||
cursor_exe = self.cursor_path / "Cursor.exe"
|
cursor_exe = self.cursor_path / "Cursor.exe"
|
||||||
if cursor_exe.exists():
|
if cursor_exe.exists():
|
||||||
os.startfile(str(cursor_exe))
|
os.startfile(str(cursor_exe))
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import os
|
|||||||
import winreg
|
import winreg
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import uuid
|
||||||
|
|
||||||
class CursorRegistry:
|
class CursorRegistry:
|
||||||
"""Cursor注册表操作工具类"""
|
"""Cursor注册表操作工具类"""
|
||||||
@@ -9,14 +10,27 @@ class CursorRegistry:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.cursor_path = Path(os.path.expanduser("~")) / "AppData" / "Local" / "Programs" / "Cursor"
|
self.cursor_path = Path(os.path.expanduser("~")) / "AppData" / "Local" / "Programs" / "Cursor"
|
||||||
self.app_path = self.cursor_path / "resources" / "app"
|
self.app_path = self.cursor_path / "resources" / "app"
|
||||||
|
self.machine_guid_path = r"SOFTWARE\Microsoft\Cryptography"
|
||||||
|
self.machine_guid_name = "MachineGuid"
|
||||||
|
|
||||||
def refresh_registry(self) -> bool:
|
def refresh_registry(self) -> bool:
|
||||||
"""刷新Cursor相关的注册表项
|
"""刷新注册表
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: 是否成功
|
bool: 是否成功
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
# 生成新的GUID
|
||||||
|
new_guid = str(uuid.uuid4())
|
||||||
|
|
||||||
|
# 修改 MachineGuid
|
||||||
|
try:
|
||||||
|
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, self.machine_guid_path, 0, winreg.KEY_ALL_ACCESS) as key:
|
||||||
|
winreg.SetValueEx(key, self.machine_guid_name, 0, winreg.REG_SZ, new_guid)
|
||||||
|
logging.info(f"更新 MachineGuid 成功: {new_guid}")
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"更新 MachineGuid 失败: {str(e)}")
|
||||||
|
return False
|
||||||
|
|
||||||
# 获取Cursor安装路径
|
# 获取Cursor安装路径
|
||||||
cursor_exe = self.cursor_path / "Cursor.exe"
|
cursor_exe = self.cursor_path / "Cursor.exe"
|
||||||
if not cursor_exe.exists():
|
if not cursor_exe.exists():
|
||||||
@@ -42,7 +56,7 @@ class CursorRegistry:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"刷新注册表过程出错: {str(e)}")
|
logging.error(f"刷新注册表失败: {str(e)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def clean_registry(self) -> bool:
|
def clean_registry(self) -> bool:
|
||||||
|
|||||||
Reference in New Issue
Block a user