mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(library): keep another program of a Steam install out of the Steam app's route (#2742)
* fix(library): keep another program of a Steam install out of the Steam app's route * fix(library): cover a Steam-edited target in the unrouted-program test and docs * fix(library): keep Steam-edited targets routed and release stale Spacewar imports for other programs * fix(library): keep Steam-edited targets adopted before the marker existed routed A saved executable and seen revision without the adoption marker are recognised from the Steam shortcut record (its target is the current executable and differs from the one the app asked for), and the marker is stored.
This commit is contained in:
1 parent
43ff1db06b
commit
46d42f9ca9
7 files changed
+170
-10
No files matched your search
@@ -71,6 +71,10 @@ def store_game(game):
|
||||
return bool(game.get("store"))
|
||||
|
||||
|
||||
def steam_program(game):
|
||||
return game.get("route") is not False
|
||||
|
||||
|
||||
def manifest_ids(steamapps, name):
|
||||
matches = []
|
||||
try:
|
||||
@@ -230,7 +234,7 @@ def remember_tried(steam_root, account, appids):
|
||||
|
||||
|
||||
def watch(steam_root, listing):
|
||||
games = [game for game in read_json(listing, []) if not store_game(game) and not game.get("native")]
|
||||
games = [game for game in read_json(listing, []) if not store_game(game) and not game.get("native") and steam_program(game)]
|
||||
if os.environ.get("DD_STEAM_OFFLINE") == "1" or not games:
|
||||
return
|
||||
candidates, sources = {}, {}
|
||||
@@ -526,6 +530,13 @@ def release(steam_root, game, stale, reason):
|
||||
print(f"droiddeck-steam-games: {game.get('name', appid)} {reason}; it is no longer Steam app {appid}")
|
||||
|
||||
|
||||
def release_stale(steam_root, game, stale):
|
||||
try:
|
||||
release(steam_root, game, stale, "names another Steam app now")
|
||||
except OSError as error:
|
||||
print(f"droiddeck-steam-games: earlier import not undone ({error})")
|
||||
|
||||
|
||||
PREFIX_LINKS = ".droiddeck-prefix-links.json"
|
||||
|
||||
|
||||
@@ -603,17 +614,18 @@ def route(steam_root, acct, games):
|
||||
if game.get("native"):
|
||||
shortcuts.append(game)
|
||||
continue
|
||||
if not steam_program(game):
|
||||
release_stale(steam_root, game, lambda old: old == SPACEWAR)
|
||||
share_prefix(steam_root, game)
|
||||
shortcuts.append(game)
|
||||
continue
|
||||
folder = game.get("folder", "")
|
||||
appid = candidates.get(folder, candidates.get(legacy_path(folder)))
|
||||
stamp = source_stamp(game)
|
||||
recorded = sources.get(folder, sources.get(legacy_path(folder)))
|
||||
current = stamp is not None and recorded in (stamp, [stamp[0], legacy_path(stamp[1])] + stamp[2:])
|
||||
named = isinstance(appid, int) and 0 < appid < 0x80000000 and appid != SPACEWAR
|
||||
try:
|
||||
release(steam_root, game, lambda old: old == SPACEWAR or (current and named and old != appid),
|
||||
"names another Steam app now")
|
||||
except OSError as error:
|
||||
print(f"droiddeck-steam-games: earlier import not undone ({error})")
|
||||
release_stale(steam_root, game, lambda old: old == SPACEWAR or (current and named and old != appid))
|
||||
confirmed = named and current and owned.get(str(appid)) is True
|
||||
if confirmed:
|
||||
try:
|
||||
|
||||
@@ -261,6 +261,27 @@ class ImportsTest(unittest.TestCase):
|
||||
imports.watch(str(self.steam), str(listing))
|
||||
identify.assert_not_called()
|
||||
|
||||
def test_another_program_of_a_steam_install_stays_a_shortcut_beside_the_steam_app(self):
|
||||
game, library = self.steam_install()
|
||||
other = dict(game, name='Mod Launcher', exe=str(Path(game['folder']) / 'ModLauncher.exe'),
|
||||
appid=0x87654322, route=False)
|
||||
Path(other['exe']).write_bytes(b'mod')
|
||||
imports.save_json(self.acct / 'config' / imports.STATE,
|
||||
dict(account='123', owned={'42': True}, candidates={game['folder']: 42},
|
||||
sources={game['folder']: imports.source_stamp(game)}))
|
||||
games, routes = imports.route(self.steam, self.acct, [game, other])
|
||||
self.assertEqual([other], games)
|
||||
self.assertEqual({str(game['appid']): 42}, routes)
|
||||
link = self.steam / 'steamapps/compatdata' / str(other['appid'] & 0xFFFFFFFF)
|
||||
self.assertEqual(library / 'steamapps/compatdata/42', link.resolve())
|
||||
|
||||
def test_watch_never_looks_up_programs_that_are_not_the_steam_apps_own(self):
|
||||
listing = self.root / 'games.json'
|
||||
listing.write_text(json.dumps([dict(self.game, route=False)]))
|
||||
with patch.object(imports, 'identify') as identify:
|
||||
imports.watch(str(self.steam), str(listing))
|
||||
identify.assert_not_called()
|
||||
|
||||
def test_native_programs_stay_shortcuts_and_are_never_looked_up(self):
|
||||
self.snapshot()
|
||||
game = dict(self.game, native=True)
|
||||
@@ -692,6 +713,21 @@ class ImportsTest(unittest.TestCase):
|
||||
self.assert_not_imported_as(480)
|
||||
self.assertEqual(b'game', self.exe.read_bytes())
|
||||
|
||||
def test_spacewar_import_is_released_for_a_program_that_is_not_the_steam_apps_own(self):
|
||||
self.import_as(480)
|
||||
other = dict(self.game, appid=0x87654322, route=False)
|
||||
with patch('builtins.print'):
|
||||
self.assertEqual(([other], {}), imports.route(self.steam, self.acct, [other]))
|
||||
self.assert_not_imported_as(480)
|
||||
self.assertEqual(b'game', self.exe.read_bytes())
|
||||
|
||||
def test_a_steam_import_stays_when_another_program_of_the_install_is_listed(self):
|
||||
self.snapshot()
|
||||
imports.route(self.steam, self.acct, [self.game])
|
||||
other = dict(self.game, appid=0x87654322, route=False)
|
||||
imports.route(self.steam, self.acct, [other])
|
||||
self.assertTrue((self.steam / 'steamapps/appmanifest_42.acf').is_file())
|
||||
|
||||
def test_import_follows_the_app_the_files_name_now(self):
|
||||
self.snapshot()
|
||||
imports.route(self.steam, self.acct, [self.game])
|
||||
|
||||
Reference in new issue
Block a user