mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
Stores: Epic overlay off by default, switches saved on disk, registry writes checked
With the overlay pointer set Metalstorm exits while loading; without it the game signs in and runs. The overlay now defaults to off: the sidecar's epic block carries a version, and a block from before it (the old default wrote overlay=true unasked) reads as off, in the app and in droiddeck-store-launch alike. The overlay is fetched only for a game that turns it on. The card's switches read the sidecar fresh, write it and read it back, and show what was read back. droiddeck-store-launch waits for a wineserver still holding the prefix before appending to user.reg - one that exits rewrites the file and drops the line - reads the value back and logs what the file holds. Its docstring is raw. The game-PATH xdg-open logs each call as scheme://host only and accepts steam://openurl.
This commit is contained in:
1 parent
1d1de10b2d
commit
a844483080
9 files changed
+165
-30
No files matched your search
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python3
|
||||
"""Before Proton starts a store game, asks the app for what that store needs at launch.
|
||||
r"""Before Proton starts a store game, asks the app for what that store needs at launch.
|
||||
|
||||
Run by droiddeck-proton / droiddeck-proton-wrap (steam-compatibility) for every real game launch,
|
||||
whoever started it: the Games tab, a pinned shortcut, or the Steam client's own Play button. It
|
||||
@@ -39,6 +39,7 @@ EPIC_CODE = ".droiddeck-epic-code"
|
||||
TIMEOUT = 5.0
|
||||
STALE_SECONDS = 300
|
||||
OVERLAY_DIR = "/root/.local/share/droiddeck/epic-overlay"
|
||||
SERVER_WAIT = 8.0
|
||||
OVERLAY_DLL = "EOSOVH-Win64-Shipping.dll"
|
||||
EOS_KEY = "[Software\\\\Epic Games\\\\EOS]"
|
||||
BROWSER_KEY = "[Software\\\\Wine\\\\WineBrowser]"
|
||||
@@ -171,24 +172,74 @@ def remove_value(reg, key, name):
|
||||
def options(sidecar):
|
||||
"""An Epic game's launch choices from its sidecar, as the Games tab's Epic card sets them."""
|
||||
e = sidecar.get("epic") if isinstance(sidecar.get("epic"), dict) else {}
|
||||
return {"eos": e.get("eos", True) is not False, "offline": e.get("offline", False) is True, "overlay": e.get("overlay", True) is not False}
|
||||
# The overlay is off unless chosen (v2 on): the old default wrote overlay=true without a version,
|
||||
# and with it on a game could exit while loading. The app's EpicOptions reads it the same way.
|
||||
chosen = isinstance(e.get("v"), int) and e.get("v") >= 2
|
||||
return {"eos": e.get("eos", True) is not False, "offline": e.get("offline", False) is True, "overlay": chosen and e.get("overlay") is True}
|
||||
|
||||
|
||||
def provision_prefix(compat_data, overlay_dir=OVERLAY_DIR, overlay=True):
|
||||
def server_socket(pfx):
|
||||
"""The wineserver socket for prefix [pfx], as Wine names it (server-<dev>-<inode> under /tmp/.wine-<uid>)."""
|
||||
try:
|
||||
st = os.stat(pfx)
|
||||
except OSError:
|
||||
return None
|
||||
base = os.environ.get("BL_WINE_SERVER_BASE") or "/tmp/.wine-%d" % os.getuid()
|
||||
return Path(base) / ("server-%x-%x" % (st.st_dev, st.st_ino)) / "socket"
|
||||
|
||||
|
||||
def wait_for_server(pfx, timeout=SERVER_WAIT):
|
||||
"""
|
||||
Waits for a wineserver still holding this prefix (an earlier verb's, or the last launch's) to
|
||||
exit: it rewrites user.reg from its own memory when it does, which drops a line appended
|
||||
meanwhile. True when none is left.
|
||||
"""
|
||||
sock = server_socket(pfx)
|
||||
if sock is None:
|
||||
return True
|
||||
deadline = time.monotonic() + timeout
|
||||
while sock.exists() and time.monotonic() < deadline:
|
||||
time.sleep(0.1)
|
||||
return not sock.exists()
|
||||
|
||||
|
||||
def has_value(reg, key, name, value=None):
|
||||
"""Whether the last word on `key` in user.reg sets "name" (to [value], when given)."""
|
||||
if not reg.is_file():
|
||||
return False
|
||||
inside, last = False, None
|
||||
for row in reg.read_text(errors="replace").splitlines():
|
||||
if row.startswith("["):
|
||||
inside = row.startswith(key + " ") or row == key
|
||||
elif inside and row.startswith('"%s"=' % name):
|
||||
last = row
|
||||
if last is None:
|
||||
return False
|
||||
return value is None or last == '"%s"="%s"' % (name, reg_escape(value))
|
||||
|
||||
|
||||
def provision_prefix(compat_data, overlay_dir=OVERLAY_DIR, overlay=False, wait=SERVER_WAIT):
|
||||
"""The EOS overlay pointer (or its removal, when [overlay] is off) and Wine's browser, in the game's prefix."""
|
||||
if not compat_data:
|
||||
return "no-prefix"
|
||||
reg = Path(compat_data) / "pfx" / "user.reg"
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
reg = pfx / "user.reg"
|
||||
if not reg.is_file():
|
||||
return "prefix-not-created"
|
||||
# A wineserver still up for this prefix would write its own copy of user.reg over these lines.
|
||||
busy = not wait_for_server(pfx, wait)
|
||||
set_value(reg, BROWSER_KEY, "Browsers", "xdg-open")
|
||||
if not overlay:
|
||||
remove_value(reg, EOS_KEY, "OverlayPath")
|
||||
return "overlay-off"
|
||||
if overlay_version(overlay_dir) is None:
|
||||
state = "overlay-off" if not has_value(reg, EOS_KEY, "OverlayPath") else "overlay-still-set"
|
||||
elif overlay_version(overlay_dir) is None:
|
||||
return "overlay-missing"
|
||||
set_value(reg, EOS_KEY, "OverlayPath", windows_path(overlay_dir))
|
||||
return "overlay-set"
|
||||
else:
|
||||
target = windows_path(overlay_dir)
|
||||
set_value(reg, EOS_KEY, "OverlayPath", target)
|
||||
# Read back, so the log says what the file holds, not what was meant.
|
||||
state = "overlay-set" if has_value(reg, EOS_KEY, "OverlayPath", target) else "overlay-not-written"
|
||||
return state + (" server-running" if busy else "")
|
||||
|
||||
|
||||
def main(argv):
|
||||
|
||||
@@ -20,9 +20,23 @@ def hand_over(url, launch_dir):
|
||||
os.rename(tmp, req / (rid + ".json"))
|
||||
|
||||
|
||||
def where(url):
|
||||
"""scheme://host only, for the log: no path, no query."""
|
||||
from urllib.parse import urlsplit
|
||||
try:
|
||||
u = urlsplit(url)
|
||||
return "%s://%s" % (u.scheme, u.hostname or "")
|
||||
except ValueError:
|
||||
return "?"
|
||||
|
||||
|
||||
def main(argv):
|
||||
url = argv[0] if argv else ""
|
||||
# The Steam client's own form (steam://openurl/<address>), in case a launcher passes it on.
|
||||
if url.startswith("steam://openurl/"):
|
||||
url = url[len("steam://openurl/"):]
|
||||
launch_dir = os.environ.get("BL_LAUNCH_DIR", "")
|
||||
print("droiddeck xdg-open: %s" % where(url), file=sys.stderr, flush=True)
|
||||
if url.startswith(("https://", "http://")) and launch_dir:
|
||||
hand_over(url, launch_dir)
|
||||
return 0
|
||||
|
||||
@@ -128,18 +128,18 @@ class Prefix(unittest.TestCase):
|
||||
def test_the_overlay_pointer_names_the_shared_copy_through_z(self):
|
||||
(self.overlay / store.OVERLAY_DLL).write_bytes(b'MZ')
|
||||
(self.overlay / 'droiddeck-version').write_text('1.0.42')
|
||||
self.assertEqual('overlay-set', store.provision_prefix(str(self.compat), str(self.overlay)))
|
||||
self.assertEqual('overlay-set', store.provision_prefix(str(self.compat), str(self.overlay), overlay=True))
|
||||
text = self.reg.read_text()
|
||||
self.assertIn('[Software\\\\Epic Games\\\\EOS] ', text)
|
||||
self.assertIn('"OverlayPath"="Z:' + str(self.overlay).replace('/', '\\\\') + '"', text)
|
||||
self.assertIn('"Browsers"="xdg-open"', text)
|
||||
# A second launch adds nothing: the last word already says so.
|
||||
store.provision_prefix(str(self.compat), str(self.overlay))
|
||||
store.provision_prefix(str(self.compat), str(self.overlay), overlay=True)
|
||||
self.assertEqual(text, self.reg.read_text())
|
||||
self.assertEqual('1.0.42', store.overlay_version(str(self.overlay)))
|
||||
|
||||
def test_no_overlay_yet_or_no_prefix_yet(self):
|
||||
self.assertEqual('overlay-missing', store.provision_prefix(str(self.compat), str(self.overlay)))
|
||||
self.assertEqual('overlay-missing', store.provision_prefix(str(self.compat), str(self.overlay), overlay=True))
|
||||
self.assertNotIn('OverlayPath', self.reg.read_text())
|
||||
self.assertEqual('prefix-not-created', store.provision_prefix(self.tmp.name + '/compatdata/1', str(self.overlay)))
|
||||
self.assertEqual('no-prefix', store.provision_prefix('', str(self.overlay)))
|
||||
@@ -150,7 +150,10 @@ class Choices(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root)
|
||||
sidecar = json.loads((folder / '.droiddeck-store.json').read_text())
|
||||
self.assertEqual({'eos': True, 'offline': False, 'overlay': True}, store.options(sidecar))
|
||||
self.assertEqual({'eos': True, 'offline': False, 'overlay': False}, store.options(sidecar))
|
||||
# The old default (no version) never turns it on; a v2 choice does.
|
||||
self.assertFalse(store.options({'epic': {'eos': True, 'offline': False, 'overlay': True}})['overlay'])
|
||||
self.assertTrue(store.options({'epic': {'v': 2, 'overlay': True}})['overlay'])
|
||||
sidecar['epic'] = {'eos': True, 'offline': True, 'overlay': False}
|
||||
(folder / '.droiddeck-store.json').write_text(json.dumps(sidecar))
|
||||
(folder / '.droiddeck-epic-code').write_text('left over')
|
||||
@@ -185,6 +188,7 @@ class Browser(unittest.TestCase):
|
||||
reqs = list((Path(root) / 'stores/req').glob('*.json'))
|
||||
self.assertEqual(1, len(reqs))
|
||||
self.assertEqual({'op': 'open-url', 'url': 'https://www.epicgames.com/activate'}, json.loads(reqs[0].read_text()))
|
||||
self.assertEqual('https://www.epicgames.com', xdg.where('https://www.epicgames.com/activate?code=SECRET'))
|
||||
|
||||
|
||||
class Launchers(unittest.TestCase):
|
||||
|
||||
Reference in new issue
Block a user