feat: default export dir to <install root>\合并后的图片 when packaged
get_output_dir() now returns <install root>\合并后的图片 (parent of app\) for frozen builds — next to Launcher.exe, easy to find, not replaced on update. Falls back to <data_dir>/output if the install root is read-only; dev mode unchanged. The export panel already uses get_output_dir(), so its default follows automatically. - tests/test_file_service.py: +3 (dev, frozen install-root, fallback) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -79,8 +79,36 @@ def get_log_dir():
|
||||
return d
|
||||
|
||||
|
||||
def _is_dir_writable(path):
|
||||
"""Create *path* and probe it; True if a file can be written there."""
|
||||
try:
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
probe = path / ".write_test"
|
||||
probe.write_text("x", encoding="ascii")
|
||||
probe.unlink()
|
||||
return True
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
# Default export folder name, placed next to Launcher.exe in the packaged layout.
|
||||
_OUTPUT_DIR_NAME = "合并后的图片"
|
||||
|
||||
|
||||
def get_output_dir():
|
||||
"""Return <data_dir>/output/ as a Path, creating the directory if absent."""
|
||||
"""Return the default export directory as a Path, creating it if absent.
|
||||
|
||||
Packaged: <install root>\\合并后的图片 (next to Launcher.exe — easy to find
|
||||
and NOT replaced on update, unlike app\\). Install root is the parent of the
|
||||
app\\ folder (get_app_dir()). Falls back to <data_dir>/output if the install
|
||||
root is not writable. Development: <data_dir>/output (the project dir).
|
||||
|
||||
This is only the default; the user's chosen output_dir takes precedence.
|
||||
"""
|
||||
if getattr(sys, "frozen", False):
|
||||
candidate = get_app_dir().parent / _OUTPUT_DIR_NAME
|
||||
if _is_dir_writable(candidate):
|
||||
return candidate
|
||||
d = get_data_dir() / "output"
|
||||
d.mkdir(parents=True, exist_ok=True)
|
||||
return d
|
||||
|
||||
Reference in New Issue
Block a user