mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
fix: stop importing games as Spacewar (480) and follow a changed Steam app id (#1896)
This commit is contained in:
1 parent
88719f25d2
commit
583f34fc55
9 files changed
+303
-26
No files matched your search
@@ -20,6 +20,7 @@ LIBRARY = "/mnt/droiddeck-sd"
|
||||
LEGACY_LIBRARY = "/mnt/bannerlator-sd"
|
||||
PARKED = ".droiddeck-parked"
|
||||
BASE_ID = 76561197960265728
|
||||
SPACEWAR = 480
|
||||
|
||||
|
||||
def read_json(path, default):
|
||||
@@ -86,14 +87,14 @@ def identify(game):
|
||||
folder = Path(game["folder"])
|
||||
steamapps = folder.parent.parent
|
||||
for library in ([steamapps] if folder.parent.name == "common" and steamapps.name == "steamapps" else []) + [folder.parent / WINNATIVE]:
|
||||
matches = manifest_ids(library, folder.name)
|
||||
matches = [appid for appid in manifest_ids(library, folder.name) if appid != SPACEWAR]
|
||||
if matches:
|
||||
return matches[0] if len(matches) == 1 else None
|
||||
ids = set()
|
||||
for parent in {folder, Path(game["exe"]).parent}:
|
||||
try:
|
||||
appid = int((parent / "steam_appid.txt").read_text().strip())
|
||||
if 0 < appid < 0x80000000:
|
||||
if 0 < appid < 0x80000000 and appid != SPACEWAR:
|
||||
ids.add(appid)
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
@@ -107,7 +108,7 @@ def identify(game):
|
||||
ids = {int(item["id"]) for item in items
|
||||
if key(item.get("name", "")) == key(game["name"]) and key(game["name"])}
|
||||
if ids:
|
||||
return next(iter(ids)) if len(ids) == 1 else None
|
||||
return next(iter(ids)) if len(ids) == 1 and SPACEWAR not in ids else None
|
||||
return None
|
||||
except (OSError, ValueError, KeyError):
|
||||
return None
|
||||
@@ -423,20 +424,20 @@ def seed_install(steam_root, game, appid):
|
||||
return True
|
||||
|
||||
|
||||
def release(steam_root, game):
|
||||
"""Undoes an import made before store games were skipped. Only our symlink and manifest go;
|
||||
the store's folder stays where it is."""
|
||||
def release(steam_root, game, stale, reason):
|
||||
"""Undoes the imports of the game's folder as the Steam apps [stale] picks. Only our symlink and
|
||||
manifest go; the folder stays where it is."""
|
||||
steamapps = Path(steam_root) / "steamapps"
|
||||
sources = {game.get("folder", ""), legacy_path(game.get("folder", ""))}
|
||||
for target in sorted((steamapps / "common").glob("DroidDeck-*")):
|
||||
appid = target.name.removeprefix("DroidDeck-")
|
||||
if not (appid.isdigit() and target.is_symlink() and os.readlink(target) in sources):
|
||||
if not (appid.isdigit() and target.is_symlink() and os.readlink(target) in sources and stale(int(appid))):
|
||||
continue
|
||||
for manifest in (steamapps / f"appmanifest_{appid}.acf", steamapps / PARKED / f"appmanifest_{appid}.acf"):
|
||||
if manifest.is_file() and ours(manifest, appid):
|
||||
manifest.unlink()
|
||||
target.unlink()
|
||||
print(f"droiddeck-steam-games: {game.get('name', appid)} came from {game['store']}; it is a shortcut again, not Steam app {appid}")
|
||||
print(f"droiddeck-steam-games: {game.get('name', appid)} {reason}; it is no longer Steam app {appid}")
|
||||
|
||||
|
||||
def route(steam_root, acct, games):
|
||||
@@ -457,7 +458,7 @@ def route(steam_root, acct, games):
|
||||
for game in games:
|
||||
if store_game(game):
|
||||
try:
|
||||
release(steam_root, game)
|
||||
release(steam_root, game, lambda old: True, f"came from {game['store']}")
|
||||
except OSError as error:
|
||||
print(f"droiddeck-steam-games: store import not undone ({error})")
|
||||
shortcuts.append(game)
|
||||
@@ -469,9 +470,14 @@ def route(steam_root, acct, games):
|
||||
appid = candidates.get(folder, candidates.get(legacy_path(folder)))
|
||||
stamp = source_stamp(game)
|
||||
recorded = sources.get(folder, sources.get(legacy_path(folder)))
|
||||
confirmed = (isinstance(appid, int) and 0 < appid < 0x80000000
|
||||
and owned.get(str(appid)) is True and stamp is not None
|
||||
and recorded in (stamp, [stamp[0], legacy_path(stamp[1])] + stamp[2:]))
|
||||
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})")
|
||||
confirmed = named and current and owned.get(str(appid)) is True
|
||||
if confirmed:
|
||||
try:
|
||||
if seed_install(steam_root, game, appid):
|
||||
@@ -480,7 +486,7 @@ def route(steam_root, acct, games):
|
||||
print(f"droiddeck-steam-games: {game.get('name', appid)} stays a shortcut this session: it could not be linked as Steam app {appid}")
|
||||
except OSError as error:
|
||||
print(f"droiddeck-steam-games: import unavailable ({error})")
|
||||
elif isinstance(appid, int) and 0 < appid < 0x80000000 and seeded(steamapps, game, appid):
|
||||
elif named and seeded(steamapps, game, appid):
|
||||
routes[str(game["appid"])] = appid
|
||||
continue
|
||||
shortcuts.append(game)
|
||||
|
||||
@@ -391,6 +391,61 @@ class ImportsTest(unittest.TestCase):
|
||||
with patch.object(imports.urllib.request, 'urlopen', side_effect=AssertionError):
|
||||
self.assertEqual(42, imports.identify(self.game))
|
||||
|
||||
def test_spacewar_appid_names_no_game(self):
|
||||
(self.folder / 'steam_appid.txt').write_text('480\n')
|
||||
with patch.object(imports.urllib.request, 'urlopen', side_effect=OSError):
|
||||
self.assertIsNone(imports.identify(self.game))
|
||||
|
||||
def import_as(self, appid):
|
||||
self.assertTrue(imports.seed_install(self.steam, self.game, appid))
|
||||
self.assertTrue((self.steam / f'steamapps/appmanifest_{appid}.acf').is_file())
|
||||
|
||||
def snapshot_names(self, appid, owned):
|
||||
imports.save_json(self.acct / 'config' / imports.STATE,
|
||||
dict(account='123', owned={str(appid): owned},
|
||||
candidates={str(self.folder): appid},
|
||||
sources={str(self.folder): imports.source_stamp(self.game)}))
|
||||
|
||||
def assert_not_imported_as(self, appid):
|
||||
self.assertFalse((self.steam / f'steamapps/appmanifest_{appid}.acf').exists())
|
||||
self.assertFalse(os.path.lexists(self.steam / f'steamapps/common/DroidDeck-{appid}'))
|
||||
|
||||
def test_spacewar_import_is_released_and_never_made_again(self):
|
||||
self.import_as(480)
|
||||
self.snapshot_names(480, owned=True)
|
||||
with patch('builtins.print'):
|
||||
self.assertEqual(([self.game], {}), imports.route(self.steam, self.acct, [self.game]))
|
||||
self.assert_not_imported_as(480)
|
||||
self.assertEqual(b'game', self.exe.read_bytes())
|
||||
|
||||
def test_import_follows_the_app_the_files_name_now(self):
|
||||
self.snapshot()
|
||||
imports.route(self.steam, self.acct, [self.game])
|
||||
self.snapshot_names(43, owned=True)
|
||||
with patch('builtins.print'):
|
||||
self.assertEqual(([], {str(self.game['appid']): 43}), imports.route(self.steam, self.acct, [self.game]))
|
||||
self.assert_not_imported_as(42)
|
||||
self.assertEqual(self.folder, (self.steam / 'steamapps/common/DroidDeck-43').resolve())
|
||||
|
||||
def test_unowned_new_appid_leaves_a_shortcut(self):
|
||||
self.snapshot()
|
||||
imports.route(self.steam, self.acct, [self.game])
|
||||
self.snapshot_names(43, owned=False)
|
||||
with patch('builtins.print'):
|
||||
self.assertEqual(([self.game], {}), imports.route(self.steam, self.acct, [self.game]))
|
||||
self.assert_not_imported_as(42)
|
||||
self.assert_not_imported_as(43)
|
||||
|
||||
def test_import_stays_while_the_new_identity_is_unknown(self):
|
||||
self.snapshot()
|
||||
imports.route(self.steam, self.acct, [self.game])
|
||||
for candidates in ({}, {str(self.folder): 43}):
|
||||
imports.save_json(self.acct / 'config' / imports.STATE,
|
||||
dict(account='123', owned={'43': True}, candidates=candidates,
|
||||
sources={str(self.folder): ['stale']}))
|
||||
imports.route(self.steam, self.acct, [self.game])
|
||||
self.assertTrue((self.steam / 'steamapps/appmanifest_42.acf').is_file())
|
||||
|
||||
def test_manifest_identity_uses_install_directory(self):
|
||||
folder = self.root / 'second/steamapps/common/Custom Name'
|
||||
folder.mkdir(parents=True)
|
||||
@@ -399,6 +454,21 @@ class ImportsTest(unittest.TestCase):
|
||||
with patch.object(imports.urllib.request, 'urlopen', side_effect=AssertionError):
|
||||
self.assertEqual(42, imports.identify(game))
|
||||
|
||||
def test_a_spacewar_manifest_names_no_game(self):
|
||||
folder = self.root / 'second/steamapps/common/PEAK'
|
||||
folder.mkdir(parents=True)
|
||||
(folder.parent.parent / 'appmanifest_480.acf').write_text('"AppState" { "installdir" "PEAK" }')
|
||||
(folder / 'steam_appid.txt').write_text('3527290\n')
|
||||
game = dict(self.game, folder=str(folder), exe=str(folder / 'PEAK.exe'))
|
||||
with patch.object(imports.urllib.request, 'urlopen', side_effect=AssertionError):
|
||||
self.assertEqual(3527290, imports.identify(game))
|
||||
|
||||
def test_a_store_search_answering_spacewar_names_no_game(self):
|
||||
with patch.object(imports.urllib.request, 'urlopen') as request:
|
||||
request.return_value.__enter__.return_value.read.return_value = json.dumps(
|
||||
{'items': [{'id': 480, 'name': 'Spacewar'}]}).encode()
|
||||
self.assertIsNone(imports.identify(dict(self.game, name='Spacewar')))
|
||||
|
||||
def test_store_requires_unique_exact_title(self):
|
||||
cases = [([{'id': 42, 'name': 'Example Deluxe'}], None),
|
||||
([{'id': 42, 'name': 'Example'}, {'id': 43, 'name': 'Example'}], None),
|
||||
|
||||
Reference in new issue
Block a user