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
}