mirror of
https://github.com/yeongpin/cursor-free-vip.git
synced 2025-04-24 08:25:23 +00:00
fix: handle permission errors in auto-update disabling process and enhance localization messages
This commit is contained in:
parent
0a779063bf
commit
a2833fcbd4
@ -79,6 +79,7 @@ class AutoUpdateDisabler:
|
|||||||
content = product_json_file.read()
|
content = product_json_file.read()
|
||||||
|
|
||||||
patterns = {
|
patterns = {
|
||||||
|
r"https://api2.cursor.sh/aiserver.v1.AuthService/DownloadUpdate": r"",
|
||||||
r"https://api2.cursor.sh/updates": r"",
|
r"https://api2.cursor.sh/updates": r"",
|
||||||
r"http://cursorapi.com/updates": r"",
|
r"http://cursorapi.com/updates": r"",
|
||||||
}
|
}
|
||||||
@ -132,17 +133,18 @@ class AutoUpdateDisabler:
|
|||||||
print(f"{Fore.CYAN}{EMOJI['FOLDER']} {self.translator.get('update.removing_directory') if self.translator else '正在删除更新程序目录...'}{Style.RESET_ALL}")
|
print(f"{Fore.CYAN}{EMOJI['FOLDER']} {self.translator.get('update.removing_directory') if self.translator else '正在删除更新程序目录...'}{Style.RESET_ALL}")
|
||||||
|
|
||||||
if os.path.exists(updater_path):
|
if os.path.exists(updater_path):
|
||||||
if os.path.isdir(updater_path):
|
try:
|
||||||
shutil.rmtree(updater_path)
|
if os.path.isdir(updater_path):
|
||||||
else:
|
shutil.rmtree(updater_path)
|
||||||
os.remove(updater_path)
|
else:
|
||||||
|
os.remove(updater_path)
|
||||||
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('update.directory_removed') if self.translator else '更新程序目录已删除'}{Style.RESET_ALL}")
|
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('update.directory_removed') if self.translator else '更新程序目录已删除'}{Style.RESET_ALL}")
|
||||||
|
except PermissionError:
|
||||||
|
print(f"{Fore.YELLOW}{EMOJI['INFO']} {self.translator.get('update.directory_locked', path=updater_path) if self.translator else f'更新程序目录已被锁定,跳过删除: {updater_path}'}{Style.RESET_ALL}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('update.remove_directory_failed', error=str(e)) if self.translator else f'删除目录失败: {e}'}{Style.RESET_ALL}")
|
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('update.remove_directory_failed', error=str(e)) if self.translator else f'删除目录失败: {e}'}{Style.RESET_ALL}")
|
||||||
# 即使删除失败,也返回 True,继续执行下一步
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _clear_update_yml_file(self):
|
def _clear_update_yml_file(self):
|
||||||
@ -155,15 +157,15 @@ class AutoUpdateDisabler:
|
|||||||
print(f"{Fore.CYAN}{EMOJI['FILE']} {self.translator.get('update.clearing_update_yml') if self.translator else '正在清空更新配置文件...'}{Style.RESET_ALL}")
|
print(f"{Fore.CYAN}{EMOJI['FILE']} {self.translator.get('update.clearing_update_yml') if self.translator else '正在清空更新配置文件...'}{Style.RESET_ALL}")
|
||||||
|
|
||||||
if os.path.exists(update_yml_path):
|
if os.path.exists(update_yml_path):
|
||||||
# 清空文件内容
|
try:
|
||||||
with open(update_yml_path, 'w') as f:
|
with open(update_yml_path, 'w') as f:
|
||||||
f.write('')
|
f.write('')
|
||||||
|
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('update.update_yml_cleared') if self.translator else '更新配置文件已清空'}{Style.RESET_ALL}")
|
||||||
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('update.update_yml_cleared') if self.translator else '更新配置文件已清空'}{Style.RESET_ALL}")
|
except PermissionError:
|
||||||
return True
|
print(f"{Fore.YELLOW}{EMOJI['INFO']} {self.translator.get('update.yml_locked') if self.translator else '更新配置文件已被锁定,跳过清空'}{Style.RESET_ALL}")
|
||||||
else:
|
else:
|
||||||
print(f"{Fore.YELLOW}{EMOJI['INFO']} {self.translator.get('update.update_yml_not_found') if self.translator else '更新配置文件不存在'}{Style.RESET_ALL}")
|
print(f"{Fore.YELLOW}{EMOJI['INFO']} {self.translator.get('update.update_yml_not_found') if self.translator else '更新配置文件不存在'}{Style.RESET_ALL}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('update.clear_update_yml_failed', error=str(e)) if self.translator else f'清空更新配置文件失败: {e}'}{Style.RESET_ALL}")
|
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('update.clear_update_yml_failed', error=str(e)) if self.translator else f'清空更新配置文件失败: {e}'}{Style.RESET_ALL}")
|
||||||
@ -180,37 +182,43 @@ class AutoUpdateDisabler:
|
|||||||
print(f"{Fore.CYAN}{EMOJI['FILE']} {self.translator.get('update.creating_block_file') if self.translator else '正在创建阻止文件...'}{Style.RESET_ALL}")
|
print(f"{Fore.CYAN}{EMOJI['FILE']} {self.translator.get('update.creating_block_file') if self.translator else '正在创建阻止文件...'}{Style.RESET_ALL}")
|
||||||
|
|
||||||
# 创建 updater_path 阻止文件
|
# 创建 updater_path 阻止文件
|
||||||
os.makedirs(os.path.dirname(updater_path), exist_ok=True)
|
try:
|
||||||
open(updater_path, 'w').close()
|
os.makedirs(os.path.dirname(updater_path), exist_ok=True)
|
||||||
|
open(updater_path, 'w').close()
|
||||||
# 设置 updater_path 为只读
|
|
||||||
if self.system == "Windows":
|
# 设置 updater_path 为只读
|
||||||
os.system(f'attrib +r "{updater_path}"')
|
if self.system == "Windows":
|
||||||
else:
|
os.system(f'attrib +r "{updater_path}"')
|
||||||
os.chmod(updater_path, 0o444) # 设置为只读
|
else:
|
||||||
|
os.chmod(updater_path, 0o444) # 设置为只读
|
||||||
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('update.block_file_created') if self.translator else '阻止文件已创建'}: {updater_path}{Style.RESET_ALL}")
|
|
||||||
|
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('update.block_file_created') if self.translator else '阻止文件已创建'}: {updater_path}{Style.RESET_ALL}")
|
||||||
|
except PermissionError:
|
||||||
|
print(f"{Fore.YELLOW}{EMOJI['INFO']} {self.translator.get('update.block_file_locked') if self.translator else '阻止文件已被锁定,跳过创建'}{Style.RESET_ALL}")
|
||||||
|
|
||||||
# 检查 update_yml_path
|
# 检查 update_yml_path
|
||||||
update_yml_path = self.update_yml_path
|
update_yml_path = self.update_yml_path
|
||||||
if update_yml_path and os.path.exists(os.path.dirname(update_yml_path)):
|
if update_yml_path and os.path.exists(os.path.dirname(update_yml_path)):
|
||||||
# 创建 update_yml_path 阻止文件
|
try:
|
||||||
with open(update_yml_path, 'w') as f:
|
# 创建 update_yml_path 阻止文件
|
||||||
f.write('# This file is locked to prevent auto-updates\nversion: 0.0.0\n')
|
with open(update_yml_path, 'w') as f:
|
||||||
|
f.write('# This file is locked to prevent auto-updates\nversion: 0.0.0\n')
|
||||||
# 设置 update_yml_path 为只读
|
|
||||||
if self.system == "Windows":
|
# 设置 update_yml_path 为只读
|
||||||
os.system(f'attrib +r "{update_yml_path}"')
|
if self.system == "Windows":
|
||||||
else:
|
os.system(f'attrib +r "{update_yml_path}"')
|
||||||
os.chmod(update_yml_path, 0o444) # 设置为只读
|
else:
|
||||||
|
os.chmod(update_yml_path, 0o444) # 设置为只读
|
||||||
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('update.yml_locked') if self.translator else '更新配置文件已锁定'}: {update_yml_path}{Style.RESET_ALL}")
|
|
||||||
|
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('update.yml_locked') if self.translator else '更新配置文件已锁定'}: {update_yml_path}{Style.RESET_ALL}")
|
||||||
|
except PermissionError:
|
||||||
|
print(f"{Fore.YELLOW}{EMOJI['INFO']} {self.translator.get('update.yml_already_locked') if self.translator else '更新配置文件已被锁定,跳过修改'}{Style.RESET_ALL}")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('update.create_block_file_failed', error=str(e)) if self.translator else f'创建阻止文件失败: {e}'}{Style.RESET_ALL}")
|
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('update.create_block_file_failed', error=str(e)) if self.translator else f'创建阻止文件失败: {e}'}{Style.RESET_ALL}")
|
||||||
return False
|
return True # 返回 True 以继续执行后续步骤
|
||||||
|
|
||||||
def disable_auto_update(self):
|
def disable_auto_update(self):
|
||||||
"""Disable auto update"""
|
"""Disable auto update"""
|
||||||
|
@ -307,7 +307,16 @@
|
|||||||
"clear_update_yml_failed": "Failed to clear update.yml file: {error}",
|
"clear_update_yml_failed": "Failed to clear update.yml file: {error}",
|
||||||
"unsupported_os": "Unsupported OS: {system}",
|
"unsupported_os": "Unsupported OS: {system}",
|
||||||
"remove_directory_failed": "Failed to remove directory: {error}",
|
"remove_directory_failed": "Failed to remove directory: {error}",
|
||||||
"create_block_file_failed": "Failed to create block file: {error}"
|
"create_block_file_failed": "Failed to create block file: {error}",
|
||||||
|
"directory_locked": "Directory is locked: {path}",
|
||||||
|
"yml_locked": "update.yml file is locked",
|
||||||
|
"block_file_locked": "block file is locked",
|
||||||
|
"yml_already_locked": "update.yml file is already locked",
|
||||||
|
"block_file_already_locked": "block file is already locked",
|
||||||
|
"block_file_locked_error": "Block file locked error: {error}",
|
||||||
|
"yml_locked_error": "update.yml file locked error: {error}",
|
||||||
|
"block_file_already_locked_error": "Block file already locked error: {error}",
|
||||||
|
"yml_already_locked_error": "update.yml file already locked error: {error}"
|
||||||
},
|
},
|
||||||
"updater": {
|
"updater": {
|
||||||
"checking": "Checking for updates...",
|
"checking": "Checking for updates...",
|
||||||
|
@ -302,7 +302,16 @@
|
|||||||
"clear_update_yml_failed": "清空 update.yml 文件失败: {error}",
|
"clear_update_yml_failed": "清空 update.yml 文件失败: {error}",
|
||||||
"unsupported_os": "不支持的操作系统: {system}",
|
"unsupported_os": "不支持的操作系统: {system}",
|
||||||
"remove_directory_failed": "删除目录失败: {error}",
|
"remove_directory_failed": "删除目录失败: {error}",
|
||||||
"create_block_file_failed": "创建阻止文件失败: {error}"
|
"create_block_file_failed": "创建阻止文件失败: {error}",
|
||||||
|
"directory_locked": "目录被锁定: {path}",
|
||||||
|
"yml_locked": "update.yml 文件被锁定",
|
||||||
|
"block_file_locked": "阻止文件被锁定",
|
||||||
|
"yml_already_locked": "update.yml 文件已锁定",
|
||||||
|
"block_file_already_locked": "阻止文件已锁定",
|
||||||
|
"block_file_locked_error": "阻止文件锁定错误: {error}",
|
||||||
|
"yml_locked_error": "update.yml 文件锁定错误: {error}",
|
||||||
|
"block_file_already_locked_error": "阻止文件已锁定错误: {error}",
|
||||||
|
"yml_already_locked_error": "update.yml 文件已锁定错误: {error}"
|
||||||
},
|
},
|
||||||
"updater": {
|
"updater": {
|
||||||
"checking": "检查更新...",
|
"checking": "检查更新...",
|
||||||
|
@ -284,7 +284,16 @@
|
|||||||
"clear_update_yml_failed": "清空 update.yml 文件失败: {error}",
|
"clear_update_yml_failed": "清空 update.yml 文件失败: {error}",
|
||||||
"unsupported_os": "不支持的操作系统: {system}",
|
"unsupported_os": "不支持的操作系统: {system}",
|
||||||
"remove_directory_failed": "刪除目錄失败: {error}",
|
"remove_directory_failed": "刪除目錄失败: {error}",
|
||||||
"create_block_file_failed": "創建阻止文件失败: {error}"
|
"create_block_file_failed": "創建阻止文件失败: {error}",
|
||||||
|
"directory_locked": "目錄被鎖定: {path}",
|
||||||
|
"yml_locked": "update.yml 文件被鎖定",
|
||||||
|
"block_file_locked": "阻止文件被鎖定",
|
||||||
|
"yml_already_locked": "update.yml 文件已鎖定",
|
||||||
|
"block_file_already_locked": "阻止文件已鎖定",
|
||||||
|
"block_file_locked_error": "阻止文件锁定错误: {error}",
|
||||||
|
"yml_locked_error": "update.yml 文件锁定错误: {error}",
|
||||||
|
"block_file_already_locked_error": "阻止文件已锁定错误: {error}",
|
||||||
|
"yml_already_locked_error": "update.yml 文件已锁定错误: {error}"
|
||||||
},
|
},
|
||||||
"updater": {
|
"updater": {
|
||||||
"checking": "檢查更新...",
|
"checking": "檢查更新...",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user