From 088c8ff1cf1a46475eca96d15a1e579ff375b682 Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Sat, 21 Nov 2026 15:31:18 -0500 Subject: [PATCH] fix(battlenet): follow the selected FEX instead of pinning an old build (#2987) * fix(battlenet): follow the selected FEX instead of pinning a d2rfix build The Battle.net prefix forced the newest FEXCore d2rfix package from the Nightlies listing, which stopped updating. Its fixes are in the bundled and nightly FEX, so the prefix now uses whatever FEX is selected. Existing d2rfix selections for the Battle.net profile are cleared once; any other choice is kept. The DXVK memory cap and Start without Steam defaults are now applied when a session starts. * fix(battlenet): import the legacy plugin state before unpinning the Battle.net FEX --- .../droiddeck/launcher/runtime/BattleNet.kt | 73 +----------- .../launcher/session/ComponentsManager.kt | 16 +++ .../launcher/session/SessionFiles.kt | 1 + .../launcher/session/SessionService.kt | 10 +- .../launcher/runtime/BattleNetTest.kt | 105 ++++-------------- .../session/ComponentsRepublishTest.kt | 31 ++++++ .../stores/battlenet/BattleNetRequestTest.kt | 3 +- .../overlay/usr/local/bin/droiddeck-battlenet | 33 ------ tools/tests/test_battlenet.py | 39 +------ 9 files changed, 79 insertions(+), 232 deletions(-) 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 eeab317af..7fb5cdc04 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/BattleNet.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/BattleNet.kt @@ -12,9 +12,6 @@ object BattleNet { const val APP_ID = 2596113170L - const val FEX_REQUEST = "battlenet-fex.request" - const val FEX_RESULT = "battlenet-fex.result" - const val PROGRAM = "/usr/local/bin/droiddeck-battlenet" class Title(val uid: String, val name: String, val code: String, val steam: Int? = null, val shop: String? = null, val product: String? = null, val flavor: String? = null) @@ -162,8 +159,6 @@ object BattleNet { source = com.droiddeck.launcher.stores.Store.BATTLENET.id, ) - fun fexInUse(context: Context): String? = ComponentsManager.gameComponents(context, APP_ID.toString())["fex"] - internal fun title(uid: String): Title? { val id = uid.lowercase() TITLES.firstOrNull { it.uid == id }?.let { return it } @@ -391,54 +386,6 @@ object BattleNet { Log.i(TAG, "removed") } - private val D2RFIX = Regex("""(?i)FEXCore-(\d+(?:\.\d+)*)-d2rfix(\d+)-linux\.wcp""") - - private const val LISTING_MAX_AGE = 6 * 3600L - - private val NEWEST = Comparator, Long>> { a, b -> - for (i in 0 until minOf(a.first.size, b.first.size)) if (a.first[i] != b.first[i]) return@Comparator a.first[i].compareTo(b.first[i]) - if (a.first.size != b.first.size) a.first.size.compareTo(b.first.size) else a.second.compareTo(b.second) - } - - internal fun d2rfix(file: String): Pair, Long>? { - val m = D2RFIX.matchEntire(file) ?: return null - val version = m.groupValues[1].split('.').map { it.toLongOrNull() ?: return null } - return version to (m.groupValues[2].toLongOrNull() ?: return null) - } - - internal fun newestD2rFix(items: List): ComponentsManager.CatalogItem? = - items.filter { it.comp == "fex" }.mapNotNull { item -> d2rfix(item.file)?.let { item to it } } - .maxWithOrNull { a, b -> NEWEST.compare(a.second, b.second) }?.first - - fun ensureFex(context: Context): String = ensureFex(context) { ComponentsManager.catalog(it, true).items } - - @Synchronized - internal fun ensureFex(context: Context, refresh: (Context) -> List): String { - val item = newestD2rFix(listing(context, refresh)) ?: error("no d2rfix FEXCore build in the Nightlies listing") - val file = ComponentsManager.safeName(item.file) - if (ComponentsManager.packages(context).none { it.file == file }) { - Log.i(TAG, "downloading ${item.file}") - ComponentsManager.download(context, item) {} - } - val scope = APP_ID.toString() - 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 - } - - private fun listing(context: Context, refresh: (Context) -> List): List { - val cached = ComponentsManager.catalog(context, false) - val age = System.currentTimeMillis() / 1000 - cached.fetchedAt - if (age in 0 until LISTING_MAX_AGE && newestD2rFix(cached.items) != null) return cached.items - val fetched = runCatching { refresh(context) } - .onFailure { Log.w(TAG, "Nightlies listing: ${it.message}") }.getOrNull().orEmpty() - return if (newestD2rFix(fetched) != null) fetched else cached.items - } - internal fun videoMemory(totalMb: Long): Int = (totalMb / 5 / 512 * 512).coerceIn(1536, 3584).toInt() internal fun videoMemoryOptions(megabytes: Int): String = @@ -464,21 +411,9 @@ object BattleNet { return true } - fun answerFexRequest(context: Context, dir: File) { - val app = context.applicationContext - Thread({ - runCatching { ensureVideoMemory(app) }.onFailure { Log.w(TAG, "video memory cap for the Battle.net profile", it) } - runCatching { ensureNoSteam(app) }.onFailure { Log.w(TAG, "Start without Steam for the Battle.net profile", it) } - val answer = try { - "ok " + ensureFex(app) - } catch (e: Exception) { - Log.w(TAG, "FEX for the Battle.net prefix", e) - "error " + (e.message ?: e.javaClass.simpleName) - } - Log.i(TAG, "FEX request: $answer") - val result = File(dir, FEX_RESULT) - val partial = File(dir, "$FEX_RESULT.tmp") - runCatching { partial.writeText(answer.replace('\n', ' ') + "\n"); partial.renameTo(result) } - }, "battlenet-fex").start() + fun ensureDefaults(context: Context, program: String?) { + if (program != PROGRAM && !installed(context)) return + runCatching { ensureVideoMemory(context) }.onFailure { Log.w(TAG, "video memory cap for the Battle.net profile", it) } + runCatching { ensureNoSteam(context) }.onFailure { Log.w(TAG, "Start without Steam for the Battle.net profile", it) } } } 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 749532cdd..fdc8e2bf5 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt @@ -238,6 +238,20 @@ object ComponentsManager { saveState(context, state) } + private val UNPINNED_FEX = Regex("""(?i)FEXCore-\d+(?:\.\d+)*-d2rfix\d+-linux\.wcp""") + + fun migrateBattleNetFex(context: Context) = synchronized(lock) { + val marker = File(dataDir(context), ".battlenet-fex-unpinned") + if (marker.isFile) return@synchronized + migratePlugin(context) + val scope = com.droiddeck.launcher.runtime.BattleNet.APP_ID.toString() + if (gameComponents(context, scope)["fex"]?.let(UNPINNED_FEX::matches) == true) { + setGameComponent(context, scope, "fex", null) + Log.i(TAG, "Battle.net follows the selected FEX again") + } + marker.writeText("1\n") + } + private fun migratePlugin(context: Context) { val marker = File(dataDir(context), ".plugin-imported") if (marker.isFile) return @@ -487,6 +501,7 @@ object ComponentsManager { fun snapshotAll(context: Context) = synchronized(lock) { migratePlugin(context) + runCatching { migrateBattleNetFex(context) }.onFailure { Log.w(TAG, "Battle.net FEX selection", it) } val state = loadState(context) for (p in protons(context)) for (comp in COMPONENTS) { runCatching { ensureOriginal(context, p, comp, state) }.onFailure { Log.w(TAG, "original $comp of ${p.name}", it) } @@ -497,6 +512,7 @@ object ComponentsManager { fun snapshot(context: Context): Snapshot = synchronized(lock) { migratePlugin(context) + runCatching { migrateBattleNetFex(context) }.onFailure { Log.w(TAG, "Battle.net FEX selection", it) } val state = loadState(context) val reapplied = HashMap() runCatching { diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index 9fb0aaab9..1082de60d 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -287,6 +287,7 @@ object SessionFiles { File(root, "usr/share/vulkan/implicit_layer.d/droiddeck_vram_cap.json").delete() LegacyNames.migrateRootfs(root) ComponentsManager.migrateLaunchDir(context) + runCatching { ComponentsManager.migrateBattleNetFex(context) }.onFailure { Log.w(TAG, "Battle.net FEX selection", it) } EsyncPacks.stageBundled(context, root) val directAudio = arrayOf( "aarch64-unix/winedirectaudio.so", 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 5d7873001..15d2844d3 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -589,7 +589,10 @@ class SessionService : Service() { val sessionDir = openSessionFolder() try { - SessionEvents.step("game-environment") { GameEnvironmentStore.publish(this) } + SessionEvents.step("game-environment") { + com.droiddeck.launcher.runtime.BattleNet.ensureDefaults(this, SessionState.program) + GameEnvironmentStore.publish(this) + } } catch (e: Exception) { Log.e(TAG, "could not publish the game environment", e) failSession(gen, "GAME_ENVIRONMENT_FAILED", getString(R.string.session_game_environment_failed), -1) @@ -1951,11 +1954,6 @@ class SessionService : Service() { } return } - if (path == com.droiddeck.launcher.runtime.BattleNet.FEX_REQUEST) { - File(dir, path).delete() - com.droiddeck.launcher.runtime.BattleNet.answerFexRequest(this@SessionService, dir) - return - } if (path != null && path.startsWith("desktop-import-") && path.endsWith(".request")) { val request = File(dir, path) val text = runCatching { request.readText() }.getOrNull() ?: return diff --git a/app/src/test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt b/app/src/test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt index f74528c72..ea0c471fa 100644 --- a/app/src/test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt @@ -73,72 +73,6 @@ class BattleNetTest { assertEquals(crc or 0x80000000L, BattleNet.APP_ID) } - @Test fun theNewestD2rfixIsTheHighestFexThenTheHighestFix() { - val items = listOf( - item("FEXCore-2610-linux.wcp"), - item("FEXCore-2609-d2rfix25-linux.wcp"), - item("FEXCore-2610-d2rfix9-linux.wcp"), - item("FEXCore-2610-d2rfix28-linux.wcp"), - item("FEXCore-2509.1-d2rfix40-linux.wcp"), - ) - assertEquals("FEXCore-2610-d2rfix28-linux.wcp", BattleNet.newestD2rFix(items)?.file) - assertEquals("FEXCore-2610.1-d2rfix1-linux.wcp", BattleNet.newestD2rFix(items + item("FEXCore-2610.1-d2rfix1-linux.wcp"))?.file) - assertEquals("FexCore-2611-D2RFIX2-linux.wcp", BattleNet.newestD2rFix(items + item("FexCore-2611-D2RFIX2-linux.wcp"))?.file) - } - - @Test fun onlyFexD2rfixPackagesCount() { - assertNull(BattleNet.newestD2rFix(listOf(item("FEXCore-2610-linux.wcp"), item("FEXCore-2610-d2rfix28-linux.wcp", comp = "dxvk")))) - assertNull(BattleNet.d2rfix("FEXCore-2610-d2rfix28-linux.wcp.part")) - assertNull(BattleNet.d2rfix("FEXCore-2610-d2rfix-linux.wcp")) - assertEquals(listOf(2610L) to 28L, BattleNet.d2rfix("FEXCore-2610-d2rfix28-linux.wcp")) - } - - @Test fun theNewestStoredBuildIsSetForThePrefix() { - catalog("FEXCore-2609-d2rfix25-linux.wcp", "FEXCore-2610-d2rfix28-linux.wcp", "FEXCore-2610-linux.wcp") - store("FEXCore-2610-d2rfix28-linux.wcp") - - assertEquals("FEXCore-2610-d2rfix28-linux.wcp", BattleNet.ensureFex(context, ::noRefresh)) - - assertEquals(mapOf("fex" to "FEXCore-2610-d2rfix28-linux.wcp"), ComponentsManager.gameComponents(context, BattleNet.APP_ID.toString())) - assertEquals("FEXCore-2610-d2rfix28-linux.wcp", BattleNet.ensureFex(context, ::noRefresh)) - } - - @Test fun aNewerBuildReplacesTheOldOne() { - catalog("FEXCore-2609-d2rfix25-linux.wcp") - store("FEXCore-2609-d2rfix25-linux.wcp") - BattleNet.ensureFex(context, ::noRefresh) - catalog("FEXCore-2609-d2rfix25-linux.wcp", "FEXCore-2610-d2rfix28-linux.wcp") - store("FEXCore-2610-d2rfix28-linux.wcp") - - BattleNet.ensureFex(context, ::noRefresh) - - assertEquals("FEXCore-2610-d2rfix28-linux.wcp", ComponentsManager.gameComponents(context, BattleNet.APP_ID.toString())["fex"]) - } - - @Test fun aStaleListingIsFetchedAgain() { - catalog("FEXCore-2609-d2rfix25-linux.wcp", fetchedAt = 1) - store("FEXCore-2610-d2rfix28-linux.wcp") - - BattleNet.ensureFex(context) { listOf(item("FEXCore-2609-d2rfix25-linux.wcp"), item("FEXCore-2610-d2rfix28-linux.wcp")) } - - assertEquals("FEXCore-2610-d2rfix28-linux.wcp", ComponentsManager.gameComponents(context, BattleNet.APP_ID.toString())["fex"]) - } - - @Test fun aFailedFetchFallsBackOnTheCachedListing() { - catalog("FEXCore-2609-d2rfix25-linux.wcp", fetchedAt = 1) - store("FEXCore-2609-d2rfix25-linux.wcp") - - assertEquals("FEXCore-2609-d2rfix25-linux.wcp", BattleNet.ensureFex(context) { error("offline") }) - } - - @Test fun aListingWithoutD2rfixIsAnError() { - catalog("FEXCore-2610-linux.wcp") - var refreshed = 0 - assertThrows(IllegalStateException::class.java) { BattleNet.ensureFex(context) { refreshed++; emptyList() } } - assertEquals(1, refreshed) - assertEquals(emptyMap(), ComponentsManager.gameComponents(context, BattleNet.APP_ID.toString())) - } - @Test fun installedIsTheLauncherInThePrefix() { assertFalse(BattleNet.installed(context)) launcher().apply { parentFile!!.mkdirs(); writeText("MZ") } @@ -152,9 +86,9 @@ class BattleNetTest { } @Test fun removeTakesThePrefixItsMenuEntryAndCacheButNothingItLinksTo() { - catalog("FEXCore-2610-d2rfix28-linux.wcp") - store("FEXCore-2610-d2rfix28-linux.wcp") - BattleNet.ensureFex(context, ::noRefresh) + store("FEXCore-2610-linux.wcp") + ComponentsManager.setGameComponent(context, BattleNet.APP_ID.toString(), "fex", "FEXCore-2610-linux.wcp") + assertEquals(mapOf("fex" to "FEXCore-2610-linux.wcp"), ComponentsManager.gameComponents(context, BattleNet.APP_ID.toString())) val root = LinuxRuntime.rootDir(context) fun put(relative: String) = File(root, relative).apply { parentFile!!.mkdirs(); writeText("x") } launcher().apply { parentFile!!.mkdirs(); writeText("MZ") } @@ -176,7 +110,7 @@ class BattleNetTest { assertTrue(otherMenu.isFile) assertFalse(log.parentFile!!.exists()) assertTrue(otherPrefix.isFile) - assertNull(BattleNet.fexInUse(context)) + assertEquals(emptyMap(), ComponentsManager.gameComponents(context, BattleNet.APP_ID.toString())) outside.deleteRecursively() } @@ -481,6 +415,22 @@ class BattleNetTest { assertTrue(BattleNet.ensureVideoMemory(context)) } + @Test fun theProfileDefaultsAreSetForTheBattleNetProgramOrOnceInstalledAndNeverForAnythingElse() { + File(context.filesDir, "game-environment.json").delete() + val manager = context.getSystemService(android.app.ActivityManager::class.java) + org.robolectric.Shadows.shadowOf(manager).setMemoryInfo(android.app.ActivityManager.MemoryInfo().apply { totalMem = 11113L shl 20 }) + val scope = BattleNet.APP_ID.toString() + BattleNet.ensureDefaults(context, null) + assertNull(GameEnvironmentStore.read(context).games[scope]?.get("DXVK_CONFIG")) + BattleNet.ensureDefaults(context, BattleNet.PROGRAM) + assertEquals(BattleNet.videoMemoryOptions(2048), GameEnvironmentStore.read(context).games[scope]?.get("DXVK_CONFIG")) + assertTrue(com.droiddeck.launcher.session.SessionPrefs.battleNetNoSteamSet(context)) + File(context.filesDir, "game-environment.json").delete() + launcher().apply { parentFile!!.mkdirs(); writeText("MZ") } + BattleNet.ensureDefaults(context, null) + assertEquals(BattleNet.videoMemoryOptions(2048), GameEnvironmentStore.read(context).games[scope]?.get("DXVK_CONFIG")) + } + private fun launcher() = File(BattleNet.prefix(context), "pfx/drive_c/Program Files (x86)/Battle.net/Battle.net Launcher.exe") private fun varint(value: Long): ByteArray { @@ -496,21 +446,6 @@ class BattleNetTest { private fun varintField(number: Int, value: Long) = varint((number shl 3).toLong()) + varint(value) private fun message(vararg fields: ByteArray) = fields.fold(ByteArray(0)) { all, f -> all + f } - private fun noRefresh(context: Context): List = error("the cached listing was fresh") - - private fun item(file: String, comp: String = "fex") = ComponentsManager.CatalogItem( - file, comp, "FexCore-Linux", "https://github.com/The412Banner/Nightlies/releases/download/FexCore-Linux/$file", 4, "sha256:" + "ab".repeat(32), - ) - - private fun catalog(vararg files: String, fetchedAt: Long = System.currentTimeMillis() / 1000) { - val cache = File(context.filesDir, "components/catalog.json") - cache.parentFile!!.mkdirs() - val items = JSONArray() - for (file in files) items.put(JSONObject().put("file", file).put("comp", "fex").put("release", "FexCore-Linux") - .put("url", item(file).url).put("size", 4).put("digest", item(file).digest)) - cache.writeText(JSONObject().put("items", items).put("fetchedAt", fetchedAt).toString()) - } - private fun store(file: String) { val wcp = File(context.filesDir, "components/packages/$file") wcp.parentFile!!.mkdirs() diff --git a/app/src/test/java/com/droiddeck/launcher/session/ComponentsRepublishTest.kt b/app/src/test/java/com/droiddeck/launcher/session/ComponentsRepublishTest.kt index 74978ee30..58d36b816 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/ComponentsRepublishTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/ComponentsRepublishTest.kt @@ -82,6 +82,37 @@ class ComponentsRepublishTest { private fun scopedTools() = rows().filter { it[0] == scope }.map { it[1] }.toSet() + @Test fun battleNetDropsAnOldPinnedFexOnceAndKeepsAnyOtherChoice() { + proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8") + packageFile() + ComponentsManager.setGameComponent(context, scope, "fex", fex) + ComponentsManager.setGameComponent(context, "123", "fex", fex) + assertTrue(rows().any { it[0] == scope }) + + ComponentsManager.migrateBattleNetFex(context) + + assertEquals(emptyMap(), ComponentsManager.gameComponents(context, scope)) + assertEquals(fex, ComponentsManager.gameComponents(context, "123")["fex"]) + assertTrue(rows().none { it[0] == scope }) + assertTrue(rows().any { it[0] == "123" }) + + ComponentsManager.setGameComponent(context, scope, "fex", fex) + ComponentsManager.migrateBattleNetFex(context) + assertEquals(fex, ComponentsManager.gameComponents(context, scope)["fex"]) + } + + @Test fun battleNetKeepsAFexTheUserChoseThemselves() { + proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8") + val own = "FEXCore-2612-linux.wcp" + packageFile() + File(context.filesDir, "components/packages/$fex").copyTo(File(context.filesDir, "components/packages/$own")) + ComponentsManager.setGameComponent(context, scope, "fex", own) + + ComponentsManager.migrateBattleNetFex(context) + + assertEquals(own, ComponentsManager.gameComponents(context, scope)["fex"]) + } + 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") diff --git a/app/src/test/java/com/droiddeck/launcher/stores/battlenet/BattleNetRequestTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/battlenet/BattleNetRequestTest.kt index f1141a871..2da34d3db 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/battlenet/BattleNetRequestTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/battlenet/BattleNetRequestTest.kt @@ -31,8 +31,7 @@ class BattleNetRequestTest { BattleNetClient.request(root, listOf("launch", "WTCG")) java.io.File(root, "battlenet-request").writeText("launch\nPro\n") java.io.File(root, "battlenet-request.1.tmp").writeText("launch\nPro\n") - java.io.File(root, "battlenet-fex.request").writeText("x") BattleNetClient.clearRequests(root) - assertEquals(listOf("battlenet-fex.request"), root.list()!!.toList()) + assertEquals(0, root.list()!!.size) } } diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet b/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet index 066f9c572..0cddb3fb4 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet @@ -37,9 +37,6 @@ USER_PREFERENCES = "UserPreferencesMask" WINE_USER_PREFERENCES = bytes((0x10, 0x00, 0x00, 0x80, 0x12, 0x00, 0x00, 0x00)) CLIENT_AREA_ANIMATION = (4, 0x02) WALLPAPER_MAX = (1280, 720) -FEX_REQUEST = "battlenet-fex.request" -FEX_RESULT = "battlenet-fex.result" -FEX_WAIT = 120 START_GRACE = 90 POLL = 2 STOP_WAIT = 5 @@ -779,32 +776,6 @@ def write_menu(path=MENU): say("menu entry not written: %s" % error) -def ask_fex(launch_dir, wait=FEX_WAIT): - if not launch_dir or not os.path.isdir(launch_dir): - say("not inside a DroidDeck session; FEX stays as Components has it") - return None - result = os.path.join(launch_dir, FEX_RESULT) - request = os.path.join(launch_dir, FEX_REQUEST) - try: - os.unlink(result) - except OSError: - pass - with open(request + ".tmp", "w", encoding="utf-8") as f: - f.write("appid=%s\n" % APP_ID) - os.replace(request + ".tmp", request) - deadline = time.monotonic() + wait - while time.monotonic() < deadline: - try: - with open(result, encoding="utf-8") as f: - answer = f.read().strip() - except OSError: - time.sleep(0.5) - continue - os.unlink(result) - return answer - return None - - def wine_processes(pfx, proc="/proc"): want = os.path.realpath(pfx).rstrip("/") found = [] @@ -1148,8 +1119,6 @@ def stop_leftovers(pfx): def open_client(root, reinstall=False): pfx = os.path.join(prefix(root), "pfx") write_menu() - answer = ask_fex(os.environ.get("DD_LAUNCH_DIR")) - say("FEX: %s" % (answer or "no answer from the app; Components' choice stays")) if running(pfx): say("Battle.net is already running in its prefix; waiting for it to close") wait_while_open(pfx, grace=0) @@ -1238,8 +1207,6 @@ def launch(root, code): try: own = None if lock is not None and not running(pfx): - answer = ask_fex(os.environ.get("DD_LAUNCH_DIR")) - say("FEX: %s" % (answer or "no answer from the app; Components' choice stays")) verb = None if stop_leftovers(pfx) else "run" configure(root, LIBRARY) own = start(launcher(root), verb) diff --git a/tools/tests/test_battlenet.py b/tools/tests/test_battlenet.py index ece44f60d..52ba9e8d4 100644 --- a/tools/tests/test_battlenet.py +++ b/tools/tests/test_battlenet.py @@ -6,7 +6,6 @@ import re import runpy import shutil import tempfile -import threading import time import unittest from unittest import mock @@ -93,8 +92,6 @@ class IdTest(unittest.TestCase): self.assertEqual(int(BNET["APP_ID"]), zlib.crc32(b'"droiddeck-battlenet"Battle.net') | 0x80000000) found = re.search(r"const val APP_ID = (\d+)L", KOTLIN.read_text()) self.assertEqual(found.group(1), BNET["APP_ID"]) - for name in ("FEX_REQUEST", "FEX_RESULT"): - self.assertIn('const val %s = "%s"' % (name, BNET[name]), KOTLIN.read_text()) class ProtonRunOptionsTest(Temp): @@ -761,36 +758,6 @@ class TidyTest(unittest.TestCase): self.assertEqual(self.stopped, []) -class FexRequestTest(Temp): - def answer(self, text, delay=0.2): - def respond(): - request = self.tmp / BNET["FEX_REQUEST"] - deadline = time.monotonic() + 5 - while not request.exists() and time.monotonic() < deadline: - time.sleep(0.02) - self.requested = request.read_text() - request.unlink() - time.sleep(delay) - (self.tmp / (BNET["FEX_RESULT"] + ".tmp")).write_text(text + "\n") - os.replace(self.tmp / (BNET["FEX_RESULT"] + ".tmp"), self.tmp / BNET["FEX_RESULT"]) - thread = threading.Thread(target=respond) - thread.start() - self.addCleanup(thread.join) - - def test_the_apps_answer_comes_back(self): - (self.tmp / BNET["FEX_RESULT"]).write_text("ok an-old-answer\n") - self.answer("ok FEXCore-2610-d2rfix28-linux.wcp") - self.assertEqual(BNET["ask_fex"](str(self.tmp), wait=5), "ok FEXCore-2610-d2rfix28-linux.wcp") - self.assertEqual(self.requested, "appid=%s\n" % BNET["APP_ID"]) - self.assertFalse((self.tmp / BNET["FEX_RESULT"]).exists()) - - def test_no_answer_or_no_session_starts_without_one(self): - with mock.patch.dict(BNET, {"say": lambda message: None}): - self.assertIsNone(BNET["ask_fex"](str(self.tmp), wait=0.3)) - self.assertIsNone(BNET["ask_fex"](None)) - self.assertIsNone(BNET["ask_fex"](str(self.tmp / "gone"))) - - class OpenTest(Temp): def setUp(self): super().setUp() @@ -799,7 +766,6 @@ class OpenTest(Temp): self.alive = [] self.menu = self.tmp / "droiddeck-battlenet.desktop" patcher = mock.patch.dict(BNET, { - "ask_fex": lambda launch_dir, wait=0: "ok fex.wcp", "say": lambda message: None, "notify": lambda *a, **k: self.calls.append(("notify", a[0])), "wine_processes": lambda pfx, proc="/proc": list(self.alive), "stop": lambda processes, wait=0: self.calls.append(("stop", [pid for pid, _ in processes])) or self.alive.clear(), @@ -988,7 +954,6 @@ class Harness(Temp): self.states = [] self.last = [] patcher = mock.patch.dict(BNET, { - "ask_fex": lambda launch_dir, wait=0: self.calls.append(("fex",)) or "ok fex.wcp", "say": lambda message: None, "notify": lambda *a, **k: self.calls.append(("notify", a[0])), "wine_processes": self.processes, "stop": lambda processes, wait=0: self.calls.append(("stop", sorted(pid for pid, _ in processes))), @@ -1019,7 +984,7 @@ class LaunchTest(Harness): self.states = [[], [], up, up + [(40, self.GAME)], up, up] self.assertEqual(BNET["launch"](self.root, "Fen"), 0) self.assertEqual(self.calls, [ - ("fex",), ("start", "Battle.net Launcher.exe", None), + ("start", "Battle.net Launcher.exe", None), ("spawn", "Battle.net.exe", "run", ["--exec=launch Fen"]), ("stop", [10, 11, 12, 13, 14, 30]), ]) @@ -1034,7 +999,7 @@ class LaunchTest(Harness): with mock.patch.dict(BNET, {"GAME_SETTLE": 0}): self.assertEqual(BNET["launch"](self.root, "Fen"), 0) self.assertEqual(self.calls, [ - ("fex",), ("start", "Battle.net Launcher.exe", None), + ("start", "Battle.net Launcher.exe", None), ("spawn", "Battle.net.exe", "run", ["--exec=launch Fen"]), ("stop", [10, 11, 12, 13, 14, 30]), ("stop", [50]),