From c781cfd5252f183d6cb106d7d4ca71c18454aee2 Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Mon, 26 Oct 2026 23:36:11 -0400 Subject: [PATCH] fix: publish component choices again when a new Proton build appears Game and global component choices were written to desired.tsv only when a selection changed, so a Proton build installed later (DroidDeck-Proton 11-11.8) had no rows and kept its bundled FEX. Battle.net's d2rfix FEX never reached it and StarCraft died in ClientSdk.dll's DllMain. The choices are now republished at session start and on Battle.net's FEX request whenever the installed tools no longer match what was published. --- .../droiddeck/launcher/runtime/BattleNet.kt | 2 + .../launcher/session/ComponentsManager.kt | 11 ++- .../launcher/session/SessionService.kt | 3 + .../session/ComponentsRepublishTest.kt | 97 +++++++++++++++++++ 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/session/ComponentsRepublishTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/BattleNet.kt b/app/src/main/java/com/droiddeck/launcher/runtime/BattleNet.kt index b41fee3171..e3a64e9628 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/BattleNet.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/BattleNet.kt @@ -360,6 +360,8 @@ object BattleNet { if (ComponentsManager.gameComponents(context, scope)["fex"] != file) { ComponentsManager.setGameComponent(context, scope, "fex", file) Log.i(TAG, "FEX for the Battle.net prefix: $file") + } else if (ComponentsManager.republish(context)) { + Log.i(TAG, "FEX for the Battle.net prefix: $file, now in every installed Proton") } return file } diff --git a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt index f10ab12448..ed271021d9 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt @@ -155,8 +155,7 @@ object ComponentsManager { if (staged.exists()) check(staged.delete()) { "Could not remove unpublished component selections" } } - private fun saveState(context: Context, state: JSONObject) { - val prepared = prepareLaunchState(context, state) + private fun saveState(context: Context, state: JSONObject, prepared: PreparedLaunchState = prepareLaunchState(context, state)) { val dir = launchDir(context) val tmp = File(dir, "desired.tsv.tmp") try { @@ -175,6 +174,14 @@ object ComponentsManager { ?.forEach { it.deleteRecursively() } } + fun republish(context: Context): Boolean = synchronized(lock) { + val state = loadState(context) + val prepared = prepareLaunchState(context, state) + if ((FileUtils.readString(File(launchDir(context), "desired.tsv")) ?: "") == prepared.text) return false + saveState(context, state, prepared) + true + } + private fun JSONObject.sub(key: String): JSONObject = optJSONObject(key) ?: JSONObject().also { put(key, it) } private fun rememberProfiledComponent(state: JSONObject, comp: String) { diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 445b2da05d..025332da3b 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -480,6 +480,9 @@ class SessionService : Service() { val size = SessionState.outputSize val guest = ArrayList() val steamHere = SessionState.mode == MODE_STEAM || SessionState.mode == MODE_DESKTOP + runCatching { ComponentsManager.republish(this) } + .onSuccess { if (it) Log.i(TAG, "component selections published for the installed Proton builds") } + .onFailure { Log.w(TAG, "component selections", it) } if (steamHere) { runCatching { ComponentsManager.ensureForcedPackages(this) } .onSuccess { if (it != null) Log.i(TAG, it) } diff --git a/app/src/test/java/com/droiddeck/launcher/session/ComponentsRepublishTest.kt b/app/src/test/java/com/droiddeck/launcher/session/ComponentsRepublishTest.kt new file mode 100644 index 0000000000..5d0ba33c6b --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/ComponentsRepublishTest.kt @@ -0,0 +1,97 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import com.droiddeck.launcher.runtime.LinuxRuntime +import com.github.luben.zstd.ZstdOutputStream +import org.apache.commons.compress.archivers.tar.TarArchiveEntry +import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream +import org.json.JSONObject +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import java.io.File + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [28], manifest = Config.NONE) +class ComponentsRepublishTest { + private val fex = "FEXCore-2610-d2rfix28-linux.wcp" + private val scope = "2596113170" + private val dll = "files/lib/wine/aarch64-windows/libwow64fex.dll" + private lateinit var context: Context + + @Before fun setUp() { + context = RuntimeEnvironment.getApplication() + File(context.filesDir, "components").deleteRecursively() + LinuxRuntime.rootDir(context).deleteRecursively() + } + + @Test fun aGameFexChoiceReachesAProtonInstalledAfterIt() { + proton("DroidDeck-Proton 11-11.7", "DroidDeck-Proton-11-11.7") + packageFile() + ComponentsManager.setGameComponent(context, scope, "fex", fex) + assertEquals(setOf("DroidDeck-Proton 11-11.7"), scopedTools()) + + proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8") + assertEquals(setOf("DroidDeck-Proton 11-11.7"), scopedTools()) + + assertTrue(ComponentsManager.republish(context)) + assertEquals(setOf("DroidDeck-Proton 11-11.7", "DroidDeck-Proton 11-11.8"), scopedTools()) + val row = rows().single { it[0] == scope && it[1] == "DroidDeck-Proton 11-11.8" && it[4] == dll } + assertEquals("DroidDeck-Proton-11-11.8", row[2]) + assertEquals("d2rfix28 wow64", File(LinuxRuntime.rootDir(context), row[6].removePrefix("/")).readText()) + assertEquals(fex, ComponentsManager.gameComponents(context, scope)["fex"]) + } + + @Test fun nothingIsRewrittenWhileTheToolsAreUnchanged() { + proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8") + packageFile() + ComponentsManager.setGameComponent(context, scope, "fex", fex) + val published = launchState().readText() + val modified = launchState().lastModified() + + assertFalse(ComponentsManager.republish(context)) + assertEquals(published, launchState().readText()) + assertEquals(modified, launchState().lastModified()) + } + + @Test fun withNoSelectionsNothingIsPublished() { + proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8") + + assertFalse(ComponentsManager.republish(context)) + assertFalse(launchState().exists()) + } + + private fun scopedTools() = rows().filter { it[0] == scope }.map { it[1] }.toSet() + + private fun rows() = launchState().readLines().filter { it.isNotEmpty() }.map { it.split('\t') } + + private fun launchState() = File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-components/desired.tsv") + + private fun proton(name: String, version: String) { + val dir = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/steamapps/common/$name") + File(dir, "files/lib/wine").mkdirs() + File(dir, "proton").writeText("#!/bin/sh\n") + File(dir, "version").writeText("1 $version\n") + File(dir, dll).apply { parentFile!!.mkdirs(); writeText("bundled FEX $version") } + } + + private fun packageFile() { + val out = File(context.filesDir, "components/packages/$fex").apply { parentFile!!.mkdirs() } + val profile = JSONObject().put("type", "FEXCore-Linux").put("versionName", "2610-d2rfix28").toString().toByteArray() + val body = "d2rfix28 wow64".toByteArray() + TarArchiveOutputStream(ZstdOutputStream(out.outputStream())).use { tar -> + tar.putArchiveEntry(TarArchiveEntry("profile.json").apply { size = profile.size.toLong() }) + tar.write(profile) + tar.closeArchiveEntry() + tar.putArchiveEntry(TarArchiveEntry(dll).apply { size = body.size.toLong() }) + tar.write(body) + tar.closeArchiveEntry() + } + } +}