Compare commits

...
Author SHA1 Message Date
maxjivi05 3716455994 fix(stores): let a newer game link supersede opening the Nexon Launcher
Take the launch ticket before the worker resolves the Nexon entry and pass
it on, so a game link that arrives meanwhile wins. Drop the Battle.net
wrappers the client refactor left unused, and clear the test runtime root
without following links.
2026-12-03 18:00:24 -05:00
maxjivi05 6be30d07b4 Merge remote-tracking branch 'droiddeck/main' into pr-3650 2026-12-03 17:56:33 -05:00
maxjivi05 2221b1a984 feat(stores): add the Nexon Launcher as a Windows client store
Battle.net's client plumbing (prefix, installer download, opener, launcher
row and open buttons) is parameterised as WindowsClient, and the Nexon
Launcher is its second instance: signing in downloads Nexon's installer,
runs it in its own Proton prefix and opens the launcher.
2026-12-03 14:21:47 -05:00
29 changed files with 457 additions and 193 deletions

No files matched your search

@@ -80,6 +80,7 @@ class App : Application() {
com.droiddeck.launcher.stores.StoresState.register(com.droiddeck.launcher.stores.xbox.XboxBackend)
com.droiddeck.launcher.sync.Syncthing.init(this)
com.droiddeck.launcher.stores.StoresState.register(com.droiddeck.launcher.stores.battlenet.BattleNetBackend)
com.droiddeck.launcher.stores.StoresState.register(com.droiddeck.launcher.stores.nexon.NexonBackend)
com.droiddeck.launcher.stores.StoresState.register(com.droiddeck.launcher.stores.ubisoft.UbisoftBackend)
com.droiddeck.launcher.stores.ea.EaBackend.app = this
com.droiddeck.launcher.stores.StoresState.register(com.droiddeck.launcher.stores.ea.EaBackend)
@@ -167,7 +167,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
private var pkgPercent by PackageOperation.percent
private var desktopInstalled by mutableStateOf(false)
private var desktopPresent by mutableStateOf(false)
private var battleNetInstalled by mutableStateOf(false)
private var clientsInstalled by mutableStateOf(emptySet<com.droiddeck.launcher.stores.Store>())
private var offlineAccount by mutableStateOf<String?>(null)
private var offline by mutableStateOf(false)
private var offlineAuto by mutableStateOf(true)
@@ -1470,7 +1470,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
packageStage = pkgStage,
packagePercent = pkgPercent,
sessionRunning = SessionState.running,
battleNetInstalled = battleNetInstalled,
clientsInstalled = clientsInstalled,
backActionsInverted = backActionsInverted,
buildLabel = BuildConfig.BUILD_LABEL,
oscMode = oscMode,
@@ -1600,7 +1600,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
.putExtra(SessionService.EXTRA_PROGRAM, app.program)
.putExtra(SessionService.EXTRA_PROGRAM_ARGS, app.args.toTypedArray()))
},
onBattleNet = { openBattleNet() },
onClient = { openClient(it) },
onFlatpakApp = { id, name ->
Library.flatpakNames[id] = name
startActivity(Intent(this, SessionActivity::class.java)
@@ -2088,6 +2088,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
// A restarted launcher starts before the old one stops, so each clears the hooks only if they are still its own.
private val libraryHook: () -> Unit = { refreshAddedGames(); refresh() }
private val battleNetHook: (List<String>) -> Unit = { args -> openBattleNet(args) }
private val nexonHook: (List<String>) -> Unit = { openNexon() }
private fun startSteamAtStartupIfEnabled(cold: Boolean = false) {
if (soundtrackLaunch || intent.getBooleanExtra(EXTRA_RESTARTED, false)) return
@@ -2376,7 +2377,8 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
refreshWifiDiscovery()
com.droiddeck.launcher.stores.StoresState.refresh(this)
com.droiddeck.launcher.stores.StoresState.libraryListener = libraryHook
com.droiddeck.launcher.stores.battlenet.BattleNetClient.opener = battleNetHook
com.droiddeck.launcher.runtime.BattleNet.CLIENT.opener = battleNetHook
com.droiddeck.launcher.runtime.Nexon.CLIENT.opener = nexonHook
com.droiddeck.launcher.ui.Motion.refresh(this)
com.droiddeck.launcher.ui.QuitFlood.take()?.let { c ->
returning = ReturningFlood(c, com.droiddeck.launcher.ui.LaunchOrigin.takeReturn())
@@ -2520,7 +2522,8 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
HomeWidgets.stopListening(this)
ui.removeCallbacks(mediaRefresh)
if (com.droiddeck.launcher.stores.StoresState.libraryListener === libraryHook) com.droiddeck.launcher.stores.StoresState.libraryListener = null
if (com.droiddeck.launcher.stores.battlenet.BattleNetClient.opener === battleNetHook) com.droiddeck.launcher.stores.battlenet.BattleNetClient.opener = null
if (com.droiddeck.launcher.runtime.BattleNet.CLIENT.opener === battleNetHook) com.droiddeck.launcher.runtime.BattleNet.CLIENT.opener = null
if (com.droiddeck.launcher.runtime.Nexon.CLIENT.opener === nexonHook) com.droiddeck.launcher.runtime.Nexon.CLIENT.opener = null
displayManager.unregisterDisplayListener(secondScreenDisplayListener)
com.droiddeck.launcher.input.DualScreen.unwatchTaken(bottomScreenListener)
getSystemService(android.hardware.input.InputManager::class.java)?.unregisterInputDeviceListener(secondScreenTouchListener)
@@ -2793,6 +2796,20 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
desktopPresent = DesktopCatalog.desktopPresent(this)
}
private fun openClient(store: com.droiddeck.launcher.stores.Store) {
if (store == com.droiddeck.launcher.stores.Store.NEXON) openNexon() else openBattleNet()
}
private fun openNexon() {
val app = applicationContext
val ticket = beginUiLaunch()
Thread({
val entry = com.droiddeck.launcher.runtime.Nexon.entry(app)
if (entry == null) com.droiddeck.launcher.stores.SetupDownload.openOrFetch(app, com.droiddeck.launcher.runtime.Nexon.CLIENT)
else ui.post { if (!isDestroyed && launchCoordinator.isCurrent(ticket)) launchWithoutSteam(entry, false, ticket = ticket) }
}, "nexon-open").start()
}
private fun openBattleNet(args: List<String> = emptyList()) {
if (pkgStage != null) {
android.widget.Toast.makeText(this, R.string.main_wait_install_game, android.widget.Toast.LENGTH_SHORT).show()
@@ -3483,7 +3500,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
addedGamesArt = SessionPrefs.addedGamesArt(this)
desktopInstalled = DesktopCatalog.desktopInstalled(this)
desktopPresent = DesktopCatalog.desktopPresent(this)
battleNetInstalled = com.droiddeck.launcher.runtime.BattleNet.installed(this)
clientsInstalled = com.droiddeck.launcher.runtime.WindowsClient.all.filter { it.installed(this) }.mapTo(mutableSetOf()) { it.store }
offlineAccount = OfflineMode.account(this)
offline = OfflineMode.enabled(this)
offlineAuto = OfflineMode.auto(this)
@@ -11,7 +11,7 @@ object GameRemoval {
enum class Kind { STORE, SHORTCUT, LAUNCHER }
fun kind(game: Library.SteamGame): Kind = when {
game.library == Library.EPIC_LAUNCHER || game.library == Library.BATTLENET_LAUNCHER -> Kind.LAUNCHER
game.library == Library.EPIC_LAUNCHER || com.droiddeck.launcher.runtime.WindowsClient.byLibrary(game.library) != null -> Kind.LAUNCHER
game.library == Library.ADDED && game.source == Library.ADDED -> Kind.SHORTCUT
else -> Kind.STORE
}
@@ -37,6 +37,7 @@ object Library {
const val EPIC_LAUNCHER = "epic-launcher"
const val EPIC_LAUNCHER_NAME = "Epic Games Launcher"
const val BATTLENET_LAUNCHER = "battlenet-launcher"
const val NEXON_LAUNCHER = "nexon-launcher"
const val XBOX_CLOUD = "xbox-cloud"
const val SOURCE_STEAM = "steam"
const val SOURCE_COLLECTION = "collection"
@@ -128,36 +128,20 @@ object BattleNet {
return Art(first("p.jpg", BLIZZARD_COVER, OLD_BLIZZARD_COVER), first(BLIZZARD, OLD_BLIZZARD, "header.jpg"))
}
fun prefix(context: Context) = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/steamapps/compatdata/$APP_ID")
val CLIENT = WindowsClient(
com.droiddeck.launcher.stores.Store.BATTLENET, APP_ID,
"https://downloader.battle.net/download/getInstallerForGame?os=win&gameProgram=BATTLENET_APP&version=Live",
"root/.cache/droiddeck/battlenet/Battle.net-Setup.exe",
"Program Files (x86)/Battle.net/Battle.net Launcher.exe",
"Program Files (x86)/Battle.net/Battle.net.exe",
com.droiddeck.launcher.frontend.Library.BATTLENET_LAUNCHER, com.droiddeck.launcher.R.string.bnet_name,
)
fun prefix(context: Context) = CLIENT.prefix(context)
fun client(context: Context) = File(prefix(context), "pfx/drive_c/Program Files (x86)/Battle.net/Battle.net.exe")
fun installed(context: Context) = File(prefix(context), "pfx/drive_c/Program Files (x86)/Battle.net/Battle.net Launcher.exe").isFile
fun profile(context: Context): Pair<String, String>? =
(APP_ID.toString() to context.getString(com.droiddeck.launcher.R.string.bnet_name)).takeIf { installed(context) }
fun icon(context: Context): File? {
val out = File(context.filesDir, "battlenet-art/launcher/icon.png")
if (out.isFile) return out
val exe = client(context).takeIf { it.isFile } ?: return null
val bitmap = runCatching { com.droiddeck.launcher.files.PeIconExtractor.extract(exe) }.getOrNull() ?: return null
return runCatching {
out.parentFile?.mkdirs()
val tmp = File(out.path + ".tmp")
tmp.outputStream().use { check(bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100, it)) }
check(tmp.renameTo(out))
out
}.getOrNull()
}
fun launcherEntry(installed: Boolean, art: File? = null): com.droiddeck.launcher.frontend.Library.SteamGame? =
if (!installed) null
else com.droiddeck.launcher.frontend.Library.SteamGame(
appId = APP_ID.toInt(), name = com.droiddeck.launcher.stores.Store.BATTLENET.label, art = art,
library = com.droiddeck.launcher.frontend.Library.BATTLENET_LAUNCHER, gameId = APP_ID,
source = com.droiddeck.launcher.stores.Store.BATTLENET.id,
)
fun installed(context: Context) = CLIENT.installed(context)
internal fun title(uid: String): Title? {
val id = uid.lowercase()
@@ -0,0 +1,39 @@
package com.droiddeck.launcher.runtime
import android.content.Context
import com.droiddeck.launcher.frontend.Library
import com.droiddeck.launcher.session.NoSteamLaunch
import com.droiddeck.launcher.stores.Store
object Nexon {
const val APP_ID = 2201491781L
internal const val SETUP = "setup"
val CLIENT = WindowsClient(
Store.NEXON, APP_ID,
"https://download.nxfs.nexon.com/download-launcher?file=NexonLauncherSetup.exe",
"root/.cache/droiddeck/nexon/NexonLauncherSetup.exe",
"Program Files (x86)/Nexon/Nexon Launcher/nexon_launcher.exe",
"Program Files (x86)/Nexon/Nexon Launcher/nexon_launcher.exe",
Library.NEXON_LAUNCHER, com.droiddeck.launcher.R.string.nexon_name,
)
fun entry(context: Context): Library.SteamGame? = when {
CLIENT.installed(context) -> CLIENT.launcherEntry(true)
WindowsClient.setupReady(CLIENT.setup(context)) -> Library.SteamGame(
appId = APP_ID.toInt(), name = Store.NEXON.label, art = null, library = Library.NEXON_LAUNCHER,
gameId = APP_ID, source = Store.NEXON.id, storeId = SETUP,
)
else -> null
}
fun command(game: Library.SteamGame): NoSteamLaunch.Command {
val exe = if (game.storeId == SETUP) CLIENT.guestSetup else CLIENT.guestLauncher
return NoSteamLaunch.Command(
NoSteamLaunch.PROTON_RUN,
listOf("--app", APP_ID.toString(), "--dir", exe.substringBeforeLast('/'), "--", exe),
game.name,
)
}
}
@@ -0,0 +1,79 @@
package com.droiddeck.launcher.runtime
import android.content.Context
import com.droiddeck.launcher.frontend.Library
import com.droiddeck.launcher.stores.Store
import java.io.File
class WindowsClient(
val store: Store,
val appId: Long,
val installerUrl: String,
private val setupPath: String,
private val launcherPath: String,
private val iconPath: String,
val library: String,
val nameRes: Int,
) {
val downloadId: String get() = "${store.id}-client"
val downloadKey: String get() = "${store.id}:$downloadId"
@Volatile var opener: ((List<String>) -> Unit)? = null
fun prefix(context: Context) = File(LinuxRuntime.rootDir(context), "$COMPATDATA/$appId")
fun launcher(context: Context) = File(prefix(context), "pfx/drive_c/$launcherPath")
fun installed(context: Context) = launcher(context).isFile
fun setup(context: Context) = File(LinuxRuntime.rootDir(context), setupPath)
private val guestPrefix: String get() = "/$COMPATDATA/$appId"
val guestLauncher: String get() = "$guestPrefix/pfx/drive_c/$launcherPath"
val guestSetup: String get() = "/$setupPath"
fun profile(context: Context): Pair<String, String>? =
(appId.toString() to context.getString(nameRes)).takeIf { installed(context) }
fun launcherEntry(installed: Boolean): Library.SteamGame? =
if (!installed) null
else Library.SteamGame(appId = appId.toInt(), name = store.label, art = null, library = library, gameId = appId, source = store.id)
fun icon(context: Context): File? {
val out = File(context.filesDir, "${store.id}-art/launcher/icon.png")
if (out.isFile) return out
val exe = File(prefix(context), "pfx/drive_c/$iconPath").takeIf { it.isFile } ?: return null
val bitmap = runCatching { com.droiddeck.launcher.files.PeIconExtractor.extract(exe) }.getOrNull() ?: return null
return runCatching {
out.parentFile?.mkdirs()
val tmp = File(out.path + ".tmp")
tmp.outputStream().use { check(bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100, it)) }
check(tmp.renameTo(out))
out
}.getOrNull()
}
fun open(args: List<String> = emptyList()) {
com.droiddeck.launcher.stores.StoresState.post { opener?.invoke(args) }
}
companion object {
private const val COMPATDATA = "root/.local/share/Steam/steamapps/compatdata"
internal const val MIN_SETUP = 1L shl 20
val all: List<WindowsClient> get() = listOf(BattleNet.CLIENT, Nexon.CLIENT)
fun byLibrary(library: String): WindowsClient? = all.firstOrNull { it.library == library }
fun byStore(store: Store?): WindowsClient? = all.firstOrNull { it.store == store }
fun setupReady(file: File): Boolean = runCatching {
file.length() >= MIN_SETUP && file.inputStream().use { input ->
val head = ByteArray(2)
input.read(head) == 2 && head[0] == 'M'.code.toByte() && head[1] == 'Z'.code.toByte()
}
}.getOrDefault(false)
}
}
@@ -15,7 +15,7 @@ object NoSteamLaunch {
fun scope(game: Library.SteamGame): String? = when {
game.library == Library.EPIC_LAUNCHER -> EpicClient.shortcutAppId.toString()
game.library == Library.BATTLENET_LAUNCHER -> com.droiddeck.launcher.runtime.BattleNet.APP_ID.toString()
com.droiddeck.launcher.runtime.WindowsClient.byLibrary(game.library) != null -> com.droiddeck.launcher.runtime.WindowsClient.byLibrary(game.library)?.appId?.toString()
game.library == Library.ADDED || game.appId > 0 -> game.profileKey
else -> null
}?.takeIf { it.isNotEmpty() && GameEnvironment.validScope(it) }
@@ -56,6 +56,7 @@ object NoSteamLaunch {
fun command(game: Library.SteamGame, added: AddedGames.Game?): Command? = when {
game.library == Library.EPIC_LAUNCHER -> Command(EPIC, listOf("run"), game.name)
game.library == Library.NEXON_LAUNCHER -> com.droiddeck.launcher.runtime.Nexon.command(game)
viaBattleNet(game) ->
game.storeId?.let(com.droiddeck.launcher.runtime.BattleNet::title)?.let { Command(BATTLENET, listOf("launch", it.code), game.name) }
game.library == Library.ADDED -> added?.let { a -> a.steamAppId?.let { Command(PROTON_RUN, listOf("--app", it.toString()), a.name) } ?: addedCommand(a) }
@@ -291,6 +291,7 @@ object StorageScan {
folders.forEach { (id, path) -> if (id !in live && path !in removedFolders && File(path).exists()) live[id] = File(path).name }
val launchers = mapOf(
com.droiddeck.launcher.runtime.BattleNet.APP_ID to com.droiddeck.launcher.stores.Store.BATTLENET.label,
com.droiddeck.launcher.runtime.Nexon.APP_ID to com.droiddeck.launcher.stores.Store.NEXON.label,
com.droiddeck.launcher.stores.ubisoft.UbisoftConnect.APP_ID to com.droiddeck.launcher.stores.Store.UBISOFT.label,
com.droiddeck.launcher.stores.epic.EpicClient.shortcutAppId to Library.EPIC_LAUNCHER_NAME,
)
@@ -113,7 +113,7 @@ object CloudSaves {
}
Store.UBISOFT -> UBISOFT_TEMPLATE
Store.EA -> eaRules(context, id) ?: return null
Store.AMAZON, Store.ITCH, Store.GAMEJOLT, Store.XBOX, Store.BATTLENET, Store.ROCKSTAR, Store.STEAM -> ""
Store.AMAZON, Store.ITCH, Store.GAMEJOLT, Store.XBOX, Store.BATTLENET, Store.NEXON, Store.ROCKSTAR, Store.STEAM -> ""
} ?: return null
p.edit()
.putString("cloud_template_$id", fetched.ifEmpty { TEMPLATE_NONE })
@@ -181,7 +181,7 @@ object CloudSaves {
Store.EPIC -> CloudSavePaths.epic(template, pfx, folder, EpicCredentialStore.load(context)?.accountId.orEmpty(), id)
Store.EA -> if (sidecar.extra["masterTitleId"].isNullOrEmpty()) null
else EaSaveRules.parse(template)?.base()?.let(EaSaveRules::template)?.let { CloudSavePaths.gog(it, pfx, folder) }
Store.AMAZON, Store.ITCH, Store.GAMEJOLT, Store.XBOX, Store.BATTLENET, Store.UBISOFT, Store.ROCKSTAR, Store.STEAM -> null
Store.AMAZON, Store.ITCH, Store.GAMEJOLT, Store.XBOX, Store.BATTLENET, Store.NEXON, Store.UBISOFT, Store.ROCKSTAR, Store.STEAM -> null
}
return dir to (if (dir == null) "unresolved" else "ok")
}
@@ -221,7 +221,7 @@ object CloudSaves {
if (rules == null || base == null || token == null || uid.isEmpty() || master.isEmpty()) null
else EaCloud(token, uid, EaCloud.keys(master, sidecar?.extra?.get("multiplayerId").orEmpty()), base, rules, saveFolder(context, store, id).first)
}
Store.AMAZON, Store.ITCH, Store.GAMEJOLT, Store.XBOX, Store.BATTLENET, Store.ROCKSTAR, Store.STEAM -> null
Store.AMAZON, Store.ITCH, Store.GAMEJOLT, Store.XBOX, Store.BATTLENET, Store.NEXON, Store.ROCKSTAR, Store.STEAM -> null
}
private fun signedIn(context: Context, store: Store): Boolean = when (store) {
@@ -16,7 +16,7 @@ internal object LoginFlows {
Store.UBISOFT -> ubisoftFlow(browserUserAgent)
Store.EA -> eaFlow(browserUserAgent)
Store.ROCKSTAR -> rockstarFlow(browserUserAgent)
Store.ITCH, Store.XBOX, Store.BATTLENET, Store.STEAM -> null
Store.ITCH, Store.XBOX, Store.BATTLENET, Store.NEXON, Store.STEAM -> null
}
@Volatile var epicFlow: () -> StoreLoginActivity.Flow? = { null }
@@ -0,0 +1,111 @@
package com.droiddeck.launcher.stores
import android.content.Context
import android.util.Log
import com.droiddeck.launcher.R
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.droiddeck.launcher.runtime.WindowsClient
import com.droiddeck.launcher.stores.download.DownloadEntry
import com.droiddeck.launcher.stores.download.DownloadQueue
import com.droiddeck.launcher.stores.download.DownloadStage
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.net.HttpURLConnection
import java.net.URL
import java.util.concurrent.atomic.AtomicBoolean
internal class SetupDownload(private val app: Context, private val client: WindowsClient) : DownloadQueue.DownloadJob {
private val cancelled = AtomicBoolean(false)
@Volatile private var connection: HttpURLConnection? = null
override fun run(handle: DownloadQueue.JobHandle): String? {
handle.stage(DownloadStage.DOWNLOAD)
if (!LinuxRuntime.isInstalled(app)) throw IllegalStateException(app.getString(R.string.epic_client_no_runtime))
val file = client.setup(app)
val partial = File(file.path + ".part")
file.parentFile?.mkdirs()
var attempt = 0
while (!cancelled.get()) {
try {
fetch(partial, handle)
if (cancelled.get()) break
if (!WindowsClient.setupReady(partial)) throw IOException("not a Windows program")
if (!partial.renameTo(file)) throw IOException("could not keep the installer")
Log.i(TAG, "${client.store.label}'s installer downloaded")
client.open()
StoresState.post { StoresState.notifyLibraryChanged(app) }
return file.absolutePath
} catch (e: IOException) {
partial.delete()
if (cancelled.get()) break
attempt++
handle.log("${client.store.label} installer attempt $attempt: ${e.message ?: e.javaClass.simpleName}")
if (attempt >= ATTEMPTS) throw IllegalStateException(app.getString(R.string.epic_client_download_failed, e.message ?: e.javaClass.simpleName))
val until = System.currentTimeMillis() + (2_000L shl (attempt - 1))
while (System.currentTimeMillis() < until && !cancelled.get()) Thread.sleep(100)
}
}
partial.delete()
return null
}
private fun fetch(partial: File, handle: DownloadQueue.JobHandle) {
val conn = (URL(client.installerUrl).openConnection() as HttpURLConnection).apply {
connectTimeout = 20_000
readTimeout = 30_000
instanceFollowRedirects = true
setRequestProperty("User-Agent", "DroidDeck")
}
connection = conn
try {
if (conn.responseCode != 200) throw IOException("HTTP ${conn.responseCode}")
if (conn.url.protocol != "https") throw IOException("not served over HTTPS")
val total = conn.contentLengthLong
var done = 0L
conn.inputStream.use { input ->
FileOutputStream(partial).use { out ->
val buf = ByteArray(64 * 1024)
while (!cancelled.get()) {
val n = input.read(buf)
if (n < 0) break
out.write(buf, 0, n)
done += n
handle.progress(done, total)
}
out.fd.sync()
}
}
if (!cancelled.get() && total > 0 && done != total) throw IOException("the download ended early")
} finally {
connection = null
runCatching { conn.disconnect() }
}
}
override fun cancel(deleteFiles: Boolean) {
cancelled.set(true)
runCatching { connection?.disconnect() }
}
companion object {
private const val TAG = "SetupDownload"
private const val ATTEMPTS = 4
fun openOrFetch(app: Context, client: WindowsClient) {
if (client.installed(app) || WindowsClient.setupReady(client.setup(app))) {
client.open()
return
}
StoresState.post {
if (DownloadQueue.isActive(client.downloadKey)) return@post
val entry = DownloadEntry(
client.store, client.downloadId, app.getString(client.nameRes),
location = StoreInstallRoot.labelFor(app, client.setup(app)),
)
DownloadQueue.enqueue(app, entry) { SetupDownload(app, client) }
StoresState.openDownloads = true
}
}
}
}
@@ -11,6 +11,7 @@ enum class Store(val id: String, val label: String, val shortLabel: String) {
AMAZON("amazon", "Amazon Games", "Amazon"),
BATTLENET("battlenet", "Battle.net", "Battle.net"),
GAMEJOLT("gamejolt", "Game Jolt", "Game Jolt"),
NEXON("nexon", "Nexon", "Nexon"),
STEAM("steamstore", "Steam", "Steam");
val folder: String get() = if (this == ITCH) "itch" else shortLabel
@@ -90,7 +90,7 @@ object StoreAccounts {
fun signedInAs(context: Context, store: Store): String? {
val json = read(context, store) ?: return if (isUnavailable(store)) store.label else null
if (store == Store.XBOX) return json.optString("username").takeIf { it.isNotBlank() }
if (store == Store.BATTLENET || store == Store.STEAM) return json.optString("display_name").takeIf { it.isNotBlank() }
if (store == Store.BATTLENET || store == Store.NEXON || store == Store.STEAM) return json.optString("display_name").takeIf { it.isNotBlank() }
if (json.optString("access_token", "").isEmpty()) return null
return json.optString("display_name", "").ifEmpty { json.optString("username", "") }.ifEmpty { store.label }
}
@@ -267,7 +267,7 @@ object StoreInstallRoot {
fun isFinished(folder: File): Boolean = StoreGameSidecar.read(folder)?.isInstalled == true
fun unfinished(context: Context): List<Unfinished> = roots(context).flatMap { root ->
Store.entries.filter { it != Store.BATTLENET && it != Store.STEAM }.flatMap { store ->
Store.entries.filter { it != Store.BATTLENET && it != Store.NEXON && it != Store.STEAM }.flatMap { store ->
storeDir(root, store).listFiles { f -> f.isDirectory }.orEmpty().mapNotNull { folder ->
val sidecar = StoreGameSidecar.read(folder)
when {
@@ -27,7 +27,7 @@ object StoreSizes {
fun size(item: CatalogItem): Long = known[item.key] ?: item.sizeBytes
private val NO_REMOTE_SIZE = setOf(Store.GOG, Store.XBOX, Store.BATTLENET, Store.UBISOFT, Store.ROCKSTAR)
private val NO_REMOTE_SIZE = setOf(Store.GOG, Store.XBOX, Store.BATTLENET, Store.NEXON, Store.UBISOFT, Store.ROCKSTAR)
private val settled = mutableStateMapOf<String, Boolean>()
// A size that can still arrive this session: not known yet, the store can report one, and no lookup came back empty.
@@ -63,7 +63,7 @@ object StoreSizes {
Store.AMAZON -> AmazonPrefs.get(app).edit().putLong("size_${item.id}", it).apply()
Store.ITCH, Store.GAMEJOLT -> {}
Store.EA -> com.droiddeck.launcher.stores.ea.EaPrefs.get(app).edit().putLong("size_${item.id}", it).apply()
Store.GOG, Store.XBOX, Store.BATTLENET, Store.UBISOFT, Store.ROCKSTAR, Store.STEAM -> {}
Store.GOG, Store.XBOX, Store.BATTLENET, Store.NEXON, Store.UBISOFT, Store.ROCKSTAR, Store.STEAM -> {}
}
}
}, pool).exceptionally { error ->
@@ -139,7 +139,7 @@ object StoreSizes {
AmazonManifest.parse(bytes).totalInstallSize
}
Store.EA -> com.droiddeck.launcher.stores.ea.EaSizes.size(context, item)
Store.GOG, Store.XBOX, Store.BATTLENET, Store.UBISOFT, Store.ROCKSTAR -> 0L
Store.GOG, Store.XBOX, Store.BATTLENET, Store.NEXON, Store.UBISOFT, Store.ROCKSTAR -> 0L
Store.ITCH -> com.droiddeck.launcher.stores.itch.ItchLibrary.size(context, item)
Store.GAMEJOLT -> com.droiddeck.launcher.stores.gamejolt.GameJoltBuilds.size(context, item)
Store.STEAM -> com.droiddeck.launcher.stores.steam.SteamStore.plannedBytes(context, item)
@@ -3,10 +3,8 @@ package com.droiddeck.launcher.stores.battlenet
import android.content.Context
import android.net.Uri
import android.util.Log
import com.droiddeck.launcher.R
import com.droiddeck.launcher.frontend.AddedGames
import com.droiddeck.launcher.runtime.BattleNet
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.droiddeck.launcher.session.GameStorage
import com.droiddeck.launcher.stores.CatalogItem
import com.droiddeck.launcher.stores.InstalledStoreGame
@@ -15,45 +13,22 @@ import com.droiddeck.launcher.stores.StoreAccounts
import com.droiddeck.launcher.stores.StoreBackend
import com.droiddeck.launcher.stores.StoreGameSidecar
import com.droiddeck.launcher.stores.StoreInstallRoot
import com.droiddeck.launcher.stores.SetupDownload
import com.droiddeck.launcher.stores.StoreShelves
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.io.FileOutputStream
import java.io.IOException
import java.net.HttpURLConnection
import java.net.URL
import java.util.concurrent.Executors
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicLong
object BattleNetClient {
private const val TAG = "BattleNetClient"
const val DOWNLOAD_ID = "battlenet-client"
const val DOWNLOAD_KEY = "battlenet:$DOWNLOAD_ID"
const val REQUEST = "battlenet-request"
internal const val INSTALLER_URL = "https://downloader.battle.net/download/getInstallerForGame?os=win&gameProgram=BATTLENET_APP&version=Live"
private const val SETUP = "root/.cache/droiddeck/battlenet/Battle.net-Setup.exe"
private const val CONFIG = "pfx/drive_c/users/steamuser/AppData/Roaming/Battle.net/Battle.net.config"
internal const val MIN_SETUP = 1L shl 20
private val work = Executors.newSingleThreadExecutor { r -> Thread(r, "battlenet-client") }
private val sequence = AtomicLong()
@Volatile var opener: ((List<String>) -> Unit)? = null
fun setup(context: Context): File = File(LinuxRuntime.rootDir(context), SETUP)
internal fun setupReady(file: File): Boolean = runCatching {
file.length() >= MIN_SETUP && file.inputStream().use { input ->
val head = ByteArray(2)
input.read(head) == 2 && head[0] == 'M'.code.toByte() && head[1] == 'Z'.code.toByte()
}
}.getOrDefault(false)
internal fun account(config: String?): String? {
val client = runCatching { JSONObject(config ?: return null).optJSONObject("Client") }.getOrNull() ?: return null
if (client.optString("AutoLogin") != "true") return null
@@ -85,19 +60,7 @@ object BattleNetClient {
fun signIn(context: Context) {
val app = context.applicationContext
work.execute {
if (BattleNet.installed(app) || setupReady(setup(app))) {
open(emptyList())
return@execute
}
StoresState.post {
if (DownloadQueue.isActive(DOWNLOAD_KEY)) return@post
val entry = DownloadEntry(
Store.BATTLENET, DOWNLOAD_ID, app.getString(R.string.bnet_name),
location = StoreInstallRoot.labelFor(app, setup(app)),
)
DownloadQueue.enqueue(app, entry) { SetupDownload(app) }
StoresState.openDownloads = true
}
SetupDownload.openOrFetch(app, BattleNet.CLIENT)
}
}
@@ -127,9 +90,7 @@ object BattleNetClient {
sessionRoot.listFiles { file -> file.name == REQUEST || file.name.startsWith("$REQUEST.") }?.forEach { it.delete() }
}
fun open(args: List<String>) {
StoresState.post { opener?.invoke(args) }
}
fun open(args: List<String>) = BattleNet.CLIENT.open(args)
fun library(context: Context, root: File? = preferred(context)): List<String> =
root?.let { AddedGames.guestPath(context, StoreInstallRoot.storeDir(it, Store.BATTLENET)) }?.let { listOf("--library", it) }.orEmpty()
@@ -144,12 +105,6 @@ object BattleNetClient {
val app = context.applicationContext
work.execute { open(library(app, root) + listOf("install-game", uid)) }
}
internal fun downloaded(context: Context) {
Log.i(TAG, "Battle.net's installer downloaded from Blizzard")
open(emptyList())
StoresState.post { StoresState.notifyLibraryChanged(context) }
}
}
object BattleNetBackend : StoreBackend {
@@ -225,79 +180,3 @@ object BattleNetBackend : StoreBackend {
)
}
}
internal class SetupDownload(private val app: Context) : DownloadQueue.DownloadJob {
private val cancelled = AtomicBoolean(false)
@Volatile private var connection: HttpURLConnection? = null
override fun run(handle: DownloadQueue.JobHandle): String? {
handle.stage(DownloadStage.DOWNLOAD)
if (!LinuxRuntime.isInstalled(app)) throw IllegalStateException(app.getString(R.string.epic_client_no_runtime))
val file = BattleNetClient.setup(app)
val partial = File(file.path + ".part")
file.parentFile?.mkdirs()
var attempt = 0
while (!cancelled.get()) {
try {
fetch(partial, handle)
if (cancelled.get()) break
if (!BattleNetClient.setupReady(partial)) throw IOException("not a Windows program")
if (!partial.renameTo(file)) throw IOException("could not keep the installer")
BattleNetClient.downloaded(app)
return file.absolutePath
} catch (e: IOException) {
partial.delete()
if (cancelled.get()) break
attempt++
handle.log("Battle.net installer attempt $attempt: ${e.message ?: e.javaClass.simpleName}")
if (attempt >= ATTEMPTS) throw IllegalStateException(app.getString(R.string.epic_client_download_failed, e.message ?: e.javaClass.simpleName))
val until = System.currentTimeMillis() + (2_000L shl (attempt - 1))
while (System.currentTimeMillis() < until && !cancelled.get()) Thread.sleep(100)
}
}
partial.delete()
return null
}
private fun fetch(partial: File, handle: DownloadQueue.JobHandle) {
val conn = (URL(BattleNetClient.INSTALLER_URL).openConnection() as HttpURLConnection).apply {
connectTimeout = 20_000
readTimeout = 30_000
instanceFollowRedirects = true
setRequestProperty("User-Agent", "DroidDeck")
}
connection = conn
try {
if (conn.responseCode != 200) throw IOException("HTTP ${conn.responseCode}")
if (conn.url.protocol != "https") throw IOException("not served over HTTPS")
val total = conn.contentLengthLong
var done = 0L
conn.inputStream.use { input ->
FileOutputStream(partial).use { out ->
val buf = ByteArray(64 * 1024)
while (!cancelled.get()) {
val n = input.read(buf)
if (n < 0) break
out.write(buf, 0, n)
done += n
handle.progress(done, total)
}
out.fd.sync()
}
}
if (!cancelled.get() && total > 0 && done != total) throw IOException("the download ended early")
} finally {
connection = null
runCatching { conn.disconnect() }
}
}
override fun cancel(deleteFiles: Boolean) {
cancelled.set(true)
runCatching { connection?.disconnect() }
}
private companion object {
const val ATTEMPTS = 4
}
}
@@ -0,0 +1,44 @@
package com.droiddeck.launcher.stores.nexon
import android.content.Context
import com.droiddeck.launcher.runtime.Nexon
import com.droiddeck.launcher.stores.CatalogItem
import com.droiddeck.launcher.stores.InstalledStoreGame
import com.droiddeck.launcher.stores.SetupDownload
import com.droiddeck.launcher.stores.Store
import com.droiddeck.launcher.stores.StoreAccounts
import com.droiddeck.launcher.stores.StoreBackend
import com.droiddeck.launcher.stores.StoreShelves
import com.droiddeck.launcher.stores.StoresState
import org.json.JSONObject
import java.io.File
object NexonBackend : StoreBackend {
override val store: Store = Store.NEXON
override fun signIn(context: Context) {
val app = context.applicationContext
Thread({
StoreAccounts.write(app, store, JSONObject().put("display_name", store.label))
StoresState.refresh(app)
SetupDownload.openOrFetch(app, Nexon.CLIENT)
}, "nexon-sign-in").start()
}
override fun signOut(context: Context) {
StoreAccounts.clear(context, store)
StoresState.post { StoresState.shelves.remove(store); StoresState.found.remove(store) }
}
override fun syncLibrary(context: Context, force: Boolean) {
StoresState.post { StoresState.library[store] = emptyList() }
}
override fun loadShelves(context: Context, force: Boolean) {
StoresState.post { StoresState.shelves[store] = StoreShelves() }
}
override fun install(context: Context, item: CatalogItem, root: File) = Nexon.CLIENT.open()
override fun uninstall(context: Context, game: InstalledStoreGame) = Nexon.CLIENT.open()
}
@@ -158,7 +158,7 @@ class FrontEndState(
val packageStage: String? = null,
val packagePercent: Int = -1,
val sessionRunning: Boolean = false,
val battleNetInstalled: Boolean = false,
val clientsInstalled: Set<com.droiddeck.launcher.stores.Store> = emptySet(),
val removalPending: Boolean = false,
val runtimeActionsBlocked: Boolean = false,
val backActionsInverted: Boolean = false,
@@ -231,7 +231,7 @@ class FrontEndActions(
val onEmulator: (Library.Emulator) -> Unit,
val onFlatpakApp: (String, String) -> Unit = { _, _ -> },
val onUserApp: (com.droiddeck.launcher.runtime.UserApps.App) -> Unit = {},
val onBattleNet: () -> Unit = {},
val onClient: (com.droiddeck.launcher.stores.Store) -> Unit = {},
val onRom: (Library.Rom) -> Unit,
val onResume: () -> Unit,
val onSteamSettings: () -> Unit,
@@ -597,7 +597,7 @@ internal fun GameActions(
SecondaryButton(stringResource(R.string.bnet_update)) { BattleNetInstall.update(ctx, installed) }
}
}
SecondaryButton(stringResource(R.string.bnet_open)) { a.onBattleNet() }
SecondaryButton(stringResource(R.string.bnet_open)) { a.onClient(Store.BATTLENET) }
}
if (game != null && !compactMenu) {
HideButton(hideKey(game), game)
@@ -102,7 +102,7 @@ internal fun GameEnvironmentEditor(byPad: Boolean, initialScope: String = "", on
runCatching {
withContext(Dispatchers.IO) {
GameEnvironmentStore.read(context) to Library.steamGames(context).map { it.appId.toString() to it.name } +
listOfNotNull(com.droiddeck.launcher.runtime.BattleNet.profile(context))
com.droiddeck.launcher.runtime.WindowsClient.all.mapNotNull { it.profile(context) }
}
}.onSuccess { (settings, installed) -> config = settings; games = installed }
.onFailure { error = true }
@@ -888,10 +888,11 @@ private fun LibraryHeader(
clearSearchFocus = searchCleared, inlineWhenStacked = true,
lead = soundLead,
) {
if (!soundMode && !s.shortcutPicker && source == Store.BATTLENET.id) {
val client = if (!soundMode && !s.shortcutPicker) com.droiddeck.launcher.runtime.WindowsClient.byStore(Store.byId(source)) else null
if (client != null) {
SecondaryButton(
stringResource(R.string.bnet_open), enabled = !s.busy && DevPreview.library == LibraryPreview.OFF,
compact = true, modifier = Modifier.testTag("library-battlenet-open"), onClick = a.onBattleNet,
clientOpenLabel(client), enabled = !s.busy && DevPreview.library == LibraryPreview.OFF,
compact = true, modifier = Modifier.testTag("library-${client.store.id}-open"), onClick = { a.onClient(client.store) },
)
}
if (soundMode) HeaderIconButton(stringResource(R.string.soundtracks_saved), Icons.Filled.BookmarkBorder, "collections", onClick = onCollections)
@@ -36,6 +36,7 @@ internal fun sourceColours(source: String): SourceColours = when (source) {
Store.ITCH.id -> SourceColours(Color(0xFF3A1A1E), Color(0xFFFFB3B3), Color(0xFFFF5C5C))
Store.GAMEJOLT.id -> SourceColours(Color(0xFF232E00), Color(0xFFE3FF66), Color(0xFFCCFF00))
Store.BATTLENET.id -> SourceColours(Color(0xFF0A2440), Color(0xFF9DD1FF), Color(0xFF148EFF))
Store.NEXON.id -> SourceColours(Color(0xFF06303A), Color(0xFF9BE7F2), Color(0xFF00B4C8))
Store.UBISOFT.id -> SourceColours(Color(0xFF0B1E44), Color(0xFFA8C6FF), Color(0xFF2E7DFF))
Store.EA.id -> SourceColours(Color(0xFF3A0E12), Color(0xFFFF9A9A), Color(0xFFFF4747))
Store.ROCKSTAR.id -> SourceColours(Color(0xFF3A2A06), Color(0xFFFFD780), Color(0xFFFCAF17))
@@ -56,6 +57,7 @@ internal fun sourceLabel(source: String): String = when (source) {
Store.ITCH.id -> Store.ITCH.label
Store.GAMEJOLT.id -> Store.GAMEJOLT.label
Store.BATTLENET.id -> Store.BATTLENET.label
Store.NEXON.id -> Store.NEXON.label
Store.UBISOFT.id -> Store.UBISOFT.shortLabel
Store.EA.id -> Store.EA.label
Store.ROCKSTAR.id -> Store.ROCKSTAR.shortLabel
@@ -223,7 +223,7 @@ private fun FinishedRow(d: DownloadEntry, s: FrontEndState, a: FrontEndActions,
ArtStrip(d.cover, d.name) {
StripLabel(d.name, d.store.id, stringResource(if (d.state == DownloadState.INSTALLED) R.string.stores_installed_chip else R.string.stores_dl_cancelled), Color.White.copy(alpha = 0.72f))
if (d.state == DownloadState.INSTALLED) Box(Modifier.bloomIn(bloom, GATHER_HOLD_MS + 150)) {
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { if (d.key == EpicClient.DOWNLOAD_KEY) a.onEpicLauncher() else if (d.key == com.droiddeck.launcher.stores.battlenet.BattleNetClient.DOWNLOAD_KEY) a.onBattleNet() else launchStoreGame(d.store, d.id, s, a) }
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { if (d.key == EpicClient.DOWNLOAD_KEY) a.onEpicLauncher() else if (com.droiddeck.launcher.runtime.WindowsClient.all.any { it.downloadKey == d.key }) a.onClient(d.store) else launchStoreGame(d.store, d.id, s, a) }
}
}
}
@@ -381,7 +381,7 @@ private fun DownloadCard(d: DownloadEntry, s: FrontEndState, a: FrontEndActions)
CancelAction { DownloadQueue.clear(ctx, d.key) }
}
DownloadState.INSTALLED -> Box(Modifier.bloomIn(true, 420)) {
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { if (d.key == EpicClient.DOWNLOAD_KEY) a.onEpicLauncher() else if (d.key == com.droiddeck.launcher.stores.battlenet.BattleNetClient.DOWNLOAD_KEY) a.onBattleNet() else launchStoreGame(d.store, d.id, s, a) }
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { if (d.key == EpicClient.DOWNLOAD_KEY) a.onEpicLauncher() else if (com.droiddeck.launcher.runtime.WindowsClient.all.any { it.downloadKey == d.key }) a.onClient(d.store) else launchStoreGame(d.store, d.id, s, a) }
}
DownloadState.CANCELLED -> {}
}
@@ -818,7 +818,7 @@ private fun ProfileStrip(store: Store, owned: Int, loaded: Boolean, s: FrontEndS
}
}
if (store == Store.EPIC) EpicLauncherRow(s, a)
if (store == Store.BATTLENET) BattleNetLauncherRow(s, a)
com.droiddeck.launcher.runtime.WindowsClient.byStore(store)?.let { ClientLauncherRow(it, s, a) }
}
}
@@ -845,22 +845,23 @@ private fun OwnedLink(label: String, onClick: () -> Unit) {
}
@Composable
private fun BattleNetLauncherRow(s: FrontEndState, a: FrontEndActions) {
private fun ClientLauncherRow(client: com.droiddeck.launcher.runtime.WindowsClient, s: FrontEndState, a: FrontEndActions) {
val ctx = LocalContext.current
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val title = stringResource(R.string.bnet_name)
val title = stringResource(client.nameRes)
val installed = client.store in s.clientsInstalled
Box(Modifier.fillMaxWidth().height(1.dp).background(pal.line))
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.fillMaxWidth().testTag("stores-battlenet-launcher")) {
val icon by androidx.compose.runtime.produceState<java.io.File?>(null, s.battleNetInstalled) {
value = if (!s.battleNetInstalled) null
else kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { com.droiddeck.launcher.runtime.BattleNet.icon(ctx) }
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.fillMaxWidth().testTag("stores-${client.store.id}-launcher")) {
val icon by androidx.compose.runtime.produceState<java.io.File?>(null, installed) {
value = if (!installed) null
else kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { client.icon(ctx) }
}
if (icon != null) AsyncImage(model = icon, contentDescription = null, contentScale = ContentScale.Fit, modifier = Modifier.size(36.dp).clip(RoundedCornerShape(8.dp)))
Text(title, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
Actions {
SecondaryButton(stringResource(R.string.bnet_open), enabled = !s.busy, compact = true) { a.onBattleNet() }
val entry = remember(s.battleNetInstalled) { com.droiddeck.launcher.runtime.BattleNet.launcherEntry(s.battleNetInstalled) }
SecondaryButton(clientOpenLabel(client), enabled = !s.busy, compact = true) { a.onClient(client.store) }
val entry = remember(installed) { client.launcherEntry(installed) }
val scope = entry?.let { com.droiddeck.launcher.session.NoSteamLaunch.scope(it) }
if (entry != null && scope != null) {
val host = rememberMenuHost()
@@ -876,6 +877,11 @@ private fun BattleNetLauncherRow(s: FrontEndState, a: FrontEndActions) {
}
}
@Composable
internal fun clientOpenLabel(client: com.droiddeck.launcher.runtime.WindowsClient): String =
if (client.store == Store.BATTLENET) stringResource(R.string.bnet_open)
else stringResource(R.string.content_open_named, stringResource(client.nameRes))
@Composable
private fun EpicLauncherRow(s: FrontEndState, a: FrontEndActions) {
val ctx = LocalContext.current
@@ -1043,6 +1049,7 @@ internal fun storePalette(base: Palette, store: Store?): Palette {
Store.ITCH -> Color(0xFFFF5C5C) to Color(0xFFD93B3B)
Store.GAMEJOLT -> Color(0xFFCCFF00) to Color(0xFFA3CC00)
Store.BATTLENET -> Color(0xFF148EFF) to Color(0xFF0B6BD3)
Store.NEXON -> Color(0xFF00B4C8) to Color(0xFF008C9E)
Store.UBISOFT -> Color(0xFF2E7DFF) to Color(0xFF1A5BD6)
Store.EA -> Color(0xFFFF4747) to Color(0xFFE03030)
Store.ROCKSTAR -> Color(0xFFFCAF17) to Color(0xFFD98E00)
+1
View File
@@ -181,6 +181,7 @@
<string name="user_apps_remove_confirm">Press again to remove</string>
<string name="user_apps_stop_session">Stop the session to remove</string>
<string name="bnet_name" translatable="false">Battle.net</string>
<string name="nexon_name" translatable="false">Nexon Launcher</string>
<string name="user_apps_script_linked">Runs %1$s from its folder, linked into the session where it lies. Removing the app leaves that folder alone.</string>
<string name="user_apps_script_copied">Runs %1$s from a copy of its folder inside DroidDeck. Removing the app deletes the copy, not the original.</string>
<string name="user_apps_runtime_required">Install the Linux runtime first</string>
@@ -80,9 +80,9 @@ class BattleNetTest {
}
@Test fun theEnvironmentEditorNamesBattleNetsProfileOnceItIsInstalled() {
assertNull(BattleNet.profile(context))
assertNull(BattleNet.CLIENT.profile(context))
launcher().apply { parentFile!!.mkdirs(); writeText("MZ") }
assertEquals(BattleNet.APP_ID.toString() to "Battle.net", BattleNet.profile(context))
assertEquals(BattleNet.APP_ID.toString() to "Battle.net", BattleNet.CLIENT.profile(context))
}
@Test fun removeTakesThePrefixItsMenuEntryAndCacheButNothingItLinksTo() {
@@ -0,0 +1,95 @@
package com.droiddeck.launcher.runtime
import android.content.Context
import com.droiddeck.launcher.frontend.Library
import com.droiddeck.launcher.session.NoSteamLaunch
import com.droiddeck.launcher.stores.Store
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertSame
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
import java.util.zip.CRC32
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.deleteRecursively
@OptIn(ExperimentalPathApi::class)
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class WindowsClientTest {
private lateinit var context: Context
@Before fun setUp() {
context = RuntimeEnvironment.getApplication()
LinuxRuntime.rootDir(context).toPath().deleteRecursively()
}
@Test fun eachClientHasItsOwnShortcutIdPrefixAndDownload() {
assertEquals(CRC32().apply { update("Nexon Launcher".toByteArray()) }.value or 0x80000000L, Nexon.APP_ID)
val clients = WindowsClient.all
assertEquals(clients.size, clients.map { it.appId }.toSet().size)
assertEquals(clients.size, clients.map { it.prefix(context) }.toSet().size)
assertEquals(clients.size, clients.map { it.downloadKey }.toSet().size)
assertEquals(clients.size, clients.map { it.library }.toSet().size)
assertNotEquals(BattleNet.CLIENT.setup(context), Nexon.CLIENT.setup(context))
}
@Test fun clientsAreFoundByLibraryAndStoreOnly() {
assertSame(Nexon.CLIENT, WindowsClient.byLibrary(Library.NEXON_LAUNCHER))
assertSame(BattleNet.CLIENT, WindowsClient.byLibrary(Library.BATTLENET_LAUNCHER))
assertSame(Nexon.CLIENT, WindowsClient.byStore(Store.NEXON))
assertNull(WindowsClient.byLibrary(Library.ADDED))
assertNull(WindowsClient.byStore(Store.GOG))
assertNull(WindowsClient.byStore(null))
}
@Test fun aSetupIsReadyOnlyWhenItIsAWholeWindowsProgram() {
val file = File(context.cacheDir, "setup.exe")
assertFalse(WindowsClient.setupReady(file))
file.writeBytes(byteArrayOf('M'.code.toByte(), 'Z'.code.toByte()))
assertFalse(WindowsClient.setupReady(file))
file.writeBytes(ByteArray(WindowsClient.MIN_SETUP.toInt()).also { it[0] = 'M'.code.toByte(); it[1] = 'Z'.code.toByte() })
assertTrue(WindowsClient.setupReady(file))
file.writeBytes(ByteArray(WindowsClient.MIN_SETUP.toInt()))
assertFalse(WindowsClient.setupReady(file))
file.delete()
}
@Test fun nexonRunsItsSetupFirstThenItsLauncherInItsOwnPrefix() {
assertNull(Nexon.entry(context))
Nexon.CLIENT.setup(context).apply {
parentFile!!.mkdirs()
writeBytes(ByteArray(WindowsClient.MIN_SETUP.toInt()).also { it[0] = 'M'.code.toByte(); it[1] = 'Z'.code.toByte() })
}
val setup = NoSteamLaunch.command(Nexon.entry(context)!!, null)!!
assertEquals(NoSteamLaunch.PROTON_RUN, setup.program)
assertEquals(
listOf("--app", Nexon.APP_ID.toString(), "--dir", "/root/.cache/droiddeck/nexon", "--", "/root/.cache/droiddeck/nexon/NexonLauncherSetup.exe"),
setup.args,
)
assertFalse(Nexon.CLIENT.installed(context))
Nexon.CLIENT.launcher(context).apply { parentFile!!.mkdirs(); writeText("MZ") }
assertTrue(Nexon.CLIENT.installed(context))
val launcher = Nexon.entry(context)!!
val run = NoSteamLaunch.command(launcher, null)!!
val exe = "/root/.local/share/Steam/steamapps/compatdata/${Nexon.APP_ID}/pfx/drive_c/Program Files (x86)/Nexon/Nexon Launcher/nexon_launcher.exe"
assertEquals(listOf("--app", Nexon.APP_ID.toString(), "--dir", exe.substringBeforeLast('/'), "--", exe), run.args)
assertEquals(Nexon.APP_ID.toString(), NoSteamLaunch.scope(launcher))
assertEquals(Nexon.APP_ID.toString(), NoSteamLaunch.scopeOf(run.program, run.args))
}
@Test fun theEnvironmentEditorNamesEachClientOnceItIsInstalled() {
assertNull(Nexon.CLIENT.profile(context))
Nexon.CLIENT.launcher(context).apply { parentFile!!.mkdirs(); writeText("MZ") }
assertEquals(Nexon.APP_ID.toString() to "Nexon Launcher", Nexon.CLIENT.profile(context))
assertNull(BattleNet.CLIENT.profile(context))
}
}
@@ -197,13 +197,13 @@ class LibraryVisibilityTest {
}
@Test fun battleNetHasAnOpenClientActionEvenWithoutInstalledGames() {
var opened = 0
show(actions(onBattleNet = { opened++ }))
val opened = mutableListOf<Store>()
show(actions(onClient = { opened += it }))
compose.onNodeWithTag("library-battlenet-open").assertDoesNotExist()
compose.onNodeWithTag("library-source-battlenet").performClick()
compose.mainClock.advanceTimeBy(1_000)
compose.onNodeWithTag("library-battlenet-open").assertIsDisplayed().performClick()
assertEquals(1, opened)
assertEquals(listOf(Store.BATTLENET), opened)
compose.onNodeWithTag("library-source-steam").performClick()
compose.mainClock.advanceTimeBy(1_000)
compose.onNodeWithTag("library-battlenet-open").assertDoesNotExist()
@@ -244,8 +244,8 @@ class LibraryVisibilityTest {
emulators = emptyList(), running = null,
)
private fun actions(onBattleNet: () -> Unit = {}) = FrontEndActions(
onBattleNet = onBattleNet,
private fun actions(onClient: (Store) -> Unit = {}) = FrontEndActions(
onClient = onClient,
onPlay = {}, onPlayDesktopUi = {}, onSteamGame = {}, onDesktop = {}, onEmulator = {},
onRom = {}, onResume = {}, onSteamSettings = {}, onDesktopSettings = {},
onInstallPackage = {}, onRemovePackage = {}, onRuntime = {}, onFrameGenPick = {},