mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Windows components: picked automatically by each game's source (#554)
Each game's Windows components now come from the list its own source trusts, and the ones that list names turn on by themselves. The user's own on/off switches always win; each automatic row says why it is on. - Steam games: the Steamworks Shared redistributables Steam installs with the game (appmanifest SharedDepots, else the client's appinfo.vdf). Steam keeps its install scripts marked as already run. - GOG: the build manifest's dependencies. Epic: the manifest's prerequisite (Unreal's maps to VC++ and DirectX). Amazon: fuel.json PostInstall. Older GOG/Epic installs get their list fetched once with the saved sign-in; game files are never downloaded again. - Custom games (the + button, Add all, migrated folders): one shared Steam match per game, also used for artwork. An appid from the game's files turns components on; a name-only match stays Recommended; no match falls back to the folder scan. - Steam app info for apps the client never saw comes from an anonymous Steam PICS lookup (CM websocket, anonymous logon, product info), cached per appid; the user's Steam sign-in is never used. - Missing components download in the background on one low-priority worker that pauses during sessions and waits on battery saver, heat or a metered network unless the user asked. A game Steam installs during a session is readied right away so it can be played without ending the session; the launch waits up to 10 s only for a component still on its way. - Page: "On for this game" with reasons, a quiet "Checking what this game needs..." only for games never worked out, rows that ease in, pieces that need a download greyed out while offline. The intro names no other app. - The folder scan skips Unity's *_Data/Managed (Mono, not .NET Framework).
This commit is contained in:
1 parent
d45933e559
commit
a2e596a200
35 files changed
+3810
-146
No files matched your search
@@ -410,6 +410,8 @@ class SessionService : Service() {
|
||||
guest.add(it)
|
||||
Log.i(TAG, "steam: handing the client $it")
|
||||
}
|
||||
// A game whose download finishes in this session gets its Windows components readied in it.
|
||||
if (SessionState.mode == MODE_STEAM) com.droiddeck.launcher.frontend.SessionInstalls.watch(this)
|
||||
// A program under gamescope: the script's run mode takes the path (an AppImage, a script
|
||||
// or a binary inside the runtime). This is how an emulator gets the GPU - the desktop's
|
||||
// KWin composites in software and offers no dma-buf, so a Vulkan swapchain cannot exist
|
||||
|
||||
@@ -77,6 +77,21 @@ object WinComponents {
|
||||
|
||||
fun validId(id: String): Boolean = ID.matches(id) && ".." !in id
|
||||
|
||||
private val BACKGROUND = ThreadLocal<Boolean>()
|
||||
|
||||
/**
|
||||
* Runs [block] as background work: the runtime helpers an install starts on this thread run
|
||||
* at the lowest CPU and I/O priority (nice 19, ionice idle where the runtime has it).
|
||||
*/
|
||||
fun <T> background(block: () -> T): T {
|
||||
BACKGROUND.set(true)
|
||||
try { return block() } finally { BACKGROUND.remove() }
|
||||
}
|
||||
|
||||
private fun guest(argv: List<String>): List<String> = if (BACKGROUND.get() != true) argv else listOf(
|
||||
"/bin/sh", "-c", "if command -v ionice >/dev/null 2>&1; then exec nice -n 19 ionice -c3 \"\$@\"; else exec nice -n 19 \"\$@\"; fi", "sh",
|
||||
) + argv
|
||||
|
||||
class Step(val action: String, val json: JSONObject) {
|
||||
fun str(key: String): String = json.optString(key, "").ifEmpty {
|
||||
if (key in NESTED_KEYS) json.optJSONObject("environment")?.optString(key, "").orEmpty() else ""
|
||||
@@ -133,8 +148,24 @@ object WinComponents {
|
||||
/** The steps a recording makes redundant: everything that places files or edits the registry. */
|
||||
private val SNAPSHOT_COVERS = INSTALLER_STEPS + setOf("download_archive", "archive_extract", "copy_dll", "copy_file") + OFFLINE_STEPS
|
||||
|
||||
fun fetch(): List<Component>? {
|
||||
val body = Downloader.downloadString(CATALOG_URL) ?: return null
|
||||
fun fetch(): List<Component>? = Downloader.downloadString(CATALOG_URL)?.let { parse(it) }
|
||||
|
||||
private const val CATALOG_CACHE = "wincomponents-catalog.json"
|
||||
|
||||
/** The catalog from the network, kept for later; the copy kept last time when offline. */
|
||||
fun fetch(context: Context): List<Component>? {
|
||||
val cache = File(context.filesDir, CATALOG_CACHE)
|
||||
Downloader.downloadString(CATALOG_URL)?.let { body ->
|
||||
parse(body)?.let { runCatching { write(cache, body) }; return it }
|
||||
}
|
||||
return runCatching { parse(cache.readText()) }.getOrNull()
|
||||
}
|
||||
|
||||
/** The copy of the catalog kept by [fetch], without asking the network; null before the first fetch. */
|
||||
fun cached(context: Context): List<Component>? =
|
||||
runCatching { parse(File(context.filesDir, CATALOG_CACHE).readText()) }.getOrNull()
|
||||
|
||||
private fun parse(body: String): List<Component>? {
|
||||
return try {
|
||||
val arr = JSONObject(body).getJSONArray("components")
|
||||
(0 until arr.length()).mapNotNull { i ->
|
||||
@@ -155,6 +186,16 @@ object WinComponents {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The catalog entry that installs [name] here: the detector names installers
|
||||
* (vcredist2022, oalinst), and their DLL-copy twin (vcredist2022_dll, oalinst_dll) is the one
|
||||
* that installs without running anything; [name] itself when there is no such twin.
|
||||
*/
|
||||
fun installable(name: String, all: Map<String, Component>): String {
|
||||
val twin = all[if (name == "oalinst") "oalinst_dll" else "${name}_dll"]
|
||||
return if (twin != null && support(twin, all) == Support.READY) twin.name else name
|
||||
}
|
||||
|
||||
/** Whether [c] can be installed here, its bundled components included. */
|
||||
fun support(c: Component, all: Map<String, Component>, depth: Int = 0): Support {
|
||||
if (c.status != "ready" || depth > 8 || protonProvides(c.name)) return Support.UNSUPPORTED
|
||||
@@ -506,7 +547,7 @@ object WinComponents {
|
||||
val inside = archive.relativeTo(root).path
|
||||
var problem: String? = null
|
||||
var ok = false
|
||||
val status = GuestCommand.run(context, listOf(MSI_INSTALL, "--unpack", "/$inside", "/$MSI_CACHE/${dir.name}"),
|
||||
val status = GuestCommand.run(context, guest(listOf(MSI_INSTALL, "--unpack", "/$inside", "/$MSI_CACHE/${dir.name}")),
|
||||
logName = "wincomponents-${c.name}") { line ->
|
||||
when {
|
||||
line.startsWith("progress ") -> engineLine(line.removePrefix("progress ")).let { (text, _) -> onProgress(Progress(c.name, text, Phase.INSTALL, -1)) }
|
||||
@@ -545,7 +586,7 @@ object WinComponents {
|
||||
onProgress(Progress(c.name, "installing", Phase.INSTALL, 0))
|
||||
var result: JSONObject? = null
|
||||
var problem: String? = null
|
||||
val status = GuestCommand.run(context, listOf(MSI_INSTALL, "/$MSI_CACHE/${file.name}", "/$STORE/${staging.name}"),
|
||||
val status = GuestCommand.run(context, guest(listOf(MSI_INSTALL, "/$MSI_CACHE/${file.name}", "/$STORE/${staging.name}")),
|
||||
logName = "wincomponents-${c.name}") { line ->
|
||||
when {
|
||||
line.startsWith("progress ") -> engineLine(line.removePrefix("progress ")).let { (text, pct) -> onProgress(Progress(c.name, text, Phase.INSTALL, pct)) }
|
||||
@@ -622,36 +663,101 @@ object WinComponents {
|
||||
fun uninstall(context: Context, id: String) {
|
||||
require(validId(id))
|
||||
FileUtils.delete(File(LinuxRuntime.rootDir(context), "$STORE/$id"))
|
||||
save(context, read(context).mapValues { (_, ids) -> ids - id }.filterValues { it.isNotEmpty() })
|
||||
save(context, selections(context).mapValues { (_, sel) -> Selection(sel.auto - id, sel.user - id) })
|
||||
}
|
||||
|
||||
/**
|
||||
* Why a component was turned on for a game by itself ([setAuto]): [kind] says whose list it came
|
||||
* from (see AutoComponents), [args] what the reason line names. Kept beside the picks.
|
||||
*/
|
||||
class AutoReason(val kind: String, val args: List<String>)
|
||||
|
||||
/**
|
||||
* Everything kept per game, by the appid its prefix is named after: [auto] - turned on by
|
||||
* itself, with its reason; [user] - a switch the user pressed (true on, false off), which wins
|
||||
* over [auto] either way. What the launch reads is [effective].
|
||||
*/
|
||||
class Selection(val auto: Map<String, AutoReason>, val user: Map<String, Boolean>) {
|
||||
val effective: List<String>
|
||||
get() = (auto.keys.filter { user[it] != false } + user.filterValues { it }.keys).distinct()
|
||||
}
|
||||
|
||||
/** Each game's picks, by the appid its prefix is named after. */
|
||||
@Synchronized
|
||||
fun read(context: Context): Map<String, List<String>> = try {
|
||||
fun selections(context: Context): Map<String, Selection> = try {
|
||||
val json = JSONObject(AtomicFile(File(context.filesDir, SELECTION)).readFully().toString(Charsets.UTF_8))
|
||||
val games = json.optJSONObject("games") ?: JSONObject()
|
||||
games.keys().asSequence().associateWith { app ->
|
||||
val ids = games.getJSONArray(app)
|
||||
(0 until ids.length()).map { ids.getString(it) }.filter { validId(it) }
|
||||
val autos = json.optJSONObject("auto") ?: JSONObject()
|
||||
val users = json.optJSONObject("user")
|
||||
val keys = games.keys().asSequence().toSet() + autos.keys().asSequence().toSet() + (users?.keys()?.asSequence()?.toSet() ?: emptySet())
|
||||
keys.associateWith { app ->
|
||||
val auto = autos.optJSONObject(app)?.let { o ->
|
||||
o.keys().asSequence().filter { validId(it) }.associateWith { id ->
|
||||
val r = o.optJSONObject(id) ?: JSONObject()
|
||||
val a = r.optJSONArray("args") ?: JSONArray()
|
||||
AutoReason(r.optString("kind"), (0 until a.length()).map { a.optString(it) })
|
||||
}
|
||||
}.orEmpty()
|
||||
// Before there were overrides, every pick was the user's own.
|
||||
val user = if (users == null) games.optJSONArray(app)?.let { ids -> (0 until ids.length()).map { ids.getString(it) }.filter { validId(it) }.associateWith { true } }.orEmpty()
|
||||
else users.optJSONObject(app)?.let { o -> o.keys().asSequence().filter { validId(it) }.associateWith { o.optBoolean(it) } }.orEmpty()
|
||||
Selection(auto, user)
|
||||
}
|
||||
} catch (_: java.io.FileNotFoundException) {
|
||||
emptyMap()
|
||||
}
|
||||
|
||||
fun picks(context: Context, appKey: String): List<String> = read(context)[appKey].orEmpty()
|
||||
/** Each game's picks as the launch takes them, by the appid its prefix is named after. */
|
||||
fun read(context: Context): Map<String, List<String>> =
|
||||
selections(context).mapValues { it.value.effective }.filterValues { it.isNotEmpty() }
|
||||
|
||||
fun picks(context: Context, appKey: String): List<String> = selections(context)[appKey]?.effective.orEmpty()
|
||||
|
||||
fun selection(context: Context, appKey: String): Selection = selections(context)[appKey] ?: Selection(emptyMap(), emptyMap())
|
||||
|
||||
/** The user's own switch for [id] in [appKey]: on or off, over whatever was picked by itself. */
|
||||
@Synchronized
|
||||
fun setPicks(context: Context, appKey: String, ids: List<String>) {
|
||||
require(ids.all { validId(it) })
|
||||
val all = read(context).toMutableMap()
|
||||
if (ids.isEmpty()) all.remove(appKey) else all[appKey] = ids.distinct()
|
||||
fun setUser(context: Context, appKey: String, id: String, on: Boolean) {
|
||||
require(validId(id))
|
||||
val all = selections(context).toMutableMap()
|
||||
val now = all[appKey] ?: Selection(emptyMap(), emptyMap())
|
||||
all[appKey] = Selection(now.auto, now.user + (id to on))
|
||||
save(context, all)
|
||||
}
|
||||
|
||||
private fun save(context: Context, games: Map<String, List<String>>) {
|
||||
val text = JSONObject().put("version", 1).put("games", JSONObject().apply {
|
||||
games.forEach { (app, ids) -> put(app, JSONArray(ids)) }
|
||||
}).toString()
|
||||
/** The components picked by themselves for [appKey], replacing the earlier ones; the user's switches stay. */
|
||||
@Synchronized
|
||||
fun setAuto(context: Context, appKey: String, auto: Map<String, AutoReason>) {
|
||||
require(auto.keys.all { validId(it) })
|
||||
val all = selections(context).toMutableMap()
|
||||
val now = all[appKey] ?: Selection(emptyMap(), emptyMap())
|
||||
all[appKey] = Selection(auto, now.user)
|
||||
save(context, all)
|
||||
}
|
||||
|
||||
/** The user's picks for [appKey] set outright (each listed on, every other user switch dropped). */
|
||||
@Synchronized
|
||||
fun setPicks(context: Context, appKey: String, ids: List<String>) {
|
||||
require(ids.all { validId(it) })
|
||||
val all = selections(context).toMutableMap()
|
||||
val now = all[appKey] ?: Selection(emptyMap(), emptyMap())
|
||||
all[appKey] = Selection(now.auto, ids.distinct().associateWith { true } + now.auto.keys.filter { it !in ids }.associateWith { false })
|
||||
save(context, all)
|
||||
}
|
||||
|
||||
private fun save(context: Context, games: Map<String, Selection>) {
|
||||
val kept = games.filterValues { it.auto.isNotEmpty() || it.user.isNotEmpty() }
|
||||
// Version 1 still: droiddeck-wincomponents reads "games" and ignores the rest.
|
||||
val text = JSONObject().put("version", 1)
|
||||
.put("games", JSONObject().apply { kept.forEach { (app, sel) -> sel.effective.takeIf { it.isNotEmpty() }?.let { put(app, JSONArray(it)) } } })
|
||||
.put("auto", JSONObject().apply {
|
||||
kept.forEach { (app, sel) ->
|
||||
if (sel.auto.isNotEmpty()) put(app, JSONObject().apply {
|
||||
sel.auto.forEach { (id, r) -> put(id, JSONObject().put("kind", r.kind).put("args", JSONArray(r.args))) }
|
||||
})
|
||||
}
|
||||
})
|
||||
.put("user", JSONObject().apply { kept.forEach { (app, sel) -> if (sel.user.isNotEmpty()) put(app, JSONObject(sel.user as Map<*, *>)) } })
|
||||
.toString()
|
||||
write(File(context.filesDir, SELECTION), text)
|
||||
publish(context, text)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user