Move config storage next to the install and auto-create it if missing
versapad_combined.DEFAULT_PATH was hardcoded to this one machine's OneDrive desktop, which made the tool unusable anywhere else. versapad_data.app_dir() now resolves to the running .exe's own folder when frozen, or the project directory when run from source, and DEFAULT_PATH hangs off that instead. load_or_fetch() previously raised when both the file was missing and the board unreachable, blocking a fresh install with no config and no board attached. It now falls back to an empty default_combined() in that case, so the tool is immediately usable either way. desktop_viewer's _current_profile_view() picks up the same fallback instead of re-implementing a narrower version of it. Also drop the hardcoded PROFILE_NAMES dict, which had drifted out of sync with the profile_names already stored in the combined JSON -- renaming a profile in Programmiermodus never showed up in the read-only/browser views. server.py and desktop_viewer.py now read names from the same JSON everywhere. versapad_data.CONFIG_PATHS (read-only interop with the official C# VersaGUI's JSON export) is intentionally left on the OneDrive desktop -- nothing in this codebase writes there, it's not part of this tool's own config.
This commit is contained in:
parent
13c3745479
commit
5d14bdd826
7 changed files with 147 additions and 57 deletions
|
|
@ -19,7 +19,7 @@ import versapad_data as vp
|
|||
import versapad_protocol as proto
|
||||
import versapad_serial as vs
|
||||
|
||||
DEFAULT_PATH = os.path.expanduser(r"~\OneDrive\Desktop\versapad_config_all.json")
|
||||
DEFAULT_PATH = os.path.join(vp.app_dir(), "versapad_config_all.json")
|
||||
|
||||
DEFAULT_NAMES = ["Windows", "Fusion 360", "BricsCAD"]
|
||||
|
||||
|
|
@ -126,18 +126,37 @@ def fetch_from_board(link=None, profile_names=None):
|
|||
|
||||
def load_or_fetch(path=DEFAULT_PATH, link=None, profile_names=None):
|
||||
"""Bevorzugt die lokale Kombi-Datei. Fehlt sie (z.B. versehentlich
|
||||
geloescht), wird sie automatisch per Serial vom Board neu aufgebaut und
|
||||
als neuer Cache gespeichert, statt einen Fehler zu werfen -- das Board
|
||||
behaelt die Config dauerhaft im NVM, die Desktop-JSON ist nur ein
|
||||
Lesecache dafuer und muss nicht von Hand gepflegt werden. Ist das Board
|
||||
nicht erreichbar (nicht verbunden, COM-Port belegt), wirft es
|
||||
RuntimeError mit Klartext-Ursache -- Aufrufer entscheidet, ob es einen
|
||||
weiteren Fallback gibt (z.B. alte Einzel-JSONs)."""
|
||||
geloescht, oder frische Installation ohne jede Config), wird sie
|
||||
automatisch neu angelegt -- zuerst per Serial-Versuch vom Board (das
|
||||
behaelt die Config dauerhaft im NVM, die JSON ist nur ein Lesecache
|
||||
dafuer), und falls auch das Board nicht erreichbar ist (nicht
|
||||
verbunden, COM-Port belegt, frisch installiert ohne Board in Reichweite)
|
||||
als leere Default-Config (vgl. default_combined()) -- damit ist das
|
||||
Tool auch ganz ohne vorhandene Config sofort benutzbar, statt mit
|
||||
einem Fehler zu blockieren."""
|
||||
if os.path.exists(path):
|
||||
return load_file(path)
|
||||
combined = fetch_from_board(link=link, profile_names=profile_names)
|
||||
try:
|
||||
combined = fetch_from_board(link=link, profile_names=profile_names)
|
||||
except RuntimeError:
|
||||
combined = default_combined()
|
||||
if profile_names:
|
||||
combined["profile_names"] = profile_names
|
||||
try:
|
||||
save_file(combined, path)
|
||||
except OSError:
|
||||
pass # Board-Daten trotzdem verwertbar, nur der Cache konnte nicht geschrieben werden
|
||||
pass # Daten trotzdem verwertbar, nur der Cache konnte nicht geschrieben werden
|
||||
return combined
|
||||
|
||||
|
||||
def read_profile_names(path=DEFAULT_PATH):
|
||||
"""Nur die (lokalen) Profilnamen lesen, ohne die volle Config zu
|
||||
brauchen -- fuer Tab-Beschriftungen im Nur-Lese-Modus. Greift bewusst
|
||||
nicht aufs Board zu (kein COM-Port-Konflikt mit Live-Sync), faellt bei
|
||||
fehlender/kaputter Datei auf DEFAULT_NAMES zurueck."""
|
||||
if os.path.exists(path):
|
||||
try:
|
||||
return load_file(path).get("profile_names", list(DEFAULT_NAMES))
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
return list(DEFAULT_NAMES)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue