fix(addons): uninstall addons the manager has not listed yet (#3060)

A row shown as installed by its toc project id before the manager's first
report had nothing to delete when the manager did not list the project, and
the dialog reported success. The dialog now falls back to the folders whose
toc names the project, deletes them through the existing addon delete, and
shows the delete error when no folder matches.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-23 06:47:25 -05:00
1 parent c78adda7ca
commit 6400a9ef09
2 files changed
+59 -3

No files matched your search

@@ -80,6 +80,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.io.File import java.io.File
import java.io.IOException
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference import java.util.concurrent.atomic.AtomicReference
@@ -367,10 +368,10 @@ internal fun AddonBrowserDialog(targets: List<WowAddons.Target>, initial: WowAdd
scope.launch { scope.launch {
val done = withContext(Dispatchers.IO) { val done = withContext(Dispatchers.IO) {
runCatching { runCatching {
val folders = if (via != null) via.call(context, into) { linked -> val folders = if (via != null) curseFolders(into, addon.id, via.call(context, into) { linked ->
CurseForgeApp.projects(context, linked.inspector, linked.guid).firstOrNull { it.id == addon.id }?.folders.orEmpty() CurseForgeApp.projects(context, linked.inspector, linked.guid).firstOrNull { it.id == addon.id }?.folders.orEmpty()
} else addon.folders }) else addon.folders
folders.forEach { name -> WowAddons.folder(into.addOns, name)?.let { deleteAddon(context, into, it.name, link) } } deleteAddons(context, into, folders, link)
} }
} }
installing.remove(key) installing.remove(key)
@@ -589,6 +590,15 @@ internal fun diskStatus(folders: List<String>, onDisk: Map<String, WowAddons.Ins
return if (WowAddonCatalog.offersUpdate(have.version, latest, sameSource = have.wowiId == id)) AddonStatus.UPDATE else AddonStatus.INSTALLED return if (WowAddonCatalog.offersUpdate(have.version, latest, sameSource = have.wowiId == id)) AddonStatus.UPDATE else AddonStatus.INSTALLED
} }
internal fun curseFolders(target: WowAddons.Target, id: String, listed: List<String>): List<String> =
listed.ifEmpty { WowAddons.details(target).filter { it.curseId == id }.map { it.name } }
internal fun deleteAddons(context: Context, target: WowAddons.Target, folders: List<String>, link: CurseLink?) {
val found = folders.mapNotNull { WowAddons.folder(target.addOns, it) }
if (found.isEmpty()) throw IOException("No addon folder to delete")
found.forEach { deleteAddon(context, target, it.name, link) }
}
internal fun deleteAddon(context: Context, target: WowAddons.Target, folder: String, link: CurseLink? = CurseLink.live()) { internal fun deleteAddon(context: Context, target: WowAddons.Target, folder: String, link: CurseLink? = CurseLink.live()) {
val managed = link?.let { runCatching { it.uninstall(context, target, folder) }.getOrDefault(false) } == true val managed = link?.let { runCatching { it.uninstall(context, target, folder) }.getOrDefault(false) } == true
val left = WowAddons.folder(target.addOns, folder) val left = WowAddons.folder(target.addOns, folder)
@@ -19,7 +19,9 @@ import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import org.junit.After import org.junit.After
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull import org.junit.Assert.assertNull
import org.junit.Assert.assertThrows
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
@@ -29,6 +31,9 @@ import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config import org.robolectric.annotation.Config
import java.io.File import java.io.File
import java.io.IOException
import java.nio.file.Files
import java.nio.file.LinkOption
import java.util.Collections import java.util.Collections
@RunWith(RobolectricTestRunner::class) @RunWith(RobolectricTestRunner::class)
@@ -142,6 +147,47 @@ class CurseLinkTabTest {
} }
} }
private fun tocFolder(addOns: File, name: String, curseId: String) =
File(addOns, name).apply { mkdirs(); File(this, "$name.toc").writeText("## X-Curse-Project-ID: $curseId\n") }
@Test
fun anAddonTheManagerDoesNotListIsFoundByItsTocProjectId() {
val target = WowAddons.Target("_retail_", temp.newFolder("AddOns"))
tocFolder(target.addOns, "Questie", "334372")
tocFolder(target.addOns, "Other", "1")
assertEquals(listOf("Questie"), curseFolders(target, "334372", emptyList()))
assertEquals(listOf("Listed"), curseFolders(target, "334372", listOf("Listed")))
}
@Test
fun uninstallingByTocProjectIdDeletesOnlyTheMatchedFolders() {
val target = WowAddons.Target("_retail_", temp.newFolder("AddOns"))
tocFolder(target.addOns, "Questie", "334372")
tocFolder(target.addOns, "Other", "1")
deleteAddons(context, target, curseFolders(target, "334372", emptyList()), null)
assertEquals(listOf("Other"), WowAddons.installed(target))
}
@Test
fun uninstallingALinkedAddonLeavesTheLinkTargetAlone() {
val target = WowAddons.Target("_retail_", temp.newFolder("AddOns"))
val outside = tocFolder(temp.newFolder("outside"), "Questie", "334372")
File(outside, "keep.lua").writeText("keep")
Files.createSymbolicLink(File(target.addOns, "Questie").toPath(), outside.toPath())
deleteAddons(context, target, curseFolders(target, "334372", emptyList()), null)
assertFalse(Files.exists(File(target.addOns, "Questie").toPath(), LinkOption.NOFOLLOW_LINKS))
assertEquals("keep", File(outside, "keep.lua").readText())
assertTrue(File(outside, "Questie.toc").isFile)
}
@Test
fun uninstallingWithNothingToDeleteFails() {
val target = WowAddons.Target("_retail_", temp.newFolder("AddOns"))
tocFolder(target.addOns, "Other", "1")
assertThrows(IOException::class.java) { deleteAddons(context, target, curseFolders(target, "334372", emptyList()), null) }
assertEquals(listOf("Other"), WowAddons.installed(target))
}
@Test @Test
fun noCurseForgeStartsWhileASessionRuns() { fun noCurseForgeStartsWhileASessionRuns() {
wow() wow()