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.withContext
import java.io.File
import java.io.IOException
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
@@ -367,10 +368,10 @@ internal fun AddonBrowserDialog(targets: List<WowAddons.Target>, initial: WowAdd
scope.launch {
val done = withContext(Dispatchers.IO) {
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()
} else addon.folders
folders.forEach { name -> WowAddons.folder(into.addOns, name)?.let { deleteAddon(context, into, it.name, link) } }
}) else addon.folders
deleteAddons(context, into, folders, link)
}
}
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
}
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()) {
val managed = link?.let { runCatching { it.uninstall(context, target, folder) }.getOrDefault(false) } == true
val left = WowAddons.folder(target.addOns, folder)