feat(addons): install the CurseForge app and update addons per game (#2986)

* feat(addons): install the CurseForge app and update addons per game

The Addons tab installs the official CurseForge Linux app from its own
update feed, checks it against the feed's SHA-512, shows its version,
offers updates and removes it with the components delete button.

Installed addons show their .toc version and are checked against
WoWInterface by X-WoWI-ID or the recorded source of addons installed
from the Download window; Update replaces them in place.

The CurseForge web search chip is replaced by the app.

* fix(addons): address review on update ordering, flavor filter, origins lock and failed checks

* fix(addons): compact scrollable addon browser with list rows

* fix(addons): compare release times as instants and replace the sources file atomically

* fix(addons): open the addon browser at the top of the list

* Keep the addon browser's search focus and installed version in sync

* Track the search field's own focus in the addon browser

* Key the installed addon version by install target

* Install rar and 7z addon archives
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-21 23:47:58 -05:00
1 parent 3577073ab9
commit d6496b2f96
16 files changed
+765 -153

No files matched your search

@@ -0,0 +1,67 @@
package com.droiddeck.launcher.runtime
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
class UserAppsFeedTest {
private val feed = "https://example.com/apps/linux/latest-linux.yml"
private val sha = "ajcSve2Wq1CgocS5zWlmdfb0pI0C+JqNvbFx6Vm9j9/fW1Q/u2dnnNvNGmi0gulEXp7tnRkYCCc7rfwtjKcoNw=="
private fun body(path: String = "App-1.2.0-7.AppImage", hash: String = sha) = """
version: 1.2.0-7
files:
- url: App-1.2.0-7.AppImage
sha512: $hash
size: 100
- url: App_1.2.0-7_amd64.deb
sha512: other
path: $path
sha512: $hash
releaseDate: '2026-11-15T18:08:09.118Z'
""".trimIndent()
@Test fun feedGivesTheAppImageRelease() {
val release = UserApps.parseFeed(feed, body())!!
assertEquals("1.2.0-7", release.tag)
assertEquals("App-1.2.0-7.AppImage", release.asset)
assertEquals("https://example.com/apps/linux/App-1.2.0-7.AppImage", release.url)
assertEquals("2026-11-15T18:08:09.118Z", release.published)
assertEquals(128, release.sha512!!.length)
assertEquals("6a3712bded96ab50a0a1c4b9cd696675f6f4a48d02f89a8dbdb171e959bd8fdfdf5b543fbb67679cdbcd1a68b482e9445e9eed9d191808273badfc2d8ca72837", release.sha512)
assertNull(release.sha256)
}
@Test fun feedWithoutAnAppImageOrHashIsRefused() {
assertNull(UserApps.parseFeed(feed, body(path = "App_1.2.0-7_amd64.deb")))
assertNull(UserApps.parseFeed(feed, body(path = "../App.AppImage")))
assertNull(UserApps.parseFeed(feed, body(path = "sub/App.AppImage")))
assertNull(UserApps.parseFeed(feed, body(hash = "c2hvcnQ=")))
assertNull(UserApps.parseFeed("http://example.com/latest-linux.yml", body()))
assertNull(UserApps.parseFeed(feed, "path: App.AppImage\n"))
}
@Test fun curseForgeIsFoundByItsFeed() {
val other = UserApps.App("appimage:a", UserApps.Kind.APPIMAGE, "CurseForge", null, null, AppImageManager.LAUNCHER, emptyList())
val official = UserApps.App("appimage:b", UserApps.Kind.APPIMAGE, "Mods", null, null, AppImageManager.LAUNCHER, emptyList(), feed = CurseForgeApp.FEED)
assertEquals("appimage:b", CurseForgeApp.find(listOf(other, official))?.key)
assertNull(CurseForgeApp.find(listOf(other)))
}
@Test fun olderOrEqualFeedReleasesAreNotOffered() {
val release = UserApps.parseFeed(feed, body())!!
assertTrue(UserApps.isNewer(release, "2026-11-01T00:00:00.000Z", "1.0"))
assertFalse(UserApps.isNewer(release, "2099-01-01T00:00:00.000Z", "9.9"))
assertFalse(UserApps.isNewer(release, "", release.tag))
assertTrue(UserApps.isNewer(release, "", "0.1"))
}
@Test fun publicationTimesCompareAsInstantsWhateverTheirPrecision() {
val release = UserApps.parseFeed(feed, body())!!
assertTrue(UserApps.isNewer(release, "2026-11-15T18:08:09Z", "1.0"))
assertFalse(UserApps.isNewer(release, "2026-11-15T18:08:09.118000Z", "1.0"))
assertFalse(UserApps.isNewer(release, "2026-11-15T18:08:10Z", "1.0"))
}
}
@@ -150,8 +150,8 @@ us|1|aa|bb|cc||tpr/wow|h|s|t||1|12.1.0.65000|kk|wowf
@Test fun wowiDetailsGiveUrlAndMd5() {
val d = WowAddonCatalog.parseWowiDetails("""[{"UID":"1","UIMD5":"abc","UIDownload":"https://cdn.wowinterface.com/downloads/getfile.php?id=1"}]""")
assertEquals("https://cdn.wowinterface.com/downloads/getfile.php?id=1", d?.first)
assertEquals("abc", d?.second)
assertEquals("https://cdn.wowinterface.com/downloads/getfile.php?id=1", d?.url)
assertEquals("abc", d?.md5)
assertNull(WowAddonCatalog.parseWowiDetails("""[{"UID":"1","UIDownload":""}]"""))
assertNull(WowAddonCatalog.parseWowiDetails("[]"))
}
@@ -162,9 +162,40 @@ us|1|aa|bb|cc||tpr/wow|h|s|t||1|12.1.0.65000|kk|wowf
assertTrue(WowAddonCatalog.isHttps("https://example.com/a.zip"))
}
@Test fun curseForgeUrlAddsTheSearchText() {
assertEquals("https://www.curseforge.com/wow/search?class=addons", WowAddonCatalog.curseForgeUrl(" "))
assertEquals("https://www.curseforge.com/wow/search?class=addons&search=deadly+boss+%26+mods", WowAddonCatalog.curseForgeUrl(" deadly boss & mods "))
private fun entry(id: String, version: String) =
WowAddonCatalog.Entry(WowAddonCatalog.Addon(id, "Addon $id", "author", version, 0L, 0L, null), "1", null)
@Test fun updatesComeFromTheInstalledSourceVersion() {
val entries = listOf(entry("10", "2.1.0"), entry("20", "v5"), entry("30", ""))
val installed = listOf(
WowAddons.Installed("Old", "2.0.9", "10"),
WowAddons.Installed("OldPart", "2.0.9", "10"),
WowAddons.Installed("Same", "5", "20"),
WowAddons.Installed("NoLatest", "1", "30"),
WowAddons.Installed("Unknown", "1", "99"),
WowAddons.Installed("Local", "1", null),
WowAddons.Installed("NoVersion", null, "10"),
)
val updates = WowAddonCatalog.findUpdates(entries, installed)
assertEquals(setOf("Old"), updates.keys)
assertEquals("2.1.0", updates.getValue("Old").summary)
}
@Test fun aCurrentRowDoesNotHideAnOutdatedRowWithTheSameSource() {
val installed = listOf(WowAddons.Installed("A", "2", "10"), WowAddons.Installed("B", "1", "10"))
assertEquals(setOf("B"), WowAddonCatalog.findUpdates(listOf(entry("10", "2")), installed).keys)
}
@Test fun wowiDetailsCarryTheDownloadedVersion() {
val d = WowAddonCatalog.parseWowiDetails("""[{"UIDownload":"https://cdn.wowinterface.com/a.zip","UIVersion":" 2.0 "}]""")
assertEquals("2.0", d?.version)
assertNull(WowAddonCatalog.parseWowiDetails("""[{"UIDownload":"https://cdn.wowinterface.com/a.zip"}]""")?.version)
}
@Test fun versionsCompareWithoutPrefixOrCase() {
assertTrue(WowAddonCatalog.sameVersion("v1.2.3", "1.2.3"))
assertTrue(WowAddonCatalog.sameVersion(" 1.2-Beta ", "1.2-beta"))
assertFalse(WowAddonCatalog.sameVersion("1.2.3", "1.2.4"))
}
@Test fun md5Check() {
@@ -0,0 +1,78 @@
package com.droiddeck.launcher.runtime
import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import java.io.File
import java.nio.file.Files
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class WowAddonsArchiveTest {
@get:Rule val temp = TemporaryFolder()
private fun target(): WowAddons.Target {
val root = temp.newFolder("World of Warcraft")
File(root, "_retail_").mkdirs()
return WowAddons.targets(BattleNet.title("wow")!!, root).single()
}
private fun sevenZip(vararg files: Pair<String, String>): File {
val file = temp.newFile("addon-${System.nanoTime()}.bin")
SevenZOutputFile(file).use { out ->
for ((name, text) in files) {
val entry = out.createArchiveEntry(File(name), name)
out.putArchiveEntry(entry)
out.write(text.toByteArray())
out.closeArchiveEntry()
}
}
return file
}
private fun unpacked() = File(RuntimeEnvironment.getApplication().cacheDir, "wowaddons").listFiles().orEmpty().filter { it.name.startsWith("unpack-") }
@Test fun sevenZipArchivesImportLikeZips() {
val target = target()
val names = WowAddons.import(sevenZip("Pack/Foo/Foo.toc" to "toc", "Pack/Foo/core.lua" to "lua", "Pack/Bar/Bar.toc" to "toc"), target, context = RuntimeEnvironment.getApplication())
assertEquals(listOf("Bar", "Foo"), names.sorted())
assertEquals("lua", File(target.addOns, "Foo/core.lua").readText())
assertTrue(File(target.addOns, "Bar/Bar.toc").isFile)
assertTrue(unpacked().isEmpty())
}
@Test fun sevenZipArchivesWithoutAnAddonChangeNothing() {
val target = target()
assertEquals(emptyList<String>(), WowAddons.import(sevenZip("readme.txt" to "x"), target, context = RuntimeEnvironment.getApplication()))
assertFalse(target.addOns.exists())
assertTrue(unpacked().isEmpty())
}
@Test fun aFolderWithAnyLinkIsRefusedWhole() {
val target = target()
val folder = temp.newFolder("unpacked")
File(folder, "Foo").mkdirs()
File(folder, "Foo/Foo.toc").writeText("toc")
Files.createSymbolicLink(File(folder, "Foo/link.lua").toPath(), File(folder, "Foo/Foo.toc").toPath())
assertEquals(emptyList<String>(), WowAddons.importFolder(folder, target, null))
assertFalse(target.addOns.exists())
}
@Test fun aFolderImportKeepsEveryFile() {
val target = target()
val folder = temp.newFolder("unpacked")
File(folder, "Foo/Libs").mkdirs()
File(folder, "Foo/Foo.toc").writeText("toc")
File(folder, "Foo/Libs/lib.lua").writeText("lib")
assertEquals(listOf("Foo"), WowAddons.importFolder(folder, target, null))
assertEquals("lib", File(target.addOns, "Foo/Libs/lib.lua").readText())
}
}
@@ -218,4 +218,50 @@ class WowAddonsTest {
File(root, "_retail_").mkdirs()
assertEquals(emptyList<String>(), WowAddons.targets(BattleNet.title("fenris")!!, root).map { it.flavor })
}
@Test fun tocFieldsReadVersionAndSourceIds() {
val fields = WowAddons.tocFields("\uFEFF## Interface: 110002\n## Title: Foo\n## Version: 1.4.2\n## X-WoWI-ID: 1234\n## Version: 9\n## X-Curse-Project-ID: @curse-id@\nFoo.lua\n")
assertEquals("1.4.2", fields["Version"])
assertEquals("1234", fields["X-WoWI-ID"])
assertEquals(null, fields["X-Curse-Project-ID"])
}
@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(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(null, details.getValue("Bar").version)
}
@Test fun importRecordsTheSourceAndPlainImportsClearIt() {
val target = target()
WowAddons.import(zip("Foo/Foo.toc" to "## Version: 1.0\n"), target, WowAddons.Origin("55", "2.0"))
val recorded = WowAddons.details(target).single()
assertEquals("2.0", recorded.version)
assertEquals("55", recorded.wowiId)
WowAddons.import(zip("Foo/Foo.toc" to "## Version: 3.0\n"), target)
val plain = WowAddons.details(target).single()
assertEquals("3.0", plain.version)
assertEquals(null, plain.wowiId)
assertFalse(File(target.addOns, ".droiddeck-sources").exists())
}
@Test fun deleteForgetsTheRecordedSource() {
val target = target()
WowAddons.import(zip("Foo/Foo.toc" to "x", "Bar/Bar.toc" to "y"), target, WowAddons.Origin("55", "2.0"))
WowAddons.delete(target, "Foo")
assertEquals(mapOf("Bar" to "55"), WowAddons.parseOrigins(File(target.addOns, ".droiddeck-sources").readText()).mapValues { it.value.id })
assertEquals(listOf("Bar"), WowAddons.installed(target))
}
@Test fun originsRoundTripAndSkipBrokenLines() {
val text = WowAddons.formatOrigins(mapOf("A" to WowAddons.Origin("1", "1.0 beta\t2")))
assertEquals("1.0 beta 2", WowAddons.parseOrigins(text).getValue("A").version)
assertEquals(emptyMap<String, WowAddons.Origin>(), WowAddons.parseOrigins("bad line\nA\t\t1\n"))
}
}