mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 07:46:01 +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
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user