mirror of
https://github.com/yeongpin/cursor-free-vip.git
synced 2025-08-02 20:47:35 +08:00
Merge pull request #528 from Cantue35/fix/disable-forced-update
Fix forced update config deletion when update check is disabled
This commit is contained in:
commit
96c0cd5274
@ -1,5 +1,10 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## v1.8.09
|
||||||
|
1. Add: Force Update Config | 添加強制更新配置
|
||||||
|
2. Add: Multilanguage support for force update | 添加強制更新功能的多語言支持
|
||||||
|
3. Fix: Some Issues | 修復一些問題
|
||||||
|
|
||||||
## v1.8.08
|
## v1.8.08
|
||||||
1. Add: Force Update Config | 添加強制更新配置
|
1. Add: Force Update Config | 添加強制更新配置
|
||||||
2. Add: Multilanguage support for force update | 添加強制更新功能的多語言支持
|
2. Add: Multilanguage support for force update | 添加強制更新功能的多語言支持
|
||||||
|
50
config.py
50
config.py
@ -54,6 +54,7 @@ def setup_config(translator=None):
|
|||||||
},
|
},
|
||||||
'Utils': {
|
'Utils': {
|
||||||
'enabled_update_check': 'True',
|
'enabled_update_check': 'True',
|
||||||
|
'enabled_force_update': 'True',
|
||||||
'enabled_account_info': 'True'
|
'enabled_account_info': 'True'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,7 +262,7 @@ def print_config(config, translator=None):
|
|||||||
|
|
||||||
def force_update_config(translator=None):
|
def force_update_config(translator=None):
|
||||||
"""
|
"""
|
||||||
Force update configuration file with latest defaults
|
Force update configuration file with latest defaults if update check is enabled.
|
||||||
Args:
|
Args:
|
||||||
translator: Translator instance
|
translator: Translator instance
|
||||||
Returns:
|
Returns:
|
||||||
@ -271,26 +272,39 @@ def force_update_config(translator=None):
|
|||||||
config_dir = os.path.join(get_user_documents_path(), ".cursor-free-vip")
|
config_dir = os.path.join(get_user_documents_path(), ".cursor-free-vip")
|
||||||
config_file = os.path.join(config_dir, "config.ini")
|
config_file = os.path.join(config_dir, "config.ini")
|
||||||
current_time = datetime.datetime.now()
|
current_time = datetime.datetime.now()
|
||||||
|
|
||||||
|
# If the config file exists, check if forced update is enabled
|
||||||
if os.path.exists(config_file):
|
if os.path.exists(config_file):
|
||||||
try:
|
# First, read the existing configuration
|
||||||
# create backup
|
existing_config = configparser.ConfigParser()
|
||||||
backup_file = f"{config_file}.bak.{current_time.strftime('%Y%m%d_%H%M%S')}"
|
existing_config.read(config_file, encoding='utf-8')
|
||||||
shutil.copy2(config_file, backup_file)
|
# Check if "enabled_update_check" is True
|
||||||
|
update_enabled = True # Default to True if not set
|
||||||
|
if existing_config.has_section('Utils') and existing_config.has_option('Utils', 'enabled_force_update'):
|
||||||
|
update_enabled = existing_config.get('Utils', 'enabled_force_update').strip().lower() in ('true', 'yes', '1', 'on')
|
||||||
|
|
||||||
|
if update_enabled:
|
||||||
|
try:
|
||||||
|
# Create a backup
|
||||||
|
backup_file = f"{config_file}.bak.{current_time.strftime('%Y%m%d_%H%M%S')}"
|
||||||
|
shutil.copy2(config_file, backup_file)
|
||||||
|
if translator:
|
||||||
|
print(f"\n{Fore.CYAN}{EMOJI['INFO']} {translator.get('config.backup_created', path=backup_file) if translator else f'Backup created: {backup_file}'}{Style.RESET_ALL}")
|
||||||
|
print(f"\n{Fore.CYAN}{EMOJI['INFO']} {translator.get('config.config_force_update_enabled') if translator else 'Config file force update enabled'}{Style.RESET_ALL}")
|
||||||
|
# Delete the original config file (forced update)
|
||||||
|
os.remove(config_file)
|
||||||
|
if translator:
|
||||||
|
print(f"{Fore.CYAN}{EMOJI['INFO']} {translator.get('config.config_removed') if translator else 'Config file removed for forced update'}{Style.RESET_ALL}")
|
||||||
|
except Exception as e:
|
||||||
|
if translator:
|
||||||
|
print(f"{Fore.RED}{EMOJI['ERROR']} {translator.get('config.backup_failed', error=str(e)) if translator else f'Failed to backup config: {str(e)}'}{Style.RESET_ALL}")
|
||||||
|
else:
|
||||||
if translator:
|
if translator:
|
||||||
print(f"{Fore.CYAN}{EMOJI['INFO']} {translator.get('config.backup_created', path=backup_file) if translator else f'Backup created: {backup_file}'}{Style.RESET_ALL}")
|
print(f"\n{Fore.CYAN}{EMOJI['INFO']} {translator.get('config.config_force_update_disabled', fallback='Config file force update disabled by configuration. Keeping existing config file.') if translator else 'Config file force update disabled by configuration. Keeping existing config file.'}{Style.RESET_ALL}")
|
||||||
|
|
||||||
# delete original file
|
# Generate a new (or updated) configuration if needed
|
||||||
os.remove(config_file)
|
|
||||||
if translator:
|
|
||||||
print(f"{Fore.CYAN}{EMOJI['INFO']} {translator.get('config.config_removed') if translator else 'Config file removed for forced update'}{Style.RESET_ALL}")
|
|
||||||
except Exception as e:
|
|
||||||
if translator:
|
|
||||||
print(f"{Fore.RED}{EMOJI['ERROR']} {translator.get('config.backup_failed', error=str(e)) if translator else f'Failed to backup config: {str(e)}'}{Style.RESET_ALL}")
|
|
||||||
|
|
||||||
# use existing setup_config function to create new config
|
|
||||||
return setup_config(translator)
|
return setup_config(translator)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if translator:
|
if translator:
|
||||||
print(f"{Fore.RED}{EMOJI['ERROR']} {translator.get('config.force_update_failed', error=str(e)) if translator else f'Force update config failed: {str(e)}'}{Style.RESET_ALL}")
|
print(f"{Fore.RED}{EMOJI['ERROR']} {translator.get('config.force_update_failed', error=str(e)) if translator else f'Force update config failed: {str(e)}'}{Style.RESET_ALL}")
|
||||||
|
@ -560,7 +560,9 @@
|
|||||||
"backup_created": "Backup created: {path}",
|
"backup_created": "Backup created: {path}",
|
||||||
"config_removed": "Config file removed for forced update",
|
"config_removed": "Config file removed for forced update",
|
||||||
"backup_failed": "Failed to backup config: {error}",
|
"backup_failed": "Failed to backup config: {error}",
|
||||||
"force_update_failed": "Force update config failed: {error}"
|
"force_update_failed": "Force update config failed: {error}",
|
||||||
|
"config_force_update_disabled": "Config file force update disabled , skipping forced update",
|
||||||
|
"config_force_update_enabled": "Config file force update enabled , performing forced update"
|
||||||
},
|
},
|
||||||
"oauth": {
|
"oauth": {
|
||||||
"authentication_button_not_found": "Authentication button not found",
|
"authentication_button_not_found": "Authentication button not found",
|
||||||
|
@ -538,7 +538,9 @@
|
|||||||
"backup_created": "备份创建: {path}",
|
"backup_created": "备份创建: {path}",
|
||||||
"config_removed": "配置文件已删除用于强制更新",
|
"config_removed": "配置文件已删除用于强制更新",
|
||||||
"backup_failed": "备份失败: {error}",
|
"backup_failed": "备份失败: {error}",
|
||||||
"force_update_failed": "强制更新配置失败: {error}"
|
"force_update_failed": "强制更新配置失败: {error}",
|
||||||
|
"config_force_update_disabled": "配置文件强制更新已禁用,跳过强制更新",
|
||||||
|
"config_force_update_enabled": "配置文件强制更新已启用,正在执行强制更新"
|
||||||
},
|
},
|
||||||
"oauth": {
|
"oauth": {
|
||||||
"authentication_button_not_found": "未找到认证按钮",
|
"authentication_button_not_found": "未找到认证按钮",
|
||||||
|
@ -520,7 +520,9 @@
|
|||||||
"backup_created": "備份已創建: {path}",
|
"backup_created": "備份已創建: {path}",
|
||||||
"config_removed": "配置文件已刪除用於強制更新",
|
"config_removed": "配置文件已刪除用於強制更新",
|
||||||
"backup_failed": "備份失敗: {error}",
|
"backup_failed": "備份失敗: {error}",
|
||||||
"force_update_failed": "強制更新配置失敗: {error}"
|
"force_update_failed": "強制更新配置失敗: {error}",
|
||||||
|
"config_force_update_disabled": "配置文件強制更新已禁用,跳過強制更新",
|
||||||
|
"config_force_update_enabled": "配置文件強制更新已啟用,正在執行強制更新"
|
||||||
},
|
},
|
||||||
"oauth": {
|
"oauth": {
|
||||||
"authentication_button_not_found": "未找到認證按鈕",
|
"authentication_button_not_found": "未找到認證按鈕",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user