The setup window starts with the last install folder, kept in a per-user file

An update needs only the install folder: the recorded game language and the other inputs come from totk-install.json. installer/recent.py stores the folder in %LOCALAPPDATA%\TotK Recomp\setup.json (XDG state dir elsewhere), outside the release folder, so a new release finds it.

Idea from #715 by DanielSvoboda.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-05 17:14:23 +03:00
1 parent f9afb9b565
commit 640990afcc
4 files changed
+100 -1

No files matched your search

+8
View File
@@ -16,6 +16,7 @@ import json
import os
import subprocess
import sys
import tempfile
from pathlib import Path
from . import dpi
@@ -34,6 +35,7 @@ except ImportError:
from . import ini
from . import layout as layouts
from . import recent
from .guilogic import (DONE, FAILED, PENDING, RUNNING, SKIPPED, UI_LANGUAGE_LABELS, UI_LANGUAGES, Catalog, Form, Model,
Process, amount, default_game_language, describe_event, parse_line, windows_ui_language)
@@ -113,6 +115,10 @@ class App:
self.bind_text(self.title, 'text', 'ui.rebuild_title')
self.vars['dest'].set(str(rebuild))
root.after(POLL_MS, self.start)
else:
last = recent.load() # an update needs only the folder: refresh_form shows the hint and the recorded language
if last:
self.vars['dest'].set(last)
# ---- text -----------------------------------------------------------------------------------------------------
@@ -358,6 +364,7 @@ class App:
self.fit()
return
self.form_error.configure(text='')
recent.save(form.dest)
# in a repository the Python running this window: the tools' embeddable Python there has no ._pth entry for
# the repository, so `-m installer` would not find the package
python = Path(sys.executable) if self.layout.dev else self.layout.python
@@ -606,6 +613,7 @@ def grab(root, path):
def selftest(layout, shots=None):
"""Every screen in every language; the window closes itself. Returns 0 when nothing raised."""
fix_tcl_paths()
os.environ[recent.ENV] = os.path.join(tempfile.mkdtemp(prefix='totk-selftest-'), 'setup.json')
root = tk.Tk()
root.geometry('+60+40')
app = App(root, 'en', layout)
+52
View File
@@ -0,0 +1,52 @@
"""The last install folder, in a per-user file, so an update starts with the folder already filled in.
{"format": 1, "dest": "<absolute path>"}
Windows: %LOCALAPPDATA%\TotK Recomp\setup.json; elsewhere $XDG_STATE_HOME/totk-recomp/setup.json (default
~/.local/state/totk-recomp/setup.json). TOTK_SETUP_RECENT names another file (tests, --selftest). Nothing else is
stored: the language comes from the install's own totk-install.json, and no key or key file path is kept.
"""
import json
import os
import sys
from pathlib import Path
from . import state
FORMAT = 1
ENV = 'TOTK_SETUP_RECENT'
def path():
override = os.environ.get(ENV)
if override:
return Path(override)
if sys.platform == 'win32':
base = os.environ.get('LOCALAPPDATA') or str(Path.home() / 'AppData' / 'Local')
return Path(base) / 'TotK Recomp' / 'setup.json'
base = os.environ.get('XDG_STATE_HOME') or str(Path.home() / '.local' / 'state')
return Path(base) / 'totk-recomp' / 'setup.json'
def load():
"""The recorded install folder when it still holds totk-install.json, else None. Never raises."""
try:
data = json.loads(path().read_text(encoding='utf-8'))
dest = data['dest']
if not isinstance(dest, str) or not dest:
return None
return dest if (Path(dest) / state.NAME).is_file() else None
except (OSError, ValueError, KeyError, TypeError):
return None
def save(dest):
"""Records dest atomically; a failure to write is ignored, the window works without it."""
target = path()
tmp = target.with_name(target.name + '.tmp')
try:
target.parent.mkdir(parents=True, exist_ok=True)
tmp.write_text(json.dumps({'format': FORMAT, 'dest': os.path.abspath(dest)}), encoding='utf-8')
os.replace(tmp, target)
except OSError:
pass