feat: install Battle.net games from Stores with downloads, updates and uninstall

Battle.net games now install like Epic, Xbox and itch games: Install,
pick a location, and the download runs in the Downloads tab while the
Stores page stays open. droiddeck-battlenet starts Blizzard's own Agent
on its own under a headless gamescope and drives its local API, so no
window opens and nothing waits on the Battle.net client.

- Progress, speed and time left come from the Agent, with pause, resume
  (the Agent keeps what it downloaded) and cancel, which uninstalls the
  partial game and removes its folder.
- A job only finishes once the Agent has really run it and the game is
  playable; the first status after a request can still describe the
  previous operation.
- Installed games check Blizzard's version service and show Update when
  the build on disk is behind; the update repairs missing files too.
- Battle.net games can be uninstalled from their page through the Agent.
- Games land in the chosen location: internal storage, other storage or
  a Games folder.
- The hero keeps its action row clear of the playtime column.
This commit is contained in:
maxjivi05 authored and MaxsTechReview committed 2026-10-26 09:01:02 -04:00
1 parent 9fc48515c1
commit b887e8653d
43 files changed
+1176 -49

No files matched your search

@@ -17,45 +17,45 @@ object BattleNet {
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)
class Title(val uid: String, val name: String, val code: String, val steam: Int? = null, val shop: String? = null, val product: String? = null)
internal val TITLES = listOf(
Title("wow", "World of Warcraft", "WoW", shop = "world-of-warcraft-midnight"),
Title("wow_classic", "World of Warcraft Classic", "WoWC", shop = "world-of-warcraft-burning-crusade-classic-anniversary-edition-upgrades"),
Title("wow_classic_era", "World of Warcraft Classic", "WoWC"),
Title("wow_classic_anniversary", "World of Warcraft Classic", "WoWC"),
Title("diablo3", "Diablo III", "D3", shop = "diablo-iii"),
Title("wow", "World of Warcraft", "WoW", shop = "world-of-warcraft-midnight", product = "wow"),
Title("wow_classic", "World of Warcraft Classic", "WoWC", shop = "world-of-warcraft-burning-crusade-classic-anniversary-edition-upgrades", product = "wow_classic"),
Title("wow_classic_era", "World of Warcraft Classic", "WoWC", product = "wow_classic_era"),
Title("wow_classic_anniversary", "World of Warcraft Classic", "WoWC", product = "wow_anniversary"),
Title("diablo3", "Diablo III", "D3", shop = "diablo-iii", product = "d3"),
Title("d3cn", "Diablo III", "D3CN", shop = "diablo-iii"),
Title("s2", "StarCraft II", "S2", shop = "starcraft-ii"),
Title("s1", "StarCraft", "S1", shop = "starcraft-remastered"),
Title("hs_beta", "Hearthstone", "WTCG", shop = "hearthstone"),
Title("heroes", "Heroes of the Storm", "Hero", shop = "heroes-of-the-storm"),
Title("prometheus", "Overwatch 2", "Pro", 2357570, shop = "overwatch"),
Title("w3", "Warcraft III: Reforged", "W3", shop = "warcraft-3-reforged"),
Title("viper", "Call of Duty: Black Ops 4", "VIPR", shop = "call-of-duty-black-ops-4"),
Title("odin", "Call of Duty: Modern Warfare", "ODIN", 2000950, shop = "call-of-duty-modern-warfare"),
Title("lazarus", "Call of Duty: Modern Warfare 2 Campaign Remastered", "LAZR", shop = "call-of-duty-modern-warfare-2-campaign-remastered"),
Title("zeus", "Call of Duty: Black Ops Cold War", "ZEUS", shop = "call-of-duty-black-ops-cold-war"),
Title("fore", "Call of Duty: Vanguard", "FORE", shop = "call-of-duty-vanguard"),
Title("auks", "Call of Duty: Modern Warfare II", "AUKS", shop = "call-of-duty-modern-warfare-ii"),
Title("pinta", "Call of Duty: Modern Warfare III", "PNTA", 2519060, shop = "call-of-duty-modern-warfare-iii"),
Title("wlby", "Crash Bandicoot 4: It's About Time", "WLBY", 1378990, shop = "crash-bandicoot-4"),
Title("osi", "Diablo II: Resurrected", "OSI"),
Title("rtro", "Blizzard Arcade Collection", "RTRO", shop = "blizzard-arcade-collection"),
Title("anbs", "Diablo Immortal", "ANBS", shop = "diablo-immortal"),
Title("fenris", "Diablo IV", "Fen", 2344520, shop = "diablo-iv"),
Title("fen", "Diablo IV", "Fen", 2344520, shop = "diablo-iv"),
Title("d1", "Diablo", "D1", shop = "diablo"),
Title("w1", "Warcraft: Orcs & Humans", "W1", shop = "warcraft-orcs-and-humans"),
Title("w2", "Warcraft II: Battle.net Edition", "W2", shop = "warcraft-2-battle-net-edition"),
Title("w1r", "Warcraft: Remastered", "W1R", shop = "warcraft-1-remastered"),
Title("w2r", "Warcraft II: Remastered", "W2R", shop = "warcraft-2-remastered"),
Title("gryphon", "Warcraft Rumble", "GRY", shop = "warcraft-rumble"),
Title("aris", "Doom: The Dark Ages", "ARIS", 3017860, shop = "doom-the-dark-ages"),
Title("scorpio", "Sea of Thieves", "SCOR", 1172620, shop = "sea-of-thieves"),
Title("arkansas", "The Outer Worlds 2", "ARK", 1449110, shop = "the-outer-worlds-2"),
Title("libra", "Tony Hawk's Pro Skater 3 + 4", "LBRA", 2545710),
Title("aqua", "Avowed", "AQUA", 2457220, shop = "avowed"),
Title("s2", "StarCraft II", "S2", shop = "starcraft-ii", product = "s2"),
Title("s1", "StarCraft", "S1", shop = "starcraft-remastered", product = "s1"),
Title("hs_beta", "Hearthstone", "WTCG", shop = "hearthstone", product = "hsb"),
Title("heroes", "Heroes of the Storm", "Hero", shop = "heroes-of-the-storm", product = "hero"),
Title("prometheus", "Overwatch 2", "Pro", 2357570, shop = "overwatch", product = "pro"),
Title("w3", "Warcraft III: Reforged", "W3", shop = "warcraft-3-reforged", product = "w3"),
Title("viper", "Call of Duty: Black Ops 4", "VIPR", shop = "call-of-duty-black-ops-4", product = "viper"),
Title("odin", "Call of Duty: Modern Warfare", "ODIN", 2000950, shop = "call-of-duty-modern-warfare", product = "odin"),
Title("lazarus", "Call of Duty: Modern Warfare 2 Campaign Remastered", "LAZR", shop = "call-of-duty-modern-warfare-2-campaign-remastered", product = "lazr"),
Title("zeus", "Call of Duty: Black Ops Cold War", "ZEUS", shop = "call-of-duty-black-ops-cold-war", product = "zeus"),
Title("fore", "Call of Duty: Vanguard", "FORE", shop = "call-of-duty-vanguard", product = "fore"),
Title("auks", "Call of Duty: Modern Warfare II", "AUKS", shop = "call-of-duty-modern-warfare-ii", product = "auks"),
Title("pinta", "Call of Duty: Modern Warfare III", "PNTA", 2519060, shop = "call-of-duty-modern-warfare-iii", product = "pinta"),
Title("wlby", "Crash Bandicoot 4: It's About Time", "WLBY", 1378990, shop = "crash-bandicoot-4", product = "wlby"),
Title("osi", "Diablo II: Resurrected", "OSI", product = "osi"),
Title("rtro", "Blizzard Arcade Collection", "RTRO", shop = "blizzard-arcade-collection", product = "rtro"),
Title("anbs", "Diablo Immortal", "ANBS", shop = "diablo-immortal", product = "anbs"),
Title("fenris", "Diablo IV", "Fen", 2344520, shop = "diablo-iv", product = "fenris"),
Title("fen", "Diablo IV", "Fen", 2344520, shop = "diablo-iv", product = "fenris"),
Title("d1", "Diablo", "D1", shop = "diablo", product = "drtl"),
Title("w1", "Warcraft: Orcs & Humans", "W1", shop = "warcraft-orcs-and-humans", product = "war1"),
Title("w2", "Warcraft II: Battle.net Edition", "W2", shop = "warcraft-2-battle-net-edition", product = "w2bn"),
Title("w1r", "Warcraft: Remastered", "W1R", shop = "warcraft-1-remastered", product = "w1r"),
Title("w2r", "Warcraft II: Remastered", "W2R", shop = "warcraft-2-remastered", product = "w2r"),
Title("gryphon", "Warcraft Rumble", "GRY", shop = "warcraft-rumble", product = "gryphon"),
Title("aris", "Doom: The Dark Ages", "ARIS", 3017860, shop = "doom-the-dark-ages", product = "aris"),
Title("scorpio", "Sea of Thieves", "SCOR", 1172620, shop = "sea-of-thieves", product = "scor"),
Title("arkansas", "The Outer Worlds 2", "ARK", 1449110, shop = "the-outer-worlds-2", product = "ark"),
Title("libra", "Tony Hawk's Pro Skater 3 + 4", "LBRA", 2545710, product = "lbra"),
Title("aqua", "Avowed", "AQUA", 2457220, shop = "avowed", product = "aqua"),
)
val STORE: List<Title> get() = TITLES.distinctBy { it.code }.filter { it.uid != "d3cn" && it.code != "WoWC" }
@@ -104,7 +104,7 @@ object BattleNet {
private val NOT_GAMES = setOf("agent", "bna", "battle.net")
class Game(val uid: String, val name: String, val code: String, val folder: File) {
class Game(val uid: String, val name: String, val code: String, val folder: File, val installUid: String = uid) {
val title: Title get() = title(uid) ?: Title(uid, name, code)
}
@@ -172,7 +172,7 @@ object BattleNet {
}
if (title.code in found) continue
val folder = hostFolder(context, path)?.takeIf { it.isDirectory } ?: continue
found[title.code] = Game(title.uid, title.name, title.code, folder)
found[title.code] = Game(title.uid, title.name, title.code, folder, uid)
}
return found.values.toList()
}
@@ -236,7 +236,7 @@ object StoresState {
fun install(context: Context, item: CatalogItem, root: java.io.File? = null, language: String? = null) {
val app = context.applicationContext
val targetRoot = root ?: StoreInstallRoot.defaultTarget(app)?.root ?: StoreInstallRoot.installRoot(app)
if (item.store == Store.BATTLENET) {
if (item.store == Store.BATTLENET && !com.droiddeck.launcher.stores.battlenet.BattleNetInstall.headless(item)) {
backends[item.store]?.install(app, item, targetRoot)
return
}
@@ -273,7 +273,7 @@ object StoresState {
uninstalling[key] = 0f
background("stores-uninstall", onFailure = { main.post { uninstalling.remove(key); onDone() } }) {
runCatching { backends[game.sidecar.store]?.uninstall(app, game) }
if (game.sidecar.store == Store.BATTLENET) {
if (game.sidecar.store == Store.BATTLENET && com.droiddeck.launcher.runtime.BattleNet.games(app).any { it.folder.absolutePath == game.folder.absolutePath }) {
main.post { uninstalling.remove(key); onDone() }
return@background
}
@@ -0,0 +1,283 @@
package com.droiddeck.launcher.stores.battlenet
import android.content.Context
import android.util.Log
import androidx.compose.runtime.mutableStateMapOf
import com.droiddeck.launcher.R
import com.droiddeck.launcher.frontend.AddedGames
import com.droiddeck.launcher.runtime.BattleNet
import com.droiddeck.launcher.runtime.GuestCommand
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.droiddeck.launcher.session.GameStorage
import com.droiddeck.launcher.session.SecondaryLibrary
import com.droiddeck.launcher.stores.CatalogItem
import com.droiddeck.launcher.stores.InstalledStoreGame
import com.droiddeck.launcher.stores.Store
import com.droiddeck.launcher.stores.StoreInstallRoot
import com.droiddeck.launcher.stores.StoreLanguage
import com.droiddeck.launcher.stores.StoresState
import com.droiddeck.launcher.stores.download.DownloadEntry
import com.droiddeck.launcher.stores.download.DownloadQueue
import com.droiddeck.launcher.stores.download.DownloadStage
import org.json.JSONObject
import java.io.File
import java.net.HttpURLConnection
import java.net.URL
import java.util.Locale
import java.util.concurrent.Executors
import java.util.concurrent.atomic.AtomicBoolean
object BattleNetInstall {
private const val TAG = "BattleNetInstall"
internal const val PROGRESS = "BNET_PROGRESS "
internal const val STATE = "BNET_STATE "
internal const val DONE = "BNET_DONE "
internal const val ERROR = "BNET_ERROR "
private const val LIBRARY_GUEST = "/mnt/droiddeck-sd"
private const val VERSIONS = "https://%s.version.battle.net/v2/products/%s/versions"
private const val BUILD_INFO = ".build.info"
private const val CHECK_AGAIN_MS = 30 * 60_000L
internal val LOCALES = listOf(
"enUS", "enGB", "esMX", "esES", "ptBR", "ptPT", "frFR", "deDE", "itIT", "ruRU", "jaJP", "koKR", "plPL", "trTR",
"zhTW", "zhCN", "thTH", "arSA",
)
private val checks = Executors.newSingleThreadExecutor { r -> Thread(r, "battlenet-updates") }
private val checkedAt = HashMap<String, Long>()
val updates = mutableStateMapOf<String, Boolean>()
fun product(id: String): String? = BattleNet.title(id)?.product
fun headless(item: CatalogItem): Boolean = item.store == Store.BATTLENET && product(item.id) != null
internal fun locale(locale: Locale): String {
val language = locale.language.lowercase(Locale.ROOT)
if (language == "zh") {
val traditional = locale.script.equals("Hant", true) || locale.country.uppercase(Locale.ROOT) in setOf("TW", "HK", "MO")
return if (traditional) "zhTW" else "zhCN"
}
val exact = language + locale.country.uppercase(Locale.ROOT)
return LOCALES.firstOrNull { it == exact } ?: LOCALES.firstOrNull { it.startsWith(language) } ?: "enUS"
}
internal fun country(locale: Locale): Pair<String, String> {
val two = locale.country.uppercase(Locale.ROOT)
val three = runCatching { locale.isO3Country.uppercase(Locale.ROOT) }.getOrDefault("")
return if (two.matches(Regex("[A-Z]{2}")) && three.matches(Regex("[A-Z]{3}"))) three to two else "USA" to "US"
}
internal fun binds(context: Context, guest: String): List<String> {
val out = ArrayList<String>()
if (guest.startsWith(StoreInstallRoot.GUEST_EXTERNAL + "/")) out += StoreInstallRoot.externalBindSpecs(context)
if (guest == LIBRARY_GUEST || guest.startsWith("$LIBRARY_GUEST/")) {
GameStorage.effective(context)?.let { library ->
File(LinuxRuntime.rootDir(context), LIBRARY_GUEST.removePrefix("/")).mkdirs()
out += SecondaryLibrary.contentPath(File(library.path)).path + ":" + LIBRARY_GUEST
}
}
return out
}
internal fun run(context: Context, args: List<String>, guest: String?, cancelled: AtomicBoolean?, onLine: (String) -> Unit): Int =
GuestCommand.run(
context, listOf(BattleNet.PROGRAM) + args, logName = "battlenet-agent",
extraBinds = guest?.let { binds(context, it) }, fastPath = true, cancelled = cancelled, onLine = onLine,
)
fun enqueue(context: Context, item: CatalogItem, folder: File, update: Boolean = false) {
val app = context.applicationContext
val entry = DownloadEntry(
Store.BATTLENET, item.id, item.title, cover = item.tallImageUrl ?: item.imageUrl,
location = StoreInstallRoot.labelFor(app, folder),
)
DownloadQueue.enqueue(app, entry) { BattleNetInstaller(app, item, folder, update) }
}
fun update(context: Context, game: InstalledStoreGame) {
val app = context.applicationContext
Thread({
val item = CatalogItem(
Store.BATTLENET, game.sidecar.id, game.sidecar.title, game.sidecar.hero, tallImageUrl = game.sidecar.cover, owned = true,
extra = mapOf(INSTALL_UID to installUid(app, game)),
)
game.folder.parentFile?.parentFile?.let { com.droiddeck.launcher.stores.download.SavedQueue.remember(app, item, it) }
enqueue(app, item, game.folder, update = true)
}, "battlenet-update").start()
}
internal const val INSTALL_UID = "installUid"
internal fun installUid(context: Context, game: InstalledStoreGame): String =
runCatching { BattleNet.games(context).firstOrNull { it.uid == game.sidecar.id }?.installUid }.getOrNull() ?: game.sidecar.id
fun uninstall(context: Context, game: InstalledStoreGame): Boolean {
if (product(game.sidecar.id) == null || !BattleNet.installed(context)) return false
val uid = installUid(context, game)
var done = false
val code = runCatching {
run(context, listOf("agent-uninstall", uid), AddedGames.guestPath(context, game.folder), null) { line ->
if (line.startsWith(DONE)) done = true
}
}.onFailure { Log.w(TAG, "uninstall $uid", it) }.getOrDefault(-1)
Log.i(TAG, "uninstall $uid: ${if (done) "done" else "exit $code"}")
if (done) StoresState.post { StoresState.notifyLibraryChanged(context.applicationContext) }
return done
}
internal fun buildKey(text: String): Pair<String, String>? {
val rows = text.lines().filter { it.isNotBlank() }
if (rows.size < 2) return null
val head = rows[0].split('|').map { it.substringBefore('!') }
val branch = head.indexOf("Branch")
val active = head.indexOf("Active")
val key = head.indexOf("Build Key")
if (branch < 0 || key < 0) return null
val row = rows.drop(1).map { it.split('|') }.firstOrNull { active < 0 || it.getOrNull(active) == "1" } ?: return null
val region = row.getOrNull(branch)?.takeIf { it.matches(Regex("[a-z]{2}")) } ?: return null
val build = row.getOrNull(key)?.takeIf { it.matches(Regex("[0-9a-f]{32}")) } ?: return null
return region to build
}
internal fun latestBuild(text: String, region: String): String? {
val rows = text.lines().filter { it.isNotBlank() && !it.startsWith("##") }
if (rows.isEmpty()) return null
val head = rows[0].split('|').map { it.substringBefore('!') }
val at = head.indexOf("Region")
val key = head.indexOf("BuildConfig")
if (at < 0 || key < 0) return null
return rows.drop(1).map { it.split('|') }.firstOrNull { it.getOrNull(at) == region }?.getOrNull(key)
?.takeIf { it.matches(Regex("[0-9a-f]{32}")) }
}
fun checkUpdate(context: Context, game: InstalledStoreGame, force: Boolean = false) = check(game.sidecar.id, game.folder, force)
internal fun check(id: String, folder: File, force: Boolean) {
val product = product(id) ?: return
val now = System.currentTimeMillis()
synchronized(checkedAt) {
if (!force && now - (checkedAt[id] ?: 0L) < CHECK_AGAIN_MS) return
checkedAt[id] = now
}
checks.execute {
val local = runCatching { buildKey(File(folder, BUILD_INFO).readText()) }.getOrNull() ?: return@execute
val latest = runCatching { latestBuild(fetch(VERSIONS.format(Locale.ROOT, local.first, product)), local.first) }
.onFailure { Log.w(TAG, "versions of $product: ${it.javaClass.simpleName}") }.getOrNull() ?: return@execute
val behind = latest != local.second
Log.i(TAG, "$id: ${if (behind) "update available" else "up to date"}")
StoresState.post { if (behind) updates[id] = true else updates.remove(id) }
}
}
private fun fetch(url: String): String {
val conn = (URL(url).openConnection() as HttpURLConnection).apply {
connectTimeout = 15_000
readTimeout = 15_000
setRequestProperty("User-Agent", "DroidDeck")
}
try {
if (conn.responseCode != 200) throw java.io.IOException("HTTP ${conn.responseCode}")
return conn.inputStream.bufferedReader().use { it.readText() }
} finally {
conn.disconnect()
}
}
internal fun failure(context: Context, reason: String?, code: Int): String {
val detail = when {
reason == null -> "exit $code"
reason == "client" -> return context.getString(R.string.bnet_dl_client_first)
reason.startsWith("agent ") -> context.getString(R.string.bnet_dl_agent_error, reason.removePrefix("agent "))
else -> reason.removePrefix("stopped ")
}
return context.getString(R.string.bnet_dl_failed, detail)
}
internal fun localeTag(context: Context): String = locale(StoreLanguage.localeFor(null, context))
internal enum class Step { PREPARING, DOWNLOADING, APPLYING }
internal fun step(state: Int, phase: Int, current: Long, total: Long): Step = when {
state == DONE_STATE || phase == APPLY_PHASE || total > 0L && current >= total -> Step.APPLYING
total > 0L -> Step.DOWNLOADING
else -> Step.PREPARING
}
private const val DONE_STATE = 1004
private const val APPLY_PHASE = 2000
}
internal class BattleNetInstaller(
private val app: Context,
private val item: CatalogItem,
private val folder: File,
private val update: Boolean,
) : DownloadQueue.DownloadJob {
private val cancelled = AtomicBoolean(false)
private var before = 0L
private var kept = -1L
override fun run(handle: DownloadQueue.JobHandle): String? {
before = DownloadQueue.entry(handle.key)?.bytesTotal ?: 0L
handle.stage(DownloadStage.MANIFEST, app.getString(R.string.bnet_dl_starting))
if (!BattleNet.installed(app)) throw IllegalStateException(app.getString(R.string.bnet_dl_client_first))
val title = BattleNet.title(item.id)
val product = title?.product ?: throw IllegalStateException(app.getString(R.string.bnet_dl_failed, item.id))
val uid = item.extra[BattleNetInstall.INSTALL_UID] ?: title.uid
if (!update) folder.mkdirs()
val guest = AddedGames.guestPath(app, folder) ?: throw IllegalStateException(app.getString(R.string.bnet_dl_failed, folder.path))
val (country, region) = BattleNetInstall.country(Locale.getDefault())
val args = if (update) listOf("agent-update", uid)
else listOf("agent-install", uid, product, guest, BattleNetInstall.localeTag(app), country, region)
var done: JSONObject? = null
var reason: String? = null
val code = BattleNetInstall.run(app, args, guest, cancelled) { line ->
when {
line.startsWith(BattleNetInstall.PROGRESS) ->
runCatching { JSONObject(line.removePrefix(BattleNetInstall.PROGRESS)) }.getOrNull()?.let { progress(handle, it) }
line == BattleNetInstall.STATE + "waiting" -> handle.stage(DownloadStage.MANIFEST, app.getString(R.string.bnet_dl_waiting))
line == BattleNetInstall.STATE + "queued" -> handle.stage(DownloadStage.MANIFEST, app.getString(R.string.bnet_dl_queued))
line == BattleNetInstall.STATE + "starting" -> handle.stage(DownloadStage.MANIFEST, app.getString(R.string.bnet_dl_starting))
line.startsWith(BattleNetInstall.DONE) -> done = runCatching { JSONObject(line.removePrefix(BattleNetInstall.DONE)) }.getOrNull()
line.startsWith(BattleNetInstall.ERROR) -> reason = line.removePrefix(BattleNetInstall.ERROR)
}
}
if (cancelled.get()) return null
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)
StoresState.notifyLibraryChanged(app)
}
BattleNetInstall.check(item.id, folder, force = true)
return folder.absolutePath
}
private fun progress(handle: DownloadQueue.JobHandle, status: JSONObject) {
val current = status.optLong("download_current", 0L)
val total = status.optLong("download_total", 0L)
when (BattleNetInstall.step(status.optInt("state", 0), status.optInt("phase", 0), current, total)) {
BattleNetInstall.Step.PREPARING -> handle.stage(DownloadStage.MANIFEST, app.getString(R.string.stores_stage_checking))
BattleNetInstall.Step.DOWNLOADING -> {
if (kept < 0L) kept = (before - total).coerceAtLeast(0L)
handle.progress(kept + current, kept + total)
}
BattleNetInstall.Step.APPLYING -> handle.stage(DownloadStage.INSTALL)
}
}
override fun cancel(deleteFiles: Boolean) {
cancelled.set(true)
if (!deleteFiles || update) return
val uid = item.extra[BattleNetInstall.INSTALL_UID] ?: BattleNet.title(item.id)?.uid ?: return
Thread({
Thread.sleep(2_000)
val gone = runCatching {
BattleNetInstall.run(app, listOf("agent-uninstall", uid), AddedGames.guestPath(app, folder), null) {}
}.getOrDefault(-1)
if (folder.isDirectory) com.droiddeck.launcher.core.FileUtils.delete(folder)
Log.i("BattleNetInstall", "cancelled install of $uid cleaned up (exit $gone)")
}, "battlenet-cancel").start()
}
}
@@ -189,9 +189,15 @@ object BattleNetBackend : StoreBackend {
override fun search(context: Context, query: String): List<CatalogItem> =
BattleNet.STORE.filter { it.name.contains(query, ignoreCase = true) }.map { item(context, it) }
override fun install(context: Context, item: CatalogItem, root: File) = BattleNetClient.installGame(context, item.id, root)
override fun install(context: Context, item: CatalogItem, root: File) {
if (!BattleNetInstall.headless(item)) return BattleNetClient.installGame(context, item.id, root)
val app = context.applicationContext
BattleNetInstall.enqueue(app, item, StoreInstallRoot.folderFor(app, store, item.id, item.title, root))
}
override fun uninstall(context: Context, game: InstalledStoreGame) = BattleNetClient.open(emptyList())
override fun uninstall(context: Context, game: InstalledStoreGame) {
if (!BattleNetInstall.uninstall(context, game)) BattleNetClient.open(emptyList())
}
fun installed(context: Context): List<BattleNet.Game> = if (BattleNet.installed(context)) BattleNet.games(context) else emptyList()
@@ -56,6 +56,7 @@ import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.boundsInRoot
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalConfiguration
@@ -86,6 +87,7 @@ import com.droiddeck.launcher.stores.StoreInstallRoot
import com.droiddeck.launcher.stores.StoreLanguage
import com.droiddeck.launcher.stores.StoreSizes
import com.droiddeck.launcher.stores.StoresState
import com.droiddeck.launcher.stores.battlenet.BattleNetInstall
import com.droiddeck.launcher.stores.download.DownloadQueue
import com.droiddeck.launcher.stores.download.DownloadState
import com.droiddeck.launcher.stores.formatBytes
@@ -267,13 +269,15 @@ private fun GameHero(
)
}
Spacer(Modifier.matchParentSize().background(Brush.horizontalGradient(0f to colors.background.copy(alpha = 0.94f), 0.55f to colors.background.copy(alpha = 0.58f), 1f to Color.Transparent)))
var scoresWidth by remember { mutableStateOf(0) }
if (scores != null) {
Spacer(Modifier.matchParentSize().background(Brush.horizontalGradient(0.45f to Color.Transparent, 1f to colors.background.copy(alpha = 0.75f))))
HeroScores(scores, Modifier.align(Alignment.BottomEnd).padding(end = 16.dp, bottom = 18.dp))
HeroScores(scores, Modifier.align(Alignment.BottomEnd).padding(end = 16.dp, bottom = 18.dp).onSizeChanged { scoresWidth = it.width })
}
val scoresSpace = with(LocalDensity.current) { if (scores != null && scoresWidth > 0) scoresWidth.toDp() + 16.dp else 0.dp }
Column(
verticalArrangement = Arrangement.spacedBy(6.dp),
modifier = Modifier.align(Alignment.BottomStart).padding(horizontal = 22.dp, vertical = 18.dp),
modifier = Modifier.align(Alignment.BottomStart).padding(start = 22.dp, end = 22.dp + scoresSpace, top = 18.dp, bottom = 18.dp),
content = content,
)
Box(Modifier.align(Alignment.TopEnd).padding(12.dp), content = corner)
@@ -358,7 +362,19 @@ internal fun GameActions(
}
SecondaryButton(stringResource(R.string.stores_xbox_manage), enabled = download == null) { XboxContent.manage(ctx, installed) }
}
if (store == Store.BATTLENET) SecondaryButton(stringResource(R.string.bnet_open)) { a.onBattleNet() }
if (store == Store.BATTLENET) {
if (installed != null && id != null) {
LaunchedEffect(id) { BattleNetInstall.checkUpdate(ctx, installed) }
if (download != null) {
ActionChip(downloadLabel(download), ok = false)
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) {
SecondaryButton(stringResource(R.string.bnet_update)) { BattleNetInstall.update(ctx, installed) }
}
}
SecondaryButton(stringResource(R.string.bnet_open)) { a.onBattleNet() }
}
}
download != null -> {
ActionChip(downloadLabel(download), ok = false)
@@ -534,7 +550,7 @@ private fun IconAction(icon: androidx.compose.ui.graphics.vector.ImageVector, la
private fun RemoveButton(title: String, game: Library.SteamGame?, installed: InstalledStoreGame?, a: FrontEndActions) {
val ctx = LocalContext.current
val colors = MaterialTheme.colorScheme
if ((installed?.sidecar?.store?.id ?: game?.source) == Store.BATTLENET.id) return
if ((installed?.sidecar?.store?.id ?: game?.source) == Store.BATTLENET.id && installed?.sidecar?.id?.let(BattleNetInstall::product) == null) return
if (installed != null) {
val key = installed.key
val gone = StoresState.uninstalling[key]
@@ -1392,7 +1392,11 @@ internal fun downloadLabel(d: com.droiddeck.launcher.stores.download.DownloadEnt
@Composable
internal fun activeStageLabel(d: com.droiddeck.launcher.stores.download.DownloadEntry): String = when (d.stage) {
DownloadStage.MANIFEST -> if (d.stageItemsTotal > 0) stringResource(R.string.stores_stage_checking) else stringResource(R.string.stores_stage_manifest)
DownloadStage.MANIFEST -> when {
d.store == Store.BATTLENET && d.detail.isNotBlank() -> d.detail
d.stageItemsTotal > 0 -> stringResource(R.string.stores_stage_checking)
else -> stringResource(R.string.stores_stage_manifest)
}
DownloadStage.DOWNLOAD -> stringResource(R.string.stores_stage_downloading)
DownloadStage.VERIFY -> stringResource(R.string.stores_stage_verifying)
DownloadStage.INSTALL -> stringResource(R.string.stores_stage_installing)