mirror of
https://git.axenov.dev/mirrors/cursor-free-vip.git
synced 2025-12-26 05:30:36 +03:00
feat: Introduce force update configuration feature with multilingual support
- Added a new function to force update the configuration file with the latest defaults, including backup and removal of the original file. - Implemented multilingual support for force update messages in English, Simplified Chinese, and Traditional Chinese locale files. - Updated CHANGELOG.md to reflect the new feature and fixes, bumping the version to 1.8.08 in the build workflow.
This commit is contained in:
39
config.py
39
config.py
@@ -3,6 +3,7 @@ import sys
|
||||
import configparser
|
||||
from colorama import Fore, Style
|
||||
from utils import get_user_documents_path, get_default_chrome_path, get_linux_cursor_path
|
||||
import shutil
|
||||
|
||||
EMOJI = {
|
||||
"INFO": "ℹ️",
|
||||
@@ -257,6 +258,44 @@ def print_config(config, translator=None):
|
||||
|
||||
print()
|
||||
|
||||
def force_update_config(translator=None):
|
||||
"""
|
||||
Force update configuration file with latest defaults
|
||||
Args:
|
||||
translator: Translator instance
|
||||
Returns:
|
||||
ConfigParser instance or None if failed
|
||||
"""
|
||||
try:
|
||||
config_dir = os.path.join(get_user_documents_path(), ".cursor-free-vip")
|
||||
config_file = os.path.join(config_dir, "config.ini")
|
||||
datetime = datetime.datetime
|
||||
time = datetime.now()
|
||||
|
||||
if os.path.exists(config_file):
|
||||
try:
|
||||
# create backup
|
||||
backup_file = f"{config_file}.bak.{time.strftime('%Y%m%d_%H%M%S')}"
|
||||
shutil.copy2(config_file, backup_file)
|
||||
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}")
|
||||
|
||||
# delete original file
|
||||
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)
|
||||
|
||||
except Exception as e:
|
||||
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}")
|
||||
return None
|
||||
|
||||
def get_config(translator=None):
|
||||
"""Get existing config or create new one"""
|
||||
return setup_config(translator)
|
||||
Reference in New Issue
Block a user