From 26a8e8da28d3fcd4da09dbfc652de9450bbb0a4d Mon Sep 17 00:00:00 2001 From: yeongpin Date: Sat, 12 Apr 2025 17:00:18 +0800 Subject: [PATCH] Update CHANGELOG.md for version 1.9.02 and enhance config handling - Added entries for version 1.9.02 in CHANGELOG.md, detailing fixes for configuration file path, Windows user permissions, and other issues. - Improved `config.py` to handle document path retrieval more robustly, including fallback to a temporary directory if the documents path is not found. - Updated localization files to include new strings for configuration messages in both English and Chinese. --- .env | 4 ++-- .github/workflows/build.yml | 2 +- CHANGELOG.md | 5 +++++ config.py | 39 +++++++++++++++++++++++++++++++++---- locales/en.json | 5 ++++- locales/zh_cn.json | 5 ++++- 6 files changed, 51 insertions(+), 9 deletions(-) diff --git a/.env b/.env index a06dda7..ce46543 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ -version=1.9.01 -VERSION=1.9.01 +version=1.9.02 +VERSION=1.9.02 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dcc43d5..1daddd0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: version: description: 'Version number (e.g. 1.0.9)' required: true - default: '1.9.01' + default: '1.9.02' permissions: contents: write diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ec81a6..62a7fe7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## v1.9.02 +1. Fix: Config File Path | 修復配置文件路徑 +2. Fix: window user permission | 修復 window 用戶權限 +3. Fix: Some Issues | 修復一些問題 + ## v1.9.01 1. Add: Bypass Token Limit | 添加繞過 Token 限制 2. Add: More Browser Support | 添加更多瀏覽器支持 diff --git a/config.py b/config.py index f94831b..c020d3f 100644 --- a/config.py +++ b/config.py @@ -18,13 +18,41 @@ EMOJI = { "SETTINGS": "⚙️" } +# global config cache +_config_cache = None + def setup_config(translator=None): """Setup configuration file and return config object""" try: - config_dir = os.path.join(get_user_documents_path(), ".cursor-free-vip") - config_file = os.path.join(config_dir, "config.ini") - os.makedirs(config_dir, exist_ok=True) + # get documents path + docs_path = get_user_documents_path() + if not docs_path or not os.path.exists(docs_path): + # if documents path not found, use current directory + print(f"{Fore.YELLOW}{EMOJI['WARNING']} {translator.get('config.documents_path_not_found', fallback='Documents path not found, using current directory') if translator else 'Documents path not found, using current directory'}{Style.RESET_ALL}") + docs_path = os.path.abspath('.') + # normalize path + config_dir = os.path.normpath(os.path.join(docs_path, ".cursor-free-vip")) + config_file = os.path.normpath(os.path.join(config_dir, "config.ini")) + + # create config directory, only print message when directory not exists + dir_exists = os.path.exists(config_dir) + try: + os.makedirs(config_dir, exist_ok=True) + if not dir_exists: # only print message when directory not exists + print(f"{Fore.CYAN}{EMOJI['INFO']} {translator.get('config.config_dir_created', path=config_dir) if translator else f'Config directory created: {config_dir}'}{Style.RESET_ALL}") + except Exception as e: + # if cannot create directory, use temporary directory + import tempfile + temp_dir = os.path.normpath(os.path.join(tempfile.gettempdir(), ".cursor-free-vip")) + temp_exists = os.path.exists(temp_dir) + config_dir = temp_dir + config_file = os.path.normpath(os.path.join(config_dir, "config.ini")) + os.makedirs(config_dir, exist_ok=True) + if not temp_exists: # only print message when temporary directory not exists + print(f"{Fore.YELLOW}{EMOJI['WARNING']} {translator.get('config.using_temp_dir', path=config_dir, error=str(e)) if translator else f'Using temporary directory due to error: {config_dir} (Error: {str(e)})'}{Style.RESET_ALL}") + + # create config object config = configparser.ConfigParser() # Default configuration @@ -330,4 +358,7 @@ def force_update_config(translator=None): def get_config(translator=None): """Get existing config or create new one""" - return setup_config(translator) \ No newline at end of file + global _config_cache + if _config_cache is None: + _config_cache = setup_config(translator) + return _config_cache \ No newline at end of file diff --git a/locales/en.json b/locales/en.json index ee5a154..dee8cbe 100644 --- a/locales/en.json +++ b/locales/en.json @@ -572,7 +572,10 @@ "backup_failed": "Failed to backup config: {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" + "config_force_update_enabled": "Config file force update enabled , performing forced update", + "documents_path_not_found": "Documents path not found, using current directory", + "config_dir_created": "Config directory created: {path}", + "using_temp_dir": "Using temporary directory due to error: {path} (Error: {error})" }, "oauth": { "authentication_button_not_found": "Authentication button not found", diff --git a/locales/zh_cn.json b/locales/zh_cn.json index 6f5abfd..2aac9f2 100644 --- a/locales/zh_cn.json +++ b/locales/zh_cn.json @@ -550,7 +550,10 @@ "backup_failed": "备份失败: {error}", "force_update_failed": "强制更新配置失败: {error}", "config_force_update_disabled": "配置文件强制更新已禁用,跳过强制更新", - "config_force_update_enabled": "配置文件强制更新已启用,正在执行强制更新" + "config_force_update_enabled": "配置文件强制更新已启用,正在执行强制更新", + "documents_path_not_found": "找不到文档路径,使用当前目录", + "config_dir_created": "已创建配置目录: {path}", + "using_temp_dir": "由于错误使用临时目录: {path} (错误: {error})" }, "oauth": { "authentication_button_not_found": "未找到认证按钮",