From a6a8504ea8e8aed38f0804939053f5e2ef174165 Mon Sep 17 00:00:00 2001 From: ila Date: Mon, 15 Jun 2026 17:13:36 +0800 Subject: [PATCH] fix: align resource and runtime paths --- .gitignore | 5 +++++ src/services/config_service.py | 10 +++++++--- src/services/file_service.py | 10 ++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 36b13f1..6bdfd7b 100644 --- a/.gitignore +++ b/.gitignore @@ -174,3 +174,8 @@ cython_debug/ # PyPI configuration file .pypirc +# Runtime data +config/ +logs/ +output/ + diff --git a/src/services/config_service.py b/src/services/config_service.py index 7594f9f..f723741 100644 --- a/src/services/config_service.py +++ b/src/services/config_service.py @@ -15,10 +15,14 @@ _CONFIG_FILENAME = "app_config.json" def load_config(): - """Load app config from JSON. Returns defaults merged with file values. + """ + 从 JSON 文件加载应用配置。 - Never raises: missing file → info log + defaults; - damaged file → warning log + defaults. + 返回默认配置与文件配置的合并字典。如果配置文件不存在、损坏或无法读取, + 函数不会抛出异常,而是记录日志并返回默认配置。 + + Returns: + dict: 合并后的配置字典 """ from services.file_service import get_config_path config_file = get_config_path(_CONFIG_FILENAME) diff --git a/src/services/file_service.py b/src/services/file_service.py index fe8fcd5..e2c1d47 100644 --- a/src/services/file_service.py +++ b/src/services/file_service.py @@ -30,8 +30,14 @@ def get_app_dir(): def get_resource_path(relative_path): - """Return absolute Path for a file under /resources/.""" - return get_app_dir() / "resources" / relative_path + """Return absolute Path for a resource file. + + Development resources live under src/resources/. In a PyInstaller onedir + build, resources are copied next to the executable under resources/. + """ + if getattr(sys, "frozen", False): + return get_app_dir() / "resources" / relative_path + return get_app_dir() / "src" / "resources" / relative_path def get_config_path(relative_path):