|
3 | 3 | import argparse |
4 | 4 | import os.path as osp |
5 | 5 | import os |
| 6 | +import shutil |
6 | 7 | import subprocess |
7 | 8 | from platform import platform |
8 | 9 |
|
@@ -64,6 +65,36 @@ def setup_locks(): |
64 | 65 | RUNTIME_LOCKS['model_loading'] = QMutex() |
65 | 66 |
|
66 | 67 |
|
| 68 | +def ensure_resource_theme_files(program_path: str = None, logger=None) -> list: |
| 69 | + """Copy moved stylesheet/theme files from the old config location if needed. |
| 70 | +
|
| 71 | + >>> ensure_resource_theme_files('/path/that/does/not/exist') |
| 72 | + [] |
| 73 | + """ |
| 74 | + |
| 75 | + root = Path(program_path or shared.PROGRAM_PATH) |
| 76 | + copied = [] |
| 77 | + for filename in ('stylesheet.css', 'themes.json'): |
| 78 | + target_path = root / 'resources' / filename |
| 79 | + if target_path.exists(): |
| 80 | + continue |
| 81 | + |
| 82 | + source_path = root / 'config' / filename |
| 83 | + if not source_path.exists(): |
| 84 | + continue |
| 85 | + |
| 86 | + try: |
| 87 | + target_path.parent.mkdir(parents=True, exist_ok=True) |
| 88 | + shutil.copy2(source_path, target_path) |
| 89 | + copied.append(filename) |
| 90 | + if logger is not None: |
| 91 | + logger.info(f'Copied missing resource file from old config path: {filename}') |
| 92 | + except OSError as e: |
| 93 | + if logger is not None: |
| 94 | + logger.warning(f'Failed to copy missing resource file {filename}: {e}') |
| 95 | + return copied |
| 96 | + |
| 97 | + |
67 | 98 | def preload_msvc_runtime(): |
68 | 99 | """Best-effort preload of the MSVC runtime before Qt alters DLL lookup. |
69 | 100 |
|
@@ -218,6 +249,7 @@ def main(): |
218 | 249 |
|
219 | 250 | from qtpy.QtCore import QTranslator, QLocale, Qt |
220 | 251 | setup_logging(shared.LOGGING_PATH) |
| 252 | + ensure_resource_theme_files(APP_DIR, LOGGER) |
221 | 253 | shared.args = args |
222 | 254 | shared.DEFAULT_DISPLAY_LANG = QLocale.system().name().replace('en_CN', 'zh_CN') |
223 | 255 | shared.HEADLESS = args.headless |
|
0 commit comments