mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
fix(battlenet): check updates per install folder on the China version line
The update state was keyed by title, so two copies of the same game in different folders shared one badge, and a China install was compared against the global version line, which it never follows. The badge is now keyed by id and folder. A China build asks the China repository for the product it is actually served from (osic, s2c, d3cn), and the check re-reads .build.info after the request so a build that changed meanwhile is retried instead of reported against a stale key. refresh() checks every installed Battle.net game, the library badge reads the same key, and the detail screen re-checks once the running session ends.
This commit is contained in:
1 parent
296b4586a4
commit
4283fd810e
5 files changed
+133
-14
No files matched your search
@@ -103,6 +103,8 @@ object StoresState {
|
||||
accountsLoaded = true
|
||||
}
|
||||
com.droiddeck.launcher.stores.gog.GogMaintenance.checkInstalled(app, onDisk)
|
||||
onDisk.filter { it.sidecar.store == Store.BATTLENET }
|
||||
.forEach { com.droiddeck.launcher.stores.battlenet.BattleNetInstall.checkUpdate(app, it) }
|
||||
}
|
||||
} while (!refreshRequests.compareAndSet(seen, 0))
|
||||
}
|
||||
|
||||
@@ -53,8 +53,19 @@ object BattleNetInstall {
|
||||
|
||||
val updates = mutableStateMapOf<String, Boolean>()
|
||||
|
||||
fun updateKey(id: String, folder: File?): String = "$id@${folder?.absolutePath ?: ""}"
|
||||
|
||||
fun product(id: String): String? = BattleNet.title(id)?.product
|
||||
|
||||
/** The China client serves StarCraft II, Diablo II and Diablo III from products of their own; anbs_cn shares anbs. */
|
||||
private val CN_PRODUCTS = mapOf(
|
||||
"osi" to "osic",
|
||||
"s2" to "s2c",
|
||||
"diablo3" to "d3cn",
|
||||
)
|
||||
|
||||
internal fun chinaProduct(id: String): String? = CN_PRODUCTS[id]
|
||||
|
||||
fun headless(item: CatalogItem): Boolean = item.store == Store.BATTLENET && product(item.id) != null
|
||||
|
||||
internal fun locale(locale: Locale): String {
|
||||
@@ -102,7 +113,7 @@ object BattleNetInstall {
|
||||
if (uid == null) {
|
||||
Log.w(TAG, "no Battle.net install matches ${game.folder}")
|
||||
StoresState.logLine("Battle.net: no registration matches ${game.folder.name}; update it from Battle.net")
|
||||
StoresState.post { updates.remove(game.sidecar.id) }
|
||||
StoresState.post { updates.remove(updateKey(game.sidecar.id, game.folder)) }
|
||||
} else {
|
||||
val item = updateItem(game, uid)
|
||||
game.folder.parentFile?.parentFile?.let { com.droiddeck.launcher.stores.download.SavedQueue.remember(app, item, it) }
|
||||
@@ -188,21 +199,29 @@ object BattleNetInstall {
|
||||
|
||||
internal fun check(id: String, folder: File, force: Boolean) {
|
||||
val product = product(id) ?: return
|
||||
val key = updateKey(id, folder)
|
||||
val now = System.currentTimeMillis()
|
||||
synchronized(checkedAt) {
|
||||
if (!force && now - (checkedAt[id] ?: 0L) < CHECK_AGAIN_MS) return
|
||||
checkedAt[id] = now
|
||||
if (!force && now - (checkedAt[key] ?: 0L) < CHECK_AGAIN_MS) return
|
||||
checkedAt[key] = now
|
||||
}
|
||||
fun retryLater() {
|
||||
synchronized(checkedAt) { if (checkedAt[key] == now) checkedAt.remove(key) }
|
||||
StoresState.post { updates.remove(key) }
|
||||
}
|
||||
fun retryLater() = synchronized(checkedAt) { if (checkedAt[id] == now) checkedAt.remove(id) }
|
||||
checks.execute {
|
||||
val local = runCatching { buildKey(File(folder, BUILD_INFO).readText()) }.getOrNull()
|
||||
?: return@execute retryLater()
|
||||
val latest = runCatching { latestBuild(fetch(versionsUrl(local.first, product)), local.first) }
|
||||
.onFailure { Log.w(TAG, "versions of $product: ${it.javaClass.simpleName}") }.getOrNull()
|
||||
val served = if (local.first == CN) chinaProduct(id) ?: product else product
|
||||
val latest = runCatching { latestBuild(fetch(versionsUrl(local.first, served)), local.first) }
|
||||
.onFailure { Log.w(TAG, "versions of $served: ${it.javaClass.simpleName}") }.getOrNull()
|
||||
?: return@execute retryLater()
|
||||
val behind = latest != local.second
|
||||
val current = runCatching { buildKey(File(folder, BUILD_INFO).readText()) }.getOrNull()
|
||||
?: return@execute retryLater()
|
||||
if (current != local) return@execute retryLater()
|
||||
val behind = latest != current.second
|
||||
Log.i(TAG, "$id: ${if (behind) "update available" else "up to date"}")
|
||||
StoresState.post { if (behind) updates[id] = true else updates.remove(id) }
|
||||
StoresState.post { if (behind) updates[key] = true else updates.remove(key) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +319,7 @@ internal class BattleNetInstaller(
|
||||
if (done == null) throw IllegalStateException(BattleNetInstall.failure(app, reason, code))
|
||||
handle.log("Battle.net: ${item.title} ${if (update) "updated" else "installed"} ${done?.optString("version").orEmpty()}".trimEnd())
|
||||
StoresState.post {
|
||||
BattleNetInstall.updates.remove(item.id)
|
||||
BattleNetInstall.updates.remove(BattleNetInstall.updateKey(item.id, folder))
|
||||
StoresState.notifyLibraryChanged(app)
|
||||
}
|
||||
BattleNetInstall.check(item.id, folder, force = true)
|
||||
|
||||
@@ -584,12 +584,25 @@ internal fun GameActions(
|
||||
}
|
||||
if (store == Store.BATTLENET) {
|
||||
if (installed != null && id != null) {
|
||||
LaunchedEffect(id) { BattleNetInstall.checkUpdate(ctx, installed) }
|
||||
val updateKey = BattleNetInstall.updateKey(id, installed.folder)
|
||||
var wasRunning by remember(updateKey) { mutableStateOf(false) }
|
||||
// SessionState.running is not snapshot state, so poll it while this detail is shown.
|
||||
val sessionRunning by produceState(SessionState.running) {
|
||||
while (true) {
|
||||
value = SessionState.running
|
||||
kotlinx.coroutines.delay(1000)
|
||||
}
|
||||
}
|
||||
LaunchedEffect(updateKey, sessionRunning) {
|
||||
val ended = wasRunning && !sessionRunning
|
||||
wasRunning = sessionRunning
|
||||
if (!sessionRunning) BattleNetInstall.checkUpdate(ctx, installed, force = ended)
|
||||
}
|
||||
if (download != null) {
|
||||
SteadyDownloadChip(download)
|
||||
if (download.state != DownloadState.PAUSED) SecondaryButton(stringResource(R.string.stores_dl_pause)) { DownloadQueue.pause(download.key) }
|
||||
else SecondaryButton(stringResource(R.string.stores_dl_resume)) { DownloadQueue.resume(ctx, download.key) }
|
||||
} else if (BattleNetInstall.updates[id] == true) {
|
||||
} else if (BattleNetInstall.updates[updateKey] == true) {
|
||||
SecondaryButton(stringResource(R.string.bnet_update)) { BattleNetInstall.update(ctx, installed) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1198,8 +1198,22 @@ internal fun LibraryMarker(e: LibraryEntry, download: DownloadEntry?, showDownlo
|
||||
}
|
||||
}
|
||||
|
||||
private fun libraryUpdateAvailable(e: LibraryEntry): Boolean = e.storeKey?.let { it in ItchUpdates.available || it in GameJoltUpdates.available || it in com.droiddeck.launcher.stores.ea.EaUpdates.available } == true ||
|
||||
e.source == Store.GOG.id && (e.item?.id ?: e.game?.storeId)?.let { GogMaintenance.checks[it]?.state } == GogMaintenance.State.AVAILABLE
|
||||
private fun libraryUpdateAvailable(e: LibraryEntry): Boolean {
|
||||
val installed = e.storeKey?.let { key ->
|
||||
val store = Store.byId(e.source)
|
||||
val id = e.item?.id ?: e.game?.storeId
|
||||
if (store != null && id != null) StoresState.installedGame(store, id, e.game?.gameFiles)
|
||||
else StoresState.installed.firstOrNull { it.key == key }
|
||||
}
|
||||
val battleNet = installed?.let {
|
||||
com.droiddeck.launcher.stores.battlenet.BattleNetInstall.updates[
|
||||
com.droiddeck.launcher.stores.battlenet.BattleNetInstall.updateKey(it.sidecar.id, it.folder)
|
||||
] == true
|
||||
} == true
|
||||
return battleNet ||
|
||||
e.storeKey?.let { it in ItchUpdates.available || it in GameJoltUpdates.available || it in com.droiddeck.launcher.stores.ea.EaUpdates.available } == true ||
|
||||
e.source == Store.GOG.id && (e.item?.id ?: e.game?.storeId)?.let { GogMaintenance.checks[it]?.state } == GogMaintenance.State.AVAILABLE
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LibraryRow(e: LibraryEntry, first: Boolean, navigation: Modifier, choose: (() -> Unit)?, onOpen: (String) -> Unit) {
|
||||
|
||||
@@ -28,6 +28,41 @@ class BattleNetInstallTest {
|
||||
eu|e474008a3535d8ea978949a90d9873e6|db0583272ed15286569b5f24ce516876||119725|16.1.2.119725|f6a454799d25791e5a37a7547d75ce49
|
||||
""".trimIndent()
|
||||
|
||||
private val osiVersions = """
|
||||
Region!STRING:0|BuildConfig!HEX:16|CDNConfig!HEX:16|KeyRing!HEX:16|BuildId!DEC:4|VersionsName!String:0|ProductConfig!HEX:16
|
||||
## seqn = 3964805
|
||||
us|11111111111111111111111111111111|aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa||93847|3.3.93847|bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
eu|11111111111111111111111111111111|aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa||93847|3.3.93847|bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
kr|11111111111111111111111111111111|aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa||93847|3.3.93847|bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
""".trimIndent()
|
||||
|
||||
private val osicVersions = """
|
||||
Region!STRING:0|BuildConfig!HEX:16|CDNConfig!HEX:16|KeyRing!HEX:16|BuildId!DEC:4|VersionsName!String:0|ProductConfig!HEX:16
|
||||
## seqn = 3964866
|
||||
cn|44444444444444444444444444444444|cccccccccccccccccccccccccccccccc||93854|3.3.93854|dddddddddddddddddddddddddddddddd
|
||||
""".trimIndent()
|
||||
|
||||
private val s2Versions = """
|
||||
Region!STRING:0|BuildConfig!HEX:16|CDNConfig!HEX:16|KeyRing!HEX:16|BuildId!DEC:4|VersionsName!String:0|ProductConfig!HEX:16
|
||||
## seqn = 4064835
|
||||
us|55555555555555555555555555555555|eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee||98310|5.0.17.98310|ffffffffffffffffffffffffffffffff
|
||||
cn|66666666666666666666666666666666|eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee||93333|5.0.14.93333|ffffffffffffffffffffffffffffffff
|
||||
""".trimIndent()
|
||||
|
||||
private val s2cVersions = """
|
||||
Region!STRING:0|BuildConfig!HEX:16|CDNConfig!HEX:16|KeyRing!HEX:16|BuildId!DEC:4|VersionsName!String:0|ProductConfig!HEX:16
|
||||
## seqn = 4064962
|
||||
cn|77777777777777777777777777777777|eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee||98370|5.0.17.98370|ffffffffffffffffffffffffffffffff
|
||||
""".trimIndent()
|
||||
|
||||
private val anbsVersions = """
|
||||
Region!STRING:0|BuildConfig!HEX:16|CDNConfig!HEX:16|KeyRing!HEX:16|BuildId!DEC:4|VersionsName!String:0|ProductConfig!HEX:16
|
||||
## seqn = 4105154
|
||||
us|88888888888888888888888888888888|99999999999999999999999999999999||3935504|5.1.3.3935504|aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab
|
||||
eu|88888888888888888888888888888888|99999999999999999999999999999999||3935504|5.1.3.3935504|aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab
|
||||
kr|88888888888888888888888888888888|99999999999999999999999999999999||3935504|5.1.3.3935504|aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab
|
||||
""".trimIndent()
|
||||
|
||||
@Test fun theActiveRowGivesTheRegionAndBuildOnDisk() {
|
||||
assertEquals("us" to "e474008a3535d8ea978949a90d9873e6", BattleNetInstall.buildKey(buildInfo))
|
||||
assertNull(BattleNetInstall.buildKey("Branch!STRING:0|Active!DEC:1\n"))
|
||||
@@ -41,9 +76,18 @@ class BattleNetInstallTest {
|
||||
assertNull(BattleNetInstall.latestBuild("", "us"))
|
||||
}
|
||||
|
||||
@Test fun theChinaProductsAreNotOnTheGlobalVersionLine() {
|
||||
assertNull(BattleNetInstall.latestBuild(osiVersions, "cn"))
|
||||
assertEquals("44444444444444444444444444444444", BattleNetInstall.latestBuild(osicVersions, "cn"))
|
||||
assertEquals("66666666666666666666666666666666", BattleNetInstall.latestBuild(s2Versions, "cn"))
|
||||
assertEquals("77777777777777777777777777777777", BattleNetInstall.latestBuild(s2cVersions, "cn"))
|
||||
assertNull(BattleNetInstall.latestBuild(anbsVersions, "cn"))
|
||||
}
|
||||
|
||||
@Test fun theVersionServiceIsBlizzardsChineseOneForChina() {
|
||||
assertEquals("https://us.version.battle.net/v2/products/wow/versions", BattleNetInstall.versionsUrl("us", "wow"))
|
||||
assertEquals("https://cn.version.battlenet.com.cn/v2/products/d3cn/versions", BattleNetInstall.versionsUrl("cn", "d3cn"))
|
||||
assertEquals("https://cn.version.battlenet.com.cn/v2/products/s2c/versions", BattleNetInstall.versionsUrl("cn", "s2c"))
|
||||
}
|
||||
|
||||
@Test fun theDeviceLanguagePicksABlizzardLocale() {
|
||||
@@ -69,6 +113,15 @@ class BattleNetInstallTest {
|
||||
assertTrue(BattleNetInstall.headless(CatalogItem(Store.BATTLENET, "gryphon", "Warcraft Rumble", null)))
|
||||
assertEquals("hsb", BattleNetInstall.product("hs_beta"))
|
||||
assertEquals("d3", BattleNetInstall.product("diablo3_enus"))
|
||||
assertEquals("d3cn", BattleNetInstall.product("d3cn"))
|
||||
assertEquals("osic", BattleNetInstall.product("osic"))
|
||||
assertEquals("s2c", BattleNetInstall.product("s2_cn"))
|
||||
assertEquals("anbs", BattleNetInstall.product("anbs_cn"))
|
||||
assertEquals("osic", BattleNetInstall.chinaProduct("osi"))
|
||||
assertEquals("s2c", BattleNetInstall.chinaProduct("s2"))
|
||||
assertEquals("d3cn", BattleNetInstall.chinaProduct("diablo3"))
|
||||
assertNull(BattleNetInstall.chinaProduct("anbs"))
|
||||
assertNull(BattleNetInstall.chinaProduct("wow"))
|
||||
assertTrue(BattleNetInstall.headless(CatalogItem(Store.BATTLENET, "d3cn", "Diablo III", null)))
|
||||
assertFalse(BattleNetInstall.headless(CatalogItem(Store.EPIC, "gryphon", "Warcraft Rumble", null)))
|
||||
}
|
||||
@@ -78,12 +131,30 @@ class BattleNetInstallTest {
|
||||
try {
|
||||
BattleNetInstall.check("gryphon", folder, false)
|
||||
BattleNetInstall.checks.submit {}.get()
|
||||
assertFalse(synchronized(BattleNetInstall.checkedAt) { "gryphon" in BattleNetInstall.checkedAt })
|
||||
assertFalse(synchronized(BattleNetInstall.checkedAt) {
|
||||
BattleNetInstall.updateKey("gryphon", folder) in BattleNetInstall.checkedAt
|
||||
})
|
||||
} finally {
|
||||
folder.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun updateStateIsSeparateForEachInstallFolder() {
|
||||
val one = Files.createTempDirectory("bnet-one").toFile()
|
||||
val two = Files.createTempDirectory("bnet-two").toFile()
|
||||
try {
|
||||
val first = BattleNetInstall.updateKey("diablo3", one)
|
||||
val second = BattleNetInstall.updateKey("diablo3", two)
|
||||
assertFalse(first == second)
|
||||
BattleNetInstall.updates[first] = true
|
||||
assertNull(BattleNetInstall.updates[second])
|
||||
BattleNetInstall.updates.remove(first)
|
||||
} finally {
|
||||
one.deleteRecursively()
|
||||
two.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theAgentStatusPicksTheDownloadStep() {
|
||||
assertEquals(BattleNetInstall.Step.PREPARING, BattleNetInstall.step(1008, 0, 0, 0))
|
||||
assertEquals(BattleNetInstall.Step.PREPARING, BattleNetInstall.step(1003, 500, 0, 0))
|
||||
|
||||
Reference in new issue
Block a user