mirror of
https://github.com/yeongpin/cursor-free-vip.git
synced 2025-08-03 04:57:36 +08:00
Fix forced update config deletion when update check is disabled
- Added a conditional check in force_update_config() to verify that enabled_update_check in the [Utils] section is read as False. - If disabled, the config file will not be deleted. - This prevents loss of custom configuration and improves usability. - Tested on macOS with our modifications.
This commit is contained in:
parent
fea2b88a8e
commit
b46a58bd23
43
config.py
43
config.py
@ -261,7 +261,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:
|
||||||
@ -272,23 +272,36 @@ def force_update_config(translator=None):
|
|||||||
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
|
||||||
if translator:
|
update_enabled = True # Default to True if not set
|
||||||
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}")
|
if existing_config.has_section('Utils') and existing_config.has_option('Utils', 'enabled_update_check'):
|
||||||
|
update_enabled = existing_config.get('Utils', 'enabled_update_check').strip().lower() in ('true', 'yes', '1', 'on')
|
||||||
|
|
||||||
# delete original file
|
if update_enabled:
|
||||||
os.remove(config_file)
|
try:
|
||||||
if translator:
|
# Create a backup
|
||||||
print(f"{Fore.CYAN}{EMOJI['INFO']} {translator.get('config.config_removed') if translator else 'Config file removed for forced update'}{Style.RESET_ALL}")
|
backup_file = f"{config_file}.bak.{current_time.strftime('%Y%m%d_%H%M%S')}"
|
||||||
except Exception as e:
|
shutil.copy2(config_file, backup_file)
|
||||||
if translator:
|
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}")
|
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}")
|
||||||
|
|
||||||
# use existing setup_config function to create new config
|
# 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:
|
||||||
|
print(f"{Fore.CYAN}{EMOJI['INFO']} {translator.get('config.force_update_disabled', fallback='Force update disabled by configuration. Keeping existing config file.') if translator else 'Force update disabled by configuration. Keeping existing config file.'}{Style.RESET_ALL}")
|
||||||
|
|
||||||
|
# Generate a new (or updated) configuration if needed
|
||||||
return setup_config(translator)
|
return setup_config(translator)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user