Skip to content

Commit

Permalink
Use new files value of PacmcFile
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobkmar committed Jul 13, 2021
1 parent 4d7d5b3 commit 0a7e0ab
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/main/kotlin/net/axay/pacmc/commands/Update.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ import net.axay.pacmc.commands.Install.findBestFile
import net.axay.pacmc.requests.CurseProxy
import net.axay.pacmc.requests.data.CurseProxyFile
import net.axay.pacmc.storage.data.DbMod
import net.axay.pacmc.storage.data.PacmcFile
import net.axay.pacmc.storage.db
import net.axay.pacmc.storage.execAsyncBatch
import net.axay.pacmc.storage.getArchiveMods
import net.axay.pacmc.storage.getArchiveOrWarn
import net.axay.pacmc.terminal
import org.kodein.db.delete
import java.io.File
import java.util.*
import java.util.concurrent.atomic.AtomicInteger

Expand Down Expand Up @@ -50,11 +48,6 @@ object Update : CliktCommand(
val dependencies = allMods.filter { !it.persistent }
val dependencyIds = dependencies.map { it.modId }

val archiveFolder = File(archive.path)
val archiveFiles = (archiveFolder.listFiles() ?: emptyArray())
.filter { it.name.startsWith("pacmc_") }
.map { it to PacmcFile(it.name) }

val updateMods = Collections.synchronizedList(ArrayList<Pair<DbMod, CurseProxyFile>>())
val freshDependencies = Collections.synchronizedList(ArrayList<Install.ResolvedDependency>())

Expand Down Expand Up @@ -82,6 +75,8 @@ object Update : CliktCommand(
// figure out which installed dependencies aren't needed anymore
val removableDependencies = dependencyIds.filter { depId -> !freshDependencies.any { it.addonId == depId } }

val archiveFiles = archive.files

// now remove all dependencies which don't have any update
freshDependencies.removeIf { dep ->
archiveFiles.any { it.second.modId == dep.addonId && it.second.versionId == dep.file.id.toString() }
Expand All @@ -96,6 +91,7 @@ object Update : CliktCommand(
// delete files which will be updated or aren't needed anymore
if (
it.second.modId in removableDependencies ||
// may be removed later as old files get removed by the downloadFile function anyways
freshDependencies.any { dep -> dep.addonId == it.second.modId } ||
updateMods.any { newMod -> newMod.first.modId == it.second.modId }
) it.first.delete()
Expand Down

0 comments on commit 0a7e0ab

Please sign in to comment.