mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
fix: removing a Proton also deletes its stored component originals
This commit is contained in:
1 parent
0b671b2144
commit
ad6d8d824a
3 files changed
+43
-1
No files matched your search
@@ -780,6 +780,17 @@ object ComponentsManager {
|
||||
true
|
||||
}
|
||||
|
||||
fun forgetProton(context: Context, dirName: String) {
|
||||
synchronized(lock) {
|
||||
val id = safeName(dirName)
|
||||
if (protons(context).any { it.id == id }) return
|
||||
val state = loadState(context)
|
||||
val selected = listOf("active", "queued").map { state.sub(it).remove(id) != null }.any { it }
|
||||
if (selected && runCatching { saveState(context, state) }.onFailure { Log.w(TAG, "forget $id", it) }.isFailure) return
|
||||
File(originalsDir(context), id).deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
fun deletePackage(context: Context, file: String): String = synchronized(lock) {
|
||||
val name = safeName(file)
|
||||
val state = loadState(context)
|
||||
|
||||
@@ -137,10 +137,14 @@ object ProtonExtras {
|
||||
fun remove(context: Context, tool: Tool, dir: String? = null) {
|
||||
val name = if (dir != null) dir.takeIf { it in installedAll(context, tool) } ?: return else installed(context, tool) ?: return
|
||||
File(toolsDir(context), name).deleteRecursively()
|
||||
ComponentsManager.forgetProton(context, name)
|
||||
}
|
||||
|
||||
fun removeOlder(context: Context, tool: Tool) {
|
||||
installedAll(context, tool).dropLast(1).forEach { File(toolsDir(context), it).deleteRecursively() }
|
||||
installedAll(context, tool).dropLast(1).forEach {
|
||||
File(toolsDir(context), it).deleteRecursively()
|
||||
ComponentsManager.forgetProton(context, it)
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
|
||||
@@ -171,4 +171,31 @@ class ProtonExtrasTest {
|
||||
assertEquals(listOf("DroidDeck-Proton 11-7.10"), ProtonExtras.installedAll(context, tool("droiddeck")))
|
||||
assertEquals("DroidDeck-Proton 11-7.10", ProtonExtras.installed(context, tool("droiddeck")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun removingABuildDropsItsStoredOriginalsAndSelections() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val tools = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/compatibilitytools.d")
|
||||
File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-components").mkdirs()
|
||||
installTool(tools, "GE-Proton11-7")
|
||||
val kept = installTool(tools, "GE-Proton11-8").apply {
|
||||
File(this, "files/lib/wine").mkdirs()
|
||||
File(this, "proton").writeText("")
|
||||
}
|
||||
val originals = File(context.filesDir, "components/originals")
|
||||
for (id in listOf("GE-Proton11-7", "GE-Proton11-8")) File(originals, "$id/$id/dxvk.wcp").apply { parentFile?.mkdirs(); writeText("x") }
|
||||
val pick = JSONObject().put("dxvk", JSONObject().put("file", "dxvk.wcp").put("protonVersion", "GE-Proton11-7"))
|
||||
File(context.filesDir, "components/state.json").writeText(JSONObject()
|
||||
.put("active", JSONObject().put("GE-Proton11-7", pick).put("GE-Proton11-8", pick))
|
||||
.put("queued", JSONObject().put("GE-Proton11-7", pick)).toString())
|
||||
ProtonExtras.remove(context, tool("ge"), "GE-Proton11-7")
|
||||
assertFalse(File(originals, "GE-Proton11-7").exists())
|
||||
assertTrue(File(originals, "GE-Proton11-8/GE-Proton11-8/dxvk.wcp").isFile)
|
||||
val state = JSONObject(File(context.filesDir, "components/state.json").readText())
|
||||
assertFalse(state.getJSONObject("active").has("GE-Proton11-7"))
|
||||
assertFalse(state.getJSONObject("queued").has("GE-Proton11-7"))
|
||||
assertTrue(state.getJSONObject("active").has("GE-Proton11-8"))
|
||||
ComponentsManager.forgetProton(context, kept.name)
|
||||
assertTrue(File(originals, "GE-Proton11-8/GE-Proton11-8/dxvk.wcp").isFile)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user