mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
feat: DroidDeck-Proton is downloaded, kept up to date and used by default (#1540)
This commit is contained in:
1 parent
2a69505199
commit
3fdc74051c
12 files changed
+389
-16
No files matched your search
@@ -41,6 +41,7 @@ internal class ProtonMenu(
|
||||
ui.post { protonStage = label; protonPercent = value }
|
||||
}
|
||||
}.getOrElse { it.message ?: it.javaClass.simpleName }
|
||||
if (problem == null && !automatic && tool.id == ProtonExtras.OWN) ProtonExtras.setDeclined(activity, false)
|
||||
ui.post {
|
||||
protonBusyId = null
|
||||
protonStage = null
|
||||
@@ -63,6 +64,7 @@ internal class ProtonMenu(
|
||||
protonPercent = -1
|
||||
Thread({
|
||||
if (older) ProtonExtras.removeOlder(activity, tool) else ProtonExtras.remove(activity, tool, dir)
|
||||
if (tool.id == ProtonExtras.OWN && ProtonExtras.installedAll(activity, tool).isEmpty()) ProtonExtras.setDeclined(activity, true)
|
||||
ui.post {
|
||||
protonBusyId = null
|
||||
protonStage = null
|
||||
@@ -94,9 +96,22 @@ internal class ProtonMenu(
|
||||
ProtonExtras.installInProgress || SessionState.running || LinuxRuntimeInstaller.isBusy() ||
|
||||
SessionState.phase !in setOf(SessionPhase.IDLE, SessionPhase.FAILED) ||
|
||||
!LinuxRuntime.isInstalled(activity) || !AutoComponents.online(activity) || AutoComponents.unfavourable(activity)) return
|
||||
if (ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == ProtonExtras.OWN }).size > 1) {
|
||||
protonBusyId = ProtonExtras.OWN
|
||||
Thread({
|
||||
ProtonExtras.tidy(activity)
|
||||
val tidied = ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == ProtonExtras.OWN }).size <= 1
|
||||
ui.post {
|
||||
protonBusyId = null
|
||||
refreshProtons()
|
||||
if (tidied) ensureAutoUpdates()
|
||||
}
|
||||
}, "proton-tidy").start()
|
||||
return
|
||||
}
|
||||
val attempts = activity.getSharedPreferences("proton-auto-updates", android.content.Context.MODE_PRIVATE)
|
||||
val (tool, update) = ProtonExtras.tools.firstNotNullOfOrNull { tool ->
|
||||
val update = ProtonExtras.update(activity, tool) ?: return@firstNotNullOfOrNull null
|
||||
val update = ProtonExtras.update(activity, tool) ?: ProtonExtras.missing(activity, tool) ?: return@firstNotNullOfOrNull null
|
||||
val previous = attempts.getLong("${tool.id}.at", 0L)
|
||||
if (attempts.getString("${tool.id}.tag", null) != update || now - previous !in 0 until 15L * 60 * 1000) tool to update else null
|
||||
} ?: return
|
||||
|
||||
@@ -780,6 +780,43 @@ object ComponentsManager {
|
||||
true
|
||||
}
|
||||
|
||||
fun carryOver(context: Context, fromDir: String, toDir: String) {
|
||||
synchronized(lock) {
|
||||
val target = protons(context).firstOrNull { it.id == safeName(toDir) } ?: return
|
||||
val state = loadState(context)
|
||||
val wanted = carried(state, safeName(fromDir)) { File(packagesDir(context), it).isFile }
|
||||
val active = state.sub("active").optJSONObject(target.id)
|
||||
val queued = state.sub("queued").sub(target.id)
|
||||
var changed = false
|
||||
wanted.forEach { (comp, entry) ->
|
||||
if (active?.has(comp) != true && !queued.has(comp)) {
|
||||
queued.put(comp, entry)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if (queued.length() == 0) state.sub("queued").remove(target.id)
|
||||
if (changed) saveState(context, state)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun carried(state: JSONObject, from: String, present: (String) -> Boolean): Map<String, JSONObject> = buildMap {
|
||||
state.optJSONObject("active")?.optJSONObject(from)?.let { active ->
|
||||
active.keys().forEach { comp ->
|
||||
val entry = active.optJSONObject(comp) ?: return@forEach
|
||||
val file = entry.optString("file")
|
||||
if (comp in COMPONENTS && file.endsWith(".wcp") && present(file)) {
|
||||
put(comp, JSONObject().put("kind", "package").put("file", file).put("label", entry.optString("label")))
|
||||
}
|
||||
}
|
||||
}
|
||||
state.optJSONObject("queued")?.optJSONObject(from)?.let { queued ->
|
||||
queued.keys().forEach { comp ->
|
||||
val entry = queued.optJSONObject(comp) ?: return@forEach
|
||||
if (comp in COMPONENTS && entry.optString("kind") == "package" && present(entry.optString("file"))) put(comp, entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun forgetProton(context: Context, dirName: String) {
|
||||
synchronized(lock) {
|
||||
val id = safeName(dirName)
|
||||
|
||||
@@ -114,12 +114,19 @@ object ProtonDefault {
|
||||
return if (SessionState.running && state.live && (tool == null || state.pending != tool.name)) Outcome.LIVE else Outcome.NEXT_START
|
||||
}
|
||||
|
||||
internal fun movedGames(choices: Map<String, GameChoice?>, from: Set<String>, to: String): Map<String, GameChoice?>? {
|
||||
if (choices.values.none { it != null && !it.valve && it.dir in from }) return null
|
||||
return choices.mapValues { (_, choice) -> if (choice != null && !choice.valve && choice.dir in from) GameChoice(false, to) else choice }
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun requestGame(context: Context, scope: String, proton: ComponentsManager.Proton?): Outcome {
|
||||
require(GameEnvironment.validScope(scope))
|
||||
fun moveGames(context: Context, from: Set<String>, to: String) {
|
||||
val d = dir(context)
|
||||
val choices = parseGames(read(File(d, GAMES))).toMutableMap()
|
||||
choices[scope] = proton?.let { GameChoice(it.valve, it.dir.name) }
|
||||
val moved = movedGames(parseGames(read(File(d, GAMES))), from, to) ?: return
|
||||
writeGames(d, moved)
|
||||
}
|
||||
|
||||
private fun writeGames(d: File, choices: Map<String, GameChoice?>) {
|
||||
val games = JSONObject()
|
||||
choices.forEach { (id, choice) ->
|
||||
games.put(id, choice?.let { JSONObject().put("valve", it.valve).put("dir", it.dir) } ?: JSONObject.NULL)
|
||||
@@ -134,6 +141,15 @@ object ProtonDefault {
|
||||
Log.w(TAG, "could not write the per-game Proton request", e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun requestGame(context: Context, scope: String, proton: ComponentsManager.Proton?): Outcome {
|
||||
require(GameEnvironment.validScope(scope))
|
||||
val d = dir(context)
|
||||
val choices = parseGames(read(File(d, GAMES))).toMutableMap()
|
||||
choices[scope] = proton?.let { GameChoice(it.valve, it.dir.name) }
|
||||
writeGames(d, choices)
|
||||
val state = state(context)
|
||||
val tool = proton?.let { selected -> state.tools.firstOrNull { it.valve == selected.valve && it.dir == selected.dir.name } }
|
||||
return if (SessionState.running && state.live && (proton == null || tool != null && state.pending != tool.name)) {
|
||||
|
||||
@@ -16,16 +16,20 @@ object ProtonExtras {
|
||||
private const val TAG = "ProtonExtras"
|
||||
private const val NEED_BYTES = 4L * 1024 * 1024 * 1024
|
||||
private const val RELEASES = "https://api.github.com/repos/%s/releases?per_page=15"
|
||||
const val CHECK_EVERY_MS = 6L * 60 * 60 * 1000
|
||||
const val CHECK_EVERY_MS = 60L * 60 * 1000
|
||||
@Volatile
|
||||
var installInProgress = false
|
||||
private set
|
||||
@Volatile
|
||||
private var replacing = false
|
||||
|
||||
class Tool(val id: String, val name: String, val prefix: String, val repo: String, val assetPattern: Regex)
|
||||
|
||||
internal data class Asset(val tag: String, val name: String, val url: String, val sha512: String?, val size: Long,
|
||||
val sha256: String? = null)
|
||||
|
||||
const val OWN = "droiddeck"
|
||||
|
||||
val tools = listOf(
|
||||
Tool("ge", "GE-Proton", "GE-Proton", "GloriousEggroll/proton-ge-custom", Regex("aarch64\\.tar\\.(gz|xz)$")),
|
||||
Tool("cachyos", "proton-cachyos", "proton-cachyos", "CachyOS/proton-cachyos", Regex("arm64\\.tar\\.(gz|xz)$")),
|
||||
@@ -78,11 +82,23 @@ object ProtonExtras {
|
||||
|
||||
fun update(context: Context, tool: Tool): String? = updateFor(installedTags(context, tool), cachedLatest(context, tool))
|
||||
|
||||
fun missing(context: Context, tool: Tool): String? =
|
||||
if (tool.id == OWN && !declined(context) && installedAll(context, tool).isEmpty()) cachedLatest(context, tool) else null
|
||||
|
||||
private fun choices(context: Context) = context.getSharedPreferences("proton-auto-updates", Context.MODE_PRIVATE)
|
||||
|
||||
fun declined(context: Context): Boolean = choices(context).getBoolean("$OWN.declined", false)
|
||||
|
||||
fun setDeclined(context: Context, declined: Boolean) {
|
||||
choices(context).edit().putBoolean("$OWN.declined", declined).apply()
|
||||
}
|
||||
|
||||
fun cachedLatest(context: Context, tool: Tool): String? =
|
||||
readJson(latestFile(context)).optJSONObject(tool.id)?.optString("tag")?.ifEmpty { null }
|
||||
|
||||
private val checkLock = Any()
|
||||
private const val RETRY_MS = 15L * 60 * 1000
|
||||
private const val USER_SETTINGS = "user_settings.py"
|
||||
private var lastAttempt = 0L
|
||||
|
||||
fun checkLatest(context: Context, force: Boolean = false, now: Long = System.currentTimeMillis()): Boolean {
|
||||
@@ -145,6 +161,44 @@ object ProtonExtras {
|
||||
}
|
||||
}
|
||||
|
||||
private fun replaceOlder(context: Context, tool: Tool) {
|
||||
val all = installedAll(context, tool)
|
||||
val newest = all.lastOrNull() ?: return
|
||||
val older = all.dropLast(1)
|
||||
if (older.isEmpty()) return
|
||||
replacing = true
|
||||
try {
|
||||
for (old in older.asReversed()) {
|
||||
if (SessionState.running) break
|
||||
if (runCatching { ComponentsManager.carryOver(context, old, newest) }.onFailure { Log.w(TAG, "components of $old", it) }.isFailure) continue
|
||||
if (runCatching { keepUserSettings(context, old, newest) }.onFailure { Log.w(TAG, "user settings of $old", it) }.isFailure) continue
|
||||
if (runCatching { ProtonDefault.moveGames(context, setOf(old), newest) }.onFailure { Log.w(TAG, "per-game picks of $old", it) }.isFailure) continue
|
||||
if (File(toolsDir(context), old).deleteRecursively()) ComponentsManager.forgetProton(context, old)
|
||||
else Log.w(TAG, "could not remove $old")
|
||||
}
|
||||
} finally {
|
||||
replacing = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun keepUserSettings(context: Context, old: String, newest: String) {
|
||||
val from = File(File(toolsDir(context), old), USER_SETTINGS)
|
||||
val to = File(File(toolsDir(context), newest), USER_SETTINGS)
|
||||
if (from.isFile && !to.exists()) from.copyTo(to)
|
||||
}
|
||||
|
||||
fun tidy(context: Context) {
|
||||
val tool = tools.firstOrNull { it.id == OWN } ?: return
|
||||
if (installedAll(context, tool).size > 1) replaceOlder(context, tool)
|
||||
}
|
||||
|
||||
fun awaitReplacement(timeoutMs: Long) {
|
||||
val until = System.currentTimeMillis() + timeoutMs
|
||||
while (replacing && System.currentTimeMillis() < until) {
|
||||
try { Thread.sleep(50) } catch (_: InterruptedException) { Thread.currentThread().interrupt(); return }
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun install(context: Context, tool: Tool, onProgress: (String, Int) -> Unit): String? {
|
||||
if (installInProgress) return context.getString(R.string.pextra_busy)
|
||||
@@ -246,6 +300,7 @@ object ProtonExtras {
|
||||
archive.delete()
|
||||
unqueue(context, tool)
|
||||
record(context, tool, placed, asset.tag)
|
||||
if (tool.id == OWN) replaceOlder(context, tool)
|
||||
if (EsyncPacks.enabled(context)) {
|
||||
onProgress(context.getString(R.string.esync_fetching), -1)
|
||||
try {
|
||||
|
||||
@@ -372,6 +372,7 @@ class SessionService : Service() {
|
||||
acquireLocks()
|
||||
Thread({
|
||||
OrphanReaper.reap("session starting")
|
||||
ProtonExtras.awaitReplacement(120_000)
|
||||
runSession(gen)
|
||||
}, "session-start").start()
|
||||
return START_NOT_STICKY
|
||||
|
||||
@@ -30,7 +30,7 @@ object SteamLiveShortcuts {
|
||||
let added = 0;
|
||||
for (const w of want) {
|
||||
if (await ${KNOWN}(w.appid, w.name, w.exe)) continue;
|
||||
if (await ${ADD}(w.name, w.exe, w.dir, true)) added++;
|
||||
if (await ${ADD}(w.name, w.exe, w.dir, true, ${JSONObject.quote(compatTool(context))})) added++;
|
||||
}
|
||||
return added;
|
||||
})()
|
||||
@@ -46,7 +46,7 @@ object SteamLiveShortcuts {
|
||||
(async () => {
|
||||
const known = await ${KNOWN}(${appId?.and(0xFFFFFFFFL) ?: 0}, ${JSONObject.quote(name)}, ${JSONObject.quote(exe)});
|
||||
if (known) return known;
|
||||
return await ${ADD}(${JSONObject.quote(name)}, ${JSONObject.quote(exe)}, ${JSONObject.quote(dir)}, $compat);
|
||||
return await ${ADD}(${JSONObject.quote(name)}, ${JSONObject.quote(exe)}, ${JSONObject.quote(dir)}, $compat, ${JSONObject.quote(compatTool(context))});
|
||||
})()
|
||||
""".trimIndent()
|
||||
val id = evaluate(context, js)?.toLongOrNull()?.and(0xFFFFFFFFL)?.takeIf { it != 0L } ?: return null
|
||||
@@ -161,12 +161,15 @@ object SteamLiveShortcuts {
|
||||
return 0;
|
||||
})"""
|
||||
|
||||
private val ADD = """(async (name, exe, dir, compat) => {
|
||||
private fun compatTool(context: Context): String =
|
||||
com.droiddeck.launcher.session.ProtonDefault.state(context).default ?: COMPAT_TOOL
|
||||
|
||||
private val ADD = """(async (name, exe, dir, compat, tool) => {
|
||||
const id = await SteamClient.Apps.AddShortcut(name, exe, dir, "");
|
||||
if (!id) return 0;
|
||||
try { SteamClient.Apps.SetShortcutName(id, name); } catch (e) {}
|
||||
try { SteamClient.Apps.AddUserTagToApps([id], ${JSONObject.quote(TAG_NAME)}); } catch (e) {}
|
||||
if (compat) { try { SteamClient.Apps.SpecifyCompatTool(id, ${JSONObject.quote(COMPAT_TOOL)}); } catch (e) {} }
|
||||
if (compat) { try { SteamClient.Apps.SpecifyCompatTool(id, tool); } catch (e) {} }
|
||||
for (let i = 0; i < 40; i++) {
|
||||
try { if (globalThis.appStore.GetAppOverviewByAppID(id)) break; } catch (e) {}
|
||||
await new Promise(r => setTimeout(r, 250));
|
||||
|
||||
@@ -88,7 +88,7 @@ class ProtonMenuAutoTest {
|
||||
fail("Proton work did not finish")
|
||||
}
|
||||
|
||||
@Test fun aCachedCheckUpdatesOnlyInstalledFamiliesAndKeepsOlderBuildsAndSelections() {
|
||||
@Test fun aCachedCheckUpdatesOnlyInstalledFamiliesAndReplacesOlderDroidDeckProton() {
|
||||
val older = install("DroidDeck-Proton-11-11.1")
|
||||
val request = File(root, "root/.local/share/droiddeck-compat/request.json").apply {
|
||||
parentFile!!.mkdirs()
|
||||
@@ -97,8 +97,8 @@ class ProtonMenuAutoTest {
|
||||
val before = request.readText()
|
||||
assertFalse(ProtonExtras.checkLatest(activity))
|
||||
menu.checkUpdates()
|
||||
waitUntil { menu.protonRows.singleOrNull { it.id == "droiddeck" }?.installed == "DroidDeck-Proton-11-12" && menu.protonBusyId == null }
|
||||
assertTrue(older.isDirectory)
|
||||
waitUntil { menu.protonRows.singleOrNull { it.id == "droiddeck" }?.installed == "DroidDeck-Proton-11-12" && menu.protonBusyId == null && !older.exists() }
|
||||
assertEquals(listOf("DroidDeck-Proton-11-12"), ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == "droiddeck" }))
|
||||
assertEquals(before, request.readText())
|
||||
assertTrue(ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == "ge" }).isEmpty())
|
||||
assertTrue(ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == "cachyos" }).isEmpty())
|
||||
@@ -128,7 +128,7 @@ class ProtonMenuAutoTest {
|
||||
|
||||
@Test fun aFailedUpdateDoesNotLoopOrBlockOtherInstalledFamilies() {
|
||||
val ge = install("GE-Proton11-11")
|
||||
val dd = install("DroidDeck-Proton-11-11.1")
|
||||
install("DroidDeck-Proton-11-11.1")
|
||||
menu.installer = { tool, _ ->
|
||||
attempts.add(tool.id)
|
||||
if (tool.id == "ge") throw IllegalStateException("download failed")
|
||||
@@ -138,10 +138,10 @@ class ProtonMenuAutoTest {
|
||||
menu.ensureAutoUpdates()
|
||||
waitUntil { menu.protonBusyId == null }
|
||||
menu.ensureAutoUpdates()
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
waitUntil { menu.protonBusyId == null }
|
||||
assertEquals(listOf("ge", "droiddeck"), attempts)
|
||||
assertTrue(ge.isDirectory)
|
||||
assertTrue(dd.isDirectory)
|
||||
assertEquals(listOf("DroidDeck-Proton-11-12"), ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == "droiddeck" }))
|
||||
assertNull(menu.protonStage)
|
||||
assertEquals(-1, menu.protonPercent)
|
||||
}
|
||||
@@ -184,6 +184,31 @@ class ProtonMenuAutoTest {
|
||||
assertEquals("DroidDeck-Proton-11-12", ProtonExtras.installed(activity, ProtonExtras.tools.first { it.id == "droiddeck" }))
|
||||
}
|
||||
|
||||
@Test fun droidDeckProtonIsInstalledWhenMissingUnlessTheUserRemovedIt() {
|
||||
menu.installer = { tool, _ -> attempts.add(tool.id); install("${tool.prefix}-11-12"); null }
|
||||
ProtonExtras.setDeclined(activity, true)
|
||||
menu.ensureAutoUpdates()
|
||||
assertNull(menu.protonBusyId)
|
||||
assertTrue(attempts.isEmpty())
|
||||
ProtonExtras.setDeclined(activity, false)
|
||||
menu.ensureAutoUpdates()
|
||||
waitUntil { menu.protonBusyId == null }
|
||||
assertEquals(listOf("droiddeck"), attempts)
|
||||
assertEquals("DroidDeck-Proton-11-12", ProtonExtras.installed(activity, ProtonExtras.tools.first { it.id == "droiddeck" }))
|
||||
assertTrue(ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == "ge" }).isEmpty())
|
||||
menu.removeProton("droiddeck")
|
||||
waitUntil { menu.protonBusyId == null }
|
||||
assertTrue(ProtonExtras.declined(activity))
|
||||
menu.installer = { _, _ -> "failed" }
|
||||
menu.installProton("droiddeck")
|
||||
waitUntil { menu.protonBusyId == null }
|
||||
assertTrue(ProtonExtras.declined(activity))
|
||||
menu.installer = { tool, _ -> install("${tool.prefix}-11-12"); null }
|
||||
menu.installProton("droiddeck")
|
||||
waitUntil { menu.protonBusyId == null }
|
||||
assertFalse(ProtonExtras.declined(activity))
|
||||
}
|
||||
|
||||
@Test fun aPendingAnimatedLaunchPreventsAnAutomaticInstall() {
|
||||
install("DroidDeck-Proton-11-11.1")
|
||||
val launcher = Robolectric.buildActivity(FrontEndActivity::class.java).get()
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class ComponentsCarryOverTest {
|
||||
@Test
|
||||
fun swappedPackagesFollowTheBuildThatReplacesTheirProton() {
|
||||
val state = JSONObject("""
|
||||
{"active": {"DroidDeck-Proton_11-11.2": {
|
||||
"dxvk": {"file": "dxvk-2.7.wcp", "label": "2.7", "protonVersion": "11-11.2"},
|
||||
"vkd3d": {"file": "original 11-11.1", "label": "Original from 11-11.1"},
|
||||
"fex": {"file": "gone.wcp", "label": "old"}}},
|
||||
"queued": {"DroidDeck-Proton_11-11.2": {
|
||||
"vkd3d": {"kind": "package", "file": "vkd3d-3.0.wcp", "label": "3.0"},
|
||||
"fex": {"kind": "original", "protonVersion": "11-11.1", "label": "Original 11-11.1"}}}}
|
||||
""".trimIndent())
|
||||
val carried = ComponentsManager.carried(state, "DroidDeck-Proton_11-11.2") { it != "gone.wcp" }
|
||||
assertEquals(setOf("dxvk", "vkd3d"), carried.keys)
|
||||
assertEquals("package", carried.getValue("dxvk").getString("kind"))
|
||||
assertEquals("dxvk-2.7.wcp", carried.getValue("dxvk").getString("file"))
|
||||
assertEquals("2.7", carried.getValue("dxvk").getString("label"))
|
||||
assertEquals("vkd3d-3.0.wcp", carried.getValue("vkd3d").getString("file"))
|
||||
assertEquals(emptyMap<String, JSONObject>(), ComponentsManager.carried(state, "GE-Proton11-7") { true })
|
||||
}
|
||||
}
|
||||
@@ -103,4 +103,28 @@ class ProtonDefaultTest {
|
||||
assertNull(ProtonDefault.gameSelectedId(context, "42", listOf(proton("GE-Proton11-7", false))))
|
||||
assertEquals(ProtonDefault.GameChoice(false, "GE-Proton9-1"), ProtonDefault.parseGames(file.readText())["42"])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aReplacedBuildsPerGamePicksMoveToTheNewest() {
|
||||
val old = ProtonDefault.GameChoice(false, "DroidDeck-Proton 11-11.2")
|
||||
val ge = ProtonDefault.GameChoice(false, "GE-Proton11-7")
|
||||
val valve = ProtonDefault.GameChoice(true, "DroidDeck-Proton 11-11.2")
|
||||
val moved = ProtonDefault.movedGames(mapOf("42" to old, "43" to ge, "44" to null, "45" to valve), setOf("DroidDeck-Proton 11-11.2"), "DroidDeck-Proton 11-11.4")
|
||||
assertEquals(mapOf("42" to ProtonDefault.GameChoice(false, "DroidDeck-Proton 11-11.4"), "43" to ge, "44" to null, "45" to valve), moved)
|
||||
assertNull(ProtonDefault.movedGames(mapOf("43" to ge, "44" to null), setOf("DroidDeck-Proton 11-11.2"), "DroidDeck-Proton 11-11.4"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun movingPicksRewritesTheGamesFile() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val file = File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-compat/games.json")
|
||||
file.parentFile?.deleteRecursively()
|
||||
ProtonDefault.requestGame(context, "42", proton("DroidDeck-Proton 11-11.2", false))
|
||||
ProtonDefault.requestGame(context, "43", null)
|
||||
ProtonDefault.moveGames(context, setOf("DroidDeck-Proton 11-11.2"), "DroidDeck-Proton 11-11.4")
|
||||
val games = ProtonDefault.parseGames(file.readText())
|
||||
assertEquals(ProtonDefault.GameChoice(false, "DroidDeck-Proton 11-11.4"), games["42"])
|
||||
assertTrue(games.containsKey("43"))
|
||||
assertNull(games["43"])
|
||||
}
|
||||
}
|
||||
@@ -198,4 +198,35 @@ class ProtonExtrasTest {
|
||||
ComponentsManager.forgetProton(context, kept.name)
|
||||
assertTrue(File(originals, "GE-Proton11-8/GE-Proton11-8/dxvk.wcp").isFile)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anUpdateKeepsTheUsersProtonSettingsFile() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val tools = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/compatibilitytools.d")
|
||||
tools.deleteRecursively()
|
||||
File(installTool(tools, "DroidDeck-Proton 11-11.1"), "user_settings.py").writeText("old")
|
||||
File(installTool(tools, "DroidDeck-Proton 11-11.4"), "user_settings.py").writeText("mine")
|
||||
installTool(tools, "DroidDeck-Proton 11-11.5")
|
||||
ProtonExtras.tidy(context)
|
||||
assertEquals(listOf("DroidDeck-Proton 11-11.5"), ProtonExtras.installedAll(context, tool("droiddeck")))
|
||||
assertEquals("mine", File(tools, "DroidDeck-Proton 11-11.5/user_settings.py").readText())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun droidDeckProtonIsFetchedWhenMissingUnlessTheUserRemovedIt() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val tools = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/compatibilitytools.d")
|
||||
tools.deleteRecursively()
|
||||
File(context.filesDir, "proton-latest.json").writeText(
|
||||
"""{"droiddeck":{"tag":"DroidDeck-Proton-11-11.4","at":1},"ge":{"tag":"GE-Proton11-7","at":1}}""")
|
||||
ProtonExtras.setDeclined(context, false)
|
||||
assertEquals("DroidDeck-Proton-11-11.4", ProtonExtras.missing(context, tool("droiddeck")))
|
||||
assertNull(ProtonExtras.missing(context, tool("ge")))
|
||||
ProtonExtras.setDeclined(context, true)
|
||||
assertNull(ProtonExtras.missing(context, tool("droiddeck")))
|
||||
ProtonExtras.setDeclined(context, false)
|
||||
installTool(tools, "DroidDeck-Proton 11-11.2")
|
||||
assertNull(ProtonExtras.missing(context, tool("droiddeck")))
|
||||
assertEquals("DroidDeck-Proton-11-11.4", ProtonExtras.update(context, tool("droiddeck")))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user