fix(gog): install scripts' support files reach the prefix (#2294)

* fix(gog): install scripts' support files reach the prefix

A goggame-<id>.script can copy files into the prefix with supportData
actions: default INI files, Plugins.txt and other settings that mods such
as one-click editions need. Only setRegistry actions were applied, so
those games started without their configuration and ran as the base game.

droiddeck-store-launch now applies supportData after the registry, once
per script revision: copies from {app} and {supportDir} into {userdocs}
and {localappdata}, matching paths without regard to case. Links are
copied as links, paths outside those folders are refused, and existing
files are replaced only when the action asks for it.

* Keep GOG support data copies inside the game and prefix folders

* Copy linked GOG support sources as links and keep a player's own links
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-08 18:45:53 -05:00
1 parent 92742f37c1
commit 6b110581ac
3 files changed
+316 -1

No files matched your search

@@ -5,6 +5,7 @@ import binascii
import json
import os
import re
import shutil
import sys
import time
import subprocess
@@ -352,6 +353,7 @@ def prepare_gog(sidecar, compat_data, launch_dir):
GOG_SCRIPTS = "goggame-*.script"
GOG_REGISTRY_MARK = ".droiddeck-gog-registry"
GOG_SUPPORT_MARK = ".droiddeck-gog-support"
GOG_ROOTS = {"HKEY_LOCAL_MACHINE": "HKEY_LOCAL_MACHINE", "HKLM": "HKEY_LOCAL_MACHINE",
"HKEY_CURRENT_USER": "HKEY_CURRENT_USER", "HKCU": "HKEY_CURRENT_USER",
"HKEY_CLASSES_ROOT": "HKEY_CLASSES_ROOT", "HKCR": "HKEY_CLASSES_ROOT"}
@@ -611,6 +613,120 @@ def apply_gog_registry(folder, compat_data, proton, timeout=90, installation=Non
return "import-failed" + note
def gog_support_actions(folder):
found = []
for script in sorted(Path(folder).glob(GOG_SCRIPTS)):
product = script.name[len("goggame-"):-len(".script")]
try:
actions = json.loads(script.read_text(encoding="utf-8-sig")).get("actions")
except (OSError, ValueError, AttributeError):
continue
for action in actions if isinstance(actions, list) else []:
install = action.get("install") if isinstance(action, dict) else None
if isinstance(install, dict) and install.get("action") == "supportData" \
and isinstance(install.get("arguments"), dict):
found.append((product, install["arguments"]))
return found
def gog_support_bases(folder, product, pfx):
user = Path(pfx) / "drive_c" / "users" / "steamuser"
support = Path(folder) / "support" / product
return {"app": Path(folder), "supportdir": support, "support": support,
"userdocs": user / "Documents", "localappdata": user / "AppData" / "Local"}
def gog_inside(path, base):
root = os.path.realpath(base)
real = os.path.realpath(path)
return real == root or real.startswith(root + os.sep)
def gog_support_path(text, bases):
match = re.fullmatch(r"\{(\w+)\}(.*)", text) if isinstance(text, str) else None
if not match or match.group(1).lower() not in bases:
return None
parts = [part for part in re.split(r"[\\/]+", match.group(2)) if part]
if any(part in (".", "..") for part in parts):
return None
base = bases[match.group(1).lower()]
path = base
for part in parts:
exact = path / part
if not exact.exists() and path.is_dir():
exact = next((child for child in path.iterdir() if child.name.lower() == part.lower()), exact)
path = exact
if path != base and not gog_inside(path.parent, base):
return None
return path, base
def gog_copy_file(source, target, root):
if not gog_inside(target.parent, root):
raise OSError("outside " + str(root))
target.parent.mkdir(parents=True, exist_ok=True)
if target.is_symlink():
target.unlink()
shutil.copy2(source, target, follow_symlinks=False)
def gog_support_data(folder, compat_data, proton):
actions = gog_support_actions(folder)
if not actions:
return "none"
pfx = Path(compat_data) / "pfx" if compat_data else None
if not pfx or not (pfx / "drive_c" / "users" / "steamuser").is_dir():
made = create_prefix(compat_data, proton)
if made not in ("present", "created") or not (pfx / "drive_c" / "users" / "steamuser").is_dir():
return "no-prefix"
stamp = hashlib.sha256(json.dumps(actions, sort_keys=True).encode("utf-8")).hexdigest()
marker = pfx / GOG_SUPPORT_MARK
try:
if marker.is_file() and marker.read_text() == stamp:
return "ready"
except OSError:
pass
copied = skipped = missing = 0
for product, arguments in actions:
bases = gog_support_bases(folder, product, pfx)
found = gog_support_path(arguments.get("target"), bases)
origin = gog_support_path(arguments["source"], bases) if "source" in arguments else None
if found is None or ("source" in arguments and origin is None):
skipped += 1
continue
target, root = found
source = origin[0] if origin else None
try:
if source is None:
target.mkdir(parents=True, exist_ok=True)
elif not source.exists():
missing += 1
elif source.is_dir() and not source.is_symlink():
for top, dirs, files in os.walk(source):
for name in sorted(files + [d for d in dirs if (Path(top) / d).is_symlink()]):
item = Path(top) / name
destination = target / item.relative_to(source)
if (destination.exists() or destination.is_symlink()) and not arguments.get("overwrite"):
continue
gog_copy_file(item, destination, root)
copied += 1
target.mkdir(parents=True, exist_ok=True)
elif (target.exists() or target.is_symlink()) and not arguments.get("overwrite"):
continue
else:
gog_copy_file(source, target, root)
copied += 1
except OSError:
skipped += 1
note = "".join(" %s=%d" % (name, count) for name, count in (("skipped", skipped), ("missing", missing)) if count)
if not skipped:
try:
marker.write_text(stamp)
except OSError:
pass
return "copied=%d%s" % (copied, note)
def main(argv):
if os.environ.get("DROIDDECK_GOG_MAINTENANCE") == "1":
return 0
@@ -654,6 +770,7 @@ def main(argv):
if store == "gog":
prepare_gog(sidecar, compat_data, launch_dir)
log("gog registry: " + apply_gog_registry(folder, compat_data, os.environ.get("BL_STORE_PROTON", "")))
log("gog support data: " + gog_support_data(folder, compat_data, os.environ.get("BL_STORE_PROTON", "")))
if store == "epic":
handled = os.environ.get(EPIC_HANDLED) == "1" and (folder / EPIC_ARGS).is_file()
if not handled: