-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_paths.py
More file actions
53 lines (37 loc) · 1.1 KB
/
Copy pathapp_paths.py
File metadata and controls
53 lines (37 loc) · 1.1 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
"""Runtime resource and writable output paths for FolderVisualizer."""
from __future__ import annotations
import os
import sys
from pathlib import Path
APP_NAME = "FolderVisualizer"
APP_VERSION = "0.2.0"
SOURCE_DIR = Path(__file__).resolve().parent
def is_frozen() -> bool:
"""Return whether the process is running from a PyInstaller bundle."""
return bool(
getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS")
)
def _resource_dir() -> Path:
if is_frozen():
return Path(getattr(sys, "_MEIPASS")).resolve()
return SOURCE_DIR
def _output_dir() -> Path:
if not is_frozen():
return SOURCE_DIR / "outputs"
local_app_data = os.environ.get("LOCALAPPDATA", "").strip()
if local_app_data:
base_dir = Path(local_app_data)
else:
base_dir = Path.home() / "AppData" / "Local"
return base_dir / APP_NAME / "outputs"
RESOURCE_DIR = _resource_dir()
OUTPUT_DIR = _output_dir()
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
__all__ = [
"APP_NAME",
"APP_VERSION",
"OUTPUT_DIR",
"RESOURCE_DIR",
"SOURCE_DIR",
"is_frozen",
]