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:
Kurt Himebauch authored and GitHub committed 2026-11-24 17:50:09 -05:00
1 parent 43ff1db06b
commit 46d42f9ca9
7 files changed
+170 -10

No files matched your search

@@ -31,6 +31,7 @@ object AddedGames {
val exeUncertain: Boolean = false,
val launchOptions: String = "",
val single: Boolean = false,
val steamProgram: Boolean = true,
) {
fun folderName(): String = folder.name
}
@@ -470,7 +471,13 @@ object AddedGames {
val guestDir = SessionPrefs.addedGameStartIn(context, folder.path).takeIf { sidecar == null && it.isNotEmpty() }
?: sidecarDir
?: guestPath(context, (if (adopted != null) adopted else launch).parentFile ?: folder) ?: return
val steamId = config?.let { steamRoute(it, appId) }
if (adopted == null && SessionPrefs.addedGameAdopted(context, folder.path, "Exe") == null &&
guestPath(context, folder)?.let { steamEditedTo(it, record, guestExe) } == true) {
SessionPrefs.setAddedGameAdopted(context, folder.path, "Exe", exe.path)
}
val steamProgram = candidates.firstOrNull()?.let { canonical(it) == canonical(exe) } ?: true ||
SessionPrefs.addedGameAdopted(context, folder.path, "Exe")?.let { canonical(File(it)) == canonical(exe) } == true
val steamId = config?.takeIf { steamProgram }?.let { steamRoute(it, appId) }
out.add(Game(folder, name, exe, guestExe, guestDir, appId,
steamId?.toLong() ?: ((appId shl 32) or 0x02000000L), candidates, steamId,
source = sidecar?.store?.id ?: Library.ADDED, storeId = sidecar?.id,
@@ -480,7 +487,7 @@ object AddedGames {
sidecar.store == Store.UBISOFT -> com.droiddeck.launcher.stores.ubisoft.UbisoftConnect.launchOptions(context)
else -> ""
},
single = single != null))
single = single != null, steamProgram = steamProgram))
}
}
@@ -520,6 +527,11 @@ object AddedGames {
return file.takeIf { inside && it.isFile }
}
internal fun steamEditedTo(folderGuest: String, record: JSONObject?, guestExe: String): Boolean {
val steam = unquote(record?.optJSONObject("steam")?.optString("Exe"))
return steam == guestExe && steam != unquote(record?.optJSONObject("app")?.optString("Exe")) && steam.startsWith("$folderGuest/")
}
private fun unquote(value: String?): String = value.orEmpty().trim().trim('"')
internal fun adoptSteamEdits(context: Context, folder: File, record: JSONObject) {
@@ -568,6 +580,7 @@ object AddedGames {
.append(",\"seen\":").append(SessionPrefs.addedGameExeSeen(context, g.folder.path))
if (g.launchOptions.isNotEmpty()) json.append(",\"launch\":").append(quote(g.launchOptions))
if (g.source != Library.ADDED) json.append(",\"store\":").append(quote(g.source))
if (!g.steamProgram) json.append(",\"route\":false")
val art = AddedGameArt.resolve(context, g)
val pieces = listOf("p" to art.portrait, "header" to art.header, "hero" to art.hero, "logo" to art.logo, "icon" to art.icon)
.mapNotNull { (k, f) -> f?.let { file -> artGuestPath(context, file)?.let { k to it } } }
@@ -1562,7 +1562,7 @@ object SessionPrefs {
fun adoptAddedGameExe(context: Context, folderPath: String, expected: String, path: String, seen: Int): Boolean =
synchronized(addedGameLock) {
val unchanged = addedGameExe(context, folderPath) == expected
if (unchanged) prefs(context).edit().putString("addedExe:$folderPath", path).putInt("addedExeSeen:$folderPath", seen).apply()
if (unchanged) prefs(context).edit().putString("addedExe:$folderPath", path).putString("addedAdopted:Exe:$folderPath", path).putInt("addedExeSeen:$folderPath", seen).apply()
unchanged
}
@@ -297,6 +297,39 @@ class AddedExesTest {
assertEquals(listOf(other.path), AddedGames.scan(app).map { it.exe.path })
}
private fun routeEveryGameTo(steamApp: Int) {
val config = File(SessionPrefs.activeSteamRoot(app), "userdata/123/config").apply { mkdirs() }
val routes = org.json.JSONObject()
AddedGames.scan(app).forEach { routes.put(it.appId.toString(), steamApp) }
File(config, ".droiddeck-routes.json").writeText(routes.toString())
}
@Test fun anotherProgramOfASteamInstallIsNotRoutedToTheSteamApp() {
noGamesFolders()
val main = onStorage("Games2/The Binding of Isaac Rebirth/isaac-ng.exe")
val launcher = onStorage("Games2/The Binding of Isaac Rebirth/REPENTOGONLauncher.exe")
AddedExes.put(app, AddedExes.Entry(main.parent!!, launcher.path))
routeEveryGameTo(250900)
val game = AddedGames.scan(app).single()
assertEquals(launcher.path, game.exe.path)
assertEquals(main.path, game.candidates.first().path)
assertNull(game.steamAppId)
assertTrue(!game.steamProgram)
assertTrue(File(AddedGames.writeListing(app, listOf(game), emptyList()).path).readText().contains("\"route\":false"))
}
@Test fun theSteamAppsOwnProgramStillRoutesToTheSteamApp() {
noGamesFolders()
val main = onStorage("Games2/The Binding of Isaac Rebirth/isaac-ng.exe")
onStorage("Games2/The Binding of Isaac Rebirth/REPENTOGONLauncher.exe")
AddedExes.put(app, AddedExes.Entry(main.parent!!, main.path))
routeEveryGameTo(250900)
val game = AddedGames.scan(app).single()
assertEquals(250900, game.steamAppId)
assertTrue(game.steamProgram)
assertTrue(!File(AddedGames.writeListing(app, listOf(game), emptyList()).path).readText().contains("route"))
}
@Test fun aDifferentGameWithANumberedNameIsNotTakenAsAnotherBuild() {
noGamesFolders()
val held = onStorage("Games2/id/Doom/Doom.exe")
@@ -47,6 +47,11 @@ class AddedGamesSteamEditsTest {
.writeText(JSONObject().put("games", JSONObject().put(appId.toString(), game)).toString())
}
private fun legacyAdoption(exe: File, seen: Int) {
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit()
.putString("addedExe:${folder.path}", exe.path).putInt("addedExeSeen:${folder.path}", seen).commit()
}
private fun scanned() = AddedGames.scan(context).single { it.folder == folder }
@Test fun aTargetChangedInSteamBecomesTheAppsChoiceOnce() {
@@ -68,6 +73,65 @@ class AddedGamesSteamEditsTest {
assertEquals(main.path, SessionPrefs.addedGameExe(context, folder.path))
}
@Test fun aTargetChosenInSteamKeepsTheSteamAppsRouteBeforeAndAfterItIsAdopted() {
val first = scanned()
val routes = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/userdata/123/config/.droiddeck-routes.json")
routes.writeText(JSONObject().put(first.appId.toString(), 250900).toString())
assertEquals(250900, scanned().steamAppId)
record(first.appId, "/root/Games/PC/Example/Example.exe", "/root/Games/PC/Example/bin/Other.exe", 1)
val adopted = scanned()
assertEquals(other, adopted.exe)
assertEquals(250900, adopted.steamAppId)
assertTrue(adopted.steamProgram)
val later = scanned()
assertEquals(other, later.exe)
assertEquals(250900, later.steamAppId)
assertTrue(later.steamProgram)
}
@Test fun aTargetAdoptedBeforeTheMarkerExistedKeepsTheSteamAppsRoute() {
val first = scanned()
val routes = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/userdata/123/config/.droiddeck-routes.json")
routes.writeText(JSONObject().put(first.appId.toString(), 250900).toString())
record(first.appId, "/root/Games/PC/Example/Example.exe", "/root/Games/PC/Example/bin/Other.exe", 1)
legacyAdoption(other, 1)
assertNull(SessionPrefs.addedGameAdopted(context, folder.path, "Exe"))
val legacy = scanned()
assertEquals(other, legacy.exe)
assertEquals(250900, legacy.steamAppId)
assertTrue(legacy.steamProgram)
assertEquals(other.path, SessionPrefs.addedGameAdopted(context, folder.path, "Exe"))
}
@Test fun aProgramPickedInDroidDeckThatSteamNeverEditedStaysOutOfTheRoute() {
val first = scanned()
val routes = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/userdata/123/config/.droiddeck-routes.json")
routes.writeText(JSONObject().put(first.appId.toString(), 250900).toString())
record(first.appId, "/root/Games/PC/Example/Example.exe", "/root/Games/PC/Example/Example.exe", 1)
legacyAdoption(other, 1)
val picked = scanned()
assertEquals(other, picked.exe)
assertNull(picked.steamAppId)
assertTrue(!picked.steamProgram)
}
@Test fun aProgramChosenInDroidDeckAfterASteamEditLeavesTheSteamAppsRoute() {
val first = scanned()
val routes = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/userdata/123/config/.droiddeck-routes.json")
routes.writeText(JSONObject().put(first.appId.toString(), 250900).toString())
record(first.appId, "/root/Games/PC/Example/Example.exe", "/root/Games/PC/Example/bin/Other.exe", 1)
assertEquals(other, scanned().exe)
val third = File(folder, "Third.exe").apply { writeBytes(ByteArray(4)) }
SessionPrefs.setAddedGameExe(context, folder.path, third.path)
val chosen = scanned()
assertEquals(third, chosen.exe)
assertNull(chosen.steamAppId)
assertTrue(!chosen.steamProgram)
}
@Test fun theListingTellsTheSessionWhichSteamEditTheAppHasTaken() {
val first = scanned()
record(first.appId, "/root/Games/PC/Example/Example.exe", "/root/Games/PC/Example/bin/Other.exe", 3)
+3 -1
View File
@@ -60,7 +60,9 @@ missing prefix is removed first, and nothing is copied.
The account's `.droiddeck-routes.json` maps shortcut IDs to real Steam app IDs so the
Android launcher uses the same title and Proton prefix as Steam. Other accounts do not
inherit those routes. Managed shortcuts are replaced; user-created shortcuts and
inherit those routes. A program chosen in DroidDeck other than the folder's default executable (for example a mod
launcher beside the game's own executable) is never routed: it stays its own shortcut and tile.
A target set in the Steam shortcut's properties keeps the route. Managed shortcuts are replaced; user-created shortcuts and
unreadable shortcut files are preserved. Both routes use the existing ARM64 Proton
registration.
@@ -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:
+36
View File
@@ -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])