mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(addons): show installed addons as installed while the manager rescans (#3057)
* fix(addons): show installed addons as installed while the manager rescans Opening the download dialog starts a fresh scan of the addon manager's installed projects, and every row showed Install until it answered (about 20 s). Rows now start from the manager's last report, kept only for projects whose folders are all still on disk, and its new report takes over, Update state included. * fix(addons): match installed addons by their toc project id before the first report Before the addon manager has reported at all, a search row whose project id matches an installed addon's X-Curse-Project-ID shows as installed. Placeholder ids are ignored and the manager's report always takes over. * fix(addons): read toc fields from flavour tocs and keep known state when a scan fails An addon whose main toc is a stub keeps its version and project id in the flavour tocs, so missing fields are now filled from the next toc in order. A failed manager scan now falls back to the last known installed state instead of clearing it.
This commit is contained in:
1 parent
43b17483fb
commit
c78adda7ca
5 files changed
+148
-14
No files matched your search
@@ -231,10 +231,11 @@ class WowAddonsTest {
|
||||
val lines = sequence {
|
||||
yield("## Version: 2.0")
|
||||
yield("## X-WoWI-ID: 5")
|
||||
yield("## X-Curse-Project-ID: 9")
|
||||
repeat(100_000) { read++; yield("## X-Data-$it: payload") }
|
||||
}
|
||||
val fields = WowAddons.tocFields(lines)
|
||||
assertEquals(mapOf("Version" to "2.0", "X-WoWI-ID" to "5"), fields)
|
||||
assertEquals(mapOf("Version" to "2.0", "X-WoWI-ID" to "5", "X-Curse-Project-ID" to "9"), fields)
|
||||
assertEquals(0, read)
|
||||
}
|
||||
|
||||
@@ -254,15 +255,39 @@ class WowAddonsTest {
|
||||
@Test fun detailsUseTheTocAndTheRecordedSource() {
|
||||
val target = target()
|
||||
val foo = File(target.addOns, "Foo").apply { mkdirs() }
|
||||
File(foo, "Foo_Mainline.toc").writeText("## Version: 1.0\n## X-WoWI-ID: 77\n")
|
||||
File(foo, "Foo_Mainline.toc").writeText("## Version: 1.0\n## X-WoWI-ID: 77\n## X-Curse-Project-ID: 334372\n")
|
||||
File(target.addOns, "Bar").mkdirs()
|
||||
val details = WowAddons.details(target).associateBy { it.name }
|
||||
assertEquals(setOf("Bar", "Foo"), details.keys)
|
||||
assertEquals("1.0", details.getValue("Foo").version)
|
||||
assertEquals("77", details.getValue("Foo").wowiId)
|
||||
assertEquals("334372", details.getValue("Foo").curseId)
|
||||
assertEquals(null, details.getValue("Bar").curseId)
|
||||
assertEquals(null, details.getValue("Bar").version)
|
||||
}
|
||||
|
||||
@Test fun detailsFillFieldsTheMainTocLacksFromTheFlavourTocs() {
|
||||
val target = target()
|
||||
val questie = File(target.addOns, "Questie").apply { mkdirs() }
|
||||
File(questie, "Questie.toc").writeText("## Interface: 00000\n## Title: Questie\n")
|
||||
File(questie, "Questie_Vanilla.toc").writeText("## Version: 12.6.4\n## X-Curse-Project-ID: 334372\n")
|
||||
File(questie, "Questie_Wrath.toc").writeText("## Version: 12.6.4\n")
|
||||
val questieDetails = WowAddons.details(target).single()
|
||||
assertEquals("12.6.4", questieDetails.version)
|
||||
assertEquals("334372", questieDetails.curseId)
|
||||
}
|
||||
|
||||
@Test fun detailsKeepTheMainTocWhenItHasTheFields() {
|
||||
val target = target()
|
||||
val foo = File(target.addOns, "Foo").apply { mkdirs() }
|
||||
File(foo, "Foo.toc").writeText("## Version: 2.0\n## X-Curse-Project-ID: 5\n")
|
||||
File(foo, "Foo_Classic.toc").writeText("## Version: 1.0\n## X-Curse-Project-ID: 6\n## X-WoWI-ID: 7\n")
|
||||
val fooDetails = WowAddons.details(target).single()
|
||||
assertEquals("2.0", fooDetails.version)
|
||||
assertEquals("5", fooDetails.curseId)
|
||||
assertEquals("7", fooDetails.wowiId)
|
||||
}
|
||||
|
||||
@Test fun importRecordsTheSourceAndPlainImportsClearIt() {
|
||||
val target = target()
|
||||
WowAddons.import(zip("Foo/Foo.toc" to "## Version: 1.0\n"), target, WowAddons.Origin("55", "2.0"))
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.runtime.CurseForgeApp
|
||||
import com.droiddeck.launcher.runtime.WowAddons
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
class CurseLinkReportTest {
|
||||
@get:Rule val temp = TemporaryFolder()
|
||||
|
||||
private fun target(vararg folders: String): WowAddons.Target {
|
||||
val addOns = temp.newFolder("AddOns")
|
||||
folders.forEach { java.io.File(addOns, it).mkdirs() }
|
||||
return WowAddons.Target("_retail_", addOns)
|
||||
}
|
||||
|
||||
private fun project(id: String, vararg folders: String, update: Boolean = false) = CurseForgeApp.Project(id, "m$id", folders.toList(), update)
|
||||
|
||||
@Test fun beforeAnyReportNothingIsKnown() {
|
||||
assertEquals(emptyMap<String, String?>(), CurseLink.lastReported(target("Questie")))
|
||||
}
|
||||
|
||||
@Test fun beforeCurseForgeReportsAddonsWhoseFoldersAreAllOnDiskShowAsInstalled() {
|
||||
val target = target("questie", "QuestieDB", "Auctionator")
|
||||
CurseLink.report(target, listOf(
|
||||
project("334372", "Questie", "QuestieDB", update = true),
|
||||
project("1", "Auctionator"),
|
||||
project("2", "Details", "Details_Streamer"),
|
||||
project("3", "Auctionator", "Auctionator_Extra"),
|
||||
))
|
||||
assertEquals(mapOf<String, String?>("334372" to null, "1" to null), CurseLink.lastReported(target))
|
||||
}
|
||||
|
||||
@Test fun anAddonRemovedFromDiskSinceTheLastReportIsNotInstalled() {
|
||||
val target = target("Questie")
|
||||
CurseLink.report(target, listOf(project("334372", "Questie")))
|
||||
java.io.File(target.addOns, "Questie").delete()
|
||||
assertEquals(emptyMap<String, String?>(), CurseLink.lastReported(target))
|
||||
}
|
||||
|
||||
private fun toc(target: WowAddons.Target, folder: String, curseId: String) {
|
||||
val dir = java.io.File(target.addOns, folder).apply { mkdirs() }
|
||||
java.io.File(dir, "$folder.toc").writeText("## Interface: 110207\n## Title: $folder\n## X-Curse-Project-ID: $curseId\n$folder.lua\n")
|
||||
}
|
||||
|
||||
@Test fun beforeAnyReportAnAddonWhoseTocNamesTheProjectShowsAsInstalled() {
|
||||
val target = target()
|
||||
toc(target, "Questie", "334372")
|
||||
toc(target, "Auctionator", "@project-id@")
|
||||
assertEquals(mapOf<String, String?>("334372" to null), CurseLink.lastReported(target))
|
||||
}
|
||||
|
||||
@Test fun aPlaceholderProjectIdIsIgnored() {
|
||||
val target = target()
|
||||
toc(target, "Auctionator", "@project-id@")
|
||||
assertEquals(emptyMap<String, String?>(), CurseLink.lastReported(target))
|
||||
}
|
||||
|
||||
@Test fun curseForgesReportOverridesTheTocProjectId() {
|
||||
val target = target()
|
||||
toc(target, "Questie", "334372")
|
||||
toc(target, "Auctionator", "1")
|
||||
CurseLink.report(target, listOf(project("1", "Auctionator", update = true)))
|
||||
assertEquals(mapOf<String, String?>("1" to null), CurseLink.lastReported(target))
|
||||
}
|
||||
}
|
||||
@@ -128,6 +128,20 @@ class CurseLinkTabTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFailedScanKeepsTheLastReportInsteadOfClearingIt() {
|
||||
val target = wow()
|
||||
val link = CurseLink(app)
|
||||
try {
|
||||
val reported = link.marks(context, target, 0)
|
||||
assertTrue(reported.isNotEmpty())
|
||||
runBlocking { link.close(context).join() }
|
||||
assertEquals(reported.mapValues { null }, link.marks(context, target, 1))
|
||||
} finally {
|
||||
runBlocking { link.close(context).join() }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun noCurseForgeStartsWhileASessionRuns() {
|
||||
wow()
|
||||
|
||||
Reference in new issue
Block a user