mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
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.
This commit is contained in:
1 parent
4c7e59ed8b
commit
c781cfd525
4 files changed
+111
-2
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -480,6 +480,9 @@ class SessionService : Service() {
|
||||
val size = SessionState.outputSize
|
||||
val guest = ArrayList<String>()
|
||||
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) }
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user