mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix: a Steam target whose file is gone goes back to the app's exe (#2411)
* fix: a Steam target whose file is gone goes back to the app's exe A shortcut Target edited in Steam is kept across the client's restart on purpose, but it was kept even after the file it names disappeared. When the app's own exe already equalled the recorded proposal, nothing replaced the dead target: Steam started `System/launcher.exe`, Wine answered `err:steam:run_process Failed to create process ...: 2`, and the game never ran (#694, after #1644 and #2022 removed the two real causes). The merge now treats a target that is not a file as no edit at all and writes the listing's exe and StartIn. The check runs in the guest, where the shortcut's paths live. Fixes #694 * fix: keep a Steam target whose card is not mounted - The app recreates /mnt/droiddeck-sd and /mnt/bannerlator-sd before binding the card, so the mountpoint outlives a removed card. A target directly under one had an existing parent, so the missing-file repair overwrote the edited Exe and Start In and kept them overwritten. - The repair now needs the target's storage to be there: a card mountpoint that lists nothing is a card that is not in the device, and the edit is kept for when it returns. Extra Steam libraries under /mnt/droiddeck-lib/<id> get the same check. - test_a_steam_target_under_a_bare_card_mountpoint_is_kept fails without the check and asserts both fields; test_a_steam_target_under_a_mounted_card_goes_back_to_the_apps keeps the repair. * fix: repair a Steam target removed with its folder - A missing target is gone when its storage is mounted and either its folder is still there or it lives in a tree the app always has (internal store installs, the internal Steam library). An update that removes the whole game folder now repairs the shortcut. - Store volumes and added game folders are removable mounts too: /mnt/droiddeck-stores/<id> and /root/Games/<name> are checked for content before a target under them is treated as gone, so an unplugged volume keeps the edited Exe and Start In. - Tests: internal folder removed repairs both fields; a bare store mountpoint and a card mountpoint keep both; a mounted card still repairs. 84 tests pass. * fix: classify a Steam target by its resolved path - A target such as /root/Games/Stores/../../../mnt/droiddeck-sd/Other.exe matched the internal prefix and was repaired while the card was out. internal_target and removable_mount now normalize the path before choosing the storage class, so the decision follows the file the target resolves to; the kept text is unchanged. - test_a_steam_target_is_classified_by_its_resolved_path fails before the normalization (the edit is replaced) and keeps both fields after it. 85 tests pass.
This commit is contained in:
1 parent
ab023667a0
commit
2a51b044c5
3 files changed
+160
-3
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import importlib.machinery
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
@@ -20,7 +21,15 @@ def load(name):
|
||||
shortcuts = load('droiddeck-steam-shortcuts')
|
||||
|
||||
APPID = 0x87654321
|
||||
GUEST = '/root/Games/PC/Example'
|
||||
GUEST = os.path.join(tempfile.mkdtemp(prefix='droiddeck-shortcuts-'), 'Games/PC/Example')
|
||||
|
||||
|
||||
def installed(*paths):
|
||||
"""Creates the files the writer checks, so a Steam edit to one of them is kept."""
|
||||
for path in paths:
|
||||
Path(path).parent.mkdir(parents=True, exist_ok=True)
|
||||
Path(path).touch()
|
||||
return paths[0]
|
||||
|
||||
|
||||
class ShortcutsTest(unittest.TestCase):
|
||||
@@ -34,7 +43,7 @@ class ShortcutsTest(unittest.TestCase):
|
||||
self.listing = self.root / 'added-games.json'
|
||||
|
||||
def game(self, exe='Example.exe', seen=0, appid=APPID, name='Example'):
|
||||
path = GUEST + '/' + exe
|
||||
path = installed(GUEST + '/' + exe)
|
||||
return dict(name=name, exe=path, folder=GUEST, dir=path.rsplit('/', 1)[0], appid=appid, seen=seen)
|
||||
|
||||
def run_writer(self, *games):
|
||||
@@ -54,10 +63,32 @@ class ShortcutsTest(unittest.TestCase):
|
||||
if value['appid'] & 0xFFFFFFFF == appid:
|
||||
value.update(fields)
|
||||
path.write_bytes(shortcuts.write({'shortcuts': data}))
|
||||
if fields.get('Exe'):
|
||||
target = Path(shortcuts.unquoted(fields['Exe']))
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.touch()
|
||||
|
||||
def record(self):
|
||||
return json.loads((self.config / shortcuts.RECORD).read_text())
|
||||
|
||||
def patched(self, **constants):
|
||||
for name, value in constants.items():
|
||||
old = getattr(shortcuts, name)
|
||||
setattr(shortcuts, name, value)
|
||||
self.addCleanup(setattr, shortcuts, name, old)
|
||||
|
||||
def merge_target(self, exe, **edits):
|
||||
"""Runs merge against a Steam-edited target, with the app's exe recorded as the base."""
|
||||
fresh = shortcuts.shortcut(self.game())
|
||||
current = dict(fresh, Exe=exe, **edits)
|
||||
state = {
|
||||
'app': {field: fresh[field] for field in shortcuts.FIELDS},
|
||||
'steam': {field: current.get(field, '') for field in ('AppName', 'Exe', 'StartDir', 'LaunchOptions')},
|
||||
'rev': 1,
|
||||
}
|
||||
entry, _ = shortcuts.merge(fresh, current, state, 0)
|
||||
return entry
|
||||
|
||||
def test_settings_changed_in_steam_survive_its_restart(self):
|
||||
self.run_writer(self.game())
|
||||
edits = dict(Exe='"%s/bin/Other.exe"' % GUEST, StartDir='"%s"' % GUEST, LaunchOptions='DXVK_HUD=1 %command%',
|
||||
@@ -82,6 +113,68 @@ class ShortcutsTest(unittest.TestCase):
|
||||
self.run_writer(self.game())
|
||||
self.assertEqual(1, self.record()['games'][str(APPID)]['rev'])
|
||||
|
||||
def test_a_steam_target_whose_file_is_gone_goes_back_to_the_apps(self):
|
||||
self.run_writer(self.game())
|
||||
self.steam_edits(Exe='"%s/bin/Other.exe"' % GUEST, StartDir='"%s/data"' % GUEST)
|
||||
Path(shortcuts.unquoted('"%s/bin/Other.exe"' % GUEST)).unlink()
|
||||
entry = self.run_writer(self.game())[APPID]
|
||||
self.assertEqual('"%s/Example.exe"' % GUEST, entry['Exe'])
|
||||
self.assertEqual('"%s"' % GUEST, entry['StartDir'])
|
||||
self.assertEqual('"%s/Example.exe"' % GUEST, self.record()['games'][str(APPID)]['steam']['Exe'])
|
||||
|
||||
def test_a_steam_target_whose_internal_folder_is_gone_goes_back_to_the_apps(self):
|
||||
games = self.root / 'games'
|
||||
(games / 'Stores').mkdir(parents=True)
|
||||
self.patched(INTERNAL_ROOTS=(str(games / 'Stores'),))
|
||||
entry = self.merge_target('"%s/old-version/Other.exe"' % (games / 'Stores'), StartDir='"%s/data"' % GUEST)
|
||||
self.assertEqual('"%s/Example.exe"' % GUEST, entry['Exe'])
|
||||
self.assertEqual('"%s"' % GUEST, entry['StartDir'])
|
||||
|
||||
def test_a_steam_target_on_an_unmounted_card_is_kept(self):
|
||||
card = self.root / 'card'
|
||||
card.mkdir()
|
||||
self.patched(REMOVABLE_ROOTS=(str(card),))
|
||||
entry = self.merge_target('"%s/steamapps/common/Other.exe"' % card)
|
||||
self.assertEqual('"%s/steamapps/common/Other.exe"' % card, entry['Exe'])
|
||||
self.assertEqual('"%s"' % GUEST, entry['StartDir'])
|
||||
|
||||
def test_a_steam_target_under_a_bare_card_mountpoint_is_kept(self):
|
||||
card = self.root / 'card'
|
||||
card.mkdir()
|
||||
self.patched(REMOVABLE_ROOTS=(str(card),))
|
||||
entry = self.merge_target('"%s/Other.exe"' % card, StartDir='"%s/data"' % GUEST)
|
||||
self.assertEqual('"%s/Other.exe"' % card, entry['Exe'])
|
||||
self.assertEqual('"%s/data"' % GUEST, entry['StartDir'])
|
||||
|
||||
def test_a_steam_target_is_classified_by_its_resolved_path(self):
|
||||
games = self.root / 'games'
|
||||
stores = games / 'Stores'
|
||||
stores.mkdir(parents=True)
|
||||
card = self.root / 'card'
|
||||
card.mkdir()
|
||||
self.patched(INTERNAL_ROOTS=(str(stores),), REMOVABLE_ROOTS=(str(card),))
|
||||
target = '"%s/../../card/Other.exe"' % stores
|
||||
entry = self.merge_target(target, StartDir='"%s/data"' % GUEST)
|
||||
self.assertEqual(target, entry['Exe'])
|
||||
self.assertEqual('"%s/data"' % GUEST, entry['StartDir'])
|
||||
|
||||
def test_a_steam_target_under_a_bare_store_mountpoint_is_kept(self):
|
||||
stores = self.root / 'stores'
|
||||
mount = stores / 'abcd1234'
|
||||
mount.mkdir(parents=True)
|
||||
self.patched(REMOVABLE_FAMILIES=(str(stores),))
|
||||
entry = self.merge_target('"%s/Other.exe"' % mount, StartDir='"%s/data"' % GUEST)
|
||||
self.assertEqual('"%s/Other.exe"' % mount, entry['Exe'])
|
||||
self.assertEqual('"%s/data"' % GUEST, entry['StartDir'])
|
||||
|
||||
def test_a_steam_target_under_a_mounted_card_goes_back_to_the_apps(self):
|
||||
card = self.root / 'card'
|
||||
(card / 'steamapps').mkdir(parents=True)
|
||||
self.patched(REMOVABLE_ROOTS=(str(card),))
|
||||
entry = self.merge_target('"%s/Other.exe"' % card, StartDir='"%s/data"' % GUEST)
|
||||
self.assertEqual('"%s/Example.exe"' % GUEST, entry['Exe'])
|
||||
self.assertEqual('"%s"' % GUEST, entry['StartDir'])
|
||||
|
||||
def test_the_app_taking_steams_target_keeps_steams_start_in(self):
|
||||
self.run_writer(self.game())
|
||||
self.steam_edits(Exe='"%s/bin/Other.exe"' % GUEST, StartDir='"%s/data"' % GUEST)
|
||||
|
||||
Reference in new issue
Block a user