-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathpaths.py
More file actions
53 lines (39 loc) · 1.64 KB
/
Copy pathpaths.py
File metadata and controls
53 lines (39 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Centralised path resolution for WritHer.
Provides a single DATA_DIR for all writable files (database, logs, recovery).
- When running from source: uses the project directory
- When running as PyInstaller exe: uses %APPDATA%/WritHer/
Also provides BUNDLE_DIR for read-only bundled assets (icons, images).
"""
import os
import sys
def _is_frozen() -> bool:
"""Return True if running as a PyInstaller bundle."""
return getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS')
def _get_data_dir() -> str:
"""Return the directory for writable user data (DB, logs, recovery)."""
if _is_frozen():
# PyInstaller exe: use %APPDATA%/WritHer/
appdata = os.environ.get("APPDATA", os.path.expanduser("~"))
data_dir = os.path.join(appdata, "WritHer")
else:
# Running from source: use the project directory
data_dir = os.path.dirname(os.path.abspath(__file__))
os.makedirs(data_dir, exist_ok=True)
return data_dir
def _get_bundle_dir() -> str:
"""Return the directory where bundled read-only assets live.
For PyInstaller this is the _MEIPASS temp dir or _internal folder.
For source, it's the project directory.
"""
if _is_frozen():
return sys._MEIPASS
return os.path.dirname(os.path.abspath(__file__))
# Resolved once at import time
DATA_DIR = _get_data_dir()
BUNDLE_DIR = _get_bundle_dir()
# Convenience paths
DB_PATH = os.path.join(DATA_DIR, "writher.db")
LOG_PATH = os.path.join(DATA_DIR, "writher.log")
RECOVERY_PATH = os.path.join(DATA_DIR, "recovery_notes.txt")
ICO_PATH = os.path.join(DATA_DIR, "writher.ico")
PNG_PATH = os.path.join(DATA_DIR, "writher_icon.png")